| 1 |
R"XXX(// #version 300 es (already in the included header) |
| 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 |
// This file will be merged with shadow-calculation.f.glsl |
| 8 |
|
| 9 |
out lowp vec4 color; |
| 10 |
|
| 11 |
uniform lowp vec3 light_color; |
| 12 |
uniform mediump float light_ambient, light_diffuse, light_specular; |
| 13 |
//uniform highp vec3 light_direction; // already in #include |
| 14 |
|
| 15 |
uniform highp vec3 cam_position; |
| 16 |
uniform lowp float materialSpecular; // [0,1] |
| 17 |
|
| 18 |
// JLBC: Was "struct" Frag .... but that requires #version 320 es. Let's keep it minimum. |
| 19 |
in highp vec3 frag_position, frag_normal; |
| 20 |
in lowp vec4 frag_materialColor; |
| 21 |
in highp vec4 frag_posLightSpace; |
| 22 |
|
| 23 |
void main() |
| 24 |
{ |
| 25 |
// diffuse lighting |
| 26 |
mediump vec3 normal = normalize(frag_normal); |
| 27 |
mediump float diff = max(dot(normal, -light_direction), 0.0f); |
| 28 |
mediump float diffuse_factor = diff * light_diffuse; |
| 29 |
|
| 30 |
// specular lighting |
| 31 |
highp vec3 cam2frag = cam_position - frag_position; |
| 32 |
mediump float cam2fragDist = length(cam2frag); |
| 33 |
highp vec3 viewDirection = normalize(cam2frag); |
| 34 |
highp vec3 reflectionDirection = reflect(light_direction, normal); |
| 35 |
mediump float specAmount = pow(max(dot(viewDirection, reflectionDirection), 0.0f), 16.0f); |
| 36 |
mediump float specular = specAmount * materialSpecular; |
| 37 |
mediump float specular_factor = specAmount * materialSpecular * light_specular; |
| 38 |
|
| 39 |
// calculate shadow |
| 40 |
mediump float shadow = ShadowCalculation(frag_posLightSpace, normal, cam2fragDist); |
| 41 |
mediump vec3 finalLight = (light_ambient + (1.0-shadow)*(diffuse_factor+specular_factor))*light_color; |
| 42 |
|
| 43 |
color = vec4(frag_materialColor.rgb * finalLight, frag_materialColor.a); |
| 44 |
} |
| 45 |
)XXX" |