http://http.develope...gems3_ch13.html
Unfortunately I don't have access to the book's demo code but afaik there's nothing more "special" going on than what is written there.
The shader is rather simple and short though it seems I'm still doing something wrong here:
// 2D Vector
extern float2 GBufferTextureSize;
// 3D Vector
const float3 LightPos = float3(0.0f, -1.0f, 1.0f);
// Matrices
float4x4 WVP;
// Sample our Composite Scene
sampler2D SceneSampler : register(s0);
// Constants
const int NUM_SAMPLES = 16;
float Density = 0.8f;
float Weight = 0.9f;
float Decay = 0.5f;
float Exposure = 0.5f;
struct VSI_VolLightScattering
{
float4 Position : POSITION0;
float2 UV : TEXCOORD0;
};
struct PSI_VolLightScattering
{
float4 Position : SV_POSITION;
float2 UV : TEXCOORD0;
float4 ScreenLightPos : TEXCOORD1;
};
PSI_VolLightScattering VolumetricLightScattering_VS(VSI_VolLightScattering input)
{
PSI_VolLightScattering output = (PSI_VolLightScattering)0;
output.Position = float4(input.Position.xy, 1, 1);
output.UV = input.UV + GBufferTextureSize;
output.ScreenLightPos = mul(LightPos, WVP);
return output;
}
float4 VolumetricLightScattering_PS(PSI_VolLightScattering input) : COLOR0
{
half2 ssPos = input.ScreenLightPos.xy / input.ScreenLightPos.w * float2(0.5, -0.5) + 0.5;
half2 deltaTexCoord = (input.UV - ssPos);
deltaTexCoord *= 1.0f / NUM_SAMPLES * Density;
half3 color = tex2D(SceneSampler, input.UV);
half illuminationDecay = 1.0f;
for(int i = 0; i < NUM_SAMPLES; i++)
{
input.UV -= deltaTexCoord;
half3 Sample = tex2D(SceneSampler, input.UV);
Sample *= illuminationDecay * Weight;
color += Sample;
illuminationDecay *= Decay;
}
return float4(color.rgb * Exposure, 1);
}
In engine it looks like this:
http://cl.ly/3J0r241G2e0J200P1i3b
It's just blurring the whole screen.
Did anyone implement this technique or can help me in any way ?
Also, I'm using a pow approach on my skydome to fake a sun, how would that translate to the Light's Position in my shader here (directional light)?