libgarbage demo update
This commit is contained in:
parent
ddcfca5b8d
commit
58f266d600
4 changed files with 553 additions and 45 deletions
|
@ -63,8 +63,8 @@ Material:
|
|||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _MaxDist: 512
|
||||
- _MaxSteps: 512
|
||||
- _MaxDist: 100
|
||||
- _MaxSteps: 256
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
|
|
|
@ -79,12 +79,6 @@ START_RAYS_IN_SPHERE // TODO: implement
|
|||
#define SCENE_SCALE 1
|
||||
#endif
|
||||
|
||||
// TODO: implement
|
||||
#ifndef AMBIENT_OCCLUSION_STEPS
|
||||
#define AMBIENT_OCCLUSION_STEPS 4
|
||||
#endif
|
||||
|
||||
|
||||
struct AppData {
|
||||
float4 vertex : POSITION;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
|
|
|
@ -39,48 +39,83 @@ Shader "CrispyPin/LibGarbageExample"
|
|||
// #define DISABLE_DEPTH
|
||||
// #define DISCARD_ON_MISS
|
||||
// #define USE_WORLD_SPACE
|
||||
#define SCENE_SCALE 0.05
|
||||
#define STEP_MULTIPLIER 0.8
|
||||
#define SCENE_SCALE 0.2
|
||||
#define LIMIT_DEPTH_TO_MESH
|
||||
#include "libgarbage.cginc"
|
||||
|
||||
float3 checkers(float3 p, float3 a, float3 b, float2 size) {
|
||||
float2 q = p.xz / size;
|
||||
q = int2(abs(q) + 0.5);
|
||||
int s = ((q.x + q.y) % 2);
|
||||
return s * a + (1 - s) * b;
|
||||
}
|
||||
|
||||
float3 floor_col(float3 p) {
|
||||
return lerp(0.08,
|
||||
checkers(p - 1, 0.06, 0.12, 2),
|
||||
smoothstep(64, 0, length(p))
|
||||
);
|
||||
}
|
||||
|
||||
SurfacePoint main(float3 p) {
|
||||
Material grass = mat(float3(0.001, 0.1, 0.001), 0.3);
|
||||
Material dirt = mat(float3(0.1, 0.04, 0.01), 0);
|
||||
Material metal = mat(0.1, 1);
|
||||
Material blue = mat(float3(0.05, 0.1, 0.2), 0);
|
||||
Material floor = mat(floor_col(p));
|
||||
|
||||
SurfacePoint d = mPlaneY(p, 0, grass);
|
||||
d = qIntersect(d, mSphere(p, 9, dirt), 0.5);
|
||||
d = qUnion(d, mSphere(p - float3(0, 2, 0), 2, metal));
|
||||
d = qUnion(d, mTorus(rotX(p, _Time * 40 + UNITY_PI / 2), 5, 0.5, blue), 0.5);
|
||||
d = qUnion(d, mTorus(rotZ(p, _Time * 40 + UNITY_PI / 2), 5, 0.5, blue), 0.5);
|
||||
d = qUnion(d, mTorus(rotX(p, _Time * 40), 5, 0.5, blue), 0.5);
|
||||
d = qUnion(d, mTorus(rotZ(p, _Time * 40), 5, 0.5, blue), 0.5);
|
||||
// small spheres
|
||||
float3 p2 = abs(rotY(p, -20 * _Time)) - float3(1.5, sin(_Time.y * 5) + 1, 1.5);
|
||||
d = qUnion(d, mSphere(p2, 0.7, metal), 0.2);
|
||||
p.y += 2.5;
|
||||
|
||||
// Material green = mat(float3(0.05, 0.8, 0.2));
|
||||
Material mat1 = mat(1, 0.3, 0.1);
|
||||
// Material mat1 = mat(0.05);
|
||||
Material helix_glossy = mat(float3(1, 0.2, 0.05), 0.5);
|
||||
|
||||
SurfacePoint d;
|
||||
|
||||
|
||||
d =/* qUnion(d, */ mSphere(p - float3(-2, 1, -2), 0.5, mat1)/* ) */;
|
||||
d = qUnion(d, mTorus(p - float3(0, 1, -2), 0.4, 0.1, mat1));
|
||||
d = qUnion(d, mLine(p, float3(1.5, 1.5, -2), float3(2.5, 0.5, -2), 0.2, mat1));
|
||||
|
||||
d = qUnion(d, mBox(p - float3(-2, 1, 0), float3(0.5, 0.5, 0.8), mat1));
|
||||
d = qUnion(d, mHexPrism(p - float3(0, 1, 0), 0.5, 0.2, mat1));
|
||||
d = qUnion(d, qIntersect(mHelix(rotY(p - float3(2, -1, 0), _Time.y), 0.5, 0.2, 0.13, helix_glossy), mBox(p - float3(2, 1, 0), 1.8, mat1),0.05));
|
||||
|
||||
d = qUnion(d, mCylinder(p - float3(-2, 1, 2), 0.4, 0.5, mat1));
|
||||
d = qRound(d, 0.05 * sin(_Time.y));
|
||||
// d.mat = mat1;
|
||||
d = qUnion(d, mPlaneY(p, 0, floor));
|
||||
d = qIntersect(d, mSphere(p, 7, d.mat)); // limit floor size for better performance
|
||||
return d;
|
||||
}
|
||||
|
||||
SurfacePoint separate_mat(float3 p) {
|
||||
Material blue = mat(float3(0.05, 0.1, 0.2), 0);
|
||||
SurfacePoint d = mSphere(p, 1, blue);
|
||||
return d;
|
||||
}
|
||||
|
||||
float separate_dist(float3 p) {
|
||||
return main(p).dist;
|
||||
}
|
||||
|
||||
float3 lighting(Ray ray) {
|
||||
if (ray.missed)
|
||||
return lRenderSky(ray.dir, normalize(float3(4,2,1)));
|
||||
float3 sun_dir = normalize(float3(2, 1, -1));
|
||||
if (ray.missed) {
|
||||
if (ray.dir.y >= 0) {
|
||||
return lRenderSky(ray.dir, sun_dir);
|
||||
} else
|
||||
{
|
||||
float3 cam = ray.start;
|
||||
cam.y += 2.5;
|
||||
float3 dir = ray.dir;
|
||||
float3 surface_pos = float3(
|
||||
cam.x - cam.y / (dir.y / dir.x),
|
||||
0,
|
||||
cam.z - cam.y / (dir.y / dir.z)
|
||||
);
|
||||
float col = floor_col(surface_pos);
|
||||
return col * (lSky(float3(0,1,0)) + lSun(float3(0,1,0), sun_dir));
|
||||
}
|
||||
}
|
||||
|
||||
float3 sun_dir = normalize(float3(4, 2, 1));
|
||||
float3 col = 0;
|
||||
col = ray.mat.col * lSun(ray.normal, sun_dir);
|
||||
float3 col = lSun(ray.normal, sun_dir);
|
||||
col *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50);
|
||||
col += ray.mat.col * lSky(ray.normal);
|
||||
return col;
|
||||
col += lSky(ray.normal);
|
||||
// col = clamp(col, 0, 1);
|
||||
// col = smoothstep(0,1,col);
|
||||
// col = pow(col, 1.3);
|
||||
|
||||
return ray.mat.col * col ;
|
||||
// return col*0.2;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue