Changing rimlight shader math to achieve a specific look

I’ve adapted this fresnel rimlight shader I found a while ago in this forum.

For my use case it would look better if the rimlight was independent from the view angle, i. e. at a fixed angle and sharp falloff, no matter where the object is located on the screen. The correct implementation gets too extreme at some angles, it washes out the colors of my objects, and it looks as if the light is coming from the center of the screen, when I actually want it to come from an large distance far behind the scene. It should always look like it does on the left sphere, never like the one on the right side.

I’ve tried to change the calculation to achieve this. For example, I made the vEye vector a constant, besides many other ideas (mostly guesswork tbh). To my shame, I failed miserably at making it work. So I’m hoping one of you wizards can help me out here with the math!

https://jsfiddle.net/z1vqe947/

1 Like

https://jsfiddle.net/rfxv01kp/8/
?

4 Likes

My man! Thanks, this is also much easier to tweak.

Before:

After:

1 Like

Far from perfect, but much simpler (no shader torturing):

https://codepen.io/boytchev/full/LEVLVOd

image

2 Likes

Nice, Pavel, thank you. I have lots of shader customizations based on PhongMaterial though, so changing to PhysicalMaterial would be a pain. And I would imagine some performance loss as well.

2 Likes

Yet another option of how to compute the values:

        shader.vertexShader = shader.vertexShader.replace(
            '#include <fog_vertex>',
            `
            #include <fog_vertex>

            vViewDir = normalize(-(modelViewMatrix * vec4(position, 1.0)).xyz);
            vNormalW = normalize(normalMatrix * normal);
            `
        );
1 Like