libgarbage: better metallic reflections, fix colour space

This commit is contained in:
Crispy 2023-08-08 20:22:50 +02:00
parent 9befad0a59
commit c9af7c9a1f
11 changed files with 386 additions and 79 deletions

View file

@ -0,0 +1,80 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Gyroid
m_Shader: {fileID: 4800000, guid: 585b5f9d03c402957aa50d1ff1b3b3ba, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _MaxDist: 16
- _MaxSteps: 256
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SurfDist: 0.0005
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 49f3c706a69469a22b8afe929025c1b2
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -259,6 +259,155 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 249645324}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &297009269
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 297009276}
- component: {fileID: 297009275}
- component: {fileID: 297009274}
- component: {fileID: 297009273}
- component: {fileID: 297009272}
- component: {fileID: 297009271}
- component: {fileID: 297009270}
m_Layer: 0
m_Name: gyroid
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &297009270
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297009269}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 990f6f4efb7f4ec98ad99f6dff1bc6f6, type: 3}
m_Name:
m_EditorClassIdentifier:
type: 3
objectId: d31bcc3e-72e6-4cc9-a179-62e88e68def5
randomNum: 59964531
--- !u!114 &297009271
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297009269}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a37fd8d654d5c2840a0ab3a5ad65a5ae, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnHeight: 0.55
useAdditionalValues: 0
syncValues: []
propPrivacy: 1
subSyncs: []
spawnableType: 0
preGeneratedInstanceId:
--- !u!114 &297009272
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297009269}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12974925555b471580cacf5d2d5fa9e3, type: 3}
m_Name:
m_EditorClassIdentifier:
gripType: 1
gripOrigin: {fileID: 0}
disallowTheft: 0
maximumGrabDistance: 0
snappingReferences: []
autoHold: 0
ikReference: {fileID: 0}
--- !u!65 &297009273
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297009269}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &297009274
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297009269}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 49f3c706a69469a22b8afe929025c1b2, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &297009275
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297009269}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &297009276
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297009269}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2, y: 0, z: 0}
m_LocalScale: {x: 2, y: 2, z: 2}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &307897118
GameObject:
m_ObjectHideFlags: 0
@ -750,7 +899,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: 19ac0a45-6040-4093-92d0-0499e618a878
randomNum: 34799555
randomNum: 77173865
--- !u!114 &683266149
MonoBehaviour:
m_ObjectHideFlags: 0
@ -884,7 +1033,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: 267a3820-e773-4d80-aa35-8f7551bc813a
randomNum:
randomNum: 70263921
--- !u!114 &772903852
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1416,7 +1565,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
type: 3
objectId: b6156cfd-0daa-4e22-ace6-220b7ba376bc
randomNum: 32637084
randomNum: 66961635
--- !u!114 &887058547
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1700,7 +1849,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1057832710}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.208, y: 0.33, z: -0.96}
m_LocalPosition: {x: -1.208, y: 0.33, z: -1.721}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

View file

@ -57,7 +57,7 @@
#define LIGHT_FN lighting
#define SCENE_FN main
#define REFLECTIONS 3
#define REFLECTIONS 2
#define SCENE_SCALE 0.025
#define LIMIT_DEPTH_TO_MESH
@ -222,14 +222,14 @@
else {
col = sky(dir, sun_dir);
}
return col;
return pow(col, 1/2.2);
}
SurfacePoint main(float3 p) {
Material grass = mat(float3(0.05, 0.5, 0.1), 0.3);
Material dirt = mat(float3(0.5, 0.2, 0.05), 0);
Material grass = mat(float3(0.26, 0.73, 0.35), 1);
Material dirt = mat(float3(0.73, 0.48, 0.26), 0);
Material metal = mat(1, 1);
Material blue = mat(float3(0.5, 0.6, 1), 0);
Material blue = mat(float3(0.73, 0.8, 1), 0);
SurfacePoint d = mPlaneY(p, 0, grass);
d = qIntersect(d, mSphere(p, 9, dirt), 0.5);
@ -242,12 +242,12 @@
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);
Material water = mat(float3(0.01, 0.015, 0.025), 0.7);
float h = 0;// sin(p.x + sin(p.z * 2+ _Time.y) * 0.3);
h *= 0.1;
h = - 2;
// Material water = mat(float3(0.12, 0.15, 0.19), 1);
// float h = 0;// sin(p.x + sin(p.z * 2+ _Time.y) * 0.3);
// h *= 0.1;
// h = - 2;
// d = qUnion(d, mPlaneY(p, h - snoise(p / 10 + _Time.xyz * 0.2) * 0.2, water));
float3 p3 = repXZ(p, 20, 20);
// float3 p3 = repXZ(p, 20, 20);
// d = qUnion(d, mSphere(p3 - float3(snoise(p), -5, 1), 8, water), 3);
// d = qUnion(d, mSphere(p3 - float3(3, h - 1.5, 2 + sin(p.x / 20)*3), 4, water), 3);
return d;
@ -259,11 +259,10 @@
}
float3 sun_dir = normalize(float3(0, 1, 10));
float3 col = 0;
col = ray.mat.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;
float3 light = lSun(ray.normal, sun_dir);
light *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50);
light += lSky(ray.normal);
return light;
}
ENDCG
}

