Revert to spheremapped reflection

This commit is contained in:
vlj 2014-05-18 03:01:24 +02:00
parent b91484a2ef
commit dc7e6cb99f
2 changed files with 11 additions and 30 deletions

View File

@ -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.);
}

View File

@ -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)