GL3: Cleanup

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 5a4dd538f1
commit 07f663a68e

@ -123,13 +123,14 @@ struct CProgramIndex
ViewMatrix,
Fog,
FogStart,
FogEnd,
FogParams,
FogColor,
Color,
//DiffuseColor,
AlphaRef,
Constant0,
Constant1,
Constant2,

@ -398,20 +398,19 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
// Alpha test
if (desc.Flags & IDRV_MAT_ALPHA_TEST)
{
ss << "uniform float alphaTreshold;" << std::endl;
ss << "uniform float alphaRef;" << std::endl;
ss << std::endl;
}
// Fog
if (desc.Fog) // FIXME: FogMode!
{
ss << "uniform float fogStart;" << std::endl;
ss << "uniform float fogEnd;" << std::endl;
ss << "uniform vec2 fogParams;" << std::endl; // s = start, t = end
ss << "uniform vec4 fogColor;" << std::endl;
/*if (desc->getFogMode() == CShaderDesc::Linear)
{*/
ss << "uniform float fogDensity;" << std::endl;
//ss << "uniform float fogDensity;" << std::endl;
/*}*/
ss << "smooth in vec4 ecPos;" << std::endl;
@ -423,7 +422,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
ss << "{" << std::endl;
ss << "float z = ecPos.z / ecPos.w;" << std::endl;
ss << "z = abs(z);" << std::endl;
ss << "float fogFactor = (fogEnd - z) / (fogEnd - fogStart);" << std::endl;
ss << "float fogFactor = (fogParams.t - z) / (fogParams.t - fogParams.s);" << std::endl;
ss << "fogFactor = clamp(fogFactor, 0.0, 1.0);" << std::endl;
ss << "vec4 fColor = mix(fogColor, col, fogFactor);" << std::endl;
ss << "return fColor;" << std::endl;
@ -488,7 +487,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
if (desc.Flags & IDRV_MAT_ALPHA_TEST)
{
ss << "if (fragColor.a < alphaTreshold) discard;" << std::endl; // TODO: VERIFY < or <= ?
ss << "if (fragColor.a < alphaRef) discard;" << std::endl; // TODO: VERIFY < or <= ?
}
if (desc.Fog)

@ -949,17 +949,9 @@ void CDriverGL3::setupUniforms(TProgram program)
setUniform3x3f(program, nmIdx, nm);
}
uint fogStartIdx = p->getUniformIndex(CProgramIndex::FogStart);
if (fogStartIdx != ~0)
{
nglProgramUniform1f(progId, fogStartIdx, _FogStart);
}
uint fogEndIdx = p->getUniformIndex(CProgramIndex::FogEnd);
if (fogEndIdx != ~0)
{
nglProgramUniform1f(progId, fogEndIdx, _FogEnd);
}
uint fogParamsIdx = p->getUniformIndex(CProgramIndex::FogParams);
if (fogParamsIdx != ~0)
nglProgramUniform2f(progId, fogParamsIdx, _FogStart, _FogEnd);
uint fogColorIdx = p->getUniformIndex(CProgramIndex::FogColor);
if (fogColorIdx != ~0)
@ -978,18 +970,9 @@ void CDriverGL3::setupUniforms(TProgram program)
nglProgramUniform4f(progId, colorIndex, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
}
/*uint diffuseIndex = p->getUniformIndex(CProgramIndex::DiffuseColor);
if (diffuseIndex != ~0)
{
/*GLfloat glCol[ 4 ];
CRGBA col = mat.getDiffuse();
glCol[ 0 ] = col.R / 255.0f;
glCol[ 1 ] = col.G / 255.0f;
glCol[ 2 ] = col.B / 255.0f;
glCol[ 3 ] = col.A / 255.0f;*/
/*nglProgramUniform4f(progId, diffuseIndex, 1.0f, 1.0f, 1.0f, 0.0f);
}*/
uint alphaRefIdx = p->getUniformIndex(CProgramIndex::AlphaRef);
if (alphaRefIdx)
nglProgramUniform1f(progId, alphaRefIdx, mat.getAlphaTestThreshold());
NLMISC::CRGBAF selfIllumination = NLMISC::CRGBAF(0.0f, 0.0f, 0.0f);
NLMISC::CRGBAF matDiffuse = NLMISC::CRGBAF(mat.getDiffuse());
@ -1046,23 +1029,6 @@ void CDriverGL3::setupUniforms(TProgram program)
nglProgramUniform1f(progId, shl, mat.getShininess());
}
/*int lac = p->getUniformIndex(CProgramIndex::TName(CProgramIndex::Light0ColAmb + i));
if (lac >= 0)
{
GLfloat glCol[ 4 ];
CRGBA col;
if (mat.getShader() == CMaterial::LightMap)
col = _UserLight[ i ].getAmbiant();
else
col.add(_UserLight[ i ].getAmbiant(), mat.getEmissive());
glCol[ 0 ] = col.R / 255.0f;
glCol[ 1 ] = col.G / 255.0f;
glCol[ 2 ] = col.B / 255.0f;
glCol[ 3 ] = col.A / 255.0f;
setUniform4f(program, lac, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
}*/
uint lca = p->getUniformIndex(CProgramIndex::TName(CProgramIndex::Light0ConstAttn + i));
if (lca != ~0)
{

@ -103,7 +103,7 @@ void vpLightFunctions(std::stringstream &ss, const CVPBuiltin &desc, int i)
ss << "}" << std::endl;
ss << std::endl;
ss << "void getLight" << i << "Color(out vec4 lightDiffuse, out vec4 lightSpecular)" << std::endl;
ss << "void addLight" << i << "Color(inout vec4 lightDiffuse, inout vec4 lightSpecular)" << std::endl;
ss << "{" << std::endl;
ss << "vec4 lightDir4 = viewMatrix * vec4(light" << i << "DirOrPos, 1.0);" << std::endl;
ss << "vec3 lightDir = lightDir4.xyz / lightDir4.w;" << std::endl;
@ -112,8 +112,8 @@ void vpLightFunctions(std::stringstream &ss, const CVPBuiltin &desc, int i)
ss << "normal3 = normalMatrix * normal3;" << std::endl;
ss << "normal3 = normalize(normal3);" << std::endl;
ss << "lightDiffuse = getIntensity" << i << "(normal3, lightDir) * light" << i << "ColDiff;" << std::endl;
ss << "lightSpecular = getSpecIntensity" << i << "(normal3, lightDir) * light" << i << "ColSpec;" << std::endl;
ss << "lightDiffuse = lightDiffuse + getIntensity" << i << "(normal3, lightDir) * light" << i << "ColDiff;" << std::endl;
ss << "lightSpecular = lightSpecular + getSpecIntensity" << i << "(normal3, lightDir) * light" << i << "ColSpec;" << std::endl;
ss << "}" << std::endl;
ss << std::endl;
break;
@ -136,7 +136,7 @@ void vpLightFunctions(std::stringstream &ss, const CVPBuiltin &desc, int i)
ss << "}" << std::endl;
ss << std::endl;
ss << "void getLight" << i << "Color(out vec4 lightDiffuse, out vec4 lightSpecular)" << std::endl;
ss << "void addLight" << i << "Color(inout vec4 lightDiffuse, inout vec4 lightSpecular)" << std::endl;
ss << "{" << std::endl;
ss << "vec3 ecPos3 = ecPos4.xyz / ecPos4.w;" << std::endl;
ss << "vec4 lightPos4 = viewMatrix * vec4(light" << i << "DirOrPos, 1.0);" << std::endl;
@ -155,8 +155,8 @@ void vpLightFunctions(std::stringstream &ss, const CVPBuiltin &desc, int i)
ss << "normal3 = normalize(normal3);" << std::endl;
ss << "float invattn = 1.0 / attenuation;" << std::endl;
ss << "lightDiffuse = getIntensity" << i << "(normal3, lightDirection) * invattn * light" << i << "ColDiff;" << std::endl;
ss << "lightSpecular = getSpecIntensity" << i << "(normal3, lightDirection) * invattn * light" << i << "ColSpec;" << std::endl;
ss << "lightDiffuse = lightDiffuse + getIntensity" << i << "(normal3, lightDirection) * invattn * light" << i << "ColDiff;" << std::endl;
ss << "lightSpecular = lightSpecular + getSpecIntensity" << i << "(normal3, lightDirection) * invattn * light" << i << "ColSpec;" << std::endl;
ss << "}" << std::endl;
ss << std::endl;
break;
@ -253,16 +253,10 @@ void vpGenerate(std::string &result, const CVPBuiltin &desc)
ss << "vec4 diffuseLight;" << std::endl;
ss << "vec4 specularLight;" << std::endl;
for (int i = 0; i < NL_OPENGL3_MAX_LIGHT; i++)
{
if (desc.LightMode[i] == CLight::DirectionalLight || desc.LightMode[i] == CLight::PointLight)
{
ss << "getLight" << i << "Color(diffuseLight, specularLight);" << std::endl;
ss << "diffuseVertex = diffuseVertex + diffuseLight;" << std::endl;
ss << "specularVertex = specularVertex + specularLight;" << std::endl;
}
}
ss << "diffuseVertex.a = 1.0;" << std::endl; // ...
ss << "specularVertex.a = 1.0;" << std::endl; // ...
ss << "addLight" << i << "Color(diffuseVertex, specularVertex);" << std::endl;
ss << "diffuseVertex.a = 1.0;" << std::endl;
ss << "specularVertex.a = 1.0;" << std::endl;
// Secondary color (lighted)
if (desc.VertexFormat & g_VertexFlags[SecondaryColor])
@ -285,7 +279,9 @@ void vpGenerate(std::string &result, const CVPBuiltin &desc)
// Primary color
if (desc.VertexFormat & g_VertexFlags[PrimaryColor])
{
ss << "diffuseVertex = diffuseVertex * vprimaryColor;" << std::endl; // Note: Might need to replace materialColor if PrimaryColor exists
}
// Add diffuse and specular color
ss << "vertexColor = diffuseVertex;" << std::endl;

@ -598,6 +598,8 @@ void CMeshGeom::render(IDriver *drv, CTransformShape *trans, float polygonCount,
bool useMeshVP= _MeshVertexProgram != NULL;
if( useMeshVP )
{
nlassert(_VBuffer.getVertexFormat() == (CVertexBuffer::PositionFlag | CVertexBuffer::NormalFlag | CVertexBuffer::TexCoord0Flag | CVertexBuffer::PrimaryColorFlag));
CMatrix invertedObjectMatrix;
invertedObjectMatrix = trans->getWorldMatrix().inverted();
// really ok if success to begin VP

@ -93,13 +93,14 @@ const char *CProgramIndex::Names[NUM_UNIFORMS] =
"viewMatrix",
"fog",
"fogStart",
"fogEnd",
"fogParams",
"fogColor",
"materialColor",
//"diffuseColor",
"alphaRef",
"constant0",
"constant1",
"constant2",

Loading…
Cancel
Save