|
|
|
@ -2,12 +2,14 @@ |
|
|
|
|
|
|
|
precision mediump float; |
|
|
|
|
|
|
|
#extension GL_OES_standard_derivatives : enable |
|
|
|
|
|
|
|
// Input vertex attributes (from vertex shader) |
|
|
|
varying vec2 fragTexCoord; |
|
|
|
varying vec4 fragColor; |
|
|
|
|
|
|
|
uniform vec3 viewEye; |
|
|
|
uniform vec3 nf">viewCenter; |
|
|
|
uniform vec3 err">viewCenter; |
|
|
|
uniform float runTime; |
|
|
|
uniform vec2 resolution; |
|
|
|
|
|
|
|
@ -31,7 +33,7 @@ uniform vec2 resolution; |
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
|
// SOFTWARE. |
|
|
|
|
|
|
|
// A list of useful distance function to simple primitives, and an example on how k">to |
|
|
|
// A list of useful distance function to simple primitives, and an example on how err">to |
|
|
|
// do some interesting boolean operations, repetition and displacement. |
|
|
|
// |
|
|
|
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm |
|
|
|
@ -142,7 +144,7 @@ float sdPryamid4(vec3 p, vec3 h ) // h = { cos a, sin a, height } |
|
|
|
{ |
|
|
|
// Tetrahedron = Octahedron - Cube |
|
|
|
float box = sdBox( p - vec3(0,-2.0*h.z,0), vec3(2.0*h.z) ); |
|
|
|
|
|
|
|
|
|
|
|
float d = 0.0; |
|
|
|
d = max( d, abs( dot(p, vec3( -h.x, h.y, 0 )) )); |
|
|
|
d = max( d, abs( dot(p, vec3( h.x, h.y, 0 )) )); |
|
|
|
@ -237,7 +239,7 @@ vec2 map( in vec3 pos ) |
|
|
|
res = opU( res, vec2( 0.5*sdTorus( opTwist(pos-vec3(-2.0,0.25, 2.0)),vec2(0.20,0.05)), 46.7 ) ); |
|
|
|
res = opU( res, vec2( sdConeSection( pos-vec3( 0.0,0.35,-2.0), 0.15, 0.2, 0.1 ), 13.67 ) ); |
|
|
|
res = opU( res, vec2( sdEllipsoid( pos-vec3( 1.0,0.35,-2.0), vec3(0.15, 0.2, 0.05) ), 43.17 ) ); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
@ -245,14 +247,14 @@ vec2 castRay( in vec3 ro, in vec3 rd ) |
|
|
|
{ |
|
|
|
float tmin = 0.2; |
|
|
|
float tmax = 30.0; |
|
|
|
|
|
|
|
|
|
|
|
#if 1 |
|
|
|
// bounding volume |
|
|
|
float tp1 = (0.0-ro.y)/rd.y; if( tp1>0.0 ) tmax = min( tmax, tp1 ); |
|
|
|
float tp2 = (1.6-ro.y)/rd.y; if( tp2>0.0 ) { if( ro.y>1.6 ) tmin = max( tmin, tp2 ); |
|
|
|
else tmax = min( tmax, tp2 ); } |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
float t = tmin; |
|
|
|
float m = -1.0; |
|
|
|
for( int i=0; i<64; i++ ) |
|
|
|
@ -286,9 +288,9 @@ float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax ) |
|
|
|
vec3 calcNormal( in vec3 pos ) |
|
|
|
{ |
|
|
|
vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; |
|
|
|
return normalize( e.xyy*map( pos + e.xyy ).x k">+ |
|
|
|
e.yyx*map( pos + e.yyx ).x k">+ |
|
|
|
e.yxy*map( pos + e.yxy ).x k">+ |
|
|
|
return normalize( e.xyy*map( pos + e.xyy ).x err">+ |
|
|
|
e.yyx*map( pos + e.yyx ).x err">+ |
|
|
|
e.yxy*map( pos + e.yxy ).x err">+ |
|
|
|
e.xxx*map( pos + e.xxx ).x ); |
|
|
|
/* |
|
|
|
vec3 eps = vec3( 0.0005, 0.0, 0.0 ); |
|
|
|
@ -312,7 +314,7 @@ float calcAO( in vec3 pos, in vec3 nor ) |
|
|
|
occ += -(dd-hr)*sca; |
|
|
|
sca *= 0.95; |
|
|
|
} |
|
|
|
return clamp( 1.0 - 3.0*occ, 0.0, 1.0 nf">); |
|
|
|
return clamp( 1.0 - 3.0*occ, 0.0, 1.0 err">); |
|
|
|
} |
|
|
|
|
|
|
|
// http://iquilezles.org/www/articles/checkerfiltering/checkerfiltering.htm |
|
|
|
@ -323,11 +325,11 @@ float checkersGradBox( in vec2 p ) |
|
|
|
// analytical integral (box filter) |
|
|
|
vec2 i = 2.0*(abs(fract((p-0.5*w)*0.5)-0.5)-abs(fract((p+0.5*w)*0.5)-0.5))/w; |
|
|
|
// xor pattern |
|
|
|
return 0.5 - 0.5nf">*i.x*i.y; |
|
|
|
return 0.5 - 0.5err">*i.x*i.y; |
|
|
|
} |
|
|
|
|
|
|
|
vec3 render( in vec3 ro, in vec3 rd ) |
|
|
|
nf">{ |
|
|
|
err">{ |
|
|
|
vec3 col = vec3(0.7, 0.9, 1.0) +rd.y*0.8; |
|
|
|
vec2 res = castRay(ro,rd); |
|
|
|
float t = res.x; |
|
|
|
@ -337,17 +339,17 @@ vec3 render( in vec3 ro, in vec3 rd ) |
|
|
|
vec3 pos = ro + t*rd; |
|
|
|
vec3 nor = calcNormal( pos ); |
|
|
|
vec3 ref = reflect( rd, nor ); |
|
|
|
|
|
|
|
// nf">material |
|
|
|
|
|
|
|
// err">material |
|
|
|
col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) ); |
|
|
|
if( m<1.5 ) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
float f = checkersGradBox( 5.0*pos.xz ); |
|
|
|
col = 0.3 + f*vec3(0.1); |
|
|
|
} |
|
|
|
|
|
|
|
// nf">lighting |
|
|
|
// err">lighting |
|
|
|
float occ = calcAO( pos, nor ); |
|
|
|
vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) ); |
|
|
|
vec3 hal = normalize( lig-rd ); |
|
|
|
@ -356,7 +358,7 @@ vec3 render( in vec3 ro, in vec3 rd ) |
|
|
|
float bac = clamp( dot( nor, normalize(vec3(-lig.x,0.0,-lig.z))), 0.0, 1.0 )*clamp( 1.0-pos.y,0.0,1.0); |
|
|
|
float dom = smoothstep( -0.1, 0.1, ref.y ); |
|
|
|
float fre = pow( clamp(1.0+dot(nor,rd),0.0,1.0), 2.0 ); |
|
|
|
|
|
|
|
|
|
|
|
dif *= calcSoftshadow( pos, lig, 0.02, 2.5 ); |
|
|
|
dom *= calcSoftshadow( pos, ref, 0.02, 2.5 ); |
|
|
|
|
|
|
|
@ -398,22 +400,22 @@ void main() |
|
|
|
// pixel coordinates |
|
|
|
vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5; |
|
|
|
vec2 p = (-resolution.xy + 2.0*(gl_FragCoord.xy+o))/resolution.y; |
|
|
|
nf">#else |
|
|
|
err">#else |
|
|
|
vec2 p = (-resolution.xy + 2.0*gl_FragCoord.xy)/resolution.y; |
|
|
|
#endif |
|
|
|
|
|
|
|
// RAY: Camera is provided from raylib |
|
|
|
//vec3 ro = vec3( -0.5+3.5*cos(0.1*time + 6.0*mo.x), 1.0 + 2.0*mo.y, 0.5 + 4.0*sin(0.1*time + 6.0*mo.x) ); |
|
|
|
|
|
|
|
|
|
|
|
vec3 ro = viewEye; |
|
|
|
vec3 ta = viewCenter; |
|
|
|
|
|
|
|
|
|
|
|
// camera-to-world transformation |
|
|
|
mat3 ca = setCamera( ro, ta, 0.0 ); |
|
|
|
// ray direction |
|
|
|
vec3 rd = ca * normalize( vec3(p.xy,2.0) ); |
|
|
|
|
|
|
|
// nf">render |
|
|
|
// err">render |
|
|
|
vec3 col = render( ro, rd ); |
|
|
|
|
|
|
|
// gamma |
|
|
|
|