DeferredDirectionalLight.bsl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "$ENGINE$\DeferredLightCommon.bslinc"
  2. Technique : inherits("DeferredLightCommon") =
  3. {
  4. Pass =
  5. {
  6. DepthRead = false;
  7. Common =
  8. {
  9. struct VStoFS
  10. {
  11. float4 position : SV_POSITION;
  12. float2 uv0 : TEXCOORD0;
  13. float3 screenDir : TEXCOORD1;
  14. };
  15. };
  16. Vertex =
  17. {
  18. struct VertexInput
  19. {
  20. float2 screenPos : POSITION;
  21. float2 uv0 : TEXCOORD0;
  22. };
  23. VStoFS main(VertexInput input)
  24. {
  25. VStoFS output;
  26. output.position = float4(input.screenPos, 0, 1);
  27. output.uv0 = input.uv0;
  28. output.screenDir = mul(gMatInvProj, float4(input.screenPos, 1, 0)).xyz - gViewOrigin.xyz;
  29. return output;
  30. }
  31. };
  32. Fragment =
  33. {
  34. float4 main(VStoFS input) : SV_Target0
  35. {
  36. uint2 pixelPos = (uint2)(input.uv0 * (float2)gViewportRectangle.zw - ((float2)gViewportRectangle.xy + 0.5f));
  37. #if MSAA_COUNT > 1
  38. SurfaceData surfaceData = getGBufferData(pixelPos, sampleIdx);
  39. #else
  40. SurfaceData surfaceData = getGBufferData(pixelPos);
  41. #endif
  42. if(surfaceData.worldNormal.w > 0.0f)
  43. {
  44. float3 cameraDir = normalize(input.screenDir);
  45. float3 worldPosition = input.screenDir * surfaceData.depth + gViewOrigin;
  46. float3 V = normalize(gViewOrigin - worldPosition);
  47. float3 N = surfaceData.worldNormal.xyz;
  48. float3 R = 2 * dot(V, N) * N - V;
  49. float roughness2 = max(surfaceData.roughness, 0.08f);
  50. roughness2 *= roughness2;
  51. LightData lightData = getLightData();
  52. return float4(getLuminanceDirectional(lightData, worldPosition, V, R, surfaceData), 1.0f);
  53. }
  54. else
  55. return float4(0.0f, 0.0f, 0.0f, 0.0f);
  56. }
  57. };
  58. };
  59. };