|
|
@ -172,6 +172,7 @@ namespace NL3D
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMaterial::PerPixelLighting:
|
|
|
|
case CMaterial::PerPixelLighting:
|
|
|
|
|
|
|
|
case CMaterial::PerPixelLightingNoSpec:
|
|
|
|
generatePPLVS();
|
|
|
|
generatePPLVS();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -215,6 +216,7 @@ namespace NL3D
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMaterial::PerPixelLighting:
|
|
|
|
case CMaterial::PerPixelLighting:
|
|
|
|
|
|
|
|
case CMaterial::PerPixelLightingNoSpec:
|
|
|
|
generatePPLPS();
|
|
|
|
generatePPLPS();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -309,11 +311,18 @@ namespace NL3D
|
|
|
|
void CGLSLShaderGenerator::generatePPLVS()
|
|
|
|
void CGLSLShaderGenerator::generatePPLVS()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ss << "uniform vec4 lightPosition;" << std::endl;
|
|
|
|
ss << "uniform vec4 lightPosition;" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( material->getShader() == CMaterial::PerPixelLighting )
|
|
|
|
|
|
|
|
{
|
|
|
|
ss << "uniform vec4 viewerPos;" << std::endl;
|
|
|
|
ss << "uniform vec4 viewerPos;" << std::endl;
|
|
|
|
ss << "uniform mat4 invModelMat;" << std::endl;
|
|
|
|
ss << "uniform mat4 invModelMat;" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
ss << std::endl;
|
|
|
|
ss << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
ss << "smooth out vec3 cubeTexCoords0;" << std::endl;
|
|
|
|
ss << "smooth out vec3 cubeTexCoords0;" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( material->getShader() == CMaterial::PerPixelLighting )
|
|
|
|
ss << "smooth out vec3 cubeTexCoords2;" << std::endl;
|
|
|
|
ss << "smooth out vec3 cubeTexCoords2;" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
ss << "void main( void )" << std::endl;
|
|
|
|
ss << "void main( void )" << std::endl;
|
|
|
@ -331,27 +340,28 @@ namespace NL3D
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ss << "vec4 n = normalize( vnormal ); //normalized normal" << std::endl;
|
|
|
|
ss << "vec4 n = normalize( vnormal ); //normalized normal" << std::endl;
|
|
|
|
ss << "vec4 R5; // second basis" << std::endl;
|
|
|
|
ss << "vec4 T; // second basis, Tangent" << std::endl;
|
|
|
|
ss << "R5.x = dot( n, texCoord1 );" << std::endl;
|
|
|
|
ss << "T = texCoord1;" << std::endl;
|
|
|
|
ss << "R5.y = R5.x;" << std::endl;
|
|
|
|
ss << "T = normalize( T );" << std::endl;
|
|
|
|
ss << "R5.z = R5.x;" << std::endl;
|
|
|
|
ss << "vec4 B;" << std::endl;
|
|
|
|
ss << "R5.w = R5.x;" << std::endl;
|
|
|
|
ss << "B.xyz = cross( n.xyz, T.xyz );" << std::endl;
|
|
|
|
ss << "R5 = n * -1 * R5 + texCoord1;" << std::endl;
|
|
|
|
|
|
|
|
ss << "R5 = normalize( R5 );" << std::endl;
|
|
|
|
|
|
|
|
ss << "vec4 B = n.yzxw * R5.zxyw; //Binormal" << std::endl;
|
|
|
|
|
|
|
|
ss << "B = R5.yzxw * -1 * n.zxyw + B;" << std::endl;
|
|
|
|
|
|
|
|
ss << "vec4 L = lightPos - vposition; //Inverse light vector" << std::endl;
|
|
|
|
ss << "vec4 L = lightPos - vposition; //Inverse light vector" << std::endl;
|
|
|
|
ss << "L = normalize( L );" << std::endl;
|
|
|
|
ss << "L = normalize( L );" << std::endl;
|
|
|
|
ss << "cubeTexCoords0.x = dot( R5.xyz, L.xyz );" << std::endl;
|
|
|
|
ss << "cubeTexCoords0.x = dot( T.xyz, L.xyz );" << std::endl;
|
|
|
|
ss << "cubeTexCoords0.y = dot( B.xyz, L.xyz );" << std::endl;
|
|
|
|
ss << "cubeTexCoords0.y = dot( B.xyz, L.xyz );" << std::endl;
|
|
|
|
ss << "cubeTexCoords0.z = dot( n.xyz, L.xyz );" << std::endl;
|
|
|
|
ss << "cubeTexCoords0.z = dot( n.xyz, L.xyz );" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( material->getShader() == CMaterial::PerPixelLighting )
|
|
|
|
|
|
|
|
{
|
|
|
|
ss << "vec4 V = invModelMat * viewerPos - vposition;" << std::endl;
|
|
|
|
ss << "vec4 V = invModelMat * viewerPos - vposition;" << std::endl;
|
|
|
|
ss << "V = normalize( V );" << std::endl;
|
|
|
|
ss << "V = normalize( V );" << std::endl;
|
|
|
|
ss << "vec4 H = L + V; // half-angle" << std::endl;
|
|
|
|
ss << "vec4 H = L + V; // half-angle" << std::endl;
|
|
|
|
ss << "vec4 H = normalize( H );" << std::endl;
|
|
|
|
ss << "vec4 H = normalize( H );" << std::endl;
|
|
|
|
ss << "cubeTexCoords2.x = dot( R5, H );" << std::endl;
|
|
|
|
ss << "cubeTexCoords2.x = dot( T, H );" << std::endl;
|
|
|
|
ss << "cubeTexCoords2.y = dot( B, H );" << std::endl;
|
|
|
|
ss << "cubeTexCoords2.y = dot( B, H );" << std::endl;
|
|
|
|
ss << "cubeTexCoords2.w = dot( n, H );" << std::endl;
|
|
|
|
ss << "cubeTexCoords2.w = dot( n, H );" << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ss << "}" << std::endl;
|
|
|
|
ss << "}" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -806,12 +816,16 @@ namespace NL3D
|
|
|
|
void CGLSLShaderGenerator::generatePPLPS()
|
|
|
|
void CGLSLShaderGenerator::generatePPLPS()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ss << "smooth in vec3 cubeTexCoords0;" << std::endl;
|
|
|
|
ss << "smooth in vec3 cubeTexCoords0;" << std::endl;
|
|
|
|
|
|
|
|
if( material->getShader() == CMaterial::PerPixelLighting )
|
|
|
|
ss << "smooth in vec3 cubeTexCoords2;" << std::endl;
|
|
|
|
ss << "smooth in vec3 cubeTexCoords2;" << std::endl;
|
|
|
|
ss << std::endl;
|
|
|
|
ss << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
ss << "uniform samplerCube cubeSampler0;" << std::endl;
|
|
|
|
ss << "uniform samplerCube cubeSampler0;" << std::endl;
|
|
|
|
ss << "uniform sampler2D sampler1;" << std::endl;
|
|
|
|
ss << "uniform sampler2D sampler1;" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( material->getShader() == CMaterial::PerPixelLighting )
|
|
|
|
ss << "uniform samplerCube cubeSampler2;" << std::endl;
|
|
|
|
ss << "uniform samplerCube cubeSampler2;" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
ss << std::endl;
|
|
|
|
ss << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
ss << "void main( void )" << std::endl;
|
|
|
|
ss << "void main( void )" << std::endl;
|
|
|
@ -823,13 +837,28 @@ namespace NL3D
|
|
|
|
|
|
|
|
|
|
|
|
ss << "vec4 texel0 = textureCube( cubeSampler0, cubeTexCoords0 );" << std::endl;
|
|
|
|
ss << "vec4 texel0 = textureCube( cubeSampler0, cubeTexCoords0 );" << std::endl;
|
|
|
|
ss << "vec4 texel1 = texture2D( sampler1, texCoord1 );" << std::endl;
|
|
|
|
ss << "vec4 texel1 = texture2D( sampler1, texCoord1 );" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( material->getShader() == CMaterial::PerPixelLighting )
|
|
|
|
ss << "vec4 texel2 = textureCube( cubeSampler2, cubeTexCoords2 );" << std::endl;
|
|
|
|
ss << "vec4 texel2 = textureCube( cubeSampler2, cubeTexCoords2 );" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
ss << "vec4 texel;" << std::endl;
|
|
|
|
ss << "vec4 texel;" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( material->getShader() == CMaterial::PerPixelLighting )
|
|
|
|
|
|
|
|
{
|
|
|
|
ss << "texel.rgb = texel0.rgb * constant0.rgb + constant0.rgb;" << std::endl;
|
|
|
|
ss << "texel.rgb = texel0.rgb * constant0.rgb + constant0.rgb;" << std::endl;
|
|
|
|
ss << "texel.rgb = texel1.rgb * texel.rgb;" << std::endl;
|
|
|
|
ss << "texel.rgb = texel1.rgb * texel.rgb;" << std::endl;
|
|
|
|
ss << "texel.rgb = texel2.rgb * constant2.rgb + texel.rgb;" << std::endl;
|
|
|
|
ss << "texel.rgb = texel2.rgb * constant2.rgb + texel.rgb;" << std::endl;
|
|
|
|
ss << "texel.a = texel0.a * diffuse.a" << std::endl;
|
|
|
|
ss << "texel.a = texel0.a * diffuse.a" << std::endl;
|
|
|
|
ss << "texel.a = texel1.a * texel.a;" << std::endl;
|
|
|
|
ss << "texel.a = texel1.a * texel.a;" << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ss << "texel.rgb = texel0.rgb * constant0.rgb + color.rgb;" << std::endl;
|
|
|
|
|
|
|
|
ss << "texel.rgb = texel1.rgb * texel.rgb;" << std::endl;
|
|
|
|
|
|
|
|
ss << "texel.a = texel0.a * diffuse.a;" << std::endl;
|
|
|
|
|
|
|
|
ss << "texel.a = texel1.a * diffuse.a;" << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ss << "fragColor = texel;" << std::endl;
|
|
|
|
ss << "fragColor = texel;" << std::endl;
|
|
|
|
ss << "}" << std::endl;
|
|
|
|
ss << "}" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|