• API
• FAQ
• Tools
• Archive
daily pastebin goal
1%
SHARE
TWEET

# Untitled

a guest Jan 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #version 330
2.
3. uniform sampler2D tex; // the texture containing the diffuse material parameter k_d
4.
5. #define MAX_LIGHT_COUNT 16
6. uniform int light_count;                        // the number of lights (always smaller than MAX_LIGHT_COUNT
7. uniform vec3 light_world_pos[MAX_LIGHT_COUNT];  // the position of the lights in world space
8. uniform vec3 light_intensity[MAX_LIGHT_COUNT];  // the intensity of the lights
9.
10. uniform vec3 k_s; // the specular material parameter
11. uniform float n;  // phong exponent of the material
12.
13. uniform vec3 cam_world_pos; // the camera position in world space
14.
15. in vec3 world_position;            // the (interpolated) world space position corresponding to the fragment
16. in vec3 world_normal_interpolated; // the (interpolated) world space normal
17. in vec2 tex_coord;                 // the (interpolated) uv coordinate
18.
19. out vec4 frag_color; // the resulting color value (will be written into the framebuffer)
20.
21. void
22. main()
23. {
24.     vec3 k_d = vec3(texture(tex,tex_coord));
25.     // according the the phong illumination model on the exercise sheet
26.     vec3 contribution = vec3(0.f);
27.     for (int i = 0; i < light_count; ++i)
28.     {
29.         vec3 L = normalize(light_world_pos[i] - world_position);
30.         vec3 N = normalize(world_normal_interpolated);
31.         vec3 R = reflect(normalize(world_position - cam_world_pos),N);
32.         float NdotL = dot(N,L);
33.         float RdotL = dot(R,L);
34.         float eA = (pow(length(world_position - light_world_pos[i]), 2.f));
35.         vec3 diffuse  = (k_d * max(0.f, NdotL));
36.         vec3 specular = (k_s * pow((max(0.f,RdotL)),n));
37.         vec3 material =  diffuse + specular;
38.         vec3 lighting = light_intensity[i]/eA;
39.         contribution += material * lighting;
40.     }
41.
42.     frag_color = vec4(contribution,1);
43.
44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top