Hi Sebastian,

Declare the function stub in the main.frag

vec3 fog(in vec3 color);

void main()..

K.

2009/11/30 Sebastien Nerig <[email protected]>:
> Hi robert
> thx for your answer
> Ok I tried what you said, but I still have a pb.
>
> I made a shader "common.frag" with a basic fog function
>
>
> Code:
> uniform vec3 fogColor;
> uniform float fogDensity;
>
> vec3 fog(in vec3 color)
> {
>  const float LOG2 = 1.442695;
>  float z = gl_FragCoord.z / gl_FragCoord.w;
>  float fogFactor = exp2(-fogDensity * fogDensity * z * z * LOG2);
>  fogFactor = clamp(fogFactor, 0.0, 1.0);
>  return mix(fogColor, color, fogFactor);
> }
>
>
>
> And I did a "main.frag" with the main function
>
>
> Code:
> void main(void)
> {
>  vec3 color = vec3(1,1,1);
>  color = fog(color);
>  gl_FragColor = vec4(color, 1);
> }
>
>
>
> then I load thoses shaders into one program as fragment shader
>
> Code:
> osg::Program* program = new osg::Program;
> osg::Shader* shader = new osg::Shader(osg::Shader::FRAGMENT);
> shader->loadShaderSourceFromFile("common.frag");
> program->addShader(shader);
> osg::Shader* shader1 = new osg::Shader(osg::Shader::FRAGMENT);
> shader1->loadShaderSourceFromFile("main.frag");
> program->addShader(shader1)
>
>
>
> But when OSG compile my shader, it fails because "fog" is not known in the 
> main function.
> Any ideas ? If I find the solution I will post...
>
> thanks a lot
> Sebastien[/code]
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=20578#20578
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to