View file

@ -0,0 +1,50 @@
Shader "CrispyPin/Gyroid"
{
Properties
{
[Header(Raymarcher Properties)]
_MaxSteps ("Max steps", Int) = 128
_MaxDist ("Max distance", Float) = 128
_SurfDist ("Surface distance threshold", Range(0.0001, 0.05)) = 0.001
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull Front
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
int _MaxSteps;
float _MaxDist;
float _SurfDist;
#define MAX_STEPS _MaxSteps
#define MAX_DIST _MaxDist
#define SURF_DIST _SurfDist
// #define REFLECTIONS 5
#define SCENE_FN main
#define DISCARD_ON_MISS
#include "lib/libgarbage.cginc"
SurfacePoint main(float3 p) {
SurfacePoint d;
d = qRound(mBox(p, 1), 0.01);
d = qIntersect(d, mGyroid(p, 16, 0, 0.2), 0.01);
// sdGyroid(p, 12, sin(_Time.y) * UNITY_PI * 0.5, 0.2),
// d.mat = mat(.8, 1);
return d;
}
ENDCG
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 585b5f9d03c402957aa50d1ff1b3b3ba
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -132,6 +132,7 @@ struct Ray {
float min_dist; // smallest distance encountered along the path (only useful for misses; shadow calculations)
};
#define UP float3(0, 1, 0)
float DISTANCE_FN(float3 p);
SurfacePoint SCENE_FN(float3 p);
@ -166,9 +167,7 @@ FragOut frag (V2F i) {
float3 ray_origin = i.cam_pos / SCENE_SCALE;
Ray ray;
float3 col;
float color_used = 0;// what amount of the final color has been calculated
float prev_gloss = 0;
float3 col_acc = 1;
float3 first_hit;
bool inside_shape;
@ -176,19 +175,15 @@ FragOut frag (V2F i) {
for (; ray_num < REFLECTIONS + 1;) {
ray = cast_ray(ray_origin, ray_dir);
if (ray_num == 0) { // before any bounces
col = LIGHT_FN(ray);
first_hit = ray.hit_pos;
inside_shape = ray.steps == 0;
} else {
float col_amount = color_used + ((1 - prev_gloss) * (1 - color_used));
col = lerp(LIGHT_FN(ray), col, col_amount);
color_used = col_amount;
}
float3 light = LIGHT_FN(ray);
col_acc *= ray.mat.col * lerp(light, 1, ray.mat.gloss);
ray_num++;
if (ray.missed || ray.mat.gloss < 0.01) {
break;
}
prev_gloss = ray.mat.gloss;
ray_dir = reflect(ray_dir, ray.normal);
ray_origin = ray.hit_pos + ray_dir * SURF_DIST * 2;
}
@ -198,7 +193,9 @@ FragOut frag (V2F i) {
#endif
FragOut o;
o.col = clamp(col, 0, 1);
// something something sRGB, colour space is annoying
col_acc = pow(col_acc, 2.2);
o.col = clamp(col_acc, 0, 1);
#ifndef DISABLE_DEPTH
float3 depth_point = first_hit * SCENE_SCALE;
@ -292,7 +289,7 @@ float3 default_lighting(Ray ray) {
float3 light = lSun(ray.normal, sun_dir);
light *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50);
light += lSky(ray.normal);
return light * ray.mat.col;
return light;
}
#endif // LIBGARBAGE_INCLUDED

View file

@ -56,8 +56,8 @@ Shader "CrispyPin/LibGarbageExample"
float atime = fmod(_Time.y * 0.3, 1);
p.x += smoothstep(0, 0.5, atime) * 2;
p.z += smoothstep(0.5, 1, atime) * 2;
return lerp(0.08,
checkers(p - 1, 0.06, 0.12, 2),
return lerp(0.42,
checkers(p - 1, 0.35, 0.45, 1),
smoothstep(64, 0, length(p))
);
}
@ -114,14 +114,14 @@ Shader "CrispyPin/LibGarbageExample"
)
);
d.mat = mat(float3(0.1, 0.6, 1.0), 0.5);
d.mat = mat(float3(0.35, 0.8, 1), 1);
float3 p2 = p - float3(0, 2, sin(_Time.x * 5) * 3);
d = qSub(d, mBox(p2, float3(5.6, 3.6, .25)), 0.02);
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, qRound(mBox(p2 - float3(0, -1.9, 0), float3(6, .2, .2), mat(0.8)), 0.01));
d = qUnion(d, qRound(mBox(p2 - float3(0, 1.9, 0), float3(6, .2, .2), mat(0.8)), 0.01));
d = qUnion(d, qRound(mBox(p2 - float3(2.9, 0, 0), float3(.2, 4, .2), mat(0.8)), 0.01));
d = qUnion(d, qRound(mBox(p2 - float3(-2.9, 0, 0), float3(.2, 4, .2), mat(0.8)), 0.01));
d = qUnion(d, minimal_floor(p, float3(-11.5, 0, -3.5), float3(3.5, 0, 7.5)));
return d;
@ -146,15 +146,10 @@ Shader "CrispyPin/LibGarbageExample"
}
}
float3 col = lSun(ray.normal, sun_dir);
col *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50);
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;
float3 light = lSun(ray.normal, sun_dir);
light *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50);
light += lSky(ray.normal);
return light;
}
ENDCG

