From 59dfebaa3331cb09a91c2f842c84e96a30367e82 Mon Sep 17 00:00:00 2001 From: gradient Date: Tue, 12 Sep 2017 21:10:01 -0500 Subject: [PATCH] make the test scene vaguely more interesting --- examples/test/shaders/test.frag | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/test/shaders/test.frag b/examples/test/shaders/test.frag index 9a38bb3..81f0743 100644 --- a/examples/test/shaders/test.frag +++ b/examples/test/shaders/test.frag @@ -3,8 +3,8 @@ #define FOV 24 #define EPSILON 0.01 -#define MAX_STEPS 64 -#define NEAR_D 0. +#define MAX_STEPS 128 +#define NEAR_D 0.1 #define FAR_D 120. #define GRAD_EPSILON 0.0001 @@ -30,8 +30,9 @@ vec3 ray_dir(float fov, vec2 uv) { } SceneResult scene_f(vec3 p) { - SceneResult ball = SceneResult(length(p-vec3(0, 2, 0)) - 2, MAT_NORMALS); - SceneResult plane = SceneResult(p.y, 2.); + SceneResult ball = SceneResult(length(p-vec3(0, 2, 0)) - 2, 3.); + SceneResult ball2 = SceneResult(length(p-vec3(2*sin(u_Time), 2-2*cos(u_Time), 0)) - 1, 3.); + SceneResult plane = SceneResult(p.y+5, 2.); // SceneResult box = SceneResult( // fOpUnionRound(fBox(p, vec3(1)), fSphere(p-vec3(.8), 1.), .2), 0.); @@ -47,7 +48,7 @@ SceneResult scene_f(vec3 p) { // fBox(p, vec3(1)), // 1.); - SceneResult res = min_sr(ball, plane); + SceneResult res = min_sr(min_sr(ball, ball2), plane); return res; } @@ -76,6 +77,10 @@ vec3 raymarch(vec3 o, vec3 d, float start, float end) { return vec3(end, N_HIT_FAR_PLANE, MAX_STEPS); } +float checker(vec2 uv) { + return sign(mod(floor(uv.x) + floor(uv.y), 2.0)); +} + vec4 shade_material(vec3 p, vec3 norm, float mat_idx) { if (mat_idx <= 0.0) { return vec4(0); @@ -85,8 +90,13 @@ vec4 shade_material(vec3 p, vec3 norm, float mat_idx) { return vec4(norm, 1.0); } if (mat_idx <= 2.0) { - return vec4(sign(mod(floor(p.x) + floor(p.z), 2.0))); + return vec4(vec3(mix(0.8, 1.0, checker(p.xz))), 1); } + if (mat_idx <= 3.0) { + return vec4(mix(vec3(0), vec3(0.05, 0, 0.1), dot(vec3(3, 3, 3), norm)), 1); + } + + return vec4(1, 0, 0, 1); //return } @@ -103,10 +113,10 @@ void main() { vec2 uv = gl_FragCoord.xy * 2.0 / u_Resolution.xy - 1.0; uv.x *= u_Resolution.x/u_Resolution.y; - float an = 0.3 * u_Time; - float d = 6.; - vec3 eye = vec3(3. * sin(an), 4., 3. * cos(an)) * d; - vec3 target = vec3(0., 0., 0.); + float an = 0.; + float d = 5.; + vec3 eye = vec3(3. * sin(an), 3., 3. * cos(an)) * d; + vec3 target = vec3(0., 2., 0.); mat3 lookAt = look_mat(eye, target, 0); vec3 dir = normalize(lookAt * ray_dir(FOV, uv)); @@ -117,13 +127,14 @@ void main() { float mat_idx = result.y; float iters = result.z; if (depth >= FAR_D) { - color = vec4(.1, .3, .9, 1.); + // color = vec4(.1, .3, .9, 1.); return; } //color = colormap(iters/MAX_STEPS+0.5); vec3 p = eye + dir * depth; // recast the ray color = shade(p, mat_idx); + //color = vec4(vec3(depth/FAR_D), 1); // gamma color = vec4(pow(clamp(color.xyz, 0.0, 1.0), vec3(0.4545)), 1.0);