Debian Codegraph @

libs/opengl/shaders/textured-triangles-light.f.glsl

raw
1 R"XXX(#version 300 es
2
3 // FRAGMENT SHADER: Default shader for MRPT CRenderizable objects
4 // Jose Luis Blanco Claraco (C) 2019-2023
5 // Part of the MRPT project
6
7 uniform lowp vec3 light_color;
8 uniform mediump float light_ambient, light_diffuse, light_specular;
9 uniform highp vec3 light_direction;
10
11
12 uniform lowp sampler2D textureSampler;
13 uniform highp vec3 cam_position;
14 uniform lowp float materialSpecular;
15
16 in highp vec3 frag_position, frag_normal;
17 in mediump vec2 frag_UV; // Interpolated values from the vertex shaders
18
19 out lowp vec4 color;
20
21 void main()
22 {
23 // diffuse lighting
24 mediump vec3 normal = normalize(frag_normal);
25 mediump float diff = max(dot(normal, -light_direction), 0.0);
26 mediump float diffuse_factor = diff * light_diffuse;
27
28 // specular lighting
29 highp vec3 viewDirection = normalize(cam_position - frag_position);
30 highp vec3 reflectionDirection = reflect(light_direction, normal);
31 mediump float specAmount = pow(max(dot(viewDirection, reflectionDirection), 0.0f), 16.0f);
32 mediump float specular_factor = specAmount * materialSpecular * light_specular;
33
34 // material texture color:
35 lowp vec4 texCol = texture(textureSampler,frag_UV);
36 mediump vec3 finalLight = (light_ambient + (diffuse_factor+specular_factor))*light_color;
37
38 color = vec4(texCol.rgb * finalLight, texCol.a);
39 }
40
41 )XXX"