[osg-users] Shader aliasing

Robert Osfield robert.osfield at gmail.com
Wed Mar 18 09:50:50 PDT 2009


Hi Anders,

For terrain type indexing I'd actually suggest switching off filtering
completely as any form of interoplation between values will result on in the
wrong type of interpretation.

Personally I'd avoid using indexing approach completely.  Could you instead
go for encoding the denisity of a certain type of terrain into the separate
RGBA channels, this would only give you four channels to work with, but
perhaps you could equate water to R, grass to G, B to forest, A to scrub.
This approach would enable mipmapping and other texture filtering to all
work without changing the basic nature of the how to intprerate a region.

Robert.

2009/3/18 Wallerman Anders <Anders.Wallerman at saabgroup.com>

>   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
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090318/1b0ed50b/attachment-0003.htm>


More information about the osg-users mailing list