Parallax mapping issue in GLSL,Opengl [英] Parallax mapping issue in GLSL, Opengl

查看:1009
本文介绍了Parallax mapping issue in GLSL,Opengl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视差映射给出错误的结果。我不知道可能出错。

My Parallax mapping gives wrong results. I don't know what can be wrong.

阴影位置错误。

去向立方体。
着色器程序(基于dhpoware.com):

Light is pointing from the viewer and goes towards the cube. Shader program (based on dhpoware.com):

[vert]
     varying vec3 lightDir;            
     varying vec3 viewDir;
     attribute vec4 tangent;
     void main() 
     { 
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
     gl_TexCoord[0] = gl_MultiTexCoord0;
     vec3 vertexPos = vec3(gl_ModelViewMatrix * gl_Vertex);
     vec3 n = normalize(gl_NormalMatrix * gl_Normal);
     vec3 t = normalize(gl_NormalMatrix * tangent.xyz);
     vec3 b = cross(n, t) * tangent.w;
     mat3 tbnMatrix = mat3(t.x, b.x, n.x,
                           t.y, b.y, n.y,
                           t.z, b.z, n.z);
     lightDir = (gl_LightSource[0].position.xyz - vertexPos) / 1000.0;
     lightDir = tbnMatrix * lightDir;
     viewDir = -vertexPos;
     viewDir = tbnMatrix * viewDir;
     } 

    [frag]
     varying vec3 lightDir;            
     varying vec3 viewDir;
     uniform sampler2D diffuseMap;
     uniform sampler2D normalMap;
     uniform sampler2D heightMap;
     uniform float scale;
     uniform float bias;
     void main() 
     { 
     vec3 v = normalize(viewDir);
     vec2 TexCoord = gl_TexCoord[0].st;
    {
     float height = texture2D(heightMap, gl_TexCoord[0].st).r;
     height = height * scale + bias;
     TexCoord = gl_TexCoord[0].st + (height * v.xy); 
    }
     vec3 l = lightDir;
     float atten = max(0.0, 1.0 - dot(l, l));
     l = normalize(l);
     vec3 n = normalize(texture2D(normalMap, TexCoord).rgb * 2.0 - 1.0);
     vec3 h = normalize(l + v);
     float nDotL = max(0.0, dot(n, l));
     float nDotH = max(0.0, dot(n, h));
     float power = (nDotL == 0.0) ? 0.0 : pow(nDotH, gl_FrontMaterial.shininess);
     vec4 ambient = gl_FrontLightProduct[0].ambient * atten;
     vec4 diffuse = gl_FrontLightProduct[0].diffuse * nDotL * atten;
     vec4 specular = gl_FrontLightProduct[0].specular * power * atten;
     vec4 color = gl_FrontLightModelProduct.sceneColor + ambient + diffuse + specular;color *= texture2D(diffuseMap,TexCoord);
     gl_FragColor = color ;
     } 



从多维数据集内容中记录日志(包括切线,第四个分量是手性) / p>

log from cube content (tangents included, the fourth component is handedness):

------------------------------------------------------------------------------------------------------------------
VecContainer<Vertex> vertices = 

size: 36
space: 36
{
-4.000000, -4.000000, -4.000000, 
-4.000000, 4.000000, -4.000000, 
4.000000, 4.000000, -4.000000, 
4.000000, 4.000000, -4.000000, 
4.000000, -4.000000, -4.000000, 
-4.000000, -4.000000, -4.000000, 
-4.000000, -4.000000, -4.000000, 
4.000000, -4.000000, -4.000000, 
4.000000, -4.000000, 4.000000, 
4.000000, -4.000000, 4.000000, 
-4.000000, -4.000000, 4.000000, 
-4.000000, -4.000000, -4.000000, 
-4.000000, -4.000000, -4.000000, 
-4.000000, -4.000000, 4.000000, 
-4.000000, 4.000000, 4.000000, 
-4.000000, 4.000000, 4.000000, 
-4.000000, 4.000000, -4.000000, 
-4.000000, -4.000000, -4.000000, 
4.000000, -4.000000, -4.000000, 
4.000000, 4.000000, -4.000000, 
4.000000, 4.000000, 4.000000, 
4.000000, 4.000000, 4.000000, 
4.000000, -4.000000, 4.000000, 
4.000000, -4.000000, -4.000000, 
-4.000000, 4.000000, -4.000000, 
-4.000000, 4.000000, 4.000000, 
4.000000, 4.000000, 4.000000, 
4.000000, 4.000000, 4.000000, 
4.000000, 4.000000, -4.000000, 
-4.000000, 4.000000, -4.000000, 
-4.000000, -4.000000, 4.000000, 
4.000000, -4.000000, 4.000000, 
4.000000, 4.000000, 4.000000, 
4.000000, 4.000000, 4.000000, 
-4.000000, 4.000000, 4.000000, 
-4.000000, -4.000000, 4.000000, 

}

------------------------------------------------------------------------------------------------------------------
VecContainer<Vertex> texcoords = 

size: 36
space: 36
{
0.000000, 0.000000, 
0.000000, 1.000000, 
1.000000, 1.000000, 
1.000000, 1.000000, 
1.000000, 0.000000, 
0.000000, 0.000000, 
0.000000, 0.000000, 
1.000000, 0.000000, 
1.000000, 1.000000, 
1.000000, 1.000000, 
0.000000, 1.000000, 
0.000000, 0.000000, 
0.000000, 0.000000, 
1.000000, 0.000000, 
1.000000, 1.000000, 
1.000000, 1.000000, 
0.000000, 1.000000, 
0.000000, 0.000000, 
1.000000, 0.000000, 
1.000000, 1.000000, 
0.000000, 1.000000, 
0.000000, 1.000000, 
0.000000, 0.000000, 
1.000000, 0.000000, 
0.000000, 1.000000, 
0.000000, 0.000000, 
1.000000, 0.000000, 
1.000000, 0.000000, 
1.000000, 1.000000, 
0.000000, 1.000000, 
0.000000, 0.000000, 
1.000000, 0.000000, 
1.000000, 1.000000, 
1.000000, 1.000000, 
0.000000, 1.000000, 
0.000000, 0.000000, 

}

------------------------------------------------------------------------------------------------------------------
VecContainer<Vertex> normals = 

size: 36
space: 36
{
0.000000, 0.000000, -1.000000, 
0.000000, 0.000000, -1.000000, 
0.000000, 0.000000, -1.000000, 
0.000000, 0.000000, -1.000000, 
0.000000, 0.000000, -1.000000, 
0.000000, 0.000000, -1.000000, 
0.000000, -1.000000, 0.000000, 
0.000000, -1.000000, 0.000000, 
0.000000, -1.000000, 0.000000, 
0.000000, -1.000000, 0.000000, 
0.000000, -1.000000, 0.000000, 
0.000000, -1.000000, 0.000000, 
-1.000000, 0.000000, 0.000000, 
-1.000000, 0.000000, 0.000000, 
-1.000000, 0.000000, 0.000000, 
-1.000000, 0.000000, 0.000000, 
-1.000000, 0.000000, 0.000000, 
-1.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 
0.000000, 1.000000, 0.000000, 
0.000000, 1.000000, 0.000000, 
0.000000, 1.000000, 0.000000, 
0.000000, 1.000000, 0.000000, 
0.000000, 1.000000, 0.000000, 
0.000000, 1.000000, 0.000000, 
0.000000, 0.000000, 1.000000, 
0.000000, 0.000000, 1.000000, 
0.000000, 0.000000, 1.000000, 
0.000000, 0.000000, 1.000000, 
0.000000, 0.000000, 1.000000, 
0.000000, 0.000000, 1.000000, 

}

------------------------------------------------------------------------------------------------------------------
VecContainer<tangent>* tangents = 

size: 36
space: 36
{
1.000000, -0.000000, 0.000000, 1.000000, 
1.000000, -0.000000, 0.000000, 1.000000, 
1.000000, -0.000000, 0.000000, 1.000000, 
1.000000, -0.000000, 0.000000, 1.000000, 
1.000000, -0.000000, 0.000000, 1.000000, 
1.000000, -0.000000, 0.000000, 1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
0.000000, 0.000000, 1.000000, -1.000000, 
0.000000, 0.000000, 1.000000, -1.000000, 
0.000000, 0.000000, 1.000000, -1.000000, 
0.000000, 0.000000, 1.000000, -1.000000, 
0.000000, 0.000000, 1.000000, -1.000000, 
0.000000, 0.000000, 1.000000, -1.000000, 
0.000000, 0.000000, -1.000000, -1.000000, 
0.000000, 0.000000, -1.000000, -1.000000, 
0.000000, 0.000000, -1.000000, -1.000000, 
0.000000, 0.000000, -1.000000, -1.000000, 
0.000000, 0.000000, -1.000000, -1.000000, 
0.000000, 0.000000, -1.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, 0.000000, -1.000000, 
1.000000, 0.000000, -0.000000, -1.000000, 
1.000000, 0.000000, -0.000000, -1.000000, 
1.000000, 0.000000, -0.000000, -1.000000 

}

------------------------------------------------------------------------------------------------------------------
VecContainer<GLuint> indices = 

size: 12
space: 12
{
3, 4, 5, 
6, 7, 8, 
9, 10, 11, 
12, 13, 14, 
15, 16, 17, 
18, 19, 20, 
21, 22, 23, 
24, 25, 26, 
27, 28, 29, 
30, 31, 32, 
33, 34, 35, 
0, 1, 2 

}

可能导致此问题的原因是什么?

What could cause this problem?

推荐答案

如你在上一个问题,我认为你仍然有同样的问题。你忘记了某处的某个地方,或者按错误的顺序执行了一个交叉乘积。

As in your previous question, I think you still have the same issue. You forget a minus somewhere, or perhaps performed a cross product in the wrong order.

这篇关于Parallax mapping issue in GLSL,Opengl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