This commit is contained in:
Crispy 2023-07-30 17:17:54 +02:00
parent b8d92002b1
commit 481a12ecee
3 changed files with 22 additions and 17 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: 17983601 randomNum: 21667702
--- !u!114 &683266149 --- !u!114 &683266149
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -64,7 +64,7 @@ Shader "CrispyPin/LibGarbageExample"
SurfacePoint main(float3 p) { SurfacePoint main(float3 p) {
Material floor = mat(floor_col(p)); Material floor = mat(floor_col(p));
p.y += 2.5; p.y += 0.5 / SCENE_SCALE;
SurfacePoint d; SurfacePoint d;
d = mSphere(p - float3(-2, 1, -2), 0.5); d = mSphere(p - float3(-2, 1, -2), 0.5);
@ -121,7 +121,7 @@ Shader "CrispyPin/LibGarbageExample"
return lRenderSky(ray.dir, sun_dir); return lRenderSky(ray.dir, sun_dir);
} else { } else {
float3 cam = ray.start; float3 cam = ray.start;
cam.y += 2.5; cam.y += 0.5 / SCENE_SCALE;
float3 dir = ray.dir; float3 dir = ray.dir;
float3 surface_pos = float3( float3 surface_pos = float3(
cam.x - cam.y / (dir.y / dir.x), cam.x - cam.y / (dir.y / dir.x),

View file

@ -1,5 +1,5 @@
#define _MAT_VARIANT1(NEW_NAME, BASE_FN, TYPE_1, ARG_1) \ #define _MAT_VARIANT1(NEW_NAME, BASE_FN, TYPE_1) \
SurfacePoint NEW_NAME(float3 p, TYPE_1 ARG_1, Material mat = DEFAULT_MAT) {\ SurfacePoint NEW_NAME(float3 p, TYPE_1 ARG_1, Material mat = DEFAULT_MAT) {\
SurfacePoint o;\ SurfacePoint o;\
o.dist = BASE_FN(p, ARG_1);\ o.dist = BASE_FN(p, ARG_1);\
@ -7,7 +7,7 @@
return o;\ return o;\
} }
#define _MAT_VARIANT2(NEW_NAME, BASE_FN, TYPE_1, ARG_1, TYPE_2, ARG_2) \ #define _MAT_VARIANT2(NEW_NAME, BASE_FN, TYPE_1, TYPE_2) \
SurfacePoint NEW_NAME(float3 p, TYPE_1 ARG_1, TYPE_2 ARG_2, Material mat = DEFAULT_MAT) {\ SurfacePoint NEW_NAME(float3 p, TYPE_1 ARG_1, TYPE_2 ARG_2, Material mat = DEFAULT_MAT) {\
SurfacePoint o;\ SurfacePoint o;\
o.dist = BASE_FN(p, ARG_1, ARG_2);\ o.dist = BASE_FN(p, ARG_1, ARG_2);\
@ -15,7 +15,7 @@
return o;\ return o;\
} }
#define _MAT_VARIANT3(NEW_NAME, BASE_FN, TYPE_1, ARG_1, TYPE_2, ARG_2, TYPE_3, ARG_3) \ #define _MAT_VARIANT3(NEW_NAME, BASE_FN, TYPE_1, TYPE_2, TYPE_3) \
SurfacePoint NEW_NAME(float3 p, TYPE_1 ARG_1, TYPE_2 ARG_2, TYPE_3 ARG_3, Material mat = DEFAULT_MAT) {\ SurfacePoint NEW_NAME(float3 p, TYPE_1 ARG_1, TYPE_2 ARG_2, TYPE_3 ARG_3, Material mat = DEFAULT_MAT) {\
SurfacePoint o;\ SurfacePoint o;\
o.dist = BASE_FN(p, ARG_1, ARG_2, ARG_3);\ o.dist = BASE_FN(p, ARG_1, ARG_2, ARG_3);\
@ -31,30 +31,35 @@ float sdBox(float3 p, float3 size) {
float3 q = abs(p) - size / 2.0; float3 q = abs(p) - size / 2.0;
return length(max(q, 0)) + min(max(q.x, max(q.y, q.z)), 0); return length(max(q, 0)) + min(max(q.x, max(q.y, q.z)), 0);
} }
_MAT_VARIANT1(mBox, sdBox, float3, size) _MAT_VARIANT1(mBox, sdBox, float3)
float sdSphere(float3 p, float radius) { float sdSphere(float3 p, float radius) {
return length(p) - radius; return length(p) - radius;
} }
_MAT_VARIANT1(mSphere, sdSphere, float, radius) _MAT_VARIANT1(mSphere, sdSphere, float)
float sdTorus(float3 p, float radius, float thickness) { float sdTorus(float3 p, float radius, float thickness) {
float2 q = float2(length(p.xz) - radius, p.y); float2 q = float2(length(p.xz) - radius, p.y);
return length(q) - thickness; return length(q) - thickness;
} }
_MAT_VARIANT2(mTorus, sdTorus, float, radius, float, thickness) _MAT_VARIANT2(mTorus, sdTorus, float, float)
float sdCappedTorus(float3 p, float2 sc, float r1, float r2) { float sdCappedTorus(float3 p, float2 sc, float r1, float r2) {
p.x = abs(p.x); p.x = abs(p.x);
float k = (sc.y * p.x > sc.x * p.z) ? dot(p.xz, sc) : length(p.xz); float k = (sc.y * p.x > sc.x * p.z) ? dot(p.xz, sc) : length(p.xz);
return sqrt(dot(p, p) + r1 * r1 - 2.0 * r1 * k) - r2; return sqrt(dot(p, p) + r1 * r1 - 2.0 * r1 * k) - r2;
} }
_MAT_VARIANT3(mCappedTorus, sdCappedTorus, float2, sc, float, r1, float, r2) _MAT_VARIANT3(mCappedTorus, sdCappedTorus, float2, float, float)
float sdPlaneY(float3 p, float height) { float sdPlaneY(float3 p, float height) {
return p.y - height; return p.y - height;
} }
_MAT_VARIANT1(mPlaneY, sdPlaneY, float, height) _MAT_VARIANT1(mPlaneY, sdPlaneY, float)
float sdPlane(float3 p, float3 normal, float height) {
return dot(p, normal) + height;
}
_MAT_VARIANT2(mPlane, sdPlane, float3, float)
float sdHexPrism(float3 p, float width, float height) { float sdHexPrism(float3 p, float width, float height) {
const float3 k = float3(-0.8660254, 0.5, 0.57735); const float3 k = float3(-0.8660254, 0.5, 0.57735);
@ -63,18 +68,18 @@ float sdHexPrism(float3 p, float width, float height) {
float2 d = float2(length(p.xz - float2(clamp(p.x,-k.z * width, k.z * width), width)) * sign(p.z - width), p.y - height); float2 d = float2(length(p.xz - float2(clamp(p.x,-k.z * width, k.z * width), width)) * sign(p.z - width), p.y - height);
return min(max(d.x, d.y), 0) + length(max(d, 0)); return min(max(d.x, d.y), 0) + length(max(d, 0));
} }
_MAT_VARIANT2(mHexPrism, sdHexPrism, float, width, float, height) _MAT_VARIANT2(mHexPrism, sdHexPrism, float, float)
float sdInfCylinder(float3 p, float3 c) { float sdInfCylinder(float3 p, float3 c) {
return length(p.xz - c.xy) - c.z; return length(p.xz - c.xy) - c.z;
} }
_MAT_VARIANT1(mInfCylinder, sdInfCylinder, float3, c) _MAT_VARIANT1(mInfCylinder, sdInfCylinder, float3)
float sdCylinder(float3 p, float r, float h) { float sdCylinder(float3 p, float r, float h) {
float2 d = abs(float2(length(p.xz), p.y)) - float2(r, h); float2 d = abs(float2(length(p.xz), p.y)) - float2(r, h);
return min(max(d.x, d.y), 0) + length(max(d, 0)); return min(max(d.x, d.y), 0) + length(max(d, 0));
} }
_MAT_VARIANT2(mCylinder, sdCylinder, float, r, float, h) _MAT_VARIANT2(mCylinder, sdCylinder, float, float)
float sdHelix(float3 p, float r1, float r2, float incline) { float sdHelix(float3 p, float r1, float r2, float incline) {
float x2 = length(p.xz) - r1; // vertical plane float x2 = length(p.xz) - r1; // vertical plane
@ -84,7 +89,7 @@ float sdHelix(float3 p, float r1, float r2, float incline) {
float dist = length(float2(x2, y)) - r2; float dist = length(float2(x2, y)) - r2;
return dist * 0.8; return dist * 0.8;
} }
_MAT_VARIANT3(mHelix, sdHelix, float, r1, float, r2, float, incline) _MAT_VARIANT3(mHelix, sdHelix, float, float, float)
float sdLine(float3 p, float3 a, float3 b, float r) { float sdLine(float3 p, float3 a, float3 b, float r) {
float3 pa = p - a; float3 pa = p - a;
@ -92,14 +97,14 @@ float sdLine(float3 p, float3 a, float3 b, float r) {
float h = clamp(dot(pa, ba) / dot(ba, ba), 0, 1); float h = clamp(dot(pa, ba) / dot(ba, ba), 0, 1);
return length(p- a - (b-a) * h) - r; return length(p- a - (b-a) * h) - r;
} }
_MAT_VARIANT3(mLine, sdLine, float3, a, float3, b, float3, r) _MAT_VARIANT3(mLine, sdLine, float3, float3, float3)
float sdGyroid(float3 p, float scale, float bias, float thickness) { float sdGyroid(float3 p, float scale, float bias, float thickness) {
float dist = abs(dot(sin(p * scale), cos(p.zxy * scale)) + bias) - thickness; float dist = abs(dot(sin(p * scale), cos(p.zxy * scale)) + bias) - thickness;
dist *= .58 / scale; dist *= .58 / scale;
return dist; return dist;
} }
_MAT_VARIANT3(mGyroid, sdGyroid, float, scale, float, bias, float, thickness) _MAT_VARIANT3(mGyroid, sdGyroid, float, float, float)
SurfacePoint mFromDist(float d, Material mat = DEFAULT_MAT) { SurfacePoint mFromDist(float d, Material mat = DEFAULT_MAT) {
SurfacePoint o; SurfacePoint o;