[osg-users] How to apply shadows to a scene with different shaders- Part 2

Wojciech Lewandowski lewandowski at ai.com.pl
Thu Sep 18 01:23:30 PDT 2008


Hi,

As a propnent of IMPROVE_TEXGEN_PRECISION fix I feel I should make a 
response but I am not sure what your problems really are. Tweak in 
ShadowMap was related to the way OSG & OpenGL computes final texture 
coordination matrix. I assume you have read OpenGL documentation and you 
know how Texgen with eye space works. Texture coord matrix is computed as 
multiplication of current inverted view matrix and texgen planes. Problem is 
that OpenGL internally uses float matrices. So if our View and TexGen 
matrices use large coordinates (for example large translations when objects 
are located on earth surface in WGS84 cartesian representation) and are cast 
to float matrices we loose lots of math precision. Their multiplication 
sucks even more. Solution to this was to make sure that large coords are 
multiplied in OSG using double matrices.

When you use shaders you are not limited by this functionality and you mays 
skip using fixed pipeline gl_EyePlane uniformsl. You may simply compute your 
own tex coord matrix by multiplying inverted view and tex gen using OSG 
double matrices. Then pass this result as an uniform to your shaders and 
compute tex cooords by multiplying view coords by your matrix.

Cheers,
Wojtek

> Hi guys, I followed this excellent thread
> http://thread.gmane.org/gmane.comp.graphics.openscenegraph.user/31360 with 
> much
> success.  I was able to mimic texgen in the vertex shader and get shadows
> applied in the frag shader.  However, the quality doesn't match what you 
> get
> with ShadowMap using fixed function vertex processing and I believe I can 
> see
> where it's coming from.  In ShadowMap.cpp there exists the macro constant
> "IMPROVE_TEXGEN_PRECISION".  What I have in the shader doesn't take this
> enhancement into account.  Anyone know how this can be done?
>
> Thanks,
> Michael Guerrero
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 




More information about the osg-users mailing list