From dc7e6cb99f420888e4e6026ac6092eadfb5575d5 Mon Sep 17 00:00:00 2001 From: vlj Date: Sun, 18 May 2014 03:01:24 +0200 Subject: [PATCH] Revert to spheremapped reflection --- data/shaders/objectpass_spheremap.frag | 17 +++++++---------- src/graphics/stkmesh.cpp | 24 ++++-------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index 629951f2b..e7174f214 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -15,7 +15,7 @@ layout (std140) uniform MatrixesData }; #endif -uniform samplerCube tex; +uniform sampler2D tex; #if __VERSION__ >= 130 in vec3 nor; @@ -27,15 +27,12 @@ varying vec3 nor; void main() { - vec3 fpos = gl_FragCoord.xyz / vec3(screen, 1.); - vec4 xpos = 2.0 * vec4(fpos, 1.0) - 1.0; - xpos = InverseProjectionMatrix * xpos; - - xpos.xyz /= xpos.w; - vec3 viewSampleDir = reflect(xpos.xyz, nor); - // Convert sampleDir in world space (where tex was generated) - vec4 sampleDir = transpose(InverseViewMatrix) * vec4(viewSampleDir, 0.); - vec4 detail0 = texture(tex, sampleDir.xyz); + const vec3 forward = vec3(0., 0., 1.); + vec3 normal_x = normalize(vec3(nor.x, 0., nor.z)); + float sin_theta_x = length(cross(forward, normal_x)) * sign(nor.x); + vec3 normal_y = normalize(vec3(0., nor.y, nor.z)); + float sin_theta_y = length(cross(forward, normal_y)) * sign(nor.y); + vec4 detail0 = texture(tex, .5 * vec2(sin_theta_x, sin_theta_y) + .5); FragColor = vec4(detail0.xyz, 1.); } diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index d772e2d4c..f2b6b8dc3 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -309,31 +309,15 @@ void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelMatrix, const c GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - glActiveTexture(GL_TEXTURE0 + MeshShader::SphereMapShader::TU_tex); - if (!irr_driver->SkyboxCubeMap) - { - glBindTexture(GL_TEXTURE_CUBE_MAP, irr_driver->FakeSkybox); - GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; - glTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } - else - { - glBindTexture(GL_TEXTURE_CUBE_MAP, irr_driver->SkyboxCubeMap); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - } + compressTexture(mesh.textures[0], true); + setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::SphereMapShader::setUniforms(ModelMatrix, InverseModelMatrix, - core::vector2df(float(UserConfigParams::m_width), + MeshShader::SphereMapShader::setUniforms(ModelMatrix, InverseModelMatrix, + core::vector2df(float(UserConfigParams::m_width), float(UserConfigParams::m_height))); assert(mesh.vao_second_pass); glBindVertexArray(mesh.vao_second_pass); glDrawElements(ptype, count, itype, 0); - if (!irr_driver->SkyboxCubeMap) - { - GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; - glTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } } void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)