Fresnel An interesting visual effect is the angle of reflection if you look at something straight on it s the least reflective as it will be however if you turn it 90 degrees so it s nearly on its edge it will be the most reflective it can be Many surfaces will become almost perfectly reflective when you view them almost edge on Instead of just using a constant reflective amount for the surface you should use the Fresnel value which determines how reflective the point should be based on the angle versus the normal so when the point is on the edge it becomes more reflective At minimum reflectivieyt will be the reflectivity of the surface and at the maximum the reflectiveity will be 100 For example given the fresnel factor f you can calculate the final color as color reflectionColor f refractionColor 1 f Schlick s Fresnel approximation R R0 1 R0 1 cos 5 for 0 90 R0 n1 n2 n1 n2 2 You can implement the algorithm using the normal and the incident vector refractive index n1 and the refractive index being entered n2 Note you could use a scaled dot product calculation to magnify values perpendicular to the view however however it s about emulating the real world accuratly comparing with measured values function sub a b return x a x b x y a y b y function add a b return x a x b x y a y b y function dist a b return Math sqrt a x b x a x b x a y b y a y b y function norm a let d Math sqrt a x a x a y a y return x a x d y a y d function len a return Math sqrt a x a x a y a y function scale a s return x a x s y a y s function dot a b return a x b x a y b y function fresnel c1 c2 i n e g color reflectionColor f refractionColor 1 f Schlicks approximation R theta R0 1 R0 1 cos theta 5 0 theta 90 R0 n1 n2 n1 n2 2 n norm n i norm i let r0 Math pow c1 c2 c1 c2 2 let cosX dot n i if c1 c2 let s c1 c2 let sinT2 s s 1 cosX cosX if sinT2 1 0 return 1 0 cosX Math sqrt 1 0 sinT2 return r0 1 r0 Math pow 1 cosX 5 console log f 0 fresnel 1 2 8 x 1 y 0 x 1 y 0 console log f 50 fresnel 1 2 8 x 1 y 0 x 1 y 1 console log f 100 fresnel 1 2 8 x 1 y 0 x 0 y 1 let i x 1 y 0 for let k 0 k 10 k let n x Math cos Math PI k 10 y Math sin Math PI k 10 let f fresnel 1 2 i n console log f var script document createElement script script src https cdn plot ly plotly 2 1 0 min js document head appendChild script document body style height 300pt let div0 document createElement div div0 id div0 document body appendChild div0 function sub a b return x a x b x y a y b y function add a b return x a x b x y a y b y function dist a b return Math sqrt a x b x a x b x a y b y a y b y function norm a let d Math sqrt a x a x a y a y return x a x d y a y d function len a return Math sqrt a x a x a y a y function scale a s return x a x s y a y s function dot a b return a x b x a y b y function fresnel c1 c2 i n ps 5 e g color reflectionColor f refractionColor 1 f Schlicks approximation R theta R0 1 R0 1 cos theta 5 0 theta 90 R0 n1 n2 n1 n2 2 n norm n i norm i let r0 Math pow c1 c2 c1 c2 2 let cosX dot n i if c1 c2 let s c1 c2 let sinT2 s s 1 cosX cosX if sinT2 1 0 return 1 0 cosX Math sqrt 1 0 sinT2 return r0 1 r0 Math pow 1 cosX ps 1 5 usually 5 is the default console log f 0 fresnel 1 2 8 x 1 y 0 x 1 y 0 console log f 50 fresnel 1 2 8 x 1 y 0 x 1 y 1 console log f 100 fresnel 1 2 8 x 1 y 0 x 0 y 1 var plot0 x y mode lines markers name dot i n var plot1 x y mode lines markers name fres power 1 var plot2 x y mode lines markers name fres power 5 let i x 1 y 0 for let k 20 k 21 k let ang 0 5 Math PI k 20 console log ang let n x Math cos ang y Math sin ang console log n let d dot i n let f fresnel 1 1 3 i n 1 let f2 fresnel 1 1 3 i n 5 plot0 x push ang plot0 y push d plot1 x push ang plot1 y push f plot2 x push ang plot2 y push f2 onload var layout width 500 height 300 plot_bgcolor rgba 0 0 0 0 paper_bgcolor rgba 0 0 0 0 margin l 20 r 10 t 10 b 20 pad 0 Plotly newPlot div0 plot0 plot1 plot2 layout console log ready
Math PI k 10 y Math sin Math PI k 10 let f fresnel 1 2 i n console log f var script document createElement script script src https cdn plot ly plotly 2 1 0 min js document head appendChild script document body style height 300pt let div0 document createElement div div0 id div0 document body appendChild div0 function sub a b return x a x b x y a y b y function add a b return x a x b x y a y b y function dist a b return Math sqrt a x b x a x b x a y b y a y b y function norm a let d Math sqrt a x a x a y a y return x a x d y a y d function len a return Math sqrt a x a x a y a y function scale a s return x a x s y a y s function dot a b return a x b x a y b y function fresnel c1 c2 i n ps 5 e g color reflectionColor f refractionColor 1 f Schlicks approximation R theta R0 1 R0 1 cos theta 5 0 theta 90 R0 n1 n2 n1 n2 2 n norm n i norm i let r0 Math pow c1 c2 c1 c2 2 let cosX dot n i if c1 c2 let s c1 c2 let sinT2 s s 1 cosX cosX if sinT2 1 0 return 1 0 cosX Math sqrt 1 0 sinT2 return r0 1 r0 Math pow 1 cosX ps 1 5 usually 5 is the default console log f 0 fresnel 1 2 8 x 1 y 0 x 1 y 0 console log f 50 fresnel 1 2 8 x 1 y 0 x 1 y 1 console log f 100 fresnel 1 2 8 x 1 y 0 x 0 y 1 var plot0 x y mode lines markers name dot i n var plot1 x y mode lines markers name fres power 1 var plot2 x y mode lines markers name fres power 5 let i x 1 y 0 for let k 20 k 21 k let ang 0 5 Math PI k 20 console log ang let n x Math cos ang y Math sin ang console log n let d dot i n let f fresnel 1 1 3 i n 1 let f2 fresnel 1 1 3 i n 5 plot0 x push ang plot0 y push d plot1 x push ang plot1 y push f plot2 x push ang plot2 y push f2 onload var layout width 500 height 300 plot_bgcolor rgba 0 0 0 0 paper_bgcolor rgba 0 0 0 0 margin l 20 r 10 t 10 b 20 pad 0 Plotly newPlot div0 plot0 plot1 plot2 layout console log ready