545 lines
No EOL
16 KiB
GLSL
545 lines
No EOL
16 KiB
GLSL
// Original created by inigo quilez - 2015 https://www.shadertoy.com/view/ld3Gz2
|
|
//
|
|
// Created by Sam Gondelman on 7/6/2016
|
|
// Copyright 2016 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
#define AA 1
|
|
|
|
float sdSphere( in vec3 p, in vec4 s )
|
|
{
|
|
return length(p-s.xyz) - s.w;
|
|
}
|
|
|
|
float sdEllipsoid( in vec3 p, in vec3 c, in vec3 r )
|
|
{
|
|
return (length( (p-c)/r ) - 1.0) * min(min(r.x,r.y),r.z);
|
|
}
|
|
|
|
float sdEllipsoid( in vec2 p, in vec2 c, in vec2 r )
|
|
{
|
|
return (length( (p-c)/r ) - 1.0) * min(r.x,r.y);
|
|
}
|
|
|
|
float sdTorus( vec3 p, vec2 t )
|
|
{
|
|
return length( vec2(length(p.xz)-t.x,p.y) )-t.y;
|
|
}
|
|
|
|
vec2 udSegment( vec3 p, vec3 a, vec3 b )
|
|
{
|
|
vec3 pa = p-a, ba = b-a;
|
|
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
|
|
return vec2( length( pa - ba*h ), h );
|
|
}
|
|
|
|
// http://research.microsoft.com/en-us/um/people/hoppe/ravg.pdf
|
|
float det( vec2 a, vec2 b ) { return a.x*b.y-b.x*a.y; }
|
|
vec3 getClosest( vec2 b0, vec2 b1, vec2 b2 )
|
|
{
|
|
float a = det(b0,b2);
|
|
float b = 2.0*det(b1,b0);
|
|
float d = 2.0*det(b2,b1);
|
|
float f = b*d - a*a;
|
|
vec2 d21 = b2-b1;
|
|
vec2 d10 = b1-b0;
|
|
vec2 d20 = b2-b0;
|
|
vec2 gf = 2.0*(b*d21+d*d10+a*d20); gf = vec2(gf.y,-gf.x);
|
|
vec2 pp = -f*gf/dot(gf,gf);
|
|
vec2 d0p = b0-pp;
|
|
float ap = det(d0p,d20);
|
|
float bp = 2.0*det(d10,d0p);
|
|
float t = clamp( (ap+bp)/(2.0*a+b+d), 0.0 ,1.0 );
|
|
return vec3( mix(mix(b0,b1,t), mix(b1,b2,t),t), t );
|
|
}
|
|
|
|
vec4 sdBezier( vec3 a, vec3 b, vec3 c, vec3 p )
|
|
{
|
|
vec3 w = normalize( cross( c-b, a-b ) );
|
|
vec3 u = normalize( c-b );
|
|
vec3 v = normalize( cross( w, u ) );
|
|
|
|
vec2 a2 = vec2( dot(a-b,u), dot(a-b,v) );
|
|
vec2 b2 = vec2( 0.0 );
|
|
vec2 c2 = vec2( dot(c-b,u), dot(c-b,v) );
|
|
vec3 p3 = vec3( dot(p-b,u), dot(p-b,v), dot(p-b,w) );
|
|
|
|
vec3 cp = getClosest( a2-p3.xy, b2-p3.xy, c2-p3.xy );
|
|
|
|
return vec4( sqrt(dot(cp.xy,cp.xy)+p3.z*p3.z), cp.z, length(cp.xy), p3.z );
|
|
}
|
|
|
|
float smin( float a, float b, float k )
|
|
{
|
|
float h = clamp( 0.5 + 0.5*(b-a)/k, 0.0, 1.0 );
|
|
return mix( b, a, h ) - k*h*(1.0-h);
|
|
}
|
|
|
|
vec2 smin( vec2 a, vec2 b, float k )
|
|
{
|
|
float h = clamp( 0.5 + 0.5*(b.x-a.x)/k, 0.0, 1.0 );
|
|
return vec2( mix( b.x, a.x, h ) - k*h*(1.0-h), mix( b.y, a.y, h ) );
|
|
}
|
|
vec4 smin( vec4 a, vec4 b, float k )
|
|
{
|
|
float h = clamp( 0.5 + 0.5*(b.x-a.x)/k, 0.0, 1.0 );
|
|
return vec4( mix( b.x, a.x, h ) - k*h*(1.0-h), mix( b.yzw, a.yzw, h ) );
|
|
}
|
|
|
|
float smax( float a, float b, float k )
|
|
{
|
|
float h = clamp( 0.5 + 0.5*(b-a)/k, 0.0, 1.0 );
|
|
return mix( a, b, h ) + k*h*(1.0-h);
|
|
}
|
|
|
|
vec3 smax( vec3 a, vec3 b, float k )
|
|
{
|
|
vec3 h = clamp( 0.5 + 0.5*(b-a)/k, 0.0, 1.0 );
|
|
return mix( a, b, h ) + k*h*(1.0-h);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
float hash1( float n )
|
|
{
|
|
return fract(sin(n)*43758.5453123);
|
|
}
|
|
|
|
vec3 hash3( float n )
|
|
{
|
|
return fract(sin(n+vec3(0.0,13.1,31.3))*158.5453123);
|
|
}
|
|
|
|
vec3 forwardSF( float i, float n)
|
|
{
|
|
const float PI = 3.141592653589793238;
|
|
const float PHI = 1.618033988749894848;
|
|
float phi = 2.0*PI*fract(i/PHI);
|
|
float zi = 1.0 - (2.0*i+1.0)/n;
|
|
float sinTheta = sqrt( 1.0 - zi*zi);
|
|
return vec3( cos(phi)*sinTheta, sin(phi)*sinTheta, zi);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
const float pi = 3.1415927;
|
|
|
|
float mapShell( in vec3 p, out vec4 matInfo )
|
|
{
|
|
|
|
const float sc = 1.0/1.0;
|
|
p -= vec3(0.05,0.12,-0.09);
|
|
|
|
p *= sc;
|
|
|
|
vec3 q = mat3(-0.6333234236, -0.7332753384, 0.2474039592,
|
|
0.7738444477, -0.6034162289, 0.1924931824,
|
|
0.0081370606, 0.3133626215, 0.9495986813) * p;
|
|
|
|
const float b = 0.1759;
|
|
|
|
float r = length( q.xy );
|
|
float t = atan( q.y, q.x );
|
|
|
|
// https://swiftcoder.wordpress.com/2010/06/21/logarithmic-spiral-distance-field/
|
|
float n = (log(r)/b - t)/(2.0*pi);
|
|
|
|
const float th = 0.11;
|
|
float nm = (log(th)/b-t)/(2.0*pi);
|
|
|
|
n = min(n,nm);
|
|
|
|
float ni = floor( n );
|
|
|
|
float r1 = exp( b * (t + 2.0*pi*ni));
|
|
float r2 = r1 * 3.019863;
|
|
|
|
//-------
|
|
|
|
float h1 = q.z + 1.5*r1 - 0.5;
|
|
float d1 = sqrt( (r1-r)*(r1-r) + h1*h1) - r1;
|
|
float h2 = q.z + 1.5*r2 - 0.5;
|
|
float d2 = sqrt( (r2-r)*(r2-r) + h2*h2) - r2;
|
|
|
|
float d, dx, dy;
|
|
if( d1<d2 ) { d = d1; dx=r1-r; dy=h1; }
|
|
else { d = d2; dx=r2-r; dy=h2; }
|
|
|
|
|
|
float di = 0.0;//texture( iChannel2, vec2(t+r,0.5) ).x;
|
|
d += 0.002*di;
|
|
|
|
matInfo = vec4(dx,dy,r/0.4,t/3.14159);
|
|
|
|
vec3 s = q;
|
|
q = q - vec3(0.34,-0.1,0.03);
|
|
q.xy = mat2(0.8,0.6,-0.6,0.8)*q.xy;
|
|
d = smin( d, sdTorus( q, vec2(0.28,0.05) ), 0.06);
|
|
d = smax( d, -sdEllipsoid(q,vec3(0.0,0.0,0.0),vec3(0.24,0.36,0.24) ), 0.03 );
|
|
|
|
d = smax( d, -sdEllipsoid(s,vec3(0.52,-0.0,0.0),vec3(0.42,0.23,0.5) ), 0.05 );
|
|
|
|
return d/sc;
|
|
}
|
|
|
|
vec3 opTwist( vec3 p, float k )
|
|
{
|
|
float cx = -0.1;
|
|
p.x -= cx;
|
|
float c = cos(k);
|
|
float s = sin(k);
|
|
mat2 m = mat2(c,-s,s,c);
|
|
vec2 q = m*p.xz;
|
|
return vec3(q.x+cx,p.y,q.y);
|
|
}
|
|
|
|
vec2 mapSnail( vec3 p, out vec4 matInfo )
|
|
{
|
|
vec3 head = vec3(-0.76,0.6,-0.3);
|
|
|
|
vec3 q = p - head;
|
|
|
|
// body
|
|
#if 1
|
|
vec4 b1 = sdBezier( vec3(-0.13,-0.65,0.0), vec3(0.24,0.9+0.1,0.0), head+vec3(0.04,0.01,0.0), p );
|
|
float d1 = b1.x;
|
|
d1 -= smoothstep(0.0,0.2,b1.y)*(0.16 - 0.07*smoothstep(0.5,1.0,b1.y));
|
|
b1 = sdBezier( vec3(-0.085,0.0,0.0), vec3(-0.1,0.9-0.05,0.0), head+vec3(0.06,-0.08,0.0), p );
|
|
float d2 = b1.x;
|
|
d2 -= 0.1 - 0.06*b1.y;
|
|
d1 = smin( d1, d2, 0.03 );
|
|
matInfo.xyz = b1.yzw;
|
|
#else
|
|
vec4 b1 = sdBezier( vec3(-0.13,-0.65,0.0), vec3(0.24,0.9+0.11,0.0), head+vec3(0.05,0.01-0.02,0.0), p );
|
|
float d1 = b1.x;
|
|
d1 -= smoothstep(0.0,0.2,b1.y)*(0.16 - 0.75*0.07*smoothstep(0.5,1.0,b1.y));
|
|
matInfo.xyz = b1.yzw;
|
|
float d2;
|
|
#endif
|
|
d2 = sdSphere( q, vec4(0.0,-0.06,0.0,0.085) );
|
|
d1 = smin( d1, d2, 0.03 );
|
|
|
|
d1 = smin( d1, sdSphere(p,vec4(0.05,0.52,0.0,0.13)), 0.07 );
|
|
|
|
q.xz = mat2(0.8,0.6,-0.6,0.8)*q.xz;
|
|
|
|
vec3 sq = vec3( q.xy, abs(q.z) );
|
|
|
|
// top antenas
|
|
vec3 af = 0.05*sin(0.5*iGlobalTime+vec3(0.0,1.0,3.0) + vec3(2.0,1.0,0.0)*sign(q.z) );
|
|
vec4 b2 = sdBezier( vec3(0.0), vec3(-0.1,0.2,0.2), vec3(-0.3,0.2,0.3)+af, sq );
|
|
float d3 = b2.x;
|
|
d3 -= 0.03 - 0.025*b2.y;
|
|
d1 = smin( d1, d3, 0.04 );
|
|
d3 = sdSphere( sq, vec4(-0.3,0.2,0.3,0.016) + vec4(af,0.0) );
|
|
d1 = smin( d1, d3, 0.01 );
|
|
|
|
// bottom antenas
|
|
vec3 bf = 0.02*sin(0.3*iGlobalTime+vec3(4.0,1.0,2.0) + vec3(3.0,0.0,1.0)*sign(q.z) );
|
|
vec2 b3 = udSegment( sq, vec3(0.06,-0.05,0.0), vec3(-0.04,-0.2,0.18)+bf );
|
|
d3 = b3.x;
|
|
d3 -= 0.025 - 0.02*b3.y;
|
|
d1 = smin( d1, d3, 0.06 );
|
|
d3 = sdSphere( sq, vec4(-0.04,-0.2,0.18,0.008)+vec4(bf,0.0) );
|
|
d1 = smin( d1, d3, 0.02 );
|
|
|
|
// bottom
|
|
vec3 pp = p-vec3(-0.17,0.15,0.0);
|
|
float co = 0.988771078;
|
|
float si = 0.149438132;
|
|
pp.xy = mat2(co,-si,si,co)*pp.xy;
|
|
d1 = smin( d1, sdEllipsoid( pp, vec3(0.0,0.0,0.0), vec3(0.084,0.3,0.15) ), 0.05 );
|
|
d1 = smax( d1, -sdEllipsoid( pp, vec3(-0.08,-0.0,0.0), vec3(0.06,0.55,0.1) ), 0.02 );
|
|
|
|
// disp
|
|
float dis = 0.0;//texture( iChannel1, 5.0*p.xy ).x;
|
|
float dx = 0.5 + 0.5*(1.0-smoothstep(0.5,1.0,b1.y));
|
|
d1 -= 0.005*dis*dx*0.5;
|
|
|
|
return vec2(d1,1.0);
|
|
}
|
|
|
|
|
|
vec2 mapOpaque( vec3 p, out vec4 matInfo )
|
|
{
|
|
matInfo = vec4(0.0);
|
|
|
|
//--------------
|
|
vec2 res = mapSnail( p, matInfo );
|
|
|
|
//---------------
|
|
vec4 tmpMatInfo;
|
|
float d4 = mapShell( p, tmpMatInfo );
|
|
if( d4<res.x ) { res = vec2(d4,2.0); matInfo = tmpMatInfo; }
|
|
|
|
//---------------
|
|
|
|
// plant
|
|
vec4 b3 = sdBezier( vec3(-0.15,-1.5,0.0), vec3(-0.1,0.5,0.0), vec3(-0.6,1.5,0.0), p );
|
|
d4 = b3.x;
|
|
d4 -= 0.04 - 0.02*b3.y;
|
|
if( d4<res.x ) { res = vec2(d4,3.0); }
|
|
|
|
//----------------------------
|
|
|
|
return res;
|
|
}
|
|
|
|
vec3 calcNormalOpaque( in vec3 pos, in float eps )
|
|
{
|
|
vec4 kk;
|
|
vec2 e = vec2(1.0,-1.0)*0.5773*eps;
|
|
return normalize( e.xyy*mapOpaque( pos + e.xyy, kk ).x +
|
|
e.yyx*mapOpaque( pos + e.yyx, kk ).x +
|
|
e.yxy*mapOpaque( pos + e.yxy, kk ).x +
|
|
e.xxx*mapOpaque( pos + e.xxx, kk ).x );
|
|
}
|
|
|
|
//=========================================================================
|
|
|
|
float calcAO( in vec3 pos, in vec3 nor )
|
|
{
|
|
vec4 kk;
|
|
float ao = 0.0;
|
|
for( int i=0; i<32; i++ )
|
|
{
|
|
vec3 ap = forwardSF( float(i), 32.0 );
|
|
float h = hash1(float(i));
|
|
ap *= sign( dot(ap,nor) ) * h*0.1;
|
|
ao += clamp( mapOpaque( pos + nor*0.01 + ap, kk ).x*3.0, 0.0, 1.0 );
|
|
}
|
|
ao /= 32.0;
|
|
|
|
return clamp( ao*6.0, 0.0, 1.0 );
|
|
}
|
|
|
|
float calcSSS( in vec3 pos, in vec3 nor )
|
|
{
|
|
vec4 kk;
|
|
float occ = 0.0;
|
|
for( int i=0; i<8; i++ )
|
|
{
|
|
float h = 0.002 + 0.11*float(i)/7.0;
|
|
vec3 dir = normalize( sin( float(i)*13.0 + vec3(0.0,2.1,4.2) ) );
|
|
dir *= sign(dot(dir,nor));
|
|
occ += (h-mapOpaque(pos-h*dir, kk).x);
|
|
}
|
|
occ = clamp( 1.0 - 11.0*occ/8.0, 0.0, 1.0 );
|
|
return occ*occ;
|
|
}
|
|
|
|
float calcSoftShadow( in vec3 ro, in vec3 rd, float k )
|
|
{
|
|
vec4 kk;
|
|
float res = 1.0;
|
|
float t = 0.01;
|
|
for( int i=0; i<32; i++ )
|
|
{
|
|
float h = mapOpaque(ro + rd*t, kk ).x;
|
|
res = min( res, smoothstep(0.0,1.0,k*h/t) );
|
|
t += clamp( h, 0.04, 0.1 );
|
|
if( res<0.01 ) break;
|
|
}
|
|
return clamp(res,0.0,1.0);
|
|
}
|
|
|
|
vec3 sunDir = normalize( vec3(0.2,0.1,0.02) );
|
|
|
|
vec3 shadeOpaque( in vec3 ro, in vec3 rd, in float t, in float m, in vec4 matInfo )
|
|
{
|
|
float eps = 0.002;
|
|
|
|
vec3 pos = ro + t*rd;
|
|
vec3 nor = calcNormalOpaque( pos, eps );
|
|
|
|
vec3 mateD = vec3(0.0);
|
|
vec3 mateS = vec3(0.0);
|
|
vec2 mateK = vec2(0.0);
|
|
vec3 mateE = vec3(0.0);
|
|
|
|
float focc = 1.0;
|
|
float fsha = 1.0;
|
|
|
|
if( m<1.5 ) // snail body
|
|
{
|
|
float dis = 0.0;//texture( iChannel1, 5.0*pos.xy ).x;
|
|
|
|
float be = sdEllipsoid( pos, vec3(-0.3,-0.5,-0.1), vec3(0.2,1.0,0.5) );
|
|
be = 1.0-smoothstep( -0.01, 0.01, be );
|
|
|
|
float ff = abs(matInfo.x-0.20);
|
|
|
|
mateS = 6.0*mix( 0.7*vec3(2.0,1.2,0.2), vec3(2.5,1.8,0.9), ff );
|
|
mateS += 2.0*dis;
|
|
mateS *= 1.5;
|
|
mateS *= 1.0 + 0.5*ff*ff;
|
|
mateS *= 1.0-0.5*be;
|
|
|
|
mateD = vec3(1.0,0.8,0.4);
|
|
mateD *= dis;
|
|
mateD *= 0.015;
|
|
mateD += vec3(0.8,0.4,0.3)*0.15*be;
|
|
|
|
mateK = vec2( 60.0, 0.7 + 2.0*dis );
|
|
|
|
float f = clamp( dot( -rd, nor ), 0.0, 1.0 );
|
|
f = 1.0-pow( f, 8.0 );
|
|
f = 1.0 - (1.0-f)*(1.0-0.0);//texture( iChannel2, 0.3*pos.xy ).x);
|
|
mateS *= vec3(0.5,0.1,0.0) + f*vec3(0.5,0.9,1.0);
|
|
|
|
float b = 1.0-smoothstep( 0.25,0.55,abs(pos.y));
|
|
focc = 0.2 + 0.8*smoothstep( 0.0, 0.15, sdSphere(pos,vec4(0.05,0.52,0.0,0.13)) );
|
|
}
|
|
else if( m<2.5 ) // shell
|
|
{
|
|
mateK = vec2(0.0);
|
|
|
|
float tip = 1.0-smoothstep(0.05,0.4, length(pos-vec3(0.17,0.2,0.35)) );
|
|
mateD = mix( 0.7*vec3(0.2,0.21,0.22), 0.2*vec3(0.15,0.1,0.0), tip );
|
|
|
|
vec2 uv = vec2( .5*atan(matInfo.x,matInfo.y)/3.1416, 1.5*matInfo.w );
|
|
|
|
vec3 ral = vec3(0.0);//texture( iChannel1, vec2(2.0*matInfo.w+matInfo.z*0.5,0.5) ).xxx;
|
|
mateD *= 0.25 + 0.75*ral;
|
|
|
|
float pa = smoothstep(-0.2,0.2, 0.3+sin(2.0+40.0*uv.x + 3.0*sin(11.0*uv.x)) );
|
|
float bar = mix(pa,1.0,smoothstep(0.7,1.0,tip));
|
|
bar *= (matInfo.z<0.6) ? 1.0 : smoothstep( 0.17, 0.21, abs(matInfo.w) );
|
|
mateD *= vec3(0.06,0.03,0.0)+vec3(0.94,0.97,1.0)*bar;
|
|
|
|
mateK = vec2( 64.0, 0.2 );
|
|
mateS = 1.5*vec3(1.0,0.65,0.6) * (1.0-tip);//*0.5;
|
|
}
|
|
else if( m<3.5 ) // plant
|
|
{
|
|
mateD = vec3(0.05,0.1,0.0)*0.2;
|
|
mateS = vec3(0.1,0.2,0.02)*25.0;
|
|
mateK = vec2(5.0,1.0);
|
|
|
|
float fre = clamp(1.0+dot(nor,rd), 0.0, 1.0 );
|
|
mateD += 0.2*fre*vec3(1.0,0.5,0.1);
|
|
|
|
vec3 te = vec3(0.0);//texture( iChannel2, pos.xy*0.2 ).xyz;
|
|
mateS *= 0.5 + 1.5*te;
|
|
mateE = 0.5*vec3(0.1,0.1,0.03)*(0.2+0.8*te.x);
|
|
}
|
|
|
|
vec3 hal = normalize( sunDir-rd );
|
|
float fre = clamp(1.0+dot(nor,rd), 0.0, 1.0 );
|
|
float occ = calcAO( pos, nor )*focc;
|
|
float sss = calcSSS( pos, nor );
|
|
sss = sss*occ + fre*occ + (0.5+0.5*fre)*pow(abs(matInfo.x-0.2),1.0)*occ;
|
|
|
|
float dif1 = clamp( dot(nor,sunDir), 0.0, 1.0 );
|
|
float sha = calcSoftShadow( pos, sunDir, 20.0 );
|
|
dif1 *= sha*fsha;
|
|
float spe1 = clamp( dot(nor,hal), 0.0, 1.0 );
|
|
|
|
float bou = clamp( 0.3-0.7*nor.y, 0.0, 1.0 );
|
|
|
|
// illumination
|
|
|
|
vec3 col = 7.0*vec3(1.7,1.2,0.6)*dif1*2.0; // sun
|
|
col += 4.0*vec3(0.2,1.2,1.6)*occ*(0.5+0.5*nor.y); // sky
|
|
col += 1.8*vec3(0.1,2.0,0.1)*bou*occ; // bounce
|
|
|
|
col *= mateD;
|
|
|
|
col += .4*sss*(vec3(0.15,0.1,0.05)+vec3(0.85,0.9,0.95)*dif1)*(0.05+0.95*occ)*mateS; // sss
|
|
col = pow(col,vec3(0.6,0.8,1.0));
|
|
|
|
col += vec3(1.0,1.0,1.0)*0.2*pow( spe1, 1.0+mateK.x )*dif1*(0.04+0.96*pow(fre,4.0))*mateK.x*mateK.y; // sun lobe1
|
|
col += vec3(1.0,1.0,1.0)*0.1*pow( spe1, 1.0+mateK.x/3.0 )*dif1*(0.1+0.9*pow(fre,4.0))*mateK.x*mateK.y; // sun lobe2
|
|
col += 0.1*vec3(1.0,max(1.5-0.7*col.y,0.0),2.0)*occ*occ*smoothstep( 0.0, 0.3, reflect( rd, nor ).y )*mateK.x*mateK.y*(0.04+0.96*pow(fre,5.0)); // sky
|
|
|
|
col += mateE;
|
|
|
|
return col;
|
|
}
|
|
|
|
//--------------------------------------------
|
|
|
|
vec2 intersectOpaque( in vec3 ro, in vec3 rd, const float mindist, const float maxdist, out vec4 matInfo )
|
|
{
|
|
vec2 res = vec2(-1.0);
|
|
|
|
float t = mindist;
|
|
for( int i=0; i<64; i++ )
|
|
{
|
|
vec3 p = ro + t*rd;
|
|
vec2 h = mapOpaque( p, matInfo );
|
|
res = vec2(t,h.y);
|
|
|
|
if( h.x<(0.001*t) || t>maxdist ) break;
|
|
|
|
t += h.x*0.9;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
|
|
vec3 render( in vec3 ro, in vec3 rd )
|
|
{
|
|
//-----------------------------
|
|
|
|
vec3 col = vec3(0);
|
|
|
|
//-----------------------------
|
|
|
|
float mindist = 0.0001;
|
|
float maxdist = 20.0;
|
|
|
|
vec4 matInfo;
|
|
vec2 tm = intersectOpaque( ro, rd, mindist, maxdist, matInfo );
|
|
if( tm.y>-0.5 && tm.x < maxdist )
|
|
{
|
|
col = shadeOpaque( ro, rd, tm.x, tm.y, matInfo );
|
|
maxdist = tm.x;
|
|
} else {
|
|
discard;
|
|
}
|
|
|
|
//-----------------------------
|
|
|
|
return pow( col, vec3(0.45) );
|
|
}
|
|
|
|
|
|
vec3 getProceduralColor() {
|
|
vec3 worldEye = getEyeWorldPos();
|
|
// this will make it movable, scalable, and rotatable
|
|
vec3 ro = _position.xyz;
|
|
vec3 eye = (inverse(iWorldOrientation) * (worldEye - iWorldPosition)) / iWorldScale;
|
|
|
|
// vec3 ro = iWorldOrientation * (_position.xyz * iWorldScale) + iWorldPosition; // world position of the current fragment
|
|
// vec3 eye = worldEye;
|
|
|
|
ro.x *= 1.8462;
|
|
ro.y *= 3.0963;
|
|
ro.z *= 0.8196;
|
|
ro.x += -0.3344;
|
|
ro.y += -0.0044;
|
|
ro.z += -0.0337;
|
|
eye.x *= 1.8462;
|
|
eye.y *= 3.0963;
|
|
eye.z *= 0.8196;
|
|
eye.x += -0.3344;
|
|
eye.y += -0.0044;
|
|
eye.z += -0.0337;
|
|
|
|
vec3 rd = normalize(ro - eye); // ray from camera eye to ro
|
|
|
|
return render(eye, rd);
|
|
}
|
|
|
|
|
|
float getProceduralColors(inout vec3 diffuse, inout vec3 specular, inout float shininess) {
|
|
vec3 color = getProceduralColor();
|
|
diffuse = color.rgb;
|
|
specular = color.rgb;
|
|
shininess = 0.5;
|
|
return 1.0;
|
|
} |