| 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 |
uniform lowp sampler2D textureSampler; |
| 19 |
|
| 20 |
in highp vec3 frag_position, frag_normal; |
| 21 |
in mediump vec2 frag_UV; // Interpolated UV texture coords |
| 22 |
in highp vec4 frag_posLightSpace; |
| 23 |
|
| 24 |
|
| 25 |
void main() |
| 26 |
{ |
| 27 |
// diffuse lighting |
| 28 |
mediump vec3 normal = normalize(frag_normal); |
| 29 |
mediump float diff = max(dot(normal, -light_direction), 0.0f); |
| 30 |
mediump float diffuse_factor = diff * light_diffuse; |
| 31 |
|
| 32 |
// specular lighting |
| 33 |
highp vec3 cam2frag = cam_position - frag_position; |
| 34 |
mediump float cam2fragDist = length(cam2frag); |
| 35 |
highp vec3 viewDirection = normalize(cam2frag); |
| 36 |
highp vec3 reflectionDirection = reflect(light_direction, normal); |
| 37 |
mediump float specAmount = pow(max(dot(viewDirection, reflectionDirection), 0.0f), 16.0f); |
| 38 |
mediump float specular = specAmount * materialSpecular; |
| 39 |
mediump float specular_factor = specAmount * materialSpecular * light_specular; |
| 40 |
|
| 41 |
// calculate shadow |
| 42 |
mediump float shadow = ShadowCalculation(frag_posLightSpace, normal, cam2fragDist); |
| 43 |
mediump vec3 finalLight = (light_ambient + (1.0 - shadow)*(diffuse_factor+specular_factor))*light_color; |
| 44 |
|
| 45 |
// material texture color: |
| 46 |
lowp vec4 texCol = texture(textureSampler,frag_UV); |
| 47 |
|
| 48 |
color = vec4(texCol.rgb * finalLight, texCol.a); |
| 49 |
} |
| 50 |
)XXX" |