Hi,
I had a look at the shader composition example. The main shader looks like this:
Code:
#pragma import_defines ( LIGHTING, TEXTURE_2D, VERTEX_FUNC(v) )
#ifdef LIGHTING
// forward declare lighting computation, provided by lighting.vert shader
void directionalLight( int lightNum, vec3 normal, inout vec4 color );
#endif
#ifdef TEXTURE_2D
varying vec2 texcoord;
#endif
#ifdef VERTEX_FUNC
uniform float osg_SimulationTime;
#endif
varying vec4 basecolor;
void main(void)
{
basecolor = gl_Color;
#ifdef LIGHTING
directionalLight( 0, gl_Normal.xyz, basecolor);
#endif
#ifdef TEXTURE_2D
// if we want texturing we need to pass on texture coords
texcoord = gl_MultiTexCoord0.xy;
#endif
#ifdef VERTEX_FUNC
gl_Position = gl_ModelViewProjectionMatrix * VERTEX_FUNC(gl_Vertex);
#else
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
#endif
}
In the example code one directional light computation can be injected. What is
the best solution if I like to inject 0 to N directional lights where N is
runtime dependent?
I could do something like:
Code:
#ifdef LIGHTING0
directionalLight( 0, gl_Normal.xyz, basecolor);
#endif
#ifdef LIGHTING1
directionalLight( 1, gl_Normal.xyz, basecolor);
#endif
#ifdef LIGHTING2
directionalLight( 2, gl_Normal.xyz, basecolor);
#endif
...
but this is not very elegant. Though I do not see any other possibility. Am I
missing a better solution?
Thank you!
Cheers,
Hartwig
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73625#73625
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org