OpenGl中的着色器代码不正确。我错过了什么?

时间:2015-05-02 19:43:47

标签: c++ opengl opengl-es glsl

大家好,我的着色器片段和顶点有很多问题。我不确定我真正想念的是什么,任何帮助都会很棒。到目前为止我的代码我得到了这个! https://www.dropbox.com/s/7qgl6h2d3p3klu0/Screenshot%202015-05-02%2015.02.50.png?dl=0

但它假设看起来像这样,我错过了什么? https://www.dropbox.com/s/uy6093tbdtmcdux/Screenshot1.jpg?dl=0

这是我的代码片段代码:

#version 150

in vec3 fN;
in vec3 fL;

in vec3 fE;             // NEW!  Coming in from the vertex shader

out vec4 fColor;

void main () {
vec3 N = normalize(fN);
vec3 L = normalize(fL);

vec3 E = normalize(-fE);    // NEW! Reverse E
vec3 H = normalize(L + E);  // NEW! Create the half vector  

// Diffuse component
float diffuse_intensity = max(dot(N, L), 100);
vec4 diffuse_final = diffuse_intensity*vec4(0.0, 0.0, 2.8, 2.0);
// NEW! Specular component
float spec_intensity = pow(max(dot(H, L), -1.5), 60);
vec4 spec_final = spec_intensity+vec4(0.0, 0.0, 2.8, 2.0);

fColor = diffuse_final + spec_final;
 }

这是我的顶点代码:

 #version 150

 // Combined our old stuff with the shader from Angel book

 in vec4 vPosition;
 in vec4 vNormal;
 uniform mat4 mM;       // The matrix for the pose of the model
 uniform mat4 mV;       // The matrix for the pose of the camera
 uniform mat4 mP;       // The perspective matrix
 uniform mat4 mR;       // The rotation matrix

 uniform vec4 lightPosition;    //

 out vec3 fN;           
 out vec3 fL;

 out vec3 fE;


void main () {

fN = (mR*vNormal).xyz; //Rotate the normal! only take the first 3 parts, since fN is a vec3
fE = (mV*mM*vPosition).xyz;
fL = (lightPosition).xyz;       // In world space
gl_Position = mP*mV*mM*vPosition;
}

0 个答案:

没有答案