From e68c2de1b522366fececc8b1e73048cd377e9cc8 Mon Sep 17 00:00:00 2001 From: utensil Date: Sat, 17 Aug 2024 16:51:14 +0800 Subject: [PATCH] Tweak for the best angle for using abs --- trees/math-000K.tree | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/trees/math-000K.tree b/trees/math-000K.tree index 5308cb4..2a5dce7 100644 --- a/trees/math-000K.tree +++ b/trees/math-000K.tree @@ -20,8 +20,10 @@ #define LIGHT_COLOR vec3(1.000,0.794,0.066) #define RESOLUTION iResolution.xy #define RAYMARCH_MULTISAMPLE 4 -#define RAYMARCH_BACKGROUND (RAYMARCH_AMBIENT + rayDirection.y * 0.8) -#define RAYMARCH_AMBIENT vec3(0.7, 0.9, 1.0) +// #define RAYMARCH_BACKGROUND (RAYMARCH_AMBIENT + rayDirection.y * 0.8) +#define RAYMARCH_BACKGROUND vec3(1.0, 1.0, 1.0) +#define RAYMARCH_AMBIENT vec3(1.0, 1.0, 1.0) +// #define RAYMARCH_AMBIENT vec3(0.7, 0.9, 1.0) // #define RAYMARCH_AMBIENT vec3(0.374,0.481,0.535) #define EPSILON 0.0001 @@ -60,7 +62,7 @@ float mySDF2(vec3 p) { float z2 = pow(z, 2.); float y3 = pow(y, 3.); - // return 5.*(z2+y3-y4-x2*y2); + return 5.*(z2+y3-y4-x2*y2); // return (y2-x2-z2); @@ -83,7 +85,7 @@ Material raymarchMap( in vec3 pos ) { // res = opUnion(res, materialNew( vec3(1.0, 2.0, 1.0), opIntersection(0.05 * abs(mySDF2(pos)), cubeSDF(pos, 1.0))) ); - Material res = materialNew( vec3(1.0, 2.0, 1.0), opIntersection(0.05 * tapping_abs(mySDF2(pos)), sphereSDF(pos, 1.8))); + Material res = materialNew( vec3(1.0, 2.0, 1.0), opIntersection(0.05 * abs(mySDF2(pos)), sphereSDF(pos, 1.8))); // res = opUnion( res, materialNew( vec3(1.0, 1.0, 1.0), 1.0, 0.0, sphereSDF(pos-vec3( 0.0, 2.0, 0.0), 0.5 ) ) ); // res = opUnion( res, materialNew( vec3(0.0, 1.0, 1.0), boxSDF( pos-vec3( 2.0, 0.5, 0.0), vec3(0.4, 0.4, 0.4) ) ) ); @@ -111,8 +113,19 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) vec2 mo = u_mouse * pixel; float time = 32.0 + u_time * 1.5; // vec3 cam = vec3( 12.5*cos(0.1*time), 2.2, 12.5*sin(0.1*time) ); - vec3 cam = vec3( 8.5*cos(0.1*time - 7.0*mo.x), 2.2, 8.5*sin(0.1*time - 7.0*mo.x) ); - + // vec3 cam = vec3( 8.5*cos(0.1*time - 7.0*mo.x), 2.2, 8.5*sin(0.1*time - 7.0*mo.x) ); + + const vec2 initMouse = vec2(0.2, -0.1); + vec2 mouse = initMouse + vec2(0.035625*sin(u_time*PI), 0.0); // initMouse; // iMouse.xy == vec2(0.,0.) ? initMouse : (iMouse.xy/iResolution.xy - 0.5); + float pitch = clamp(- mouse.x * 2.*PI * 1., -PI,PI); + float yaw = clamp( mouse.y * PI * 1.2, -PI*0.5, PI*0.5); + // pitch and yaw rotations (column-wise matrices) + mat3 rot = mat3(cos(yaw), sin(yaw), 0., -sin(yaw), cos(yaw), 0., 0., 0., 1.); + rot = rot * mat3(cos(pitch), 0., -sin(pitch), 0., 1., 0., sin(pitch), 0., cos(pitch)); + vec3 camPos = vec3(-3., 2., -2.); + // apply + vec3 cam = rot*camPos; + color = raymarch(cam, vec3(0.0), uv).rgb; color = linear2gamma(color);