libgarbage example: fix shadow of cutter frame

This commit is contained in:
Crispy 2023-07-30 20:23:29 +02:00
parent 05e0789077
commit 9bf8c0962b
3 changed files with 25 additions and 11 deletions

View file

@ -750,7 +750,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
type: 3 type: 3
objectId: 19ac0a45-6040-4093-92d0-0499e618a878 objectId: 19ac0a45-6040-4093-92d0-0499e618a878
randomNum: 21667702 randomNum: 34799555
--- !u!114 &683266149 --- !u!114 &683266149
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -136,6 +136,7 @@ struct Ray {
float DISTANCE_FN(float3 p); float DISTANCE_FN(float3 p);
SurfacePoint SCENE_FN(float3 p); SurfacePoint SCENE_FN(float3 p);
float3 LIGHT_FN(Ray ray); float3 LIGHT_FN(Ray ray);
float3 SKY_FN(float3 d);
Ray cast_ray(float3 p, float3 d, float startDist = 0); Ray cast_ray(float3 p, float3 d, float startDist = 0);
#include "libgarbage_shapes.cginc" #include "libgarbage_shapes.cginc"
@ -287,7 +288,7 @@ SurfacePoint default_material_sdf(float3 p) {
float3 default_lighting(Ray ray) { float3 default_lighting(Ray ray) {
float3 sun_dir = normalize(float3(1, 0.5, -0.5)); float3 sun_dir = normalize(float3(1, 0.5, -0.5));
if (ray.missed) if (ray.missed)
return lRenderSky(ray.dir, sun_dir); return SKY_FN(ray.dir);
float3 light = lSun(ray.normal, sun_dir); float3 light = lSun(ray.normal, sun_dir);
light *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50); light *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50);
light += lSky(ray.normal); light += lSky(ray.normal);

View file

@ -40,7 +40,7 @@ Shader "CrispyPin/LibGarbageExample"
// #define DISCARD_ON_MISS // #define DISCARD_ON_MISS
// #define USE_WORLD_SPACE // #define USE_WORLD_SPACE
// #define STEP_MULTIPLIER 0.8 // #define STEP_MULTIPLIER 0.8
#define SCENE_SCALE 0.17 #define SCENE_SCALE (1/6.0)
#define LIMIT_DEPTH_TO_MESH #define LIMIT_DEPTH_TO_MESH
#include "libgarbage.cginc" #include "libgarbage.cginc"
@ -62,6 +62,20 @@ Shader "CrispyPin/LibGarbageExample"
); );
} }
SurfacePoint minimal_floor(float3 p, float3 a, float3 b) {
float3 pmin = min(a, b);
float3 pmax = max(a, b);
float3 center = (pmin + pmax) / 2;
center.y = -0.05;
float3 size = pmax - pmin;
size.y = 0.1;
SurfacePoint f = mBox(p - center, size, mat(floor_col(p)));
// f = qUnion(f, mSphere(p - center, 0.3, mat(1,0,0)));
// f = qUnion(f, mSphere(p - a, 0.3, mat(0,1,0)));
// f = qUnion(f, mSphere(p - b, 0.3, mat(0,0,1)));
return f;
}
SurfacePoint main(float3 p) { SurfacePoint main(float3 p) {
Material floor = mat(floor_col(p)); Material floor = mat(floor_col(p));
p.y += 0.5 / SCENE_SCALE; p.y += 0.5 / SCENE_SCALE;
@ -79,7 +93,7 @@ Shader "CrispyPin/LibGarbageExample"
d = qUnion(d, d = qUnion(d,
qIntersect( qIntersect(
mHelix(rotY(p - float3(2, -1, 0), _Time.y), 0.5, 0.2, 0.13), mHelix(rotY(p - float3(2, -1, 0), _Time.y), 0.5, 0.2, 0.13),
mBox(p - float3(2, 1, 0), 1.8), mBox(p - float3(2, 1.5, 0), 2),
0.05 0.05
) )
); );
@ -102,15 +116,14 @@ Shader "CrispyPin/LibGarbageExample"
d.mat = mat(float3(0.1, 0.6, 1.0), 0.5); d.mat = mat(float3(0.1, 0.6, 1.0), 0.5);
float3 p2 = p - float3(0, 2, sin(_Time.x * 5) * 3); float3 p2 = p - float3(0, 2, sin(_Time.x * 5) * 3);
d = qUnion(d, qRound(mBox(p2, float3(6, 4, .2), mat(0.1)), 0.01));
d = qSub(d, mBox(p2, float3(5.6, 3.6, .25)), 0.02); d = qSub(d, mBox(p2, float3(5.6, 3.6, .25)), 0.02);
d = qUnion(d, d = qUnion(d, qRound(mBox(p2 - float3(0, -1.9, 0), float3(6, .2, .2), mat(0.1)), 0.01));
qIntersect( d = qUnion(d, qRound(mBox(p2 - float3(0, 1.9, 0), float3(6, .2, .2), mat(0.1)), 0.01));
mPlaneY(p, 0, floor), d = qUnion(d, qRound(mBox(p2 - float3(2.9, 0, 0), float3(.2, 4, .2), mat(0.1)), 0.01));
mSphere(p, 7, floor) d = qUnion(d, qRound(mBox(p2 - float3(-2.9, 0, 0), float3(.2, 4, .2), mat(0.1)), 0.01));
) // limit floor size for better performance
); d = qUnion(d, minimal_floor(p, float3(-11.5, 0, -3.5), float3(3.5, 0, 7.5)));
return d; return d;
} }