Added built-in support for lighting.vert

This commit is contained in:
Robert Osfield 2017-10-20 11:37:41 +01:00
parent 711e04751f
commit cf044027a7
2 changed files with 29 additions and 1 deletions

View File

@ -601,7 +601,10 @@ osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTyp
_programMap[layerTypes] = program;
// add shader that provides the lighting functions
program->addShader(osgDB::readRefShaderFile("shaders/lighting.vert"));
{
#include "shaders/lighting_vert.cpp"
program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::VERTEX, "shaders/lighting.vert", lighting_vert));
}
// OSG_NOTICE<<") creating new Program "<<program.get()<<std::endl;
{

View File

@ -0,0 +1,25 @@
char lighting_vert[] = "#pragma requires(LIGHTING)\n"
"\n"
"void directionalLight( int lightNum, vec3 normal, inout vec4 color )\n"
"{\n"
" vec3 n = normalize(gl_NormalMatrix * normal);\n"
"\n"
" float NdotL = dot( n, normalize(gl_LightSource[lightNum].position.xyz) );\n"
" NdotL = max( 0.0, NdotL );\n"
"\n"
" float NdotHV = dot( n, gl_LightSource[lightNum].halfVector.xyz );\n"
" NdotHV = max( 0.0, NdotHV );\n"
"#if 1\n"
" color *= gl_LightSource[lightNum].ambient +\n"
" gl_LightSource[lightNum].diffuse * NdotL;\n"
"#else\n"
" color *= gl_FrontLightModelProduct.sceneColor +\n"
" gl_FrontLightProduct[lightNum].ambient +\n"
" gl_FrontLightProduct[lightNum].diffuse * NdotL;\n"
"#endif\n"
"#if 0\n"
" if ( NdotL * NdotHV > 0.0 )\n"
" color += gl_FrontLightProduct[lightNum].specular * pow( NdotHV, gl_FrontMaterial.shininess );\n"
"#endif\n"
"}\n"
"\n";