[osg-users] Shader aliasing
Anders.Wallerman at saabgroup.com
Wed Mar 18 09:14:14 PDT 2009
We are drawing textured terrain tiles, and want to write a shader that uses different code paths for different types of terrain. Water surfaces, for instance, are to be drawn differently than forested surfaces. To do this we have a texture with different discrete values for different classes of terrain as a basis for selecting code path.
In the shader, it is obviously not possible to simply use an if statement, and select code path depending on values in the classification texture, since that would introduce aliasing.
To reduce aliasing I tried to reduce the frequency by "filtering" the texture like this:
vec2 distx = dFdx(texcoord);
vec2 disty = dFdy(texcoord);
float r = texture2D(classmap,texcoord-distx) + texture2D(classmap,texcoord+distx) +
texture2D(classmap,texcoord-disty) + texture2D(classmap,texcoord+disty) +
texture2D(classmap,texcoord-distx-disty) + texture2D(classmap,texcoord+distx+disty) +
texture2D(classmap,texcoord-distx+disty) + texture2D(classmap,texcoord+distx-disty) +
r = r/10.0;
...and using the value r as basis for the final fragment color. (In this case, the classmap only contains two values (0 and 1) and aliasing could be removed by using mipmap filtering etc of the classmap texture, but we will extend this into using more classes, and then normal texture filtering can't be used. I hope this illustrates the aliasing problem anyway.)
This "filter" is probably too simple, but am I on the correct path? Is it possible to create a filter that reduces the aliasing to an acceptable level, and if so, what should it look like?
I can't be the first one that wants to use terrain class maps like this, how is it generally done?
We're using OSG 2.6.1, RHEL 5.1 and GTX280.
Anders Wallerman, Saab AB, Sweden
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the osg-users