Re: [osg-users] Need help fixing my atmospheric transmission shader, it's so close to working!

2012-01-30 Thread Ethan Fahy
I should have mentioned before that only the red channel is of any importance; 
There is a viewer further down the pipeline that picks up the red channel 
values from the framebuffer so the green and blue channels don't matter at all. 
 I just set the green and blue channels to the red channel in case I ever want 
to use a different viewer and see things in grey-scale.

I tried to do a bit of research on GLSL texture binding but am very confused by 
it and not sure what I could change about my shader to fix binding issues.

I tried using this line:

Code:
vec4 color = texture2D(baseTexture, gl_TexCoord[0].st) + gl_Color;


thinking that by adding the texture color to the tree colors I might get the 
correct result.  This actually makes me see both the terrain texture and the 
tree colors.  This may then be the correct solution, but I'm not sure if it is 
really doing what I think it's doing...

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45118#45118





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Need help fixing my atmospheric transmission shader, it's so close to working!

2012-01-30 Thread Sergey Polischuk
Only your terrain have texture and for your trees - function call 
texture2D(baseTexture, gl_TexCoord[0].st) return black (0,0,0,1). Your trees 
have per-vertex color attribute, and your ground dont(?) (i dont know to what 
value it defaults). Simplest options to fix this - set 1x1 white texture to 
your trees or add color array to ground (with black color values) and use 
texture2D(baseTexture, gl_TexCoord[0].st) + gl_Color, or write different 
shaders (one version with texture, one without). If gl_Color defaults to black 
without color array, you can use vec4 color = texture2D(baseTexture, 
gl_TexCoord[0].st) + gl_Color; without any changes.

30.01.2012, 17:30, Ethan Fahy ethanf...@gmail.com:
 I should have mentioned before that only the red channel is of any 
 importance; There is a viewer further down the pipeline that picks up the red 
 channel values from the framebuffer so the green and blue channels don't 
 matter at all.  I just set the green and blue channels to the red channel in 
 case I ever want to use a different viewer and see things in grey-scale.

 I tried to do a bit of research on GLSL texture binding but am very confused 
 by it and not sure what I could change about my shader to fix binding issues.

 I tried using this line:

 Code:
 vec4 color = texture2D(baseTexture, gl_TexCoord[0].st) + gl_Color;

 thinking that by adding the texture color to the tree colors I might get the 
 correct result.  This actually makes me see both the terrain texture and the 
 tree colors.  This may then be the correct solution, but I'm not sure if it 
 is really doing what I think it's doing...

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=45118#45118

 ___
 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


Re: [osg-users] Need help fixing my atmospheric transmission shader, it's so close to working!

2012-01-28 Thread Sergey Polischuk
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


[osg-users] Need help fixing my atmospheric transmission shader, it's so close to working!

2012-01-27 Thread Ethan Fahy
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