가 여기 내 쉐이더 프로그램 쉐이더 프로그램 오작동 :조명
는#version 330 core
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexNormal_modelspace;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 M;
uniform mat3 blNormalMatrix;
uniform vec3 lightPos;
out vec4 forFragColor;
const vec3 diffuseColor = vec3(0.55, 0.09, 0.09);
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
vec3 MaterialAmbientColor = vec3(0.1,0.1,0.1) * diffuseColor;
// all following gemetric computations are performed in the
// camera coordinate system (aka eye coordinates)
vec3 vertexNormal_cameraspace = (V*M*vec4(vertexNormal_modelspace,0)).xyz;
vec4 vertexPosition_cameraspace4 = V*M* vec4(vertexPosition_modelspace,1);
vec3 vertexPosition_cameraspace = vec3(vertexPosition_cameraspace4).xyz;
vec3 lightDir = normalize(lightPos - vertexPosition_cameraspace);
float lambertian = clamp(dot(lightDir,vertexNormal_cameraspace), 0.0,1.0);
forFragColor = vec4(lambertian*diffuseColor , 1.0);
}
내 문제는 이것이 기존의 OpenGL을 프로필에 "일"이다, 심지어 버전 번호가 없었어요, 나는 주위에 생각 OpenGL 2.1 또는 그 주요 변경 사항은 원래 정상적으로 = gl_normalMatrix * gl_normal이었고 모든 것이 효과가있었습니다. 나는 3.3 이상 핵심 프로필 업데이트되었습니다 어쩌면 지금이 왼쪽하고 사용되지 않는 기능을 고정 후 교수님의 코드에 기반하지만
:
https://drive.google.com/file/d/0B6oLZ_d7S-U7cVpkUXpVXzdaZEk/edit?usp=sharing이의 동영상 링크 내 프로그램의 동작.
광원은 움직이지 않아야하는 (0,0,3) 지점 광이어야합니다. 하지만 특히 논리적 인 행동 패턴을 따르지 않는 경우, 나는 그것을 이해할 수 없습니다.
모델 행렬의 역행렬을 전달하여 대체 normalMatrix로 사용하려고 시도했지만 내 법선을 파멸 시켰습니다. 그래서 나는 모른다.
이
내 normalMatrix이었다glm::mat3 MyNormalMatrix = glm::mat3(glm::transpose(glm::inverse(ModelMatrix)));
편집 : 여기 내 디스플레이 코드 : 문제는 궁극적으로 내 교수에 의해 제공되는 모델 로더에 문제가 밝혀졌다
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
// Use our shader
glUseProgram(programID);
// Get our transformations iff we move the camera around.
glm::mat4 MyModelMatrix = ModelMatrix * thisTran * ThisRot;
MVP = ProjectionMatrix * ViewMatrix * MyModelMatrix;
glm::mat4 ModelView = ViewMatrix * MyModelMatrix;
glm::mat3 MyNormalMatrix = glm::mat3(glm::transpose(glm::inverse(ModelView)));
glm::vec3 newLightPos = lightPos;
// Send our transformation to the currently bound shader,
// in the "MVP" uniform
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &MyModelMatrix[0][0]);
glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]);
glUniformMatrix4fv(BlNormalMatrix,1,GL_FALSE, &MyNormalMatrix[0][0]);
glUniformMatrix4fv(BlRotations, 1, GL_FALSE, &ThisRot[0][0]);
glUniform3f(BlCamera, cameraLoc.x, cameraLoc.y, cameraLoc.z);
glUniform3f(lPosition, newLightPos.x,newLightPos.y,newLightPos.z);
// VBO buffer: vertices
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 2rd attribute buffer : normals
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
glVertexAttribPointer(
1, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// draw object using opengl 3.3 shit
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
. 당신은 정점 셰이더의 모델 뷰 매트릭스에 의한 정점의 곱셈과 프래그먼트 셰이더의 lightinh 계산과 같은 작업을 수행해야합니다. –
왜 셰이더 조각에 불이 들어 옵니까? 꼭 필요한가 아니면 버텍스 쉐이더에서 할 수 있습니까? 예전의 OpenGL에서 본 대부분의 예제는 버텍스 쉐이더에 모든 것을 넣었으므로 문제가 어떻게 발생하는지 확신 할 수 없습니다. – RaenirSalazar