PDA

View Full Version : Trouble with my shader code



Chaz32621
05-02-2015, 01:10 PM
Hello guys Im having alot of trouble with my shader my fragment and vertex. Im not sure what im really missing with this, Any help would be great. Also if anyone is really good with shaders I have a few more questions I can quite get. So far I have this:
1776

This is suppose to be the final output:
1777

My fragment class is:

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

And my vertex:


#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; // NEW! These go to the fragment shader for interpolation
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;
}

Any help? Im not sure what I need to add. Its bothering me so much. Also if I can be point in the right direction for these two shaders as well -

17781779