Use correct mapping for spheremap

This commit is contained in:
vlj
2014-05-18 03:19:18 +02:00
parent dc7e6cb99f
commit a2e1724389
4 changed files with 13 additions and 11 deletions

View File

@@ -1,3 +1,5 @@
// See http://www.ozone3d.net/tutorials/glsl_texturing_p04.php for ref
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
@@ -25,14 +27,15 @@ varying vec3 nor;
#define FragColor gl_FragColor
#endif
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main() {
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);
vec3 texc = gl_FragCoord.xyz / vec3(screen, 1.);
vec3 u = getPosFromUVDepth(texc, InverseProjectionMatrix).xyz;
vec3 r = reflect(u, nor);
float m = 2.0 * sqrt(r.x * r.x + r.y * r.y + (r.z + 1.0) * (r.z + 1.0));
vec4 detail0 = texture(tex, r.xy / m + .5);
FragColor = vec4(detail0.xyz, 1.);
}

View File

@@ -1187,6 +1187,7 @@ namespace MeshShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_normal = glGetAttribLocation(Program, "Normal");
@@ -1202,7 +1203,7 @@ namespace MeshShader
glUseProgram(0);
}
void SphereMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::vector2df& screen)
void SphereMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);

View File

@@ -254,7 +254,7 @@ public:
static GLuint TU_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::vector2df& screen);
static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix);
};
class SplattingShader

View File

@@ -312,9 +312,7 @@ void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelMatrix, const c
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),
float(UserConfigParams::m_height)));
MeshShader::SphereMapShader::setUniforms(ModelMatrix, InverseModelMatrix);
assert(mesh.vao_second_pass);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);