정상적인 매핑 문제가 있습니다. ASSIMP 라이브러리를 통해로드 된 각 모델에 텍스처와 일반 텍스처가 있습니다. 나는 ASSIMP 라이브러리의 도움으로 각 객체의 접선 벡터를 계산할 것이므로 이것들이 잘되어야한다. 객체는 일반 매핑을 사용하여 완벽하게 작동하지만 객체 중 하나를 번역하기 시작하면 (즉, 변형 된 모델 행렬에 영향을 미침) 조명이 실패합니다. 이미지에서 볼 수 있듯이 바닥 (y 축 아래로 이동)은 확산 조명의 대부분을 잃어버린 듯하며 반사 조명이 잘못된 방향입니다 (전구와 플레이어 위치 사이에 있어야합니다).정상적인 매핑과 변환으로 인해 조명이 깨집니다.
정상적인 매트릭스와 관련이있을 수 있지만 (번역은 손실되어야 함) 셰이더에 잘못된 매트릭스가 사용 된 것일 수 있습니다. 나는 아이디어가 부족하여 문제에 대한 통찰력을 얻을 수 있기를 바랍니다.
버텍스 쉐이더 :
#version 330
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec3 tangent;
layout(location = 3) in vec3 color;
layout(location = 4) in vec2 texCoord;
// fragment pass through
out vec3 Position;
out vec3 Normal;
out vec3 Tangent;
out vec3 Color;
out vec2 TexCoord;
out vec3 TangentSurface2Light;
out vec3 TangentSurface2View;
uniform vec3 lightPos;
uniform vec3 playerPos;
// vertex transformation
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
mat3 normalMatrix = mat3(transpose(inverse(model)));
Position = vec3(model * vec4(position, 1.0));
Normal = normalMatrix * normal;
Tangent = tangent;
Color = color;
TexCoord = texCoord;
gl_Position = projection * view * model * vec4(position, 1.0);
// Calculate tangent matrix and calculate fragment bump mapping coord space.
vec3 light = lightPos;
vec3 n = normalize(normalMatrix * normal);
vec3 t = normalize(normalMatrix * tangent);
vec3 b = cross(n, t);
// create matrix for tangent (from vertex to tangent-space)
mat3 mat = mat3(t.x, b.x ,n.x, t.y, b.y ,n.y, t.z, b.z ,n.z);
vec3 vector = normalize(light - Position);
TangentSurface2Light = mat * vector;
vector = normalize(playerPos - Position);
TangentSurface2View = mat * vector;
}
조각 쉐이더
#version 330
in vec3 Position;
in vec3 Normal;
in vec3 Tangent;
in vec3 Color;
in vec2 TexCoord;
in vec3 TangentSurface2Light;
in vec3 TangentSurface2View;
out vec4 outColor;
uniform vec3 lightPos;
uniform vec3 playerPos;
uniform mat4 view;
uniform sampler2D texture0;
uniform sampler2D texture_normal; // normal
uniform float repeatFactor = 1;
void main()
{
vec4 texColor = texture(texture0, TexCoord * repeatFactor);
vec4 matColor = vec4(Color, 1.0);
vec3 light = vec3(vec4(lightPos, 1.0));
float dist = length(light - Position);
// float att = 1.0/(1.0 + 0.01 * dist + 0.001 * dist * dist);
float att = 1.0;
// Ambient
vec4 ambient = vec4(0.2);
// Diffuse
// vec3 surface2light = normalize(light - Position);
vec3 surface2light = normalize(TangentSurface2Light);
// vec3 norm = normalize(Normal);
vec3 norm = normalize(texture(texture_normal, TexCoord * repeatFactor).xyz * 2.0 - 1.0);
float contribution = max(dot(norm, surface2light), 0.0);
vec4 diffuse = contribution * vec4(0.6);
// Specular
// vec3 surf2view = normalize(-Position); // Player is always at position 0
vec3 surf2view = normalize(TangentSurface2View);
vec3 reflection = reflect(-surface2light, norm); // reflection vector
float specContribution = pow(max(dot(surf2view, reflection), 0.0), 32);
vec4 specular = vec4(1.0) * specContribution;
outColor = (ambient + (diffuse * att)+ (specular * pow(att, 3))) * texColor;
// outColor = vec4(Color, 1.0) * texture(texture0, TexCoord);
}
편집
대신 세계와 카메라 공간 사이 pingponging의 세계 공간에서 모든 것을 (쉽게 계산하는 쉐이더 코드를 편집 이해하기 쉽고 오류가 발생하기 쉽지 않음).
** 물어볼 곳이 잘못되었습니다. ** 극도로 행운이 없다면 아마 답을 얻지 못할 것입니다. http://gamedev.stackexchange.com 또는 http://www.gamedev.net에 문의하십시오. –
@ TheOtherGuy : 제안에 감사드립니다.나는 거기에 게시하려고 시도 할 것입니다. 왜냐하면이 게임은 밀접하게 관련되어 있기 때문에 아마도 더 많은 행운을 가질 것입니다. –
좋아, 행운을 빈다! –