Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #shader vertex
- #version 330 core
- layout(location = 0) in vec4 in_position;
- layout(location = 2) in vec3 in_normal;
- out vec3 i_normal;
- out vec4 i_pos;
- uniform mat4 uni_model;
- uniform mat4 uni_view;
- uniform mat4 uni_projection;
- void main()
- {
- gl_Position = uni_projection * uni_view * uni_model * in_position;
- i_normal = in_normal;
- i_pos = uni_model * in_position;
- }
- #shader end
- #shader fragment
- #version 330 core
- in vec3 i_normal;
- in vec4 i_pos;
- out vec4 out_color;
- uniform vec4 uni_color = vec4(1, 0, 0, 1);
- uniform vec3 uni_lightPos = vec3(0, 0.5, 0.2);
- const vec3 lightColor = vec3(1, 1, 1);
- void main()
- {
- float ambientStrength = 0.1;
- vec3 ambient = ambientStrength * lightColor;
- vec3 norm = normalize(i_normal);
- vec3 lightDir = normalize(uni_lightPos);
- float diff = max(dot(norm, lightDir), 0.0);
- vec3 diffuse = diff * lightColor;
- vec3 result = (ambient + diffuse) * uni_color.xyz;
- out_color = vec4(result, 1.0);
- }
- #shader end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement