Skip to content

Commit

Permalink
Tweaks, trying to be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
utensil committed Sep 23, 2024
1 parent 17efa3e commit 37df0af
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions trees/ag-001J.tree
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ float fio(float t) {

void timeLine(float time)
{
cameraPos = vec3(5., 5., -3.); // mix(vec3(0.0), , eio(t));
cameraPos = vec3(5., 2., -3.); // mix(vec3(0.0), , eio(t));
cameraTarget = vec3(0.0, 0.0, 5.);

//time += 32.;
Expand All @@ -98,8 +98,8 @@ void timeLine(float time)
// t = tl(time, 0.5, 1.0);
// cornersAnim = mix(0., 1., t);

// t = tl(time, 1.0, 1.0);
///cameraPos = vec3(2., 3., -3.); //mix(cameraPos, , eio(t));
t = tl(time, 0.0, 0.5);
cameraPos = mix(cameraPos, vec3(5., 6., -3.) , t); // eio(t));
///cameraTarget = vec3(0.0, 0.0, 3.0); //mix(cameraTarget, , eio(t));

// t = tl(time, 0.5, 0.5);
Expand Down Expand Up @@ -133,7 +133,7 @@ void timeLine(float time)

raySphereAlpha = 1.;

for (int i=0; i<6; i++) {
for (int i=0; i<10; i++) {
t = tl(time, 0., 0.5);
radiusAnim = mix(radiusAnim, float(i) + 2., t);
t = tl(time, 0., 0.5);
Expand All @@ -152,17 +152,20 @@ void timeLine(float time)
// colToUv = mix(colToUv, 1.0, eio(t));
// screenAlpha = mix(screenAlpha, 0.0, t);

t = tl(time, 0.5, 0.0);
radiusAnim = mix(radiusAnim, 0.0, t);
routeAnim = mix(routeAnim, 0.0, t);
sphereAnim = mix(sphereAnim, 0.0, t);


t = tl(time, 0.5, 1.0);
rayDirectionAnim2 = mix(rayDirectionAnim2, 1.0, t); // fio(t)); // eio(t));

t = tl(time, 0.5, 3.0);
rayDirectionAnim = mix(rayDirectionAnim, 1.0, fio(t));

t = tl(time, 3.5, 0.5);
t = tl(time, 3.5, 0.0);
rayDirectionAnim2 = mix(rayDirectionAnim2, 0.0, t);
radiusAnim = mix(radiusAnim, 0.0, t);
routeAnim = mix(routeAnim, 0.0, t);
sphereAnim = mix(sphereAnim, 0.0, t);
raySphereAlpha = mix(raySphereAlpha, 0.0, t);

// rayDirectionAnim = mix(rayDirectionAnim, 0.0, t);
Expand Down Expand Up @@ -218,7 +221,7 @@ vec3 screenPos;
vec2 sceneSpheres(vec3 p)
{
vec2 s1 = vec2(sdSphere(p - vec3(-2.0, 0.0, 6.0), 1.), MAT_SPHERE1);
vec2 s2 = vec2(sdSphere(p - vec3(0.0, 0.0, 12.0), 1.), MAT_SPHERE2);
vec2 s2 = vec2(sdSphere(p - vec3(0.0, 0.0, 16.0), 1.), MAT_SPHERE2);
vec2 s3 = vec2(sdSphere(p - vec3(2.0, 0.0, 9.0), 1.), MAT_SPHERE3);
return opU(opU(s1, s2), s3);
}
Expand Down Expand Up @@ -306,18 +309,29 @@ vec2 gizmoScreenZ(vec3 p)
}

float sphereID = 0.0;
float hitSphereID = 0.0;
vec2 gizmoMarching(vec3 p)
{
vec3 ray = vec3(0., 0., 1.);
vec2 d = vec2(10000.);

// if(rayDirectionAnim2 > 0.0) {
// float a1 = fract(rayDirectionAnim * 19.99999);
// float a2 = floor(rayDirectionAnim * 19.99999) / 20.;
// vec2 screenSize = iResolution.xy / min(iResolution.x, iResolution.y);
// screenSize.y *= -1.;
// screenSize = mix(-screenSize, screenSize, vec2(a1, a2));
// ray = mix(vec3(0.), vec3(screenSize, screenZ) * 10.0, rayDirectionAnim2) - vec3(0.);
// }

float t = 0.0;
for(int i=0; i<7; i++) {
vec3 pos = ray * t;
vec3 pos;
for(int i=0; i<10; i++) {
pos = ray * t;
vec2 s = vec2(sdSphere(p - pos, 0.15), MAT_MARCHSPHERE);
if (s.x < d.x) {
d = s;
sphereID = float(i);
sphereID = float(i);
}

float dist = sceneSpheres(pos).x;
Expand All @@ -327,7 +341,8 @@ vec2 gizmoMarching(vec3 p)

d = opU(d, c1);
t += dist;
}

}
return d;
}

Expand Down Expand Up @@ -356,7 +371,7 @@ vec2 gizmoRayDirection(vec3 p)
t += d.x;
}

c1 = opU(c1, vec2(sdSphere(p - pos, 0.3), MAT_HITPOINT));
c1 = opU(c1, vec2(sdSphere(p - pos, 0.15), MAT_HITPOINT));

return c1;
}
Expand Down Expand Up @@ -518,7 +533,7 @@ vec4 gizmoShade(vec2 mat, vec3 p)
col = vec4(0.05, 0.05, 1., screenZAlpha);
} else if (mat.y == MAT_MARCHSPHERE) {
float alpha = clamp(sphereAnim - sphereID, 0.0, 1.0);
vec3 sc = mix(vec3(.0, .1, 3.), vec3(.02, 1., .02), float(sphereID == 0. || sphereID == 6.));
vec3 sc = mix(vec3(.0, .1, 3.), vec3(.02, 1., .02), float(sphereID == 0. || sphereID >= hitSphereID));
col = vec4(sc, alpha * raySphereAlpha);
} else if (mat.y == MAT_MARCHROUTE) {
col = vec4(1., 0., 0., .9);
Expand All @@ -538,10 +553,13 @@ vec4 radiusShade(vec2 mat, vec3 p)
vec2 d = vec2(10000.);

float t = 0.0;
for(int i=0; i<7; i++) {
for(int i=0; i<10; i++) {
vec3 pos = ray * t;
vec2 dd = sceneSpheres(pos);
d = vec2(sdSphere(p - pos, dd.x), MAT_MARCHSPHERE);
if(dd.x < 0.001 && hitSphereID == 0.) {
hitSphereID = float(i);
}
float alpha2 = step(radiusAnim, float(i) + 2.);
float alpha = clamp(radiusAnim - float(i) - 1., 0.0, 1.0);

Expand Down Expand Up @@ -623,19 +641,16 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )

vec3 col = vec3(0.);


// AA
// https://www.shadertoy.com/view/Msl3Rr
for(int y = 0; y < 2; y++) {
for(int x = 0; x < 2; x++) {
vec2 off = vec2(float(x),float(y))/2.;
vec2 xy = (-iResolution.xy+2.0*(fragCoord + off * dp / 4.0)) / iResolution.y;
col += render(xy)*0.25;
col += render(xy)*0.25;
}
}

// vec2 off = vec2(0.);
// vec2 xy = (-iResolution.xy+2.0*(fragCoord+off)) / iResolution.y;
// col = render(p);

col = reinhard(col, 1.0, 1000.0);
col = pow(col, vec3(1.0/2.2));
Expand Down

0 comments on commit 37df0af

Please sign in to comment.