c++ - GLSL 的第二个网格具有奇怪的黑色面
问题描述
平台:Windows10 上下文:OpenGL、glew、Win32
所以我加载了 2 个网格(使用一个简单的 OBJ 解析器,它只读取三角网格),带有顶点、紫外线和法线数据。第一个网格点亮正常。没有黑脸。第二个看起来像这样。 奇怪的影响
- 我的顶点着色器:
#version 440
in vec3 pos;
in vec2 tex;
in vec3 nor;
uniform float Scale;
uniform mat4 perspective;
uniform mat4 model;
out vec3 normaldir;
out vec2 texOut;
out vec3 FragPos;
void main()
{
normaldir = normalize(mat3(transpose(inverse(model))) * nor);
gl_Position = perspective * model * vec4(pos.xyz, 1.0);
texOut = tex;
FragPos = vec3(model * vec4(pos, 1.0));
}
- 我的片段着色器:
#version 440
uniform float Scale;
uniform sampler2D diffuse;
uniform sampler2D normal;
uniform vec3 viewPos;
//uniform sampler2D normalMap0;
in vec3 normaldir;
in vec2 texOut;
in vec3 FragPos;
layout(location = 0) out vec4 FragColor0;
void main()
{
vec3 lightPos = {2,6,0};
lightPos.x = sin(Scale)*5;
lightPos.z = cos(Scale)*5;
vec3 lightDir = normalize(lightPos - FragPos);
vec3 lightColor = {1.0,1.0,1.0};
float specularStrength = 1.6;
float diff = max(dot(normaldir, lightDir), 0.0);
vec3 diffuseD = diff * lightColor;
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, normaldir);
vec3 ambient = {0.0,0.2,0.4};
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 25);
vec3 specular = specularStrength * spec * lightColor;
vec3 diffuseCol = texture(diffuse, texOut).xyz;
vec3 result = (ambient + diffuseD+ specular) * diffuseCol;
FragColor0 = vec4(result, 1.0);
}
解决方案
对不起,我犯了一个非常愚蠢的错误。感谢您对@Rabbid76 的所有支持(是的,我确实颠倒了法线是的)@paddy
问题是绑定普通缓冲区。我绑定glm::vec2 * size
而不是glm::vec3 * size
法线缓冲区
推荐阅读
- javascript - PowerBI Embedded - 如何自定义菜单操作/上下文和自定义布局
- css - SVG 图像未显示在 ios 设备中
- c# - 如何在 Excel 中使用 C# 有效地比较连续行和连续行?
- gremlin - 如何进入/退出带有可读标签的节点的生成树以响应gremlin?
- flutter - 使用颤振对 google api(日历)进行身份验证
- javascript - 循环分配然后中断
- filter - 如何在列中的字符串中查找_并在SAS中删除_
- django - JSON 与 PostgreSQL 中的表
- azure - Azure 数据流创建/管理身份关系的密钥
- javascript - Discord JS,等待消息,不同的输入