Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Position, Incident, Normal, nt/ni
- vec4 fresnel(vec3 P,vec3 I,vec3 N,number eta)
- {
- number dNI=dot(N,I);//Compute once, use 5x
- vec3 R=I-2.0*dNI*N;//Reflected direction
- vec3 T=vec3(0.0);//Transmitted direction
- number k=1.0-eta*eta*(1.0-dNI*dNI);//Yolo
- if(k>=0.0)
- T=eta*I-(eta*dNI+sqrt(k))*N;//Swag
- number mag=dot(N,T)/dNI;//Magnification
- vec2 cd=vec2(1+mag*eta,mag+eta);//Common divisor
- vec2 r=vec2(1-mag*eta,mag-eta)/cd;//Reflected (S,P)
- vec2 t=vec2(2)/cd;//Transmitted (S,P)
- vec4 Colour_R=(r.x*r.x+r.y*r.y)*getColour(P,R);//getColour is some function that gets the colour along a ray at point P in direction R.
- if(k<0.0)
- return Colour_R;
- else
- return Colour_R+mag*eta*(t.x*t.x+t.y*t.y)*getColour(P,T);//Colour_T
- //Look maa, no trig! (Trig is a lie BTW.)
- }
Advertisement
Add Comment
Please, Sign In to add comment