How to implement a shader to create highlights/shadows?

How to implement a shader to create highlights/shadows ? I found this code for the highlights part (taken from https://gitlab.bestminr.com/bestminr/FrontShaders/blob/master/shaders/) but i can’t find the equivalent for the shadows

varying vec4 coord;

uniform sampler2D texture;
uniform float highlights;

const float a = 1.357697966704323E-01;
const float b = 1.006045552016985E+00;
const float c = 4.674339906510876E-01;
const float d = 8.029414702292208E-01;
const float e = 1.127806558508491E-01;

void main() {
    vec4 color = texture2D(texture, coord.xy);
    float maxx = max(color.r, max(color.g, color.b));
    float minx = min(color.r, min(color.g, color.b));
    float lum = (maxx+minx)/2.0;
    float x1 = abs(highlights);
    float x2 = lum;
    float lum_new =  lum < 0.5 ? lum : lum+ a * sign(highlights) * exp(-0.5 * (((x1-b)/c)*((x1-b)/c) + ((x2-d)/e)*((x2-d)/e)));
    // gl_FragColor = color * lum_new / lum;
    gl_FragColor = vec4(color * lum_new / lum);
}

[QUOTE=loki5100;1291878]How to implement a shader to create highlights/shadows ?
I found this code for the highlights part … but i can’t find the equivalent for the shadows[/QUOTE]

Shadows in general aren’t just a “shader math trick”, as shading points on one object requires knowledge of other objects in the scene.

Often times this cross-object communication occurs through “occlusion textures” that are precomputed before shading the camera’s view of the scene. Though sometimes you can get away with cheats that render the occluders directly onto the scene.

Are you sure you mean shadows (i.e. one object blocking another object’s view of the light source) and not merely directional lighting effects (where surfaces facing away from the light source receive less illumination)?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.