| 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 |
uniform highp vec3 cam_position; |
| 12 |
uniform lowp float materialSpecular; |
| 13 |
|
| 14 |
in highp vec3 frag_position, frag_normal; |
| 15 |
in lowp vec4 frag_materialColor; |
| 16 |
|
| 17 |
out lowp vec4 color; |
| 18 |
|
| 19 |
void main() |
| 20 |
{ |
| 21 |
// diffuse lighting |
| 22 |
highp vec3 normal = normalize(frag_normal); |
| 23 |
highp float diff = max(dot(normal, -light_direction), 0.0f); |
| 24 |
highp float diffuse_factor = diff * light_diffuse; |
| 25 |
|
| 26 |
// specular lighting |
| 27 |
highp vec3 viewDirection = normalize(cam_position - frag_position); |
| 28 |
highp vec3 reflectionDirection = reflect(light_direction, normal); |
| 29 |
highp float specAmount = pow(max(dot(viewDirection, reflectionDirection), 0.0f), 16.0f); |
| 30 |
mediump float specular_factor = specAmount * materialSpecular * light_specular; |
| 31 |
|
| 32 |
mediump vec3 finalLight = (light_ambient + (diffuse_factor+specular_factor))*light_color; |
| 33 |
|
| 34 |
color = vec4(frag_materialColor.rgb * finalLight, frag_materialColor.a); |
| 35 |
} |
| 36 |
)XXX" |