mirror of https://github.com/raysan5/raylib
Replace tabs by 4 spaces
This commit is contained in:
parent
f3ce3a6f74
commit
65b299c6cf
|
@ -41,27 +41,27 @@ float RadicalInverseVdC(uint bits)
|
|||
// Compute Hammersley coordinates
|
||||
vec2 Hammersley(uint i, uint N)
|
||||
{
|
||||
return vec2(float(i)/float(N), RadicalInverseVdC(i));
|
||||
return vec2(float(i)/float(N), RadicalInverseVdC(i));
|
||||
}
|
||||
|
||||
// Integrate number of importance samples for (roughness and NoV)
|
||||
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float phi = 2.0 * PI * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y)/(1.0 + (a*a - 1.0)*Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
float a = roughness*roughness;
|
||||
float phi = 2.0 * PI * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y)/(1.0 + (a*a - 1.0)*Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
|
||||
// Transform from spherical coordinates to cartesian coordinates (halfway vector)
|
||||
vec3 H = vec3(cos(phi)*sinTheta, sin(phi)*sinTheta, cosTheta);
|
||||
// Transform from spherical coordinates to cartesian coordinates (halfway vector)
|
||||
vec3 H = vec3(cos(phi)*sinTheta, sin(phi)*sinTheta, cosTheta);
|
||||
|
||||
// Transform from tangent space H vector to world space sample vector
|
||||
vec3 up = ((abs(N.z) < 0.999) ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0));
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
vec3 sampleVec = tangent*H.x + bitangent*H.y + N*H.z;
|
||||
// Transform from tangent space H vector to world space sample vector
|
||||
vec3 up = ((abs(N.z) < 0.999) ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0));
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
vec3 sampleVec = tangent*H.x + bitangent*H.y + N*H.z;
|
||||
|
||||
return normalize(sampleVec);
|
||||
return normalize(sampleVec);
|
||||
}
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
|
|
|
@ -54,26 +54,26 @@ float RadicalInverse_VdC(uint bits)
|
|||
|
||||
vec2 Hammersley(uint i, uint N)
|
||||
{
|
||||
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
|
||||
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float phi = 2.0*PI*Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y)/(1.0 + (a*a - 1.0)*Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
float a = roughness*roughness;
|
||||
float phi = 2.0*PI*Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y)/(1.0 + (a*a - 1.0)*Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
|
||||
// Transform from spherical coordinates to cartesian coordinates (halfway vector)
|
||||
vec3 H = vec3(cos(phi)*sinTheta, sin(phi)*sinTheta, cosTheta);
|
||||
// Transform from spherical coordinates to cartesian coordinates (halfway vector)
|
||||
vec3 H = vec3(cos(phi)*sinTheta, sin(phi)*sinTheta, cosTheta);
|
||||
|
||||
// Transform from tangent space H vector to world space sample vector
|
||||
vec3 up = ((abs(N.z) < 0.999) ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0));
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
vec3 sampleVec = tangent*H.x + bitangent*H.y + N*H.z;
|
||||
// Transform from tangent space H vector to world space sample vector
|
||||
vec3 up = ((abs(N.z) < 0.999) ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0));
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
vec3 sampleVec = tangent*H.x + bitangent*H.y + N*H.z;
|
||||
|
||||
return normalize(sampleVec);
|
||||
return normalize(sampleVec);
|
||||
}
|
||||
|
||||
void main()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* Copyright (c) 2017 Victor Fisac
|
||||
*
|
||||
* 19-Jun-2020 - modified by Giuseppe Mastrangelo (@peppemas) - VFlip Support
|
||||
* 19-Jun-2020 - modified by Giuseppe Mastrangelo (@peppemas) - VFlip Support
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ uniform vec4 colDiffuse;
|
|||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
@ -34,4 +34,4 @@ void main()
|
|||
color = color/9.5;
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
}
|
|
@ -42,7 +42,7 @@ uniform vec2 resolution;
|
|||
|
||||
float sdPlane( vec3 p )
|
||||
{
|
||||
return p.y;
|
||||
return p.y;
|
||||
}
|
||||
|
||||
float sdSphere( vec3 p, float s )
|
||||
|
@ -85,9 +85,9 @@ float sdHexPrism( vec3 p, vec2 h )
|
|||
|
||||
float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
|
||||
{
|
||||
vec3 pa = p-a, ba = b-a;
|
||||
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
|
||||
return length( pa - ba*h ) - r;
|
||||
vec3 pa = p-a, ba = b-a;
|
||||
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
|
||||
return length( pa - ba*h ) - r;
|
||||
}
|
||||
|
||||
float sdEquilateralTriangle( in vec2 p )
|
||||
|
@ -154,19 +154,19 @@ float sdPryamid4(vec3 p, vec3 h ) // h = { cos a, sin a, height }
|
|||
|
||||
float length2( vec2 p )
|
||||
{
|
||||
return sqrt( p.x*p.x + p.y*p.y );
|
||||
return sqrt( p.x*p.x + p.y*p.y );
|
||||
}
|
||||
|
||||
float length6( vec2 p )
|
||||
{
|
||||
p = p*p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/6.0 );
|
||||
p = p*p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/6.0 );
|
||||
}
|
||||
|
||||
float length8( vec2 p )
|
||||
{
|
||||
p = p*p; p = p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/8.0 );
|
||||
p = p*p; p = p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/8.0 );
|
||||
}
|
||||
|
||||
float sdTorus82( vec3 p, vec2 t )
|
||||
|
@ -195,7 +195,7 @@ float opS( float d1, float d2 )
|
|||
|
||||
vec2 opU( vec2 d1, vec2 d2 )
|
||||
{
|
||||
return (d1.x<d2.x) ? d1 : d2;
|
||||
return (d1.x<d2.x) ? d1 : d2;
|
||||
}
|
||||
|
||||
vec3 opRep( vec3 p, vec3 c )
|
||||
|
@ -216,25 +216,25 @@ vec3 opTwist( vec3 p )
|
|||
vec2 map( in vec3 pos )
|
||||
{
|
||||
vec2 res = opU( vec2( sdPlane( pos), 1.0 ),
|
||||
vec2( sdSphere( pos-vec3( 0.0,0.25, 0.0), 0.25 ), 46.9 ) );
|
||||
vec2( sdSphere( pos-vec3( 0.0,0.25, 0.0), 0.25 ), 46.9 ) );
|
||||
res = opU( res, vec2( sdBox( pos-vec3( 1.0,0.25, 0.0), vec3(0.25) ), 3.0 ) );
|
||||
res = opU( res, vec2( udRoundBox( pos-vec3( 1.0,0.25, 1.0), vec3(0.15), 0.1 ), 41.0 ) );
|
||||
res = opU( res, vec2( sdTorus( pos-vec3( 0.0,0.25, 1.0), vec2(0.20,0.05) ), 25.0 ) );
|
||||
res = opU( res, vec2( sdTorus( pos-vec3( 0.0,0.25, 1.0), vec2(0.20,0.05) ), 25.0 ) );
|
||||
res = opU( res, vec2( sdCapsule( pos,vec3(-1.3,0.10,-0.1), vec3(-0.8,0.50,0.2), 0.1 ), 31.9 ) );
|
||||
res = opU( res, vec2( sdTriPrism( pos-vec3(-1.0,0.25,-1.0), vec2(0.25,0.05) ),43.5 ) );
|
||||
res = opU( res, vec2( sdCylinder( pos-vec3( 1.0,0.30,-1.0), vec2(0.1,0.2) ), 8.0 ) );
|
||||
res = opU( res, vec2( sdCone( pos-vec3( 0.0,0.50,-1.0), vec3(0.8,0.6,0.3) ), 55.0 ) );
|
||||
res = opU( res, vec2( sdTorus82( pos-vec3( 0.0,0.25, 2.0), vec2(0.20,0.05) ),50.0 ) );
|
||||
res = opU( res, vec2( sdTorus88( pos-vec3(-1.0,0.25, 2.0), vec2(0.20,0.05) ),43.0 ) );
|
||||
res = opU( res, vec2( sdCylinder6( pos-vec3( 1.0,0.30, 2.0), vec2(0.1,0.2) ), 12.0 ) );
|
||||
res = opU( res, vec2( sdHexPrism( pos-vec3(-1.0,0.20, 1.0), vec2(0.25,0.05) ),17.0 ) );
|
||||
res = opU( res, vec2( sdPryamid4( pos-vec3(-1.0,0.15,-2.0), vec3(0.8,0.6,0.25) ),37.0 ) );
|
||||
res = opU( res, vec2( sdTriPrism( pos-vec3(-1.0,0.25,-1.0), vec2(0.25,0.05) ),43.5 ) );
|
||||
res = opU( res, vec2( sdCylinder( pos-vec3( 1.0,0.30,-1.0), vec2(0.1,0.2) ), 8.0 ) );
|
||||
res = opU( res, vec2( sdCone( pos-vec3( 0.0,0.50,-1.0), vec3(0.8,0.6,0.3) ), 55.0 ) );
|
||||
res = opU( res, vec2( sdTorus82( pos-vec3( 0.0,0.25, 2.0), vec2(0.20,0.05) ),50.0 ) );
|
||||
res = opU( res, vec2( sdTorus88( pos-vec3(-1.0,0.25, 2.0), vec2(0.20,0.05) ),43.0 ) );
|
||||
res = opU( res, vec2( sdCylinder6( pos-vec3( 1.0,0.30, 2.0), vec2(0.1,0.2) ), 12.0 ) );
|
||||
res = opU( res, vec2( sdHexPrism( pos-vec3(-1.0,0.20, 1.0), vec2(0.25,0.05) ),17.0 ) );
|
||||
res = opU( res, vec2( sdPryamid4( pos-vec3(-1.0,0.15,-2.0), vec3(0.8,0.6,0.25) ),37.0 ) );
|
||||
res = opU( res, vec2( opS( udRoundBox( pos-vec3(-2.0,0.2, 1.0), vec3(0.15),0.05),
|
||||
sdSphere( pos-vec3(-2.0,0.2, 1.0), 0.25)), 13.0 ) );
|
||||
sdSphere( pos-vec3(-2.0,0.2, 1.0), 0.25)), 13.0 ) );
|
||||
res = opU( res, vec2( opS( sdTorus82( pos-vec3(-2.0,0.2, 0.0), vec2(0.20,0.1)),
|
||||
sdCylinder( opRep( vec3(atan(pos.x+2.0,pos.z)/6.2831, pos.y, 0.02+0.5*length(pos-vec3(-2.0,0.2, 0.0))), vec3(0.05,1.0,0.05)), vec2(0.02,0.6))), 51.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdSphere( pos-vec3(-2.0,0.25,-1.0), 0.2 ) + 0.03*sin(50.0*pos.x)*sin(50.0*pos.y)*sin(50.0*pos.z), 65.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdTorus( opTwist(pos-vec3(-2.0,0.25, 2.0)),vec2(0.20,0.05)), 46.7 ) );
|
||||
sdCylinder( opRep( vec3(atan(pos.x+2.0,pos.z)/6.2831, pos.y, 0.02+0.5*length(pos-vec3(-2.0,0.2, 0.0))), vec3(0.05,1.0,0.05)), vec2(0.02,0.6))), 51.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdSphere( pos-vec3(-2.0,0.25,-1.0), 0.2 ) + 0.03*sin(50.0*pos.x)*sin(50.0*pos.y)*sin(50.0*pos.z), 65.0 ) );
|
||||
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 ) );
|
||||
|
||||
|
@ -257,11 +257,11 @@ vec2 castRay( in vec3 ro, in vec3 rd )
|
|||
float m = -1.0;
|
||||
for( int i=0; i<64; i++ )
|
||||
{
|
||||
float precis = 0.0005*t;
|
||||
vec2 res = map( ro+rd*t );
|
||||
float precis = 0.0005*t;
|
||||
vec2 res = map( ro+rd*t );
|
||||
if( res.x<precis || t>tmax ) break;
|
||||
t += res.x;
|
||||
m = res.y;
|
||||
m = res.y;
|
||||
}
|
||||
|
||||
if( t>tmax ) m=-1.0;
|
||||
|
@ -271,11 +271,11 @@ vec2 castRay( in vec3 ro, in vec3 rd )
|
|||
|
||||
float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
|
||||
{
|
||||
float res = 1.0;
|
||||
float res = 1.0;
|
||||
float t = mint;
|
||||
for( int i=0; i<16; i++ )
|
||||
{
|
||||
float h = map( ro + rd*t ).x;
|
||||
float h = map( ro + rd*t ).x;
|
||||
res = min( res, 8.0*h/t );
|
||||
t += clamp( h, 0.02, 0.10 );
|
||||
if( h<0.001 || t>tmax ) break;
|
||||
|
@ -287,22 +287,22 @@ 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 +
|
||||
e.yyx*map( pos + e.yyx ).x +
|
||||
e.yxy*map( pos + e.yxy ).x +
|
||||
e.xxx*map( pos + e.xxx ).x );
|
||||
e.yyx*map( pos + e.yyx ).x +
|
||||
e.yxy*map( pos + e.yxy ).x +
|
||||
e.xxx*map( pos + e.xxx ).x );
|
||||
/*
|
||||
vec3 eps = vec3( 0.0005, 0.0, 0.0 );
|
||||
vec3 nor = vec3(
|
||||
map(pos+eps.xyy).x - map(pos-eps.xyy).x,
|
||||
map(pos+eps.yxy).x - map(pos-eps.yxy).x,
|
||||
map(pos+eps.yyx).x - map(pos-eps.yyx).x );
|
||||
return normalize(nor);
|
||||
*/
|
||||
vec3 eps = vec3( 0.0005, 0.0, 0.0 );
|
||||
vec3 nor = vec3(
|
||||
map(pos+eps.xyy).x - map(pos-eps.xyy).x,
|
||||
map(pos+eps.yxy).x - map(pos-eps.yxy).x,
|
||||
map(pos+eps.yyx).x - map(pos-eps.yyx).x );
|
||||
return normalize(nor);
|
||||
*/
|
||||
}
|
||||
|
||||
float calcAO( in vec3 pos, in vec3 nor )
|
||||
{
|
||||
float occ = 0.0;
|
||||
float occ = 0.0;
|
||||
float sca = 1.0;
|
||||
for( int i=0; i<5; i++ )
|
||||
{
|
||||
|
@ -331,7 +331,7 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
vec3 col = vec3(0.7, 0.9, 1.0) +rd.y*0.8;
|
||||
vec2 res = castRay(ro,rd);
|
||||
float t = res.x;
|
||||
float m = res.y;
|
||||
float m = res.y;
|
||||
if( m>-0.5 )
|
||||
{
|
||||
vec3 pos = ro + t*rd;
|
||||
|
@ -339,7 +339,7 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
vec3 ref = reflect( rd, nor );
|
||||
|
||||
// material
|
||||
col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) );
|
||||
col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) );
|
||||
if( m<1.5 )
|
||||
{
|
||||
|
||||
|
@ -349,9 +349,9 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
|
||||
// lighting
|
||||
float occ = calcAO( pos, nor );
|
||||
vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) );
|
||||
vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) );
|
||||
vec3 hal = normalize( lig-rd );
|
||||
float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 );
|
||||
float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 );
|
||||
float dif = clamp( dot( nor, lig ), 0.0, 1.0 );
|
||||
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 );
|
||||
|
@ -360,31 +360,31 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
dif *= calcSoftshadow( pos, lig, 0.02, 2.5 );
|
||||
dom *= calcSoftshadow( pos, ref, 0.02, 2.5 );
|
||||
|
||||
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0)*
|
||||
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0)*
|
||||
dif *
|
||||
(0.04 + 0.96*pow( clamp(1.0+dot(hal,rd),0.0,1.0), 5.0 ));
|
||||
|
||||
vec3 lin = vec3(0.0);
|
||||
vec3 lin = vec3(0.0);
|
||||
lin += 1.30*dif*vec3(1.00,0.80,0.55);
|
||||
lin += 0.40*amb*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*dom*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*bac*vec3(0.25,0.25,0.25)*occ;
|
||||
lin += 0.25*fre*vec3(1.00,1.00,1.00)*occ;
|
||||
col = col*lin;
|
||||
col += 10.00*spe*vec3(1.00,0.90,0.70);
|
||||
col = col*lin;
|
||||
col += 10.00*spe*vec3(1.00,0.90,0.70);
|
||||
|
||||
col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0002*t*t*t ) );
|
||||
col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0002*t*t*t ) );
|
||||
}
|
||||
|
||||
return vec3( clamp(col,0.0,1.0) );
|
||||
return vec3( clamp(col,0.0,1.0) );
|
||||
}
|
||||
|
||||
mat3 setCamera( in vec3 ro, in vec3 ta, float cr )
|
||||
{
|
||||
vec3 cw = normalize(ta-ro);
|
||||
vec3 cp = vec3(sin(cr), cos(cr),0.0);
|
||||
vec3 cu = normalize( cross(cw,cp) );
|
||||
vec3 cv = normalize( cross(cu,cw) );
|
||||
vec3 cp = vec3(sin(cr), cos(cr),0.0);
|
||||
vec3 cu = normalize( cross(cw,cp) );
|
||||
vec3 cv = normalize( cross(cu,cw) );
|
||||
return mat3( cu, cv, cw );
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ void main()
|
|||
vec2 p = (-resolution.xy + 2.0*gl_FragCoord.xy)/resolution.y;
|
||||
#endif
|
||||
|
||||
// RAY: Camera is provided from raylib
|
||||
// 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;
|
||||
|
@ -413,10 +413,10 @@ void main()
|
|||
// ray direction
|
||||
vec3 rd = ca * normalize( vec3(p.xy,2.0) );
|
||||
|
||||
// render
|
||||
// render
|
||||
vec3 col = render( ro, rd );
|
||||
|
||||
// gamma
|
||||
// gamma
|
||||
col = pow( col, vec3(0.4545) );
|
||||
|
||||
tot += col;
|
||||
|
|
|
@ -15,26 +15,26 @@ vec2 resolution = vec2(800.0, 450.0);
|
|||
|
||||
void main()
|
||||
{
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
}
|
|
@ -5,9 +5,9 @@ precision mediump float;
|
|||
#define MAX_SPOTS 3
|
||||
|
||||
struct Spot {
|
||||
vec2 pos; // window coords of spot
|
||||
float inner; // inner fully transparent centre radius
|
||||
float radius; // alpha fades out to this radius
|
||||
vec2 pos; // window coords of spot
|
||||
float inner; // inner fully transparent centre radius
|
||||
float radius; // alpha fades out to this radius
|
||||
};
|
||||
|
||||
uniform Spot spots[MAX_SPOTS]; // Spotlight positions array
|
||||
|
@ -15,63 +15,63 @@ uniform float screenWidth; // Width of the screen
|
|||
|
||||
void main()
|
||||
{
|
||||
float alpha = 1.0;
|
||||
float alpha = 1.0;
|
||||
|
||||
// Get the position of the current fragment (screen coordinates!)
|
||||
vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y);
|
||||
|
||||
// Find out which spotlight is nearest
|
||||
float d = 65000.0; // some high value
|
||||
int fi = -1; // found index
|
||||
// Get the position of the current fragment (screen coordinates!)
|
||||
vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y);
|
||||
|
||||
// Find out which spotlight is nearest
|
||||
float d = 65000.0; // some high value
|
||||
int fi = -1; // found index
|
||||
|
||||
for (int i = 0; i < MAX_SPOTS; i++)
|
||||
{
|
||||
for (int j = 0; j < MAX_SPOTS; j++)
|
||||
{
|
||||
float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius;
|
||||
for (int j = 0; j < MAX_SPOTS; j++)
|
||||
{
|
||||
float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius;
|
||||
|
||||
if (d > dj)
|
||||
{
|
||||
d = dj;
|
||||
fi = i;
|
||||
}
|
||||
}
|
||||
if (d > dj)
|
||||
{
|
||||
d = dj;
|
||||
fi = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// d now equals distance to nearest spot...
|
||||
// allowing for the different radii of all spotlights
|
||||
if (fi == 0)
|
||||
{
|
||||
if (d > spots[0].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[0].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[0].inner)/(spots[0].radius - spots[0].inner);
|
||||
}
|
||||
}
|
||||
if (d > spots[0].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[0].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[0].inner)/(spots[0].radius - spots[0].inner);
|
||||
}
|
||||
}
|
||||
else if (fi == 1)
|
||||
{
|
||||
if (d > spots[1].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[1].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[1].inner)/(spots[1].radius - spots[1].inner);
|
||||
}
|
||||
}
|
||||
if (d > spots[1].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[1].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[1].inner)/(spots[1].radius - spots[1].inner);
|
||||
}
|
||||
}
|
||||
else if (fi == 2)
|
||||
{
|
||||
if (d > spots[2].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[2].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[2].inner)/(spots[2].radius - spots[2].inner);
|
||||
}
|
||||
}
|
||||
|
||||
// Right hand side of screen is dimly lit,
|
||||
if (d > spots[2].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[2].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[2].inner)/(spots[2].radius - spots[2].inner);
|
||||
}
|
||||
}
|
||||
|
||||
// Right hand side of screen is dimly lit,
|
||||
// could make the threshold value user definable
|
||||
if ((pos.x > screenWidth/2.0) && (alpha > 0.9)) alpha = 0.9;
|
||||
if ((pos.x > screenWidth/2.0) && (alpha > 0.9)) alpha = 0.9;
|
||||
|
||||
// could make the black out colour user definable...
|
||||
// could make the black out colour user definable...
|
||||
gl_FragColor = vec4(0, 0, 0, alpha);
|
||||
}
|
||||
|
|
|
@ -22,15 +22,15 @@ uniform float speedX;
|
|||
uniform float speedY;
|
||||
|
||||
void main() {
|
||||
float pixelWidth = 1.0 / size.x;
|
||||
float pixelHeight = 1.0 / size.y;
|
||||
float aspect = pixelHeight / pixelWidth;
|
||||
float boxLeft = 0.0;
|
||||
float boxTop = 0.0;
|
||||
float pixelWidth = 1.0 / size.x;
|
||||
float pixelHeight = 1.0 / size.y;
|
||||
float aspect = pixelHeight / pixelWidth;
|
||||
float boxLeft = 0.0;
|
||||
float boxTop = 0.0;
|
||||
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
|
||||
gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor;
|
||||
gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ uniform vec4 colDiffuse;
|
|||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
@ -32,4 +32,4 @@ void main()
|
|||
color = color/9.5;
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
}
|
|
@ -13,26 +13,26 @@ vec2 resolution = vec2(800.0, 450.0);
|
|||
|
||||
void main()
|
||||
{
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
}
|
|
@ -15,7 +15,7 @@ out vec4 finalColor;
|
|||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
@ -31,4 +31,4 @@ void main()
|
|||
color = color/9.5;
|
||||
|
||||
fragColor = color;
|
||||
}
|
||||
}
|
|
@ -38,9 +38,9 @@ vec4 Colorizer(float counter, float maxSize)
|
|||
|
||||
void main()
|
||||
{
|
||||
vec4 color = vec4(1.0);
|
||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
||||
int value = int(scale*floor(fragTexCoord.y*scale)+floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values
|
||||
vec4 color = vec4(1.0);
|
||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
||||
int value = int(scale*floor(fragTexCoord.y*scale)+floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values
|
||||
|
||||
if ((value == 0) || (value == 1) || (value == 2)) finalColor = vec4(1.0);
|
||||
else
|
||||
|
|
|
@ -43,7 +43,7 @@ uniform vec2 resolution;
|
|||
|
||||
float sdPlane( vec3 p )
|
||||
{
|
||||
return p.y;
|
||||
return p.y;
|
||||
}
|
||||
|
||||
float sdSphere( vec3 p, float s )
|
||||
|
@ -86,9 +86,9 @@ float sdHexPrism( vec3 p, vec2 h )
|
|||
|
||||
float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
|
||||
{
|
||||
vec3 pa = p-a, ba = b-a;
|
||||
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
|
||||
return length( pa - ba*h ) - r;
|
||||
vec3 pa = p-a, ba = b-a;
|
||||
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
|
||||
return length( pa - ba*h ) - r;
|
||||
}
|
||||
|
||||
float sdEquilateralTriangle( in vec2 p )
|
||||
|
@ -155,19 +155,19 @@ float sdPryamid4(vec3 p, vec3 h ) // h = { cos a, sin a, height }
|
|||
|
||||
float length2( vec2 p )
|
||||
{
|
||||
return sqrt( p.x*p.x + p.y*p.y );
|
||||
return sqrt( p.x*p.x + p.y*p.y );
|
||||
}
|
||||
|
||||
float length6( vec2 p )
|
||||
{
|
||||
p = p*p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/6.0 );
|
||||
p = p*p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/6.0 );
|
||||
}
|
||||
|
||||
float length8( vec2 p )
|
||||
{
|
||||
p = p*p; p = p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/8.0 );
|
||||
p = p*p; p = p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/8.0 );
|
||||
}
|
||||
|
||||
float sdTorus82( vec3 p, vec2 t )
|
||||
|
@ -196,7 +196,7 @@ float opS( float d1, float d2 )
|
|||
|
||||
vec2 opU( vec2 d1, vec2 d2 )
|
||||
{
|
||||
return (d1.x<d2.x) ? d1 : d2;
|
||||
return (d1.x<d2.x) ? d1 : d2;
|
||||
}
|
||||
|
||||
vec3 opRep( vec3 p, vec3 c )
|
||||
|
@ -217,25 +217,25 @@ vec3 opTwist( vec3 p )
|
|||
vec2 map( in vec3 pos )
|
||||
{
|
||||
vec2 res = opU( vec2( sdPlane( pos), 1.0 ),
|
||||
vec2( sdSphere( pos-vec3( 0.0,0.25, 0.0), 0.25 ), 46.9 ) );
|
||||
vec2( sdSphere( pos-vec3( 0.0,0.25, 0.0), 0.25 ), 46.9 ) );
|
||||
res = opU( res, vec2( sdBox( pos-vec3( 1.0,0.25, 0.0), vec3(0.25) ), 3.0 ) );
|
||||
res = opU( res, vec2( udRoundBox( pos-vec3( 1.0,0.25, 1.0), vec3(0.15), 0.1 ), 41.0 ) );
|
||||
res = opU( res, vec2( sdTorus( pos-vec3( 0.0,0.25, 1.0), vec2(0.20,0.05) ), 25.0 ) );
|
||||
res = opU( res, vec2( sdTorus( pos-vec3( 0.0,0.25, 1.0), vec2(0.20,0.05) ), 25.0 ) );
|
||||
res = opU( res, vec2( sdCapsule( pos,vec3(-1.3,0.10,-0.1), vec3(-0.8,0.50,0.2), 0.1 ), 31.9 ) );
|
||||
res = opU( res, vec2( sdTriPrism( pos-vec3(-1.0,0.25,-1.0), vec2(0.25,0.05) ),43.5 ) );
|
||||
res = opU( res, vec2( sdCylinder( pos-vec3( 1.0,0.30,-1.0), vec2(0.1,0.2) ), 8.0 ) );
|
||||
res = opU( res, vec2( sdCone( pos-vec3( 0.0,0.50,-1.0), vec3(0.8,0.6,0.3) ), 55.0 ) );
|
||||
res = opU( res, vec2( sdTorus82( pos-vec3( 0.0,0.25, 2.0), vec2(0.20,0.05) ),50.0 ) );
|
||||
res = opU( res, vec2( sdTorus88( pos-vec3(-1.0,0.25, 2.0), vec2(0.20,0.05) ),43.0 ) );
|
||||
res = opU( res, vec2( sdCylinder6( pos-vec3( 1.0,0.30, 2.0), vec2(0.1,0.2) ), 12.0 ) );
|
||||
res = opU( res, vec2( sdHexPrism( pos-vec3(-1.0,0.20, 1.0), vec2(0.25,0.05) ),17.0 ) );
|
||||
res = opU( res, vec2( sdPryamid4( pos-vec3(-1.0,0.15,-2.0), vec3(0.8,0.6,0.25) ),37.0 ) );
|
||||
res = opU( res, vec2( sdTriPrism( pos-vec3(-1.0,0.25,-1.0), vec2(0.25,0.05) ),43.5 ) );
|
||||
res = opU( res, vec2( sdCylinder( pos-vec3( 1.0,0.30,-1.0), vec2(0.1,0.2) ), 8.0 ) );
|
||||
res = opU( res, vec2( sdCone( pos-vec3( 0.0,0.50,-1.0), vec3(0.8,0.6,0.3) ), 55.0 ) );
|
||||
res = opU( res, vec2( sdTorus82( pos-vec3( 0.0,0.25, 2.0), vec2(0.20,0.05) ),50.0 ) );
|
||||
res = opU( res, vec2( sdTorus88( pos-vec3(-1.0,0.25, 2.0), vec2(0.20,0.05) ),43.0 ) );
|
||||
res = opU( res, vec2( sdCylinder6( pos-vec3( 1.0,0.30, 2.0), vec2(0.1,0.2) ), 12.0 ) );
|
||||
res = opU( res, vec2( sdHexPrism( pos-vec3(-1.0,0.20, 1.0), vec2(0.25,0.05) ),17.0 ) );
|
||||
res = opU( res, vec2( sdPryamid4( pos-vec3(-1.0,0.15,-2.0), vec3(0.8,0.6,0.25) ),37.0 ) );
|
||||
res = opU( res, vec2( opS( udRoundBox( pos-vec3(-2.0,0.2, 1.0), vec3(0.15),0.05),
|
||||
sdSphere( pos-vec3(-2.0,0.2, 1.0), 0.25)), 13.0 ) );
|
||||
sdSphere( pos-vec3(-2.0,0.2, 1.0), 0.25)), 13.0 ) );
|
||||
res = opU( res, vec2( opS( sdTorus82( pos-vec3(-2.0,0.2, 0.0), vec2(0.20,0.1)),
|
||||
sdCylinder( opRep( vec3(atan(pos.x+2.0,pos.z)/6.2831, pos.y, 0.02+0.5*length(pos-vec3(-2.0,0.2, 0.0))), vec3(0.05,1.0,0.05)), vec2(0.02,0.6))), 51.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdSphere( pos-vec3(-2.0,0.25,-1.0), 0.2 ) + 0.03*sin(50.0*pos.x)*sin(50.0*pos.y)*sin(50.0*pos.z), 65.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdTorus( opTwist(pos-vec3(-2.0,0.25, 2.0)),vec2(0.20,0.05)), 46.7 ) );
|
||||
sdCylinder( opRep( vec3(atan(pos.x+2.0,pos.z)/6.2831, pos.y, 0.02+0.5*length(pos-vec3(-2.0,0.2, 0.0))), vec3(0.05,1.0,0.05)), vec2(0.02,0.6))), 51.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdSphere( pos-vec3(-2.0,0.25,-1.0), 0.2 ) + 0.03*sin(50.0*pos.x)*sin(50.0*pos.y)*sin(50.0*pos.z), 65.0 ) );
|
||||
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 ) );
|
||||
|
||||
|
@ -258,11 +258,11 @@ vec2 castRay( in vec3 ro, in vec3 rd )
|
|||
float m = -1.0;
|
||||
for( int i=0; i<64; i++ )
|
||||
{
|
||||
float precis = 0.0005*t;
|
||||
vec2 res = map( ro+rd*t );
|
||||
float precis = 0.0005*t;
|
||||
vec2 res = map( ro+rd*t );
|
||||
if( res.x<precis || t>tmax ) break;
|
||||
t += res.x;
|
||||
m = res.y;
|
||||
m = res.y;
|
||||
}
|
||||
|
||||
if( t>tmax ) m=-1.0;
|
||||
|
@ -272,11 +272,11 @@ vec2 castRay( in vec3 ro, in vec3 rd )
|
|||
|
||||
float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
|
||||
{
|
||||
float res = 1.0;
|
||||
float res = 1.0;
|
||||
float t = mint;
|
||||
for( int i=0; i<16; i++ )
|
||||
{
|
||||
float h = map( ro + rd*t ).x;
|
||||
float h = map( ro + rd*t ).x;
|
||||
res = min( res, 8.0*h/t );
|
||||
t += clamp( h, 0.02, 0.10 );
|
||||
if( h<0.001 || t>tmax ) break;
|
||||
|
@ -288,22 +288,22 @@ 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 +
|
||||
e.yyx*map( pos + e.yyx ).x +
|
||||
e.yxy*map( pos + e.yxy ).x +
|
||||
e.xxx*map( pos + e.xxx ).x );
|
||||
e.yyx*map( pos + e.yyx ).x +
|
||||
e.yxy*map( pos + e.yxy ).x +
|
||||
e.xxx*map( pos + e.xxx ).x );
|
||||
/*
|
||||
vec3 eps = vec3( 0.0005, 0.0, 0.0 );
|
||||
vec3 nor = vec3(
|
||||
map(pos+eps.xyy).x - map(pos-eps.xyy).x,
|
||||
map(pos+eps.yxy).x - map(pos-eps.yxy).x,
|
||||
map(pos+eps.yyx).x - map(pos-eps.yyx).x );
|
||||
return normalize(nor);
|
||||
*/
|
||||
vec3 eps = vec3( 0.0005, 0.0, 0.0 );
|
||||
vec3 nor = vec3(
|
||||
map(pos+eps.xyy).x - map(pos-eps.xyy).x,
|
||||
map(pos+eps.yxy).x - map(pos-eps.yxy).x,
|
||||
map(pos+eps.yyx).x - map(pos-eps.yyx).x );
|
||||
return normalize(nor);
|
||||
*/
|
||||
}
|
||||
|
||||
float calcAO( in vec3 pos, in vec3 nor )
|
||||
{
|
||||
float occ = 0.0;
|
||||
float occ = 0.0;
|
||||
float sca = 1.0;
|
||||
for( int i=0; i<5; i++ )
|
||||
{
|
||||
|
@ -332,7 +332,7 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
vec3 col = vec3(0.7, 0.9, 1.0) +rd.y*0.8;
|
||||
vec2 res = castRay(ro,rd);
|
||||
float t = res.x;
|
||||
float m = res.y;
|
||||
float m = res.y;
|
||||
if( m>-0.5 )
|
||||
{
|
||||
vec3 pos = ro + t*rd;
|
||||
|
@ -340,7 +340,7 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
vec3 ref = reflect( rd, nor );
|
||||
|
||||
// material
|
||||
col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) );
|
||||
col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) );
|
||||
if( m<1.5 )
|
||||
{
|
||||
|
||||
|
@ -350,9 +350,9 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
|
||||
// lighting
|
||||
float occ = calcAO( pos, nor );
|
||||
vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) );
|
||||
vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) );
|
||||
vec3 hal = normalize( lig-rd );
|
||||
float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 );
|
||||
float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 );
|
||||
float dif = clamp( dot( nor, lig ), 0.0, 1.0 );
|
||||
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 );
|
||||
|
@ -361,31 +361,31 @@ vec3 render( in vec3 ro, in vec3 rd )
|
|||
dif *= calcSoftshadow( pos, lig, 0.02, 2.5 );
|
||||
dom *= calcSoftshadow( pos, ref, 0.02, 2.5 );
|
||||
|
||||
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0)*
|
||||
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0)*
|
||||
dif *
|
||||
(0.04 + 0.96*pow( clamp(1.0+dot(hal,rd),0.0,1.0), 5.0 ));
|
||||
|
||||
vec3 lin = vec3(0.0);
|
||||
vec3 lin = vec3(0.0);
|
||||
lin += 1.30*dif*vec3(1.00,0.80,0.55);
|
||||
lin += 0.40*amb*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*dom*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*bac*vec3(0.25,0.25,0.25)*occ;
|
||||
lin += 0.25*fre*vec3(1.00,1.00,1.00)*occ;
|
||||
col = col*lin;
|
||||
col += 10.00*spe*vec3(1.00,0.90,0.70);
|
||||
col = col*lin;
|
||||
col += 10.00*spe*vec3(1.00,0.90,0.70);
|
||||
|
||||
col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0002*t*t*t ) );
|
||||
col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0002*t*t*t ) );
|
||||
}
|
||||
|
||||
return vec3( clamp(col,0.0,1.0) );
|
||||
return vec3( clamp(col,0.0,1.0) );
|
||||
}
|
||||
|
||||
mat3 setCamera( in vec3 ro, in vec3 ta, float cr )
|
||||
{
|
||||
vec3 cw = normalize(ta-ro);
|
||||
vec3 cp = vec3(sin(cr), cos(cr),0.0);
|
||||
vec3 cu = normalize( cross(cw,cp) );
|
||||
vec3 cv = normalize( cross(cu,cw) );
|
||||
vec3 cp = vec3(sin(cr), cos(cr),0.0);
|
||||
vec3 cu = normalize( cross(cw,cp) );
|
||||
vec3 cv = normalize( cross(cu,cw) );
|
||||
return mat3( cu, cv, cw );
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ void main()
|
|||
vec2 p = (-resolution.xy + 2.0*gl_FragCoord.xy)/resolution.y;
|
||||
#endif
|
||||
|
||||
// RAY: Camera is provided from raylib
|
||||
// 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;
|
||||
|
@ -414,10 +414,10 @@ void main()
|
|||
// ray direction
|
||||
vec3 rd = ca * normalize( vec3(p.xy,2.0) );
|
||||
|
||||
// render
|
||||
// render
|
||||
vec3 col = render( ro, rd );
|
||||
|
||||
// gamma
|
||||
// gamma
|
||||
col = pow( col, vec3(0.4545) );
|
||||
|
||||
tot += col;
|
||||
|
|
|
@ -15,26 +15,26 @@ uniform float time; // Total run time (in secods)
|
|||
// Draw circle
|
||||
vec4 DrawCircle(vec2 fragCoord, vec2 position, float radius, vec3 color)
|
||||
{
|
||||
float d = length(position - fragCoord) - radius;
|
||||
float t = clamp(d, 0.0, 1.0);
|
||||
return vec4(color, 1.0 - t);
|
||||
float d = length(position - fragCoord) - radius;
|
||||
float t = clamp(d, 0.0, 1.0);
|
||||
return vec4(color, 1.0 - t);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fragCoord = gl_FragCoord.xy;
|
||||
vec2 position = vec2(mouse.x, resolution.y - mouse.y);
|
||||
float radius = 40.0;
|
||||
vec2 fragCoord = gl_FragCoord.xy;
|
||||
vec2 position = vec2(mouse.x, resolution.y - mouse.y);
|
||||
float radius = 40.0;
|
||||
|
||||
// Draw background layer
|
||||
vec4 colorA = vec4(0.2,0.2,0.8, 1.0);
|
||||
vec4 colorB = vec4(1.0,0.7,0.2, 1.0);
|
||||
vec4 layer1 = mix(colorA, colorB, abs(sin(time*0.1)));
|
||||
vec4 layer1 = mix(colorA, colorB, abs(sin(time*0.1)));
|
||||
|
||||
// Draw circle layer
|
||||
vec3 color = vec3(0.9, 0.16, 0.21);
|
||||
vec4 layer2 = DrawCircle(fragCoord, position, radius, color);
|
||||
|
||||
// Blend the two layers
|
||||
finalColor = mix(layer1, layer2, layer2.a);
|
||||
// Draw circle layer
|
||||
vec3 color = vec3(0.9, 0.16, 0.21);
|
||||
vec4 layer2 = DrawCircle(fragCoord, position, radius, color);
|
||||
|
||||
// Blend the two layers
|
||||
finalColor = mix(layer1, layer2, layer2.a);
|
||||
}
|
||||
|
|
|
@ -16,26 +16,26 @@ uniform vec2 resolution = vec2(800, 450);
|
|||
|
||||
void main()
|
||||
{
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
}
|
|
@ -12,9 +12,9 @@ out vec4 finalColor;
|
|||
#define MAX_SPOTS 3
|
||||
|
||||
struct Spot {
|
||||
vec2 pos; // window coords of spot
|
||||
float inner; // inner fully transparent centre radius
|
||||
float radius; // alpha fades out to this radius
|
||||
vec2 pos; // window coords of spot
|
||||
float inner; // inner fully transparent centre radius
|
||||
float radius; // alpha fades out to this radius
|
||||
};
|
||||
|
||||
uniform Spot spots[MAX_SPOTS]; // Spotlight positions array
|
||||
|
@ -22,44 +22,44 @@ uniform float screenWidth; // Width of the screen
|
|||
|
||||
void main()
|
||||
{
|
||||
float alpha = 1.0;
|
||||
float alpha = 1.0;
|
||||
|
||||
// Get the position of the current fragment (screen coordinates!)
|
||||
vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y);
|
||||
|
||||
// Find out which spotlight is nearest
|
||||
float d = 65000; // some high value
|
||||
int fi = -1; // found index
|
||||
// Get the position of the current fragment (screen coordinates!)
|
||||
vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y);
|
||||
|
||||
// Find out which spotlight is nearest
|
||||
float d = 65000; // some high value
|
||||
int fi = -1; // found index
|
||||
|
||||
for (int i = 0; i < MAX_SPOTS; i++)
|
||||
{
|
||||
for (int j = 0; j < MAX_SPOTS; j++)
|
||||
{
|
||||
float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius;
|
||||
for (int j = 0; j < MAX_SPOTS; j++)
|
||||
{
|
||||
float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius;
|
||||
|
||||
if (d > dj)
|
||||
{
|
||||
d = dj;
|
||||
fi = i;
|
||||
}
|
||||
}
|
||||
if (d > dj)
|
||||
{
|
||||
d = dj;
|
||||
fi = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// d now equals distance to nearest spot...
|
||||
// allowing for the different radii of all spotlights
|
||||
if (fi != -1)
|
||||
{
|
||||
if (d > spots[fi].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[fi].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[fi].inner) / (spots[fi].radius - spots[fi].inner);
|
||||
}
|
||||
}
|
||||
|
||||
// Right hand side of screen is dimly lit,
|
||||
if (d > spots[fi].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[fi].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[fi].inner) / (spots[fi].radius - spots[fi].inner);
|
||||
}
|
||||
}
|
||||
|
||||
// Right hand side of screen is dimly lit,
|
||||
// could make the threshold value user definable
|
||||
if ((pos.x > screenWidth/2.0) && (alpha > 0.9)) alpha = 0.9;
|
||||
if ((pos.x > screenWidth/2.0) && (alpha > 0.9)) alpha = 0.9;
|
||||
|
||||
finalColor = vec4(0, 0, 0, alpha);
|
||||
}
|
||||
|
|
|
@ -23,15 +23,15 @@ uniform float speedX;
|
|||
uniform float speedY;
|
||||
|
||||
void main() {
|
||||
float pixelWidth = 1.0 / size.x;
|
||||
float pixelHeight = 1.0 / size.y;
|
||||
float aspect = pixelHeight / pixelWidth;
|
||||
float boxLeft = 0.0;
|
||||
float boxTop = 0.0;
|
||||
float pixelWidth = 1.0 / size.x;
|
||||
float pixelHeight = 1.0 / size.y;
|
||||
float aspect = pixelHeight / pixelWidth;
|
||||
float boxLeft = 0.0;
|
||||
float boxTop = 0.0;
|
||||
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
|
||||
finalColor = texture(texture0, p)*colDiffuse*fragColor;
|
||||
finalColor = texture(texture0, p)*colDiffuse*fragColor;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue