Question about inner glow shader

I have found this nice project! link
It is very cool! I do not understand the inner glow vertex shader the author use.
Why need reflect function and why need r.z + 1?
``

    void main()
    {
        vUv = uv;

        vec4 p = vec4( position, 1. );

		  vec3 e = normalize( vec3( modelViewMatrix * p ) );
		  vec3 n = normalize( normalMatrix * normal );

		  vec3 r = reflect( e, n );
		  float m = 2. * sqrt(
		    pow( r.x, 2. ) +
		    pow( r.y, 2. ) +
		    pow( r.z + 1., 2. )
		  );
		  vN = r.xy / m + .5;


        gl_Position =   projectionMatrix *
                        modelViewMatrix *
                        vec4(position,1.0);
    }

``

@chenxiaoleizi
Hi!
Just out of curiousity, what your solution would be in this case?

I just use the n for r.
img
And got the similar result.
im1

But when zoomed in, the inner glow becomes thin !

And what result do you expect?

The expected result is to use this texture in a sphere to simulate the planet’s inner glow.

I do not understand why the author uses the reflect function?

it is probably just in-house matcap shader. you can try THREE.MatcapMeshMaterial instead

why the author uses the reflect function?

turns out it was borrowed from Creating a Spherical Environment Mapping shader - Blog - Clicktorelease - and it is explained there

p.s. you can probably skip the entire reflect part and do r = n; m = 2.0;

2 Likes

Thanks! That is really helpful!