Added some more example shaders
This commit is contained in:
92
shaders/cineshader_lava.frag
Normal file
92
shaders/cineshader_lava.frag
Normal file
@@ -0,0 +1,92 @@
|
||||
/* Based on shader by edankwan: https://www.shadertoy.com/view/3sySRK
|
||||
* CC BY-NC-SA 3.0 - https://creativecommons.org/licenses/by-nc-sa/3.0/
|
||||
* Modified by m11
|
||||
*/
|
||||
|
||||
float opSmoothUnion( float d1, float d2, float k )
|
||||
{
|
||||
float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );
|
||||
return mix( d2, d1, h ) - k*h*(1.0-h);
|
||||
}
|
||||
|
||||
float sdSphere( vec3 p, float s )
|
||||
{
|
||||
return length(p)-s;
|
||||
}
|
||||
|
||||
float map(vec3 p)
|
||||
{
|
||||
float aspect = iResolution.x / iResolution.y;
|
||||
vec2 worldSize = vec2(6.0 * aspect, 6.0);
|
||||
vec3 motionExtent = vec3(worldSize * 0.5 - 1.5, 0.2);
|
||||
|
||||
float d = 10.0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
float fi = float(i);
|
||||
float time = iTime * (fract(fi * 412.531 + 0.513) - 0.5) * 2.0;
|
||||
d = opSmoothUnion(
|
||||
sdSphere(p + sin(time + fi * vec3(52.5126, 64.62744, 632.25)) * motionExtent, mix(0.7, 1.4, fract(fi * 412.531 + 0.5124))),
|
||||
d,
|
||||
0.3
|
||||
);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
vec3 calcNormal( in vec3 p )
|
||||
{
|
||||
const float h = 1e-5; // or some other value
|
||||
const vec2 k = vec2(1,-1);
|
||||
return normalize( k.xyy*map( p + k.xyy*h ) +
|
||||
k.yyx*map( p + k.yyx*h ) +
|
||||
k.yxy*map( p + k.yxy*h ) +
|
||||
k.xxx*map( p + k.xxx*h ) );
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = fragCoord/iResolution.xy;
|
||||
|
||||
float aspect = iResolution.x / iResolution.y;
|
||||
vec2 worldSize = vec2(6.0 * aspect, 6.0);
|
||||
|
||||
float pixelSize = worldSize.y / iResolution.y;
|
||||
|
||||
// screen size is...
|
||||
vec3 rayOri = vec3((uv - 0.5) * worldSize, 3.0);
|
||||
vec3 rayDir = vec3(0.0, 0.0, -1.0);
|
||||
|
||||
float depth = 0.0;
|
||||
float dist = 0.0;
|
||||
vec3 p;
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
p = rayOri + rayDir * depth;
|
||||
dist = map(p);
|
||||
depth += dist;
|
||||
if (dist < 1e-6) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
depth = min(6.0, depth);
|
||||
vec3 n = calcNormal(p);
|
||||
float b = max(0.0, dot(n, vec3(0.577)));
|
||||
vec3 col = (0.5 + 0.5 * cos((b + iTime * 3.0) + uv.xyx * 2.0 + vec3(0,2,4))) * (0.85 + b * 0.35);
|
||||
col *= exp( -depth * 0.15 );
|
||||
|
||||
float hit = step(dist, 1e-6);
|
||||
float aa = hit * smoothstep(pixelSize, 0.0, dist);
|
||||
fragColor = vec4(col, aa);
|
||||
|
||||
// maximum thickness is 2m in alpha channel
|
||||
//fragColor = vec4(col, 1.0 - (depth - 0.5) / 2.0);
|
||||
}
|
||||
|
||||
/** SHADERDATA
|
||||
* { *
|
||||
* "title": "My Shader 0",
|
||||
* "description": "Lorem ipsum dolor",
|
||||
* "model": "person"
|
||||
* }
|
||||
*/
|
||||
Reference in New Issue
Block a user