DeferredLightCommon.bslinc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "$ENGINE$\GBufferInput.bslinc"
  2. #include "$ENGINE$\PerCameraData.bslinc"
  3. #include "$ENGINE$\LightingCommon.bslinc"
  4. mixin DeferredLightCommon
  5. {
  6. mixin GBufferInput;
  7. mixin PerCameraData;
  8. mixin LightingCommon;
  9. depth
  10. {
  11. write = false;
  12. #ifdef INSIDE_GEOMETRY
  13. read = false;
  14. #else
  15. read = true;
  16. #endif
  17. };
  18. blend
  19. {
  20. target
  21. {
  22. enabled = true;
  23. color = { one, one, add };
  24. writemask = RGB;
  25. };
  26. };
  27. raster
  28. {
  29. #ifdef INSIDE_GEOMETRY
  30. cull = cw;
  31. #else
  32. cull = ccw;
  33. #endif
  34. };
  35. code
  36. {
  37. cbuffer PerLight
  38. {
  39. // x, y, z - World position of the light
  40. // w - Radius of the area light source, zero if not an area light
  41. float4 gLightPositionAndSrcRadius;
  42. float4 gLightColorAndLuminance;
  43. // x - outerAngle in radians, y - cos(outerAngle), z - 1.0f/(cos(innerAngle) - cos(outerAngle)), w - inverse light attenuation radius
  44. float4 gLightSpotAnglesAndSqrdInvAttRadius;
  45. float4 gLightDirectionAndAttRadius;
  46. // xyz - light position shifted in order to adjust for area spot lights
  47. // w - light type -> Directional = 0, Radial = >0, Spot = >0.5
  48. float4 gShiftedLightPositionAndType;
  49. // x - Num sides (zero for radial lights)
  50. // y - Num slices (zero for radial lights)
  51. // z - Sphere radius for radial lights
  52. // w - Cone radius for spot lights
  53. float4 gLightGeometry;
  54. float4x4 gMatConeTransform;
  55. }
  56. LightData getLightData()
  57. {
  58. LightData output;
  59. output.position = gLightPositionAndSrcRadius.xyz;
  60. output.attRadius = gLightDirectionAndAttRadius.w;
  61. output.direction = gLightDirectionAndAttRadius.xyz;
  62. output.luminance = gLightColorAndLuminance.w;
  63. output.spotAngles = gLightSpotAnglesAndSqrdInvAttRadius.xyz;
  64. output.attRadiusSqrdInv = gLightSpotAnglesAndSqrdInvAttRadius.w;
  65. output.color = gLightColorAndLuminance.rgb;
  66. output.srcRadius = gLightPositionAndSrcRadius.w;
  67. output.shiftedLightPosition = gShiftedLightPositionAndType.rgb;
  68. return output;
  69. }
  70. #if MSAA_COUNT > 1
  71. Texture2DMS<float4> gLightOcclusionTex;
  72. #else
  73. Texture2D<float4> gLightOcclusionTex;
  74. #endif
  75. };
  76. };