2023-07-23 18:31:33 +02:00
|
|
|
Shader "CrispyPin/LibGarbageExample"
|
|
|
|
{
|
|
|
|
Properties
|
|
|
|
{
|
|
|
|
[Header(Raymarcher Properties)]
|
2023-07-24 08:42:25 +02:00
|
|
|
_MaxSteps ("Max steps", Int) = 128
|
|
|
|
_MaxDist ("Max distance", Float) = 128
|
2023-07-23 18:31:33 +02:00
|
|
|
_SurfDist ("Surface distance threshold", Range(0.00001, 0.05)) = 0.001
|
|
|
|
|
|
|
|
}
|
|
|
|
SubShader
|
|
|
|
{
|
|
|
|
Tags { "RenderType"="Opaque" }
|
2023-07-24 08:42:25 +02:00
|
|
|
Cull Front
|
2023-07-23 18:31:33 +02:00
|
|
|
LOD 100
|
|
|
|
|
|
|
|
Pass
|
|
|
|
{
|
|
|
|
CGPROGRAM
|
|
|
|
#pragma vertex vert
|
|
|
|
#pragma fragment frag
|
|
|
|
|
2023-07-24 08:42:25 +02:00
|
|
|
int _MaxSteps;
|
|
|
|
#define MAX_STEPS _MaxSteps
|
2023-07-23 18:31:33 +02:00
|
|
|
|
2023-07-24 14:47:24 +02:00
|
|
|
#define REFLECTIONS 1
|
|
|
|
#define DISTANCE_FN main_dist
|
|
|
|
#define MATERIAL_FN main_mat
|
|
|
|
#define DISABLE_DEPTH
|
|
|
|
#define DISCARD_ON_MISS
|
|
|
|
#define USE_WORLD_SPACE
|
2023-07-24 08:42:25 +02:00
|
|
|
#include "libgarbage.cginc"
|
2023-07-23 18:31:33 +02:00
|
|
|
|
2023-07-24 14:47:24 +02:00
|
|
|
float main_dist(float3 p) {
|
|
|
|
p = repXYZ(p, 2);
|
|
|
|
return qSub(sdSphere(p, 0.5), sdSphere(p - 0.3, 0.2), 0.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfacePoint main_mat(float3 p) {
|
|
|
|
float3 p2 = repXYZ(p, 2);
|
|
|
|
return mSphere(p2, 0.5, mat(clamp(abs(p), 0, 1), 0.1));
|
|
|
|
}
|
|
|
|
|
2023-07-23 18:31:33 +02:00
|
|
|
ENDCG
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|