Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 330
- layout(location = 0) in vec3 v_position;
- layout(location = 1) in vec3 v_normal;
- layout(location = 2) in vec2 v_texture_coord;
- // Uniform properties
- uniform mat4 Model;
- uniform mat4 View;
- uniform mat4 Projection;
- // Uniforms for light properties
- uniform vec3 light_position;
- uniform vec3 eye_position;
- uniform float material_kd;
- uniform float material_ks;
- uniform int material_shininess;
- uniform vec3 object_color;
- // Output value to fragment shader
- out vec3 color;
- void main()
- {
- // TODO: compute world space vectors
- vec3 world_pos = (Model * vec4(v_position,1)).xyz;
- vec3 Npos = normalize( mat3(Model) * v_normal );
- vec3 Lpos = normalize( light_position - world_pos );
- vec3 Vpos = normalize( eye_position - world_pos );
- vec3 Hpos = normalize( Lpos + Vpos );
- // TODO: define ambient light component
- float ambient_light = 0.25;
- // TODO: compute diffuse light component
- float dotNL = dot(Npos,Lpos);
- float diffuse_light;
- diffuse_light = max(dotNL, 0);
- // TODO: compute specular light component
- float _specular_light = 0;
- if (dotNL > 0)
- {
- _specular_light = pow(dotNL, material_shininess);
- }
- float specular_light = (dotNL > 0 ? _specular_light : 0);
- float light = ambient_light + diffuse_light + specular_light;
- float look = distance(world_pos, eye_position);
- const float x = .01, y = .02, z = 1;
- float atten = 1 / (x * look * look + y * look + z);
- color = light * object_color * atten;
- gl_Position = Projection * View * Model * vec4(v_position, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement