diff --git a/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp b/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp index db1210d8a..22cccb957 100644 --- a/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.cpp @@ -52,7 +52,6 @@ namespace NL3D void CGLSLShaderGenerator::reset() { material = NULL; - vbFormat = 0; desc = NULL; ss.str(""); ss.clear(); @@ -73,7 +72,7 @@ namespace NL3D for (int i = Weight; i < NumOffsets; i++) { - if (hasFlag(vbFormat, g_VertexFlags[i])) + if (hasFlag(desc->vbFlags, g_VertexFlags[i])) { ss << "smooth in vec4 "; ss << g_AttribNames[i] << ";" << std::endl; @@ -540,7 +539,11 @@ namespace NL3D for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++) { if (desc->getUseTexStage(i)) - ss << "uniform sampler2D sampler" << sampler << ";" << std::endl; + { + ss << "uniform " + << ((desc->textureSamplerMode[i] == SamplerCube) ? "samplerCube" : "sampler2D") + << " sampler" << sampler << ";" << std::endl; + } sampler++; } @@ -577,7 +580,7 @@ namespace NL3D ss << "diffuse = applyLights(diffuse);" << std::endl; ss << "diffuse.a = 1.0;" << std::endl; } - if (hasFlag(vbFormat, g_VertexFlags[PrimaryColor])) + if (hasFlag(desc->vbFlags, g_VertexFlags[PrimaryColor])) ss << "diffuse = color * diffuse;" << std::endl; // TODO: If this is the correct location, we should premultiply light and color in VS. bool textures = false; @@ -587,9 +590,10 @@ namespace NL3D { ss << "vec4 texel" << i << " = texture(sampler" << i << ", "; if (desc->hasVBFlags(g_VertexFlags[TexCoord0 + i])) - ss << g_AttribNames[TexCoord0 + i] << ".st);"; + ss << g_AttribNames[TexCoord0 + i]; else - ss << g_AttribNames[TexCoord0] << ".st);"; + ss << g_AttribNames[TexCoord0]; + ss << ((desc->textureSamplerMode[i] == SamplerCube) ? ".str);" : ".st);"); ss << std::endl; textures = true; } @@ -823,7 +827,7 @@ namespace NL3D int ntextures = 0; for (int i = TexCoord0; i < TexCoord4; i++) { - if (hasFlag(vbFormat, g_VertexFlags[i])) + if (hasFlag(desc->vbFlags, g_VertexFlags[i])) ntextures++; } diff --git a/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.h b/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.h index a7bf29bd7..2f0985f2f 100644 --- a/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.h +++ b/code/nel/src/3d/driver/opengl3/driver_glsl_shader_generator.h @@ -40,7 +40,6 @@ namespace NL3D void generatePS(std::string &ps); void setMaterial(CMaterial *mat) { material = mat; } - void setVBFormat(uint16 format) { vbFormat = format; } void setShaderDesc(CShaderDesc *d) { desc = d; } private: @@ -143,7 +142,6 @@ namespace NL3D //////////////////////////////////////////////////////////////////////////////////////////////////////// std::stringstream ss; - uint16 vbFormat; CMaterial const *material; CShaderDesc const *desc; }; diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_material.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_material.cpp index ea287dc8a..a49056f02 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_material.cpp @@ -1091,9 +1091,12 @@ void CDriverGL3::setupSpecularBegin() // For all cases, setup the TexCoord gen for stage1 _DriverGLStates.activeTexture(1); - // setup the good matrix for stage 1. - _UserTexMat[ 1 ] = _SpecularTexMtx; + // todo hulud remove - lol + // _DriverGLStates.setTextureMode(CDriverGLStates::TextureCubeMap); + setTexGenModeVP(1, TexGenReflectionMap); + // setup the good matrix for stage 1. + _UserTexMat[1] = _SpecularTexMtx; } // *************************************************************************** @@ -1103,8 +1106,8 @@ void CDriverGL3::setupSpecularEnd() // Disable Texture coord generation. setTexGenModeVP(1, TexGenDisabled); - // Happiness !!! we have already enabled the stage 1 - _UserTexMat[ 1 ].identity(); + // Happiness !!! we have already enabled the stage 1 - lolwhat + _UserTexMat[1].identity(); } // *************************************************************************** diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp index 554c6dd9f..455ee9651 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp @@ -556,8 +556,13 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat) desc.setShaderType(mat.getShader()); uint16 vbFlags = _CurrentVertexBufferHard->VB->getVertexFormat(); for (sint i = 0; i < IDRV_MAT_MAXTEXTURES; ++i) - if (m_VPBuiltinCurrent.TexGenMode[0] >= 0) - vbFlags |= g_VertexFlags[TexCoord0 + i]; // texgen hack for keeping pp simpler + { + if (m_VPBuiltinCurrent.TexGenMode[i] >= 0) + { + //nldebug("texgen hack for keeping pp simpler, stage %i, tex %s valid", i, mat.getTexture(i) ? "IS" : "NOT"); + vbFlags |= g_VertexFlags[TexCoord0 + i]; + } + } desc.setVBFlags(vbFlags); if (mat.getShader() == CMaterial::LightMap) @@ -565,14 +570,20 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat) //int i = 0; - if (mat.getShader() == CMaterial::Normal) + if (mat.getShader() == CMaterial::Normal + || mat.getShader() == CMaterial::UserColor + || mat.getShader() == CMaterial::Specular) { bool useTextures = false; int maxTextures = std::min(int(IDRV_MAT_MAXTEXTURES), int(IDRV_MAT_MAXTEXTURES)); - for (int i = 0; i < maxTextures; i++) + + if (mat.getShader() == CMaterial::Normal) { - desc.setTexEnvMode(i, mat.getTexEnvMode(i)); + for (int i = 0; i < maxTextures; i++) + { + desc.setTexEnvMode(i, mat.getTexEnvMode(i)); + } // todo specular env mode.. } for (int i = 0; i < maxTextures; i++) @@ -582,8 +593,18 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat) && (desc.hasVBFlags(g_VertexFlags[TexCoord0]) || desc.hasVBFlags(g_VertexFlags[TexCoord0 + i])) ) { + //nldebug("use stage %i", i); + desc.setUseTexStage(i, true); useTextures = true; + + desc.textureSamplerMode[i] = mat.getTexture(i)->isTextureCube() ? SamplerCube : Sampler2D; // Driver state + } + else + { + /*nldebug("stage fail %i, tex %s, tc0 %s, tci, %s", i, mat.getTexture(i) ? "VALID" : "NO", + desc.hasVBFlags(g_VertexFlags[TexCoord0]) ? "YES" : "NO", + desc.hasVBFlags(g_VertexFlags[TexCoord0 + i]) ? "YES" : "NO");*/ } } @@ -599,7 +620,7 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat) desc.setAlphaTestThreshold(mat.getAlphaTestThreshold()); } - if (m_VPBuiltinCurrent.Fog) + if (m_VPBuiltinCurrent.Fog) // Driver state { desc.setFog(true); desc.setFogMode(CShaderDesc::Linear); @@ -711,7 +732,6 @@ bool CDriverGL3::setupBuiltinPixelProgram(CMaterial &mat) shaderGenerator->reset(); shaderGenerator->setMaterial(&mat); - shaderGenerator->setVBFormat(_CurrentVertexBufferHard->VB->getVertexFormat()); shaderGenerator->setShaderDesc(&desc); // If we don't already have a vertex program attached, we'll generate it now diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h b/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h index 8796c5f77..06e6b70a9 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_shader_desc.h @@ -153,6 +153,10 @@ namespace NL3D if (texEnvMode[ i ] != o.texEnvMode[ i ]) return false; + for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++) + if (textureSamplerMode[ i ] != o.textureSamplerMode[ i ]) + return false; + for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++) if (useTextureStage[ i ] != o.useTextureStage[ i ]) return false; @@ -250,7 +254,7 @@ namespace NL3D void setShaders(SShaderPair sp) { shaderPair = sp; } SShaderPair getShaders() const{ return shaderPair; } - private: + public: enum TShaderFeatures { diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp index bbba8902f..9b78b00b0 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp @@ -356,8 +356,8 @@ void CDriverGL3::setTexGenModeVP(uint stage, sint mode) H_AUTO_OGL(CDriverGL3_setTexGenModeVP) if (m_VPBuiltinCurrent.TexGenMode[stage] != mode) { - if (mode >= 0) - nlwarning("enable texgen %i, %i, not implemented", stage, mode); + //if (mode >= 0) + // nlwarning("enable texgen %i, %i, not implemented", stage, mode); m_VPBuiltinCurrent.TexGenMode[stage] = mode; m_VPBuiltinTouched = true; }