Skip to content

Instantly share code, notes, and snippets.

@lcrs
Last active October 26, 2015 12:41
Show Gist options
  • Save lcrs/c50e4ae4fe527546abb9 to your computer and use it in GitHub Desktop.
Save lcrs/c50e4ae4fe527546abb9 to your computer and use it in GitHub Desktop.
Snow rotate-o
// based on https://www.shadertoy.com/view/4tSSzt by FabriceNeyret2
// using the base ray-marcher of Trisomie21: https://www.shadertoy.com/view/4tfGRB#
vec3 adsk_getVertexPosition();
vec3 adsk_getCameraPosition();
vec3 adsk_getLightPosition();
vec3 adsk_getLightDirection();
vec3 adsk_getLightTangent();
vec3 adsk_getLightColour();
vec3 adsk_getDiffuseMapCoord();
vec4 adsk_getDiffuseMapValue(in vec2 texCoord);
float adsk_getTime();
uniform float adskUID_Speed;
uniform float adskUID_Offset;
uniform float amount, pp1, pp2;
uniform vec3 speed;
vec2 adskUID_resolution = vec2(1920., 1080.);
float adskUID_time = adsk_getTime() * 0.05 * adskUID_Speed + adskUID_Offset;
#define r(v,t) v *= mat2( C = cos((t)*adskUID_time), S = sin((t)*adskUID_time), -S, C )
float smin( float a, float b )
{
return min(a,b);
}
vec4 adskUID_lightbox(vec4 source)
{
vec3 uv = adsk_getDiffuseMapCoord();
vec3 camera = adsk_getCameraPosition();
vec3 vertex = adsk_getVertexPosition();
vec3 light = adsk_getLightPosition();
vec3 lightdir = adsk_getLightDirection();
vec3 lighttan = adsk_getLightTangent();
vec3 lightbitan = cross(lightdir, lighttan);
mat3 lightbasis = mat3(lighttan, -lightbitan, lightdir);
vec3 dir = normalize(vertex - camera);
vec3 ro = camera - light;
ro *= lightbasis;
ro /= 100.;
vec3 rd = dir * lightbasis;
//ro += rd;
vec2 w = uv.xy;
vec4 f = vec4(0.0);
float C,S,r,r1,x,x1,i0;
vec4 p = vec4(w,0,1)/adskUID_resolution.yyxy-.5, d,p2, u,t,t1,M,m; p.x-=.4; // init ray
//r(p.xz,.13); r(p.yz,.2); r(p.xy,.1); // camera rotations
d.xyz = rd; // ray dir = ray0-vec3(0)
p.xyz = -ro;
p.xyz += adskUID_time * speed;
for (float i=1. * amount; i>0.; i-=.01)
{ x = 1e3;
for(float j=0.; j<=1.; j++) {
u = floor(p/8.+11.5*j); // objects id + local frame
u = fract(1234.*sin(78.*(u+u.yzxw))); // randomize ids
p2 = p+11.5*j;
if (j==0.) p2.x -= 15.*adskUID_time*(2.*u.y-1.); // offset column
else p2.y -= 15.*adskUID_time*(2.*u.z-1.);
u = floor(p2/8.); t = mod(p2, 8.)-4.;
u = fract(1234.*sin(78.*(u+u.yzxw)*vec4(1,-12,8,-4)));
r = .17*pp1 + 0.1 *pp2 * u.w;
r1 =3.15;
t1 = t+r1*sin(1.*adskUID_time+u*6.); x1 = length(t .xyz)-r; x = smin(x,x1);
t1 = t+r1*sin(2.*adskUID_time-u*6.); r(t1.xy,u.z); x1 = length(t1.xyz)-r*.8; x = smin(x,x1);
t1 = t+r1*sin(3.*adskUID_time+u*3.); r(t1.yz,u.x); x1 = length(t1.xyz)-r*.5; x = smin(x,x1);
if(x<.01) break; // hit !
}
if(x<.01) {i0=i; break; } // hit !
p -= d*x; // march ray
}
if(x<.01) // hit !
{
f = i0*i0*(t);
} // color texture + black fog
return vec4(f.rrr, source.a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment