-1
我将凹凸贴图应用到树上。当没有应用正常的映射时,它看起来像这样。为什么法线贴图无法正确显示?
但是当使用法线贴图,它竟然是过于激进的遵循这是丑陋的。
我检查应该是精细切数据。所以我想知道是不是因为使用了错误的普通纹理图像。
这里是我的顶点着色器代码:
"#version 430 \n" +
"layout (location = 3) uniform mat4 mvMatrix; \n" +
"layout (location = 4) uniform mat4 proMatrix; \n" +
"uniform vec3 light_pos = vec3(100.0, 100.0, 100.0);\n" +
" \n" +
"layout (location = 0) in vec4 position; \n" +
"layout (location = 1) in vec2 tc_in; \n" +
"layout (location = 2) in vec3 normal; \n" +
"layout (location = 5) in vec3 tangent; \n" +
"layout (location = 10) in uint draw_id; \n" +
" \n" +
"out VS_OUT \n" +
"{ \n" +
" vec2 UV; \n" +
" vec3 L; \n" +
" vec3 V; \n" +
"} vs_out; \n" +
" \n" +
"void main(void) \n" +
"{ \n" +
" vec4 P = mvMatrix * position; \n" +
" \n" +
" vec3 N = normalize(mat3(mvMatrix) * normal); \n" +
" vec3 T = normalize(mat3(mvMatrix) * tangent); \n" +
" vec3 B = cross(N, T); \n" +
//" vs_out.L = light_pos - P.xyz; \n" +
" vec3 Light = mat3(mvMatrix) * light_pos - P.xyz;\n" +
" vs_out.L = normalize(vec3(dot(Light, T), dot(Light, B), dot(Light, N))); \n" +
" \n" +
" vec3 View = -P.xyz; \n" +
" vs_out.V = normalize(vec3(dot(View, T), dot(View, B), dot(View, N))); \n" +
" \n" +
" vs_out.UV = tc_in; \n" +
" \n" +
" gl_Position = proMatrix * P; \n" +
"}"
FS代码:
"#version 430 \n" +
"layout (binding = 0) uniform sampler2D tex_color; \n" +
"layout (binding = 1) uniform sampler2D tex_normal; \n" +
"out vec4 color; \n" +
" \n" +
"in VS_OUT \n" +
"{ \n" +
" vec2 UV; \n" +
" vec3 L; \n" +
" vec3 V; \n" +
"} fs_in; \n" +
" \n" +
"void main(void) \n" +
"{ \n" +
//" vec3 ambient = texture(tex_color, fs_in.UV).xyz * 0.2; \n" +
" vec3 diffuse_albedo = texture(tex_color, fs_in.UV).rgb; \n" +
" vec3 specular_albedo = vec3(0.7); \n" +
" float specular_power = 128.0; \n" +
" \n" +
" vec3 N = normalize(texture(tex_normal, fs_in.UV).rgb * 2.0 - vec3(1.0)); \n" +
" vec3 L = fs_in.L; \n" +
" vec3 V = fs_in.V; \n" +
" vec3 R = reflect(-L, N); \n" +
" \n" +
" vec3 diffuse = max(dot(N, L), 0.0) * diffuse_albedo; \n" +
" vec3 specular = pow(max(dot(R, V), 0.0), specular_power) * specular_albedo; \n" +
" \n" +
" color = vec4(diffuse, 1.0);\n" + //ambient + + specular
//" color = vec4(texture(tex_color, fs_in.UV).rgb * 0.6, 1.0);\n" +
"}"
绘图命令:
gl.glActiveTexture(GL4.GL_TEXTURE0);
texture.bind(gl);
gl.glActiveTexture(GL4.GL_TEXTURE1);
bumpTexture.bind(gl);
gl.glBindVertexArray(vaoBuff.get(0));
gl.glMultiDrawElementsIndirect(...);
修正了一个正常的地图图像。什么是高度图用于?我在photoshop中看到两个选项,生成法线贴图,另一个是生成凹凸贴图。生成的凹凸贴图与高度贴图非常相似。 – Oscar
高度图通常用于实际更改几何图形的位移贴图。法线贴图使用法线贴图,因为它需要更少的纹理样本。还有一些非常先进的技术,例如视差映射或视差遮挡映射。 –