Hi all
I would like to implement the nvidia snow accumulation program in GLSL
The method consists in rendering the scene into a depthmap from the sky and looking down with a 2D ortho frustum (1st pass). Then using this depthmap and compare depth componant and identify the fragment that will be “snowed” (2nd pass). It really looks like the shadow map method.
Well I tried to implement this with shaders, but it just does’nt work :eek:
Here is the fragment shader for the 1st pass, it creates the depth map
void main(void)
{
float z = gl_FragCoord.z / gl_FragCoord.w;
gl_FragColor = 1.0 - z;
}
Then the vertex shader for the 2nd pass
uniform mat4 mViewFromSky;
uniform mat4 mProjFromSky;
varying vec4 texCoord;
void main(void)
{
mat4 bias = mat4(0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0);
texCoord = bias * mViewFromSky * mProjFromSky * gl_Vertex;
texCoord = texCoord / texCoord.w;
gl_Position = ftransform();
}
mViewFromSky is a up located looking down camera model view matrix (like the light model view matrix for a shadowmap)
mProjFromSky is a 2D ortho camera projection matrix
Then finally the 2nd pass fragment shader:
uniform sampler2DShadow depthMap;
varying vec4 texCoord;
void main(void)
{
vec4 color = ComputeFragment();
float depthMapDepth = shadow2DProj(depthMap, texCoord).x;
if(depthMapDepth == 0.0)
color = vec4(1,1,1,1);
gl_FragColor = color;
}
My idea is to use shadow2D GLSL function to know if the fragment is “snowed” or not.
My problem is that all my object are white now …
I think my problem may come from the texCoord computing, but I really do not know how to compute it.
Any help much appreciated …
thanks