diff --git a/Assets/raymarched/lib/libgarbage.cginc b/Assets/raymarched/lib/libgarbage.cginc index ad23504..a12d038 100644 --- a/Assets/raymarched/lib/libgarbage.cginc +++ b/Assets/raymarched/lib/libgarbage.cginc @@ -285,12 +285,13 @@ SurfacePoint default_material_sdf(float3 p) { } float3 default_lighting(Ray ray) { - float3 sun_dir = normalize(float3(1, 0.5, 0)); + float3 sun_dir = normalize(float3(1, 0.5, -0.5)); if (ray.missed) - return 0.1; - float3 col = 0; - col = ray.mat.col * dot(ray.normal, sun_dir); - return col; + return lRenderSky(ray.dir, sun_dir); + float3 light = lSun(ray.normal, sun_dir); + light *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50); + light += lSky(ray.normal); + return light * ray.mat.col; } #endif // LIBGARBAGE_INCLUDED diff --git a/Assets/raymarched/lib/libgarbage_example.shader b/Assets/raymarched/lib/libgarbage_example.shader index 730f76c..fea419d 100644 --- a/Assets/raymarched/lib/libgarbage_example.shader +++ b/Assets/raymarched/lib/libgarbage_example.shader @@ -52,6 +52,9 @@ Shader "CrispyPin/LibGarbageExample" } float3 floor_col(float3 p) { + p = rotY(p, sin(length(p.xz) * 0.2) * 0.2); + p.x += smoothstep(0, 0.5, fmod(_Time.x, 1)) * 2; + p.z += smoothstep(0.5, 1, fmod(_Time.x, 1)) * 2; return lerp(0.08, checkers(p - 1, 0.06, 0.12, 2), smoothstep(64, 0, length(p)) @@ -92,8 +95,7 @@ Shader "CrispyPin/LibGarbageExample" if (ray.missed) { if (ray.dir.y >= 0) { return lRenderSky(ray.dir, sun_dir); - } else - { + } else { float3 cam = ray.start; cam.y += 2.5; float3 dir = ray.dir; diff --git a/Assets/raymarched/lib/libgarbage_lighting.cginc b/Assets/raymarched/lib/libgarbage_lighting.cginc index 024ffd3..1ad8561 100644 --- a/Assets/raymarched/lib/libgarbage_lighting.cginc +++ b/Assets/raymarched/lib/libgarbage_lighting.cginc @@ -3,18 +3,17 @@ // common lighting operations // -------------------------------- -float3 lRenderSun(float3 ray_dir, float3 sun_dir) { +float3 lRenderSun(float3 ray_dir, float3 sun_dir, float3 sun_col = float3(0.8, 0.4, 0.1)) { float alignment = min(acos(dot(ray_dir, sun_dir)), 1); - float sun_amount = smax(min(0.03 / alignment, 5) - 0.06, 0, 0.15); - return sun_amount* float3(0.8, 0.4, 0.1); + float sun_amount = pow(0.025/alignment, 3); + return sun_amount * sun_col; } // a basic procedural sky float3 lRenderSky(float3 ray_dir, float3 sun_dir) { float3 rendered_sun = lRenderSun(ray_dir, sun_dir); - // float3 rendered_sun = max(0, pow(dot(ray_dir, sun_dir) + 0.4, 10)-28) * float3(0.8, 0.4, 0); - return float3(0.7, 0.75, 0.8) - abs(ray_dir.y) * 0.5 + rendered_sun; - // return rendered_sun; + float a = 1 - abs(ray_dir.y); + return lerp(float3(0.3, 0.3, 0.7), float3(0.6, 0.7, 0.9), a) + rendered_sun; } //calculate sky light