View file

@ -17,7 +17,7 @@ float3 lRenderSky(float3 ray_dir, float3 sun_dir) {
}
//calculate sky light
float3 lSky(float3 normal, float3 sky_col = float3(0.1, 0.16, 0.18)) {
float3 lSky(float3 normal, float3 sky_col = float3(0.35, 0.43, 0.46)) {
return sky_col * (0.5 + 0.5 * normal.y);
}
@ -38,6 +38,35 @@ float lShadow(float3 p, float3 sun_dir, float sharpness = 8) {
return shadow;
}
// max ray steps, from last bounce (reset on each reflection)
#ifndef SHADOW_MAX_STEPS
#define SHADOW_MAX_STEPS 128
#endif
// max ray length, from last bounce (length is reset on each reflection)
#ifndef SHADOW_MAX_DIST
#define SHADOW_MAX_DIST 128
#endif
// the largest surface distance that is counted as a hit
#ifndef SHADOW_SURF_DIST
#define SHADOW_SURF_DIST 0.001
#endif
// soft shadows
// float lShadow(float3 p, float3 sun_dir, float sharpness = 8) {
// float light = 1;
// float ray_len = SHADOW_SURF_DIST*2;
// for (int steps = 0; steps < SHADOW_MAX_STEPS; steps++) {
// float dist = DISTANCE_FN(p + sun_dir * ray_len);
// light = min(light, sharpness * dist / ray_len);
// ray_len += dist;
// if (dist < SHADOW_SURF_DIST) return 0;
// if (ray_len > SHADOW_MAX_DIST) return light;
// }
// return light;
// }
// --------------------------------
// misc
// --------------------------------

View file

@ -30,22 +30,16 @@ Shader "CrispyPin/Nut"
#define MAX_DIST _MaxDist
#define SURF_DIST _SurfDist
#define REFLECTIONS 3
#define REFLECTIONS 2
#define SCENE_FN main
#define LIGHT_FN lighting
// #define SEPARATE_MATERIAL_AND_DIST_FUNCTIONS
// #define SCENE_FN separate_mat
// #define DISTANCE_FN separate_dist
// #define STEP_MULTIPLIER 0.1
#define SCENE_SCALE 0.7
// #define DISABLE_DEPTH
// #define DISCARD_ON_MISS
#define LIMIT_DEPTH_TO_MESH
// #define USE_WORLD_SPACE
#include "lib/libgarbage.cginc"
float3 checkers(float3 p, float3 a, float3 b, float2 size) {
@ -56,8 +50,8 @@ Shader "CrispyPin/Nut"
}
float3 floor(float3 p) {
return lerp(0.15,
checkers(p - 1, 0.10, 0.18, .2),
return lerp(0.42,
checkers(p - 1, 0.35, 0.45, .2),
smoothstep(16, 0, length(p))
);
}
@ -79,7 +73,8 @@ Shader "CrispyPin/Nut"
float3 thread_box = float3(thread, thread, UNITY_PI/4);
SurfacePoint d;
float3 rp = rotY(p, _Time.y);
float3 rp = p;
rp = rotY(rp, _Time.y);
rp = rotX(rp, _Time.x);
// nut
d = mRoundedHex(rp, girth, height);
@ -98,10 +93,10 @@ Shader "CrispyPin/Nut"
bp.y -= h;
SurfacePoint bolt = qSub(mCylinder(bp, inner_radius+thread*2, 0.2), bolt_thread);
bolt = qUnion(bolt, mRoundedHex(bp - float3(0, 0.13, 0), girth, height));
// Material metal1 = mat(float3(0.5, 0.3, 0.1), 1);
// Material metal2 = mat(float3(0.3, 0.3, 0.5), 1);
Material metal1 = mat(0.3, 1);
Material metal2 = mat(0.3, 1);
Material metal1 = mat(float3(0.62, 0.62, 0.64), 1);
Material metal2 = mat(float3(0.58, 0.32, 0.12), 1);
// Material metal1 = mat(0.3, 1);
// Material metal2 = mat(0.3, 1);
d.mat = metal1;
bolt.mat = metal2;
@ -156,14 +151,14 @@ Shader "CrispyPin/Nut"
);
float col = 1;
col = floor(surface_pos);
return col * (lSky(float3(0,1,0)) + lSun(float3(0,1,0), sun_dir));
return col * (lSky(UP) + lSun(UP, sun_dir));
}
}
float3 light = lSun(ray.normal, sun_dir)
* lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50)
+ lSky(ray.normal);
return light * ray.mat.col;
return light;
}

