Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: How to implement a shader to create highlights/shadows?

  1. #1
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    15

    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...aster/shaders/) but i can't find the equivalent for the shadows

    Code :
    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);
    }

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,421
    Quote Originally Posted by loki5100 View Post
    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
    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)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •