Diffuse texenv should work with the material color, not the diffuse color. Also modulate the texenv result with vertex color if applicable. Also add the shader type as comment in the top of the shader.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent 34de0b5569
commit 931c18cb51

@ -108,6 +108,20 @@ namespace NL3D
"constant3" "constant3"
}; };
const char *shaderNames[] =
{
"Normal",
"Bump",
"Usercolor",
"Lightmap",
"Specular",
"Caustics",
"Per-Pixel Lighting",
"Per-Pixel Lighting, no specular",
"Cloud",
"Water"
};
CGLSLShaderGenerator::CGLSLShaderGenerator() CGLSLShaderGenerator::CGLSLShaderGenerator()
{ {
reset(); reset();
@ -129,6 +143,8 @@ namespace NL3D
{ {
ss.str( "" ); ss.str( "" );
ss.clear(); ss.clear();
ss << "// " << shaderNames[ material->getShader() ] << " Vertex Shader" << std::endl;
ss << std::endl;
ss << "#version 330" << std::endl; ss << "#version 330" << std::endl;
ss << "uniform mat4 mvpMatrix;" << std::endl; ss << "uniform mat4 mvpMatrix;" << std::endl;
@ -190,6 +206,9 @@ namespace NL3D
ss.str( "" ); ss.str( "" );
ss.clear(); ss.clear();
ss << "// " << shaderNames[ material->getShader() ] << " Pixel Shader" << std::endl;
ss << std::endl;
ss << "#version 330" << std::endl; ss << "#version 330" << std::endl;
ss << std::endl; ss << std::endl;
@ -247,6 +266,17 @@ namespace NL3D
ss << std::endl; ss << std::endl;
} }
void CGLSLShaderGenerator::addColor()
{
CRGBA color = material->getColor();
ss << "vec4 mcolor = vec4( ";
ss << color.R / 255.0f << ", ";
ss << color.G / 255.0f << ", ";
ss << color.B / 255.0f << ", ";
ss << color.A / 255.0f << " );";
ss << std::endl;
}
void CGLSLShaderGenerator::addConstants() void CGLSLShaderGenerator::addConstants()
{ {
int j = 0; int j = 0;
@ -458,7 +488,7 @@ namespace NL3D
ss << "void main( void )" << std::endl; ss << "void main( void )" << std::endl;
ss << "{" << std::endl; ss << "{" << std::endl;
addDiffuse(); addColor();
bool textures = false; bool textures = false;
sampler = 0; sampler = 0;
@ -474,13 +504,26 @@ namespace NL3D
sampler++; sampler++;
} }
if( textures ) bool vertexColor = false;
if( hasFlag( vbFormat, vertexFlags[ PrimaryColor ] ) )
vertexColor = true;
if( textures && !vertexColor )
ss << "vec4 texel = vec4( 1.0, 1.0, 1.0, 1.0 );" << std::endl; ss << "vec4 texel = vec4( 1.0, 1.0, 1.0, 1.0 );" << std::endl;
else
if( vertexColor )
ss << "vec4 texel = color;" << std::endl;
else else
ss << "vec4 texel = vec4( 0.5, 0.5, 0.5, 1.0 );" << std::endl; ss << "vec4 texel = vec4( 0.5, 0.5, 0.5, 1.0 );" << std::endl;
generateTexEnv(); generateTexEnv();
// This is just an idea I had, but it seems to be working.
// Unfortunately it's not documented anywhere I looked in the GL spec, but if I don't have this modulation here,
// the Ryzom UI looks horrific.
if( vertexColor )
ss << "texel = color * texel;" << std::endl;
// Alpha test // Alpha test
//ss << "if( texel.a <= 0.5 ) discard;" << std::endl; //ss << "if( texel.a <= 0.5 ) discard;" << std::endl;
@ -786,19 +829,19 @@ namespace NL3D
switch( op ) switch( op )
{ {
case CMaterial::SrcColor: case CMaterial::SrcColor:
ds << "diffuse.rgb"; ds << "mcolor.rgb";
break; break;
case CMaterial::InvSrcColor: case CMaterial::InvSrcColor:
ds << "( vec3( 1.0, 1.0, 1.0 ) - diffuse.rgb )"; ds << "( vec3( 1.0, 1.0, 1.0 ) - mcolor.rgb )";
break; break;
case CMaterial::SrcAlpha: case CMaterial::SrcAlpha:
ds << "diffuse.a"; ds << "mcolor.a";
break; break;
case CMaterial::InvSrcAlpha: case CMaterial::InvSrcAlpha:
ds << "( 1.0 - diffuse.a )"; ds << "( 1.0 - mcolor.a )";
break; break;
} }
break; break;

@ -40,6 +40,7 @@ namespace NL3D
private: private:
void addDiffuse(); void addDiffuse();
void addColor();
void addConstants(); void addConstants();
void generateNormalVS(); void generateNormalVS();

Loading…
Cancel
Save