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:
type: 3
objectId: 19ac0a45-6040-4093-92d0-0499e618a878
randomNum: 21667702
randomNum: 34799555
--- !u!114 &683266149
MonoBehaviour:
m_ObjectHideFlags: 0

View file

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

View file

@ -40,7 +40,7 @@ Shader "CrispyPin/LibGarbageExample"
// #define DISCARD_ON_MISS
// #define USE_WORLD_SPACE
// #define STEP_MULTIPLIER 0.8
#define SCENE_SCALE 0.17
#define SCENE_SCALE (1/6.0)
#define LIMIT_DEPTH_TO_MESH
#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) {
Material floor = mat(floor_col(p));
p.y += 0.5 / SCENE_SCALE;
@ -79,7 +93,7 @@ Shader "CrispyPin/LibGarbageExample"
d = qUnion(d,
qIntersect(
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
)
);
@ -102,15 +116,14 @@ Shader "CrispyPin/LibGarbageExample"
d.mat = mat(float3(0.1, 0.6, 1.0), 0.5);
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 = qUnion(d,
qIntersect(
mPlaneY(p, 0, floor),
mSphere(p, 7, floor)
) // limit floor size for better performance
);
d = qUnion(d, qRound(mBox(p2 - float3(0, -1.9, 0), float3(6, .2, .2), mat(0.1)), 0.01));
d = qUnion(d, qRound(mBox(p2 - float3(0, 1.9, 0), float3(6, .2, .2), mat(0.1)), 0.01));
d = qUnion(d, qRound(mBox(p2 - float3(2.9, 0, 0), float3(.2, 4, .2), mat(0.1)), 0.01));
d = qUnion(d, qRound(mBox(p2 - float3(-2.9, 0, 0), float3(.2, 4, .2), mat(0.1)), 0.01));
d = qUnion(d, minimal_floor(p, float3(-11.5, 0, -3.5), float3(3.5, 0, 7.5)));
return d;
}