나는 C (0, 0, 0)을 중심으로하는 구를 가지고 있습니다. 지금은 버텍스 쉐이더 내부의 정상을 계산합니다. 나는 그것을 그것에 전달하지 않는다.조명이 왜 잘못 되었습니까?
#version 330
layout(location = 0) in vec3 in_Position; //declare position
layout(location = 1) in vec3 in_Color;
// mvpmatrix is the result of multiplying the model, view, and projection matrices */
uniform mat4 MVP_matrix;
vec3 constant_col;
vec3 normal_pos,normal_light_pos;
vec3 Light_Pos = vec3(3.0f, 2.0f, 4.0f); //Light Source
float light_magn,norm_magn;
float dot_prod;
float angle;
float Light_in;
out vec3 ex_Color;
void main(void) {
// Multiply the MVP_ matrix by the vertex to obtain our final vertex position (mvp was created in *.cpp)
gl_Position = MVP_matrix * vec4(in_Position, 1.0);
//normalizing vectors
normal_pos = normalize(in_Position);
normal_light_pos = normalize(Light_Pos);
//calculating the vector's magnitude
light_magn = sqrt(pow(normal_light_pos.x,2) + pow(normal_light_pos.y,2) + pow(normal_light_pos.z,2));
norm_magn = sqrt(pow(normal_pos.x,2) + pow(normal_pos.y,2) + pow(normal_pos.z,2));
dot_prod = dot(normal_light_pos, normal_pos); //getting the dot product
angle = dot_prod/ (light_magn*norm_magn); //getting angle in radians
angle = clamp(angle, 0, 1);
Light_in = cos(angle); // here I calculate the light intensity
constant_col = vec3(1.0f,0.0f,0.0f); //set the sphere's color to red
ex_Color = constant_col * Light_in ; //for sphere
}
내 코드가 산란 방사 코사인 규칙에 따라 기본적으로 여기에서있다
: 이
이 문제를 해결할 수 있을지는 확실하지 않지만 내적 길이가 A *의 길이로 정의되고 벡터의 길이가 벡터 사이의 각도의 코사인이고 A와 B가 1 인 경우 ' dot_prod'와'Light_in'은 같은 값이어야하고 많은 계산을 줄일 수 있습니다. – slugonamission
구체적으로 무엇이 잘못 되었습니까? 중심의 날카로운 주요 사건을 제외하고, 나머지는 ok로 보인다. – NickLH
셰이더에서 법선을 "계산"하는 것이 아닙니다. 표면 점 위치에서 법선을 추론 할 수있는 유일한 모양이 있으며, 그 점은 원점 주변의 구입니다. 다른 모든 도형의 경우 로컬 꼭지점 위치에서 결정할 수 없으므로 normal을 명시 적으로 지정해야합니다 (일부 트릭에서는 프래그먼트 셰이더에서 패싯 normal을 추출 할 수 있지만 결과는 좋지 않습니다). 셰이더에서 법선을 전혀 계산하지 마십시오. 그것은 무의미합니다. – datenwolf