[osg-users] Shader aliasing

Guy guy at dvp.co.il
Wed Mar 18 23:53:19 PDT 2009


Hi Andres,

 

If there are different geometries you could use uniforms else you could
use attributes to set the class id.

 

If you plan to use different map textures on the same geometry (the more
general solution) than use Robert's advice :-)

 

Can you describe what are distx and disty? 

Your filter seems to smooth the texture neighborhood with a slight
emphasis of the value in texcoord. Generally smoothing does remove
aliasing, but for indexing how does it help? Suppose you get a 1.23
value, what path in the shader r u planning to use?!?

 

And what ever path you eventually use, u draw adjacent pixels with
distinct shader paths, so you will still have aliasing in the resulting
image.

 

Hmm... I ment to help but now I'm not sure I really do :-)

 

Guy.

 

   

 

 

________________________________

 

 

Hi all,

 

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) +

            texture2D(classmap,texcoord)*2.0;

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.

 

Regards;

Anders Wallerman, Saab AB, Sweden

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090319/d91ea853/attachment-0003.htm>


More information about the osg-users mailing list