Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. float4 ToLightVS(float3 pos, float w = 1)
  2. ...
  3.  
  4. float AvailabilityFromVS(in float4 pos)
  5. ...
  6.  
  7. void RayMarch(
  8. inout float4 PosLightVS,
  9. in float fStepSize,
  10. in float4 InvDirLightVS,
  11. inout float3 accum,
  12. in float l
  13. )
  14. {
  15. // Increment
  16. PosLightVS.xyz += fStepSize * InvDirLightVS.xyz;
  17.  
  18. // Check for availability
  19. float3 occlusion = AvailabilityFromVS(PosLightVS).xxx;
  20.  
  21. // Get Distance
  22. float d = length(PosLightVS.xyz);
  23. float dRcp = rcp(d);
  24.  
  25. // Calculate Lighting Energy
  26. float3 energy =
  27. TAU * (occlusion * (PHI * 0.25 * PI_RCP) * dRcp * dRcp) * exp(-d * TAU) * exp(-l * TAU)
  28. * fStepSize;
  29.  
  30. accum += energy;
  31. }
  32.  
  33. float3 VolumetricLighting(VS_Output inp)
  34. {
  35. #define STEPS 50.0f
  36. #define STEPS_RCP (1.0f / STEPS)
  37.  
  38. // Max resolving distance
  39. float fDistMax = 99.0;
  40.  
  41. // Get WS Position
  42. float depth = t_dX.Sample(ss, inp.Tex);
  43. float3 viewRay = normalize(inp.ViewRay);
  44. float3 positionWS = cameraPosition + viewRay * depth;
  45.  
  46. // View space positions
  47. float4 CamLightVS = ToLightVS(cameraPosition, 1);
  48. float4 PosLightVS = ToLightVS(positionWS, 1);
  49.  
  50. float3 DirLight = positionWS - cameraPosition;
  51. float4 DirLightVS = ToLightVS(DirLight, 0);
  52.  
  53. // Noise reducing
  54. float fDist = trunc(clamp(length(
  55. distance(CamLightVS.xyz, PosLightVS.xyz)
  56. ), 0.0, fDistMax));
  57.  
  58. // Size of each step
  59. float fStepSize = fDist * STEPS_RCP;
  60. float4 RayLightVS = PosLightVS;
  61.  
  62. // Total Light Accum
  63. float3 accum = 0;
  64.  
  65. // Ray march
  66. [loop] for (float l = fDist; l > fStepSize; l -= fStepSize)
  67. {
  68. RayMarch(RayLightVS, fStepSize, DirLightVS, accum, l);
  69. }
  70.  
  71. return accum;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement