diff --git a/src/osgFX/BumpMapping.cpp b/src/osgFX/BumpMapping.cpp index b3ac89fb9..005b85ffb 100644 --- a/src/osgFX/BumpMapping.cpp +++ b/src/osgFX/BumpMapping.cpp @@ -258,10 +258,10 @@ namespace "ATTRIB v18 = vertex.normal;" "ATTRIB v16 = vertex.position;" "PARAM s259[4] = { state.matrix.mvp };" - "PARAM s18 = state.light[0].position;" - "PARAM s77 = state.lightprod[0].specular;" + "PARAM s18 = state.light["<<_lightnum<<"].position;" + "PARAM s77 = state.lightprod["<<_lightnum<<"].specular;" "PARAM s4 = state.material.shininess;" - "PARAM s75 = state.lightprod[0].ambient;" + "PARAM s75 = state.lightprod["<<_lightnum<<"].ambient;" "PARAM s223[4] = { state.matrix.modelview };" "PARAM c0[4] = { program.local[0..3] };" " MOV result.texcoord[" << freeunit << "].xyz, s75.xyzx;" diff --git a/src/osgFX/Cartoon.cpp b/src/osgFX/Cartoon.cpp index 0e57f2575..6cf15db02 100644 --- a/src/osgFX/Cartoon.cpp +++ b/src/osgFX/Cartoon.cpp @@ -179,15 +179,23 @@ namespace { // implement pass #1 (solid surfaces) { - const char * vert_source = - "const vec3 LightPosition = vec3( 0.0, 2.0, 4.0 );" - "varying float CartoonTexCoord;" - "void main( void )" - "{" - "vec3 eye_space_normal = normalize(gl_NormalMatrix * gl_Normal);" - "CartoonTexCoord = max(0.0, dot(normalize(LightPosition), eye_space_normal));" - "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;" - "}"; + std::ostringstream vert_source; + vert_source << + "varying float CartoonTexCoord;\n" + "void main( void )\n" + "{\n" + " vec4 LightPosition = gl_LightSource["<<_lightnum<<"].position;\n" + " vec3 LightDirection;\n" + " if (LightPosition[3]!=0.0) { \n" + " vec4 eye_space_position = gl_ModelViewMatrix * gl_Vertex;\n" + " LightDirection = (LightPosition.xyz-eye_space_position.xyz);\n" + " } else {\n" + " LightDirection = LightPosition.xyz;\n" + " }\n" + " vec3 eye_space_normal = normalize(gl_NormalMatrix * gl_Normal);\n" + " CartoonTexCoord = max(0.0, dot(normalize(LightDirection), eye_space_normal));\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + "}\n"; const char * frag_source = "uniform sampler1D CartoonTexUnit;" @@ -205,7 +213,7 @@ namespace ss->setAttributeAndModes(polyoffset.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); osg::ref_ptr program = new osg::Program; - program->addShader( new osg::Shader( osg::Shader::VERTEX, vert_source ) ); + program->addShader( new osg::Shader( osg::Shader::VERTEX, vert_source.str() ) ); program->addShader( new osg::Shader( osg::Shader::FRAGMENT, frag_source ) ); ss->addUniform( new osg::Uniform("CartoonTexUnit", 0));