View file

@ -26,7 +26,7 @@ Shader "CrispyPin/LibGarbageSpinny"
#define MAX_DIST _MaxDist
#define SURF_DIST _SurfDist
#define REFLECTIONS 3
#define REFLECTIONS 5
#define LIGHT_FN lighting
#define SCENE_FN main
@ -42,10 +42,10 @@ Shader "CrispyPin/LibGarbageSpinny"
#include "lib/libgarbage.cginc"
SurfacePoint main(float3 p) {
Material grass = mat(float3(0.05, 0.5, 0.1), 0.3);
Material dirt = mat(float3(0.5, 0.2, 0.05), 0);
Material grass = mat(float3(0.26, 0.73, 0.35), 1);
Material dirt = mat(float3(0.73, 0.48, 0.26), 0);
Material metal = mat(1, 1);
Material blue = mat(float3(0.5, 0.6, 1), 0);
Material blue = mat(float3(0.73, 0.8, 1), 0);
SurfacePoint d = mPlaneY(p, 0, grass);
d = qIntersect(d, mSphere(p, 9, dirt), 0.5);
@ -71,19 +71,15 @@ Shader "CrispyPin/LibGarbageSpinny"
// }
float3 lighting(Ray ray) {
if (ray.missed)
return lRenderSky(ray.dir, normalize(float3(4,2,1)));
float3 sun_dir = normalize(float3(4, 2, 1));
float3 col = 0;
col = //ray.mat.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);
if (ray.missed) {
return lRenderSky(ray.dir, sun_dir);
}
float3 light = lSun(ray.normal, sun_dir);
light *= lShadow(ray.hit_pos + ray.normal * SURF_DIST, sun_dir, 50);
light += lSky(ray.normal);
return col * ray.mat.col;
return light;
}
ENDCG