Problem understanding texture reduction in shader based 2D soft shadows technique

Hi all,

I’m still a beginner in shading (started a month ago) but i’ve been able to implement some nice shader in my custom project (that I mostly use as a test bed for OpenGL and CG stuff) and so I know the basics. I know my question is more shader in general than GLSL but anyway…

I’m trying to implement this : http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/

Right now, I was able to do the white/black, distance and distort shader and get the desired result. But I’m at a lost on how to do the Horizontal Reduction Shader.

float4 HorizontalReductionPS(float2 TexCoord : TEXCOORD0) : COLOR0
{
float2 color = tex2D(inputSampler, TexCoord);
float2 colorR = tex2D(inputSampler, TexCoord + float2(TextureDimensions.x,0));

float2 result = min(color,colorR);
return float4(result,0,1);
}

From what I understand the shader compare the pixel color to its neighbor and output the lesser value. This is what’s needed to determine the nearest collision with a shadow caster. But I don’t know how to actually generate this reduced 2X512 texture! I’m I supposed to do a pass, then cut the texture in 2 and do it again until the width is 2? This part of the technique is kinda quickly explained and if you can give some more details on how to achieve this, I think I might actually be done since the last pass basically just use that texture and I could easily implement that (at least I think!)

If anyone could give me a hand with this, it would be really appreciated!

I can give sample code or the whole project for that matter if it’s necessary.

Thanks in advance!

In each pass, you use the full-width input texture as a texture and the half-width output texture as the colour buffer (glFramebufferTexture2D). Set the viewport to the size of the half-width texture and draw a unit quad. The half-width texture then becomes the full-width texture for the next pass, so you’re halving the width at each step.

Hi GClements,

I’ll be trying something similar to what you propose but right now I’m limited in the OpenGL feature I can use. glFramebufferTexture2D is not available, but I do something similar. I’ll post what I tried later since I don’t have the time to look into it right now! Thanks for the answer!

If you don’t have render-to-texture, you can render to a renderbuffer or the hardware framebuffer then copy the pixels into a texture with glCopyTexImage2D.

If you can only render to the hardware framebuffer, you’re limited in the choice of available formats. Render-to-texture is a fairly important feature for many advanced techniques.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.