Skip to content

Instantly share code, notes, and snippets.

@lcrs
Created December 24, 2013 21:39
Show Gist options
  • Save lcrs/8118031 to your computer and use it in GitHub Desktop.
Save lcrs/8118031 to your computer and use it in GitHub Desktop.
#ifdef GL_ES
precision mediump float;
#endif
uniform float adsk_time;
uniform float adsk_result_w, adsk_result_h;
uniform float Rotation;
uniform float pLeft;
uniform bool vignette;
vec2 resolution = vec2(adsk_result_w, adsk_result_h);
vec2 mouse = vec2(Rotation, pLeft);
float globalltime = adsk_time*.05;
uniform float time;
// Added for camera
uniform vec3 camera_position, camera_interest;
uniform float camera_roll, camera_fov;
uniform bool camera_use;
#define pi 3.1415926535897932384624433832795
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// original here: https://www.shadertoy.com/view/MsXGRf - please preserve credits in downstream experiments.
// hash based 3d value noise
float hash( float n )
{
return fract(sin(n)*43758.5453);
}
float noise( in vec3 x )
{
vec3 p = floor(x);
vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*57.0 + 113.0*p.z;
return mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
mix(mix( hash(n+113.0), hash(n+114.0),f.x),
mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
}
vec4 map( vec3 p )
{
vec3 r = p;
float den = -0.6 - p.y;
// invert space
// p.y += 0.6;
p = -2.0*p/dot(p,p);
// twist space
float an = -1.0*sin(0.1*time*globalltime + 1.0*length(p.xz) + 1.0*p.y);
float co = cos(an);
float si = sin(an);
p.xz = mat2(co,-si,si,co)*p.xz;
// distort
p.xz += 1.0*(-1.0+2.0*noise( p*1.1 ));
// pattern
float f;
vec3 q = p*0.85 - vec3(0.0,1.0,0.0)*time*globalltime*0.12;
f = 0.50000*noise( q ); q = q*2.02 - vec3(0.0,1.0,0.0)*time*globalltime*0.12;
f += 0.25000*noise( q ); q = q*2.03 - vec3(0.0,1.0,0.0)*time*globalltime*0.12;
f += 0.12500*noise( q ); q = q*2.01 - vec3(0.0,1.0,0.0)*time*globalltime*0.12;
f += 0.06250*noise( q ); q = q*2.02 - vec3(0.0,1.0,0.0)*time*globalltime*0.12;
f += 0.04000*noise( q ); q = q*2.00 - vec3(0.0,1.0,0.0)*time*globalltime*0.12;
den = clamp( (den + 4.0*f)*1.2, 0.0, 1.0 );
vec3 col = 1.2*mix( vec3(1.0,0.8,0.6), 0.9*vec3(0.3,0.2,0.35), den ) ;
col += 0.05*sin(0.05*q);
//col *= 1.0 - 0.8*smoothstep(0.6,1.0,sin(0.7*q.x)*sin(0.7*q.y)*sin(0.7*q.z))*vec3(0.6,1.0,0.8);
//col *= 1.0 + 1.0*smoothstep(0.5,1.0,1.0-length( (fract(q.xz*0.12)-0.5)/0.5 ))*vec3(1.0,0.9,0.8) ;
col = mix( vec3(0.8,0.3,0.2), col, clamp( (r.y+0.1)/1.5, 0.0, 1.0 ) );
return vec4( col, den );
}
vec3 raymarch( in vec3 ro, in vec3 rd )
{
vec4 sum = vec4( 0.0 );
vec3 bg = vec3(0.4,0.5,0.5)*1.3;
float t = 0.0;
// dithering
// t += 0.05*texture2D( iChannel0, gl_FragCoord.xy/iChannelResolution[0].x ).x;
for( int i=0; i<128; i++ )
{
if( sum.a > 0.99 ) continue;
vec3 pos = ro + t*rd;
vec4 col = map( pos );
col.xyz = mix( bg, col.xyz, exp(-0.002*t*t*t) );
col.a *= 0.5;
col.rgb *= col.a;
sum = sum + col*(1.0 - sum.a);
t += 0.05;
}
sum.xyz = mix( bg, sum.xyz/(0.001+sum.w), sum.w );
return clamp( sum.xyz, 0.0, 1.0 );
}
// Added for camera. Returns a matrix that rotates about an axis
mat4 rot(vec3 axis, float angle) {
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
0.0, 0.0, 0.0, 1.0);
}
// Added for camera
float deg2rad(float angle) {
return(angle/(180.0/pi));
}
void main(void)
{
// inputs
vec2 q = gl_FragCoord.xy / resolution.xy;
vec2 p = -1.0 + 2.0*q;
p.x *= resolution.x/ resolution.y;
vec2 mo = mouse.xy / resolution.xy;
if( mouse.x<=0.00001 ) mo=vec2(0.0);
vec3 ro, rd;
if(camera_use) {
// ok.
vec3 camera_position_r = camera_position * vec3(-1.0, 1.0, 1.0);
vec3 camera_interest_r = camera_interest * vec3(-1.0, 1.0, 1.0);
vec3 camera_direction = camera_interest_r - camera_position_r;
camera_direction = normalize(camera_direction);
vec3 camera_up = (vec4(0.0, 1.0, 0.0, 0.0) * rot(camera_direction, deg2rad(camera_roll))).xyz;
vec3 camera_right = cross(camera_direction, camera_up);
camera_up = cross(camera_right, camera_direction);
p *= tan(deg2rad(camera_fov/2.0));
vec3 image_point = -p.x * camera_right + p.y * camera_up + camera_position_r + camera_direction;
rd = normalize(image_point - camera_position_r);
ro = camera_position_r;
} else {
// camera
float an = -0.07*time*globalltime + 3.0*mo.x;
ro = 4.5*normalize(vec3(cos(an), 0.5, sin(an)));
ro.y += 1.0;
vec3 ta = vec3(0.0, 0.5, 0.0);
float cr = -0.4*cos(0.02*time*globalltime);
// build ray
vec3 ww = normalize( ta - ro);
vec3 uu = normalize(cross( vec3(sin(cr),cos(cr),0.0), ww ));
vec3 vv = normalize(cross(ww,uu));
rd = normalize( p.x*uu + p.y*vv + 2.5*ww );
}
// raymarch
vec3 col = raymarch( ro, rd );
// contrast
col = col*col*(3.0-2.0*col)*1.4 - 0.4;
col.y *= 1.05;
// vignetting
if (vignette)
{
col *= 0.25 + 0.75*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.1 );
gl_FragColor = vec4( col, 1.0 );
}
gl_FragColor = vec4( col, 1.0 );
}
<ShaderNodePreset SupportsAdaptiveDegradation="0" Description="
This Matchbox shader simulates puffy noise.
Setup:
- Rotation : camera rotation around the puffy clouds
- Speed : speed of the noise animation (use negative values for backward playback)
Demo clip: https://vimeo.com/82495451
Based on https://www.shadertoy.com/view/MsXGRf
License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
ivar@inferno-op.com" Name="Crok Puffy Noise">
<Shader OutputBitDepth="Output" Index="1">
<Uniform ResDependent="None" Max="1000000.0" Min="0.0" Default="0.0" Inc="10.0" Tooltip="" Row="0" Col="0" Page="0" DisplayName="Rotation" Type="float" Name="Rotation">
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="5.0" Inc="0.01" Tooltip="" Row="1" Col="0" Page="0" DisplayName="Speed" Type="float" Name="time">
</Uniform>
<Uniform Row="2" Col="0" Page="0" Default="False" Tooltip="" DisplayName="Vignette" Type="bool" Name="vignette">
</Uniform>
<Uniform Row="0" Col="0" Page="1" Default="False" Tooltip="Use explicit camera controls instead of the default rotating camera. You can expression-link these to an Action camera's channels and plug this node into Action's Back input, then drive the camera about with Orbit, Dolly and friends" DisplayName="Use Camera" Type="bool" Name="camera_use">
</Uniform>
<Uniform Inc="0.01" Tooltip="" Row="0" Col="1" Page="1" DisplayName="Position" ValueType="Position" Type="vec3" Name="camera_position">
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="-4.0">
</SubUniform>
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="3.0">
</SubUniform>
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.0">
</SubUniform>
</Uniform>
<Uniform Inc="0.01" Tooltip="" Row="2" Col="1" Page="1" DisplayName="Interest" ValueType="Position" Type="vec3" Name="camera_interest">
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.0">
</SubUniform>
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.5">
</SubUniform>
<SubUniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.0">
</SubUniform>
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="0.0" Inc="0.1" Tooltip="" Row="1" Col="2" Page="1" DisplayName="Roll" Type="float" Name="camera_roll">
</Uniform>
<Uniform ResDependent="None" Max="1000000.0" Min="-1000000.0" Default="50.0" Inc="0.1" Tooltip="" Row="2" Col="2" Page="1" DisplayName="FOV" Type="float" Name="camera_fov">
</Uniform>
</Shader>
<Page Name="Puffy Noise" Page="0">
<Col Name="Setup" Col="0" Page="0">
</Col>
</Page>
<Page Name="Camera" Page="1">
<Col Name="" Col="0" Page="1">
</Col>
<Col Name="" Col="1" Page="1">
</Col>
<Col Name="" Col="2" Page="1">
</Col>
</Page>
</ShaderNodePreset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment