GLSL视差映射问题

时间:2013-12-11 09:33:30

标签: opengl glsl shader

我在GLSL中编写了视差贴图着色器,但它工作错误。在某些地方,它显示正确的图像,具有良好的凹凸,但在其他位置,它变得平坦。当我移动相机父亲而不是平台(前进)时,它变得最平坦

#version 120
varying vec3 pos;
varying vec3 normal;
varying vec2 tc;
varying vec3 color;
uniform vec3 camera;

void main(void)
{
    pos = (-gl_Vertex.xyz + camera);
    tc = gl_MultiTexCoord0.xy;
    normal = normalize(gl_Normal);
    color = gl_Color.xyz;
    gl_Position = ftransform();
}

#version 120
uniform sampler2D normal_map;
uniform sampler2D diffuse_map;
uniform sampler2D displacement;
uniform float mode;

varying vec2 tc;
varying vec3 pos;

void main(void)
{
    vec3 lightPos = vec3( 0.0, -45.0, -40.0);
    vec4 color;
    if (mode > 1)
    {
        vec3 eyeVec = normalize(pos);
        vec2 eyeProj = normalize(eyeVec.xz);
        float curHeight = texture2D(displacement, tc).r - 0.5;
        vec2 trTc = tc - (eyeProj) * curHeight * 0.035;
        vec3 normal = normalize(texture2D(normal_map, trTc).xzy*2.0 - 1.0);
        color = texture2D(diffuse_map, trTc) * dot( normalize(pos - lightPos), normal) * 1.0;
        color.w = 1.0;
    }
    else
    {
        vec3 normal = normalize(texture2D(normal_map, tc).xzy*2.0 - 1.0);
        color = texture2D(diffuse_map, tc) * dot( normalize(pos - lightPos), normal) * 1.0;
    }
    gl_FragColor = color;
}

我甚至无法想象哪里可能是错误的。我正在试验相机和顶点值,但它没有帮助;

0 个答案:

没有答案