퐁 조명-스페 큘러 조명에는 매우 이상한 것이 있습니다


17

퐁 조명을 구현했습니다. 모든 것이 작동하는 것처럼 보입니다. 원환 체와 구가 예상대로 조명됩니다. 그러나 방향성 빛의 반사 조명과 관련하여 이상한 점이 있습니다.

다음은 두 개의 스크린 샷입니다.

먼저:

여기에 이미지 설명을 입력하십시오

둘째:

여기에 이미지 설명을 입력하십시오

보시다시피 카메라가 물체에서 멀리 떨어져있을 때 더 많은 영역에 반사 조명이 있습니다.

단순화 된 버텍스 쉐이더는 다음과 같습니다.

#version 330 core

layout(location = 0) in vec3 vertexPos;
layout(location = 1) in vec3 vertexNorm;
layout(location = 2) in vec2 vertexUV;

uniform mat4 MVP;
uniform mat4 M;

out vec2 fragmentUV;
out vec3 fragmentNormal;
out vec3 fragmentPos;

void main() {
  fragmentUV = vertexUV;
  fragmentNormal = (M * vec4(vertexNorm, 0)).xyz;
  fragmentPos = (M * vec4(vertexPos, 1)).xyz;

  gl_Position = MVP * vec4(vertexPos, 1);
}

... 및 조각 쉐이더 :

#version 330 core

in vec2 fragmentUV;
in vec3 fragmentNormal;
in vec3 fragmentPos;

struct DirectionalLight {
  vec3 Color;
  vec3 Direction;
  float AmbientIntensity;
  float DiffuseIntensity;
};

uniform sampler2D textureSampler;
uniform vec3 cameraPos;
uniform float materialSpecularFactor;
uniform float materialSpecularIntensity;
uniform DirectionalLight directionalLight;

out vec4 color;

void main() {
  vec3 normal = normalize(fragmentNormal); // should be normalized after interpolation

  vec4 ambientColor = vec4(directionalLight.Color, 1) * directionalLight.AmbientIntensity;

  float diffuseFactor = clamp(dot(normal, -directionalLight.Direction), 0, 1);
  vec4 diffuseColor = vec4(directionalLight.Color, 1) * directionalLight.DiffuseIntensity * diffuseFactor;

  vec3 vertexToCamera = normalize(cameraPos - fragmentPos);
  vec3 lightReflect = normalize(reflect(directionalLight.Direction, normal));
  float specularFactor = pow(clamp(dot(vertexToCamera, lightReflect), 0, 1), materialSpecularFactor);
  vec4 specularColor = vec4(directionalLight.Color, 1) * materialSpecularIntensity * specularFactor;

  color = texture(textureSampler, fragmentUV) * (ambientColor + diffuseColor + specularColor);
}

단순화없이 전체 소스 코드 를이 저장소에서 찾을 수 있습니다 .

내가 잘못 구현했는지 알고 싶었다. 아니면 퐁 조명에도 괜찮습니까?


2
이 질문에 대한 더 나은 답변을 얻을 수있는 컴퓨터 그래픽 스택이 있습니다.
— Andrew Wilson

답변:


34

디렉 셔널 라이트의 스페 큘러 라이팅

카메라가 물체에서 멀리 떨어져있을 때 더 많은 영역에 정반사 조명이 있습니다

그래, 나에게 잘 보인다.

방향성 조명의 반사 영역은 동일한 반사 표면을 고려할 때 카메라에서 다소 일정해야합니다. 비교해 보면 , 기본적으로 sunglint 라고하는 현상을 볼 수 있는데 , 이것은 기본적으로 물에 태양을 반사하는 반사이며 태양은 거의 지상의 목적을위한 지향성 광원이고, 반사 표면은 대략 평평한 지구입니다. 이것은 Phong 조명의 좋은 아날로그입니다.

실시 예 1 : 주거용 부지와 대략 동일한 선글 립의 영역

호수 위에 Sunglint

http://academic.emporia.edu/aberjame/remote/lec10/lec10.htm

예 2 : 대호에 근접한 선글 린트 영역

오대호 위의 Sunglint

http://earthobservatory.nasa.gov/IOTD/view.php?id=78617

사실, 햇빛이 번지는 부분은 지구에서 멀어 질 때까지 계속해서 넓어지고 평평한 곳보다 더 둥글게됩니다.

Phong 반사 모델의 관점에서, 정반사는 세 가지 방향, 즉 눈, 빛 및 표면에 의존합니다. 카메라가 같은 표면을 바라보고 있기 때문에 그냥 움직이면 눈은 그대로 유지됩니다. 표면은 평평하기 때문에 동일하게 유지되고, 빛은 정의에 의해 동일하게 유지되므로 (직향 광임), 거울 반사는 물론 카메라 / 스크린의 관점에서 동일 할 것입니다.


1
프로그래밍 질문에 대한 실제 예제 답변을 좋아하십시오
— defhlt

젠장, 당신은 그냥 공감하기 위해 계정을 만들었습니다.
— Spongman
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.