Hi

this piece completely eliminate any green and blue values of original color, if 
you trees dont have red color component they will look black.
>         color.r = color.r * exp( -1.0 * ExtinctionCoefficient * eyeDistance );
>         color.g = color.r;
>         color.b = color.r;

Sampling texture when it not currently bound iirc should return (0,0,0,1), here 
you get your black color (also this could cause crash on some drivers).

27.01.2012, 23:19, "Ethan Fahy" <ethanf...@gmail.com>:
> My scene contains virtualplanetbuilder-generated terrain that has a texture 
> wrapped on it along with surface objects such as trees that I generated by 
> creating osg primitives and coloring them "PER_VERTEX" without using any 
> textures.
>
> I have written an atmospheric transmission shader that decreases the r,g and 
> b values as a function of distance from the viewer to the object.  However, I 
> can't seem to get the shader to work properly on both the terrain and trees 
> at the same time.  Here is the code:
>
> Vertex Shader:
>
> Code:
> varying float eyeDistance;
> void main(void)
> {
>     gl_TexCoord[0] = gl_MultiTexCoord0;
>     gl_FrontColor = gl_Color;
>         eyeDistance = length(gl_ModelViewMatrix * gl_Vertex);
>         gl_Position = ftransform();
> }
>
> Fragment Shader:
>
> Code:
> uniform float ExtinctionCoefficient;
> uniform sampler2D baseTexture;
> varying float eyeDistance;
> void main(void)
> {
>         vec4 color = texture2D(baseTexture, gl_TexCoord[0].st);
>         color.r = color.r * exp( -1.0 * ExtinctionCoefficient * eyeDistance );
>         color.g = color.r;
>         color.b = color.r;
>         gl_FragColor = color;
> }
>
> The above shader pair will successfully make the terrain darker in color as I 
> zoom out, but the trees all look completely black no matter what, even if 
> they originally had varying colors without the shader.
>
> If instead of setting "color" in the frag shader to texture2D() I instead set 
> it equal to "gl_Color", the shader then works on all the objects in the scene 
> but I no longer see any remnants of the underlying terrain texture.  Based on 
> this page 
> http://stackoverflow.com/questions/2552676/change-the-color-of-a-vertex-in-a-vertex-shader
>  I would have expected that setting color = texture2D(baseTexture, 
> gl_TexCoord[0].st) * gl_Color would have produced the result I was looking 
> for, but instead the result is identical to if I leave out * gl_Color.
>
> I think my shader code is very close to being correct and just needs a nudge 
> in the right direction.  Anyone?
>
> Thanks very much in advance.
>
> -Ethan
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=45086#45086
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to