Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float4 ToLightVS(float3 pos, float w = 1)
- ...
- float AvailabilityFromVS(in float4 pos)
- ...
- void RayMarch(
- inout float4 PosLightVS,
- in float fStepSize,
- in float4 InvDirLightVS,
- inout float3 accum,
- in float l
- )
- {
- // Increment
- PosLightVS.xyz += fStepSize * InvDirLightVS.xyz;
- // Check for availability
- float3 occlusion = AvailabilityFromVS(PosLightVS).xxx;
- // Get Distance
- float d = length(PosLightVS.xyz);
- float dRcp = rcp(d);
- // Calculate Lighting Energy
- float3 energy =
- TAU * (occlusion * (PHI * 0.25 * PI_RCP) * dRcp * dRcp) * exp(-d * TAU) * exp(-l * TAU)
- * fStepSize;
- accum += energy;
- }
- float3 VolumetricLighting(VS_Output inp)
- {
- #define STEPS 50.0f
- #define STEPS_RCP (1.0f / STEPS)
- // Max resolving distance
- float fDistMax = 99.0;
- // Get WS Position
- float depth = t_dX.Sample(ss, inp.Tex);
- float3 viewRay = normalize(inp.ViewRay);
- float3 positionWS = cameraPosition + viewRay * depth;
- // View space positions
- float4 CamLightVS = ToLightVS(cameraPosition, 1);
- float4 PosLightVS = ToLightVS(positionWS, 1);
- float3 DirLight = positionWS - cameraPosition;
- float4 DirLightVS = ToLightVS(DirLight, 0);
- // Noise reducing
- float fDist = trunc(clamp(length(
- distance(CamLightVS.xyz, PosLightVS.xyz)
- ), 0.0, fDistMax));
- // Size of each step
- float fStepSize = fDist * STEPS_RCP;
- float4 RayLightVS = PosLightVS;
- // Total Light Accum
- float3 accum = 0;
- // Ray march
- [loop] for (float l = fDist; l > fStepSize; l -= fStepSize)
- {
- RayMarch(RayLightVS, fStepSize, DirLightVS, accum, l);
- }
- return accum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement