태그 보관물: opengl

opengl

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

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

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

먼저:

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

둘째:

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

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

#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);
}

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

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



답변

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

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

그래, 나에게 잘 보인다.

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

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

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

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

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

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

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


답변