How doing GLSL + PCF + jitter?
Tried googling around like mad but found nothing that helped me one single bit.
I have right now a shadow map working in GLSL with PCF. Now as we all know this turns out still blocky hence some jittering is required to make things more nice to look at. Now that's where I don't get any further.
How to I make this "jittering" in GLSL?
I know the basics of this in that you take the center of the point and add a random offset in s and t direction beeing half the pixel size. Now though how doing this? In he GLSL docs there is mentioned a "noise2" function which takes a vec2 and gives a pseudo-random vec2 out. Is this what I need for jittering? Or is there some other function that should be used there?
Does your code look like this?
Could make this into a for loop if your card supports it.
vec3 shadowST = projCoord.xyz / projCoord.w;float mapScale = 1.0 / 1024.0; //match this to shadowmap sizevec4 shadowColor = shadow2D(shadowmap, shadowST); shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3( mapScale, mapScale, 0));shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3( mapScale, -mapScale, 0));shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3( mapScale, 0, 0));shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3(-mapScale, mapScale, 0));shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3(-mapScale, -mapScale, 0));shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3(-mapScale, 0, 0));shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3( 0, mapScale, 0));shadowColor += shadow2D(shadowmap, shadowST.xyz + vec3( 0, -mapScale, 0));shadowColor = shadowColor / 9.0; //9 samples
Could make this into a for loop if your card supports it.
Nah, I use something like this:
shadow2D(shadowmap, vec3( shadowST.s + pixelSize, shadowST.t + pixelSize, shadowST.p ));
as this should be quicker ( no + operator involved ).
But I can change to whatever is required to get jittering to work.
And BTW for-loops are a no-no in shaders even if the language provides it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement