2023-07-23 12:41:47 +02:00
|
|
|
Shader "Demo/Spinny thing"
|
|
|
|
{
|
|
|
|
Properties
|
|
|
|
{
|
|
|
|
[Header(Lighting)]
|
|
|
|
_SunPos ("Sun position", Vector) = (8, 4, 2)
|
|
|
|
|
|
|
|
[Header(Raymarcher Properties)]
|
2023-09-22 21:24:21 +02:00
|
|
|
_MaxSteps ("Max steps", Integer) = 256
|
2023-07-23 12:41:47 +02:00
|
|
|
_MaxDist ("Max distance", Float) = 256
|
|
|
|
_SurfDist ("Surface distance threshold", Range(0.00001, 0.05)) = 0.001
|
|
|
|
|
|
|
|
}
|
|
|
|
SubShader
|
|
|
|
{
|
|
|
|
Tags { "RenderType"="Opaque" }
|
2023-07-23 18:31:33 +02:00
|
|
|
Cull Front
|
2023-07-23 12:41:47 +02:00
|
|
|
LOD 100
|
|
|
|
|
|
|
|
Pass
|
|
|
|
{
|
|
|
|
CGPROGRAM
|
|
|
|
#pragma vertex vert
|
|
|
|
#pragma fragment frag
|
|
|
|
|
|
|
|
#define USE_DYNAMIC_QUALITY
|
|
|
|
// #define USE_WORLD_SPACE
|
|
|
|
#define USE_REFLECTIONS
|
2023-07-23 18:31:33 +02:00
|
|
|
#define MAX_REFLECTIONS 3
|
2023-07-23 12:41:47 +02:00
|
|
|
#define DISCARD_ON_MISS
|
|
|
|
//#define CONSTRAIN_TO_MESH
|
|
|
|
#include "RayMarchLib.cginc"
|
|
|
|
|
|
|
|
float3 _SunPos;
|
|
|
|
|
|
|
|
sdfData scene(float3 p)
|
|
|
|
{
|
|
|
|
sdfData o;
|
|
|
|
const material mGrass = mat(0.001, 0.1, 0.001, 0.7);
|
|
|
|
o = sdfPlane(p, 0, mGrass);
|
|
|
|
material mDirt = mat(0.1, 0.04, 0.01, 1);
|
|
|
|
o = sdfInter(p, o, sdfSphere(p, 9, mDirt), 0.5);
|
|
|
|
|
|
|
|
const material mMetal = mat(0.1, 0);
|
|
|
|
|
|
|
|
o = sdfAdd(p, o, sdfSphere(p - V_Y*2, 2, mMetal));
|
|
|
|
material m = mat(0.05, 0.1, 0.2, 1);
|
|
|
|
o = sdfAdd(p, o, sdfTorus(rotX(p, _Time* 40+UNITY_PI/2), 5, 0.5, m), 0.5);
|
|
|
|
o = sdfAdd(p, o, sdfTorus(rotZ(p, _Time* 40+UNITY_PI/2), 5, 0.5, m), 0.5);
|
|
|
|
o = sdfAdd(p, o, sdfTorus(rotX(p, _Time* 40), 5, 0.5, m), 0.5);
|
|
|
|
o = sdfAdd(p, o, sdfTorus(rotZ(p, _Time* 40), 5, 0.5, m), 0.5);
|
|
|
|
|
2023-07-23 18:31:33 +02:00
|
|
|
o = sdfAdd(p, o, sdfSphere(abs(rotY(p, -20 * _Time)) - float3(1.5, sin(_Time.y*5) +1,1.5), 0.7, mMetal), 0.2);
|
2023-07-23 12:41:47 +02:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
fixed4 lightPoint(rayData ray)
|
|
|
|
{
|
|
|
|
float3 vSunDir = normalize(_SunPos);
|
|
|
|
|
|
|
|
if (ray.bMissed)
|
|
|
|
{
|
|
|
|
return sky(ray.vRayDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
fixed4 col = 0;
|
|
|
|
|
|
|
|
col = ray.mat.col * lightSun(ray.vNorm, vSunDir);
|
2023-07-23 18:31:33 +02:00
|
|
|
col *= lightShadow(ray.vHit + ray.vNorm * _SurfDist, vSunDir, 50);
|
2023-07-23 12:41:47 +02:00
|
|
|
col += ray.mat.col * lightSky(ray.vNorm, 1);
|
2023-07-23 18:31:33 +02:00
|
|
|
// col *= lightAO(ray.vHit, ray.vNorm);
|
2023-07-23 12:41:47 +02:00
|
|
|
|
2023-07-23 18:31:33 +02:00
|
|
|
// col = pow(col, 0.5);
|
2023-07-23 12:41:47 +02:00
|
|
|
return col;
|
|
|
|
}
|
|
|
|
ENDCG
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|