From 3408d9ff8ed09721256285bd1c2fddd91378b675 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 29 Jul 2023 21:05:57 +0200 Subject: [PATCH] add wip raymarching shaders --- Assets/raymarched/Distortion.mat | 80 ++++++ Assets/raymarched/Distortion.mat.meta | 8 + Assets/raymarched/Nut.mat | 80 ++++++ Assets/raymarched/Nut.mat.meta | 8 + Assets/raymarched/Raymarching.unity | 262 +++++++++++-------- Assets/raymarched/Spinny Sunset.mat | 123 +++++++++ Assets/raymarched/Spinny Sunset.mat.meta | 8 + Assets/raymarched/Spinny.mat | 80 ++++++ Assets/raymarched/Spinny.mat.meta | 8 + Assets/raymarched/Spinny_Sunset.shader | 271 ++++++++++++++++++++ Assets/raymarched/Spinny_Sunset.shader.meta | 9 + Assets/raymarched/distortion.shader | 131 ++++++++++ Assets/raymarched/distortion.shader.meta | 9 + Assets/raymarched/nut.shader | 158 ++++++++++++ Assets/raymarched/nut.shader.meta | 9 + Assets/raymarched/spinny.shader | 92 +++++++ Assets/raymarched/spinny.shader.meta | 9 + 17 files changed, 1242 insertions(+), 103 deletions(-) create mode 100644 Assets/raymarched/Distortion.mat create mode 100644 Assets/raymarched/Distortion.mat.meta create mode 100644 Assets/raymarched/Nut.mat create mode 100644 Assets/raymarched/Nut.mat.meta create mode 100644 Assets/raymarched/Spinny Sunset.mat create mode 100644 Assets/raymarched/Spinny Sunset.mat.meta create mode 100644 Assets/raymarched/Spinny.mat create mode 100644 Assets/raymarched/Spinny.mat.meta create mode 100644 Assets/raymarched/Spinny_Sunset.shader create mode 100644 Assets/raymarched/Spinny_Sunset.shader.meta create mode 100644 Assets/raymarched/distortion.shader create mode 100644 Assets/raymarched/distortion.shader.meta create mode 100644 Assets/raymarched/nut.shader create mode 100644 Assets/raymarched/nut.shader.meta create mode 100644 Assets/raymarched/spinny.shader create mode 100644 Assets/raymarched/spinny.shader.meta diff --git a/Assets/raymarched/Distortion.mat b/Assets/raymarched/Distortion.mat new file mode 100644 index 0000000..979acba --- /dev/null +++ b/Assets/raymarched/Distortion.mat @@ -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: Distortion + m_Shader: {fileID: 4800000, guid: ebb4c5ee330ee4a57bf8516adc9a7828, 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: 128 + - _MaxSteps: 256 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SurfDist: 0.001 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/raymarched/Distortion.mat.meta b/Assets/raymarched/Distortion.mat.meta new file mode 100644 index 0000000..25e33a7 --- /dev/null +++ b/Assets/raymarched/Distortion.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d41f18ea246cea60bae44bca806c0728 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/Nut.mat b/Assets/raymarched/Nut.mat new file mode 100644 index 0000000..cd24932 --- /dev/null +++ b/Assets/raymarched/Nut.mat @@ -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: Nut + m_Shader: {fileID: 4800000, guid: 4ba2b5d5658a2f257b227615f65e87f6, 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: 32 + - _MaxSteps: 128 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SurfDist: 0.002 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/raymarched/Nut.mat.meta b/Assets/raymarched/Nut.mat.meta new file mode 100644 index 0000000..9c7bf4b --- /dev/null +++ b/Assets/raymarched/Nut.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c881d33e96e5ee113a7ca92a93839d15 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/Raymarching.unity b/Assets/raymarched/Raymarching.unity index b0b323c..da0c86e 100644 --- a/Assets/raymarched/Raymarching.unity +++ b/Assets/raymarched/Raymarching.unity @@ -338,7 +338,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &365616531 MonoBehaviour: m_ObjectHideFlags: 0 @@ -444,7 +444,7 @@ Transform: m_LocalScale: {x: 5, y: 5, z: 5} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 11 + m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &393448822 GameObject: @@ -733,7 +733,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 7 + m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &683266148 MonoBehaviour: @@ -787,98 +787,6 @@ MonoBehaviour: snappingReferences: [] autoHold: 0 ikReference: {fileID: 0} ---- !u!1 &695617482 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 695617484} - - component: {fileID: 695617483} - m_Layer: 0 - m_Name: Point Light - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!108 &695617483 -Light: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 695617482} - m_Enabled: 1 - serializedVersion: 10 - m_Type: 2 - m_Shape: 0 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Intensity: 1 - m_Range: 10 - m_SpotAngle: 30 - m_InnerSpotAngle: 21.80208 - m_CookieSize: 10 - m_Shadows: - m_Type: 0 - m_Resolution: -1 - m_CustomResolution: -1 - m_Strength: 1 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_CullingMatrixOverride: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 - m_UseCullingMatrixOverride: 0 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingLayerMask: 1 - m_Lightmapping: 4 - m_LightShadowCasterMode: 0 - m_AreaSize: {x: 1, y: 1} - m_BounceIntensity: 1 - m_ColorTemperature: 6570 - m_UseColorTemperature: 0 - m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} - m_UseBoundingSphereOverride: 0 - m_ShadowRadius: 0 - m_ShadowAngle: 0 ---- !u!4 &695617484 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 695617482} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.464, y: -0.099, z: 0.326} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 5 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &703968045 GameObject: m_ObjectHideFlags: 0 @@ -938,6 +846,154 @@ MonoBehaviour: maxValue: 1 updateMethod: 1 sampleDirection: 0 +--- !u!1 &772903850 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 772903857} + - component: {fileID: 772903856} + - component: {fileID: 772903855} + - component: {fileID: 772903854} + - component: {fileID: 772903853} + - component: {fileID: 772903852} + - component: {fileID: 772903851} + m_Layer: 0 + m_Name: Spinny + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &772903851 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 772903850} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 990f6f4efb7f4ec98ad99f6dff1bc6f6, type: 3} + m_Name: + m_EditorClassIdentifier: + type: 3 + objectId: 267a3820-e773-4d80-aa35-8f7551bc813a +--- !u!114 &772903852 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 772903850} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a37fd8d654d5c2840a0ab3a5ad65a5ae, type: 3} + m_Name: + m_EditorClassIdentifier: + spawnHeight: 0.5 + useAdditionalValues: 0 + syncValues: [] + propPrivacy: 1 + subSyncs: [] + spawnableType: 0 + preGeneratedInstanceId: +--- !u!114 &772903853 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 772903850} + 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 &772903854 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 772903850} + 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 &772903855 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 772903850} + 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: ae433e7abcbb34568a34bf2056a24a89, 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 &772903856 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 772903850} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &772903857 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 772903850} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.75, y: 0, z: 1.75} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 11 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &779234488 GameObject: m_ObjectHideFlags: 0 @@ -978,7 +1034,7 @@ Transform: - {fileID: 393448823} - {fileID: 307897119} m_Father: {fileID: 0} - m_RootOrder: 6 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &779234490 MonoBehaviour: @@ -1431,7 +1487,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 10 + m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &887058546 MonoBehaviour: @@ -1713,7 +1769,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 9 + m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1057832715 MonoBehaviour: @@ -1741,7 +1797,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a37fd8d654d5c2840a0ab3a5ad65a5ae, type: 3} m_Name: m_EditorClassIdentifier: - spawnHeight: 1 + spawnHeight: 0.55 useAdditionalValues: 0 syncValues: [] propPrivacy: 1 @@ -1780,12 +1836,12 @@ GameObject: - component: {fileID: 1274159450} - component: {fileID: 1274159449} m_Layer: 0 - m_Name: Cube (2) + m_Name: (old) spinny m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!65 &1274159449 BoxCollider: m_ObjectHideFlags: 0 @@ -1854,11 +1910,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1274159448} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 1, y: 0.26, z: -0.407} + m_LocalPosition: {x: -0.5, y: 0.01, z: 2.093} m_LocalScale: {x: 0.05, y: 0.05, z: 0.05} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 8 + m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1450495540 GameObject: diff --git a/Assets/raymarched/Spinny Sunset.mat b/Assets/raymarched/Spinny Sunset.mat new file mode 100644 index 0000000..d488bf9 --- /dev/null +++ b/Assets/raymarched/Spinny Sunset.mat @@ -0,0 +1,123 @@ +%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: Spinny Sunset + m_Shader: {fileID: 4800000, guid: bf32a865560b32c028bf9030b99bb087, 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: 2800000, guid: 1f675a065618d234abec48e229fcf618, type: 3} + 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} + - _NoiseTex: + m_Texture: {fileID: 2800000, guid: 1f675a065618d234abec48e229fcf618, type: 3} + 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} + - _TempTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _WaterAO: + m_Texture: {fileID: 2800000, guid: dd4d5ec12dc0480c4844ce7523f236de, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _WaterHeight: + m_Texture: {fileID: 2800000, guid: f7d421fd3d8201f31938dea0107230ef, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _WaterNormal: + m_Texture: {fileID: 2800000, guid: 5da9476453fb6074bb8baeb93d8c9513, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _WaterSurface: + m_Texture: {fileID: 2800000, guid: cafeae09bbcef5a6cabeaac76bab5462, type: 3} + m_Scale: {x: 1.6, 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 + - _Grid: 0 + - _HeightOffset: 0 + - _HorizonTint: 0.1 + - _MaxDist: 4000 + - _MaxSteps: 128 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _StarDensity: 30 + - _StarRandom: 0.85 + - _StarSize: 0.06 + - _StarSizeRandom: 0.5 + - _StarTint: 0.2 + - _StarsMissing: 0.75 + - _SunAngle: 0 + - _SunCutoff: 0.121 + - _SunRadius: 0.037 + - _SurfDist: 0.001 + - _Temp: 0.703 + - _UVSec: 0 + - _WaveSpeed: 1 + - _WaveStrength: 0.5 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _HorizonCol: {r: 0.43, g: 0.27, b: 0.49, a: 1} + - _SkyCol: {r: 0.08235293, g: 0.09343877, b: 0.27450982, a: 1} + - _SunCol: {r: 1, g: 0.5988961, b: 0.05098039, a: 1} + - _WaterCol: {r: 0.6035511, g: 0.9339623, b: 0.63756216, a: 1} diff --git a/Assets/raymarched/Spinny Sunset.mat.meta b/Assets/raymarched/Spinny Sunset.mat.meta new file mode 100644 index 0000000..c178fb2 --- /dev/null +++ b/Assets/raymarched/Spinny Sunset.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 628e41df70b6f01c9ae6b4499ad54dd6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/Spinny.mat b/Assets/raymarched/Spinny.mat new file mode 100644 index 0000000..ed40ec4 --- /dev/null +++ b/Assets/raymarched/Spinny.mat @@ -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: Spinny + m_Shader: {fileID: 4800000, guid: 0779c46007e531d31b99fa29d899e9ab, 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: 128 + - _MaxSteps: 128 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SurfDist: 0.001 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/raymarched/Spinny.mat.meta b/Assets/raymarched/Spinny.mat.meta new file mode 100644 index 0000000..fed01b4 --- /dev/null +++ b/Assets/raymarched/Spinny.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ae433e7abcbb34568a34bf2056a24a89 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/Spinny_Sunset.shader b/Assets/raymarched/Spinny_Sunset.shader new file mode 100644 index 0000000..763ced1 --- /dev/null +++ b/Assets/raymarched/Spinny_Sunset.shader @@ -0,0 +1,271 @@ +Shader "CrispyPin/Spinny_Sunset" +{ + 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 + [Header(Sky)] + _SkyCol ("Sky color", Color) = (0.22, 0.23, 0.58, 1.0) + _HorizonTint ("Horizon tint", Range(0, 1)) = 0.1 + [Header(Sun)] + _SunCol ("Sun color", Color) = (1.0, 0.65, 0.05, 1.0) + _SunAngle ("Sun angle", Range(0, 6.28)) = 0 + _SunRadius ("Sun radius", Range(0, 0.3)) = 0.06 + _SunCutoff ("Sun cutoff", Range(0, 0.5)) = 0.08 + [Header(Star Layout)] + [NoScaleOffset] + _NoiseTex ("Noise source", 2D) = "white" {} + _StarDensity ("Star density", Range(4, 50)) = 20 + _StarRandom ("Star randomness", Range(0, 1)) = 0.85 + [Header(Star)] + _StarsMissing ("Stars missing", Range(0, 1)) = 0.75 + _StarSize ("Star size", Range(0, 0.1)) = 0.06 + _StarSizeRandom ("Star size randomness", Range(0, 1)) = 0.5 + _StarTint ("Star tint", Range(0, 1)) = 0.4 + [Header(Water)] + _HeightOffset ("Height offset", Range(-10, 10)) = -0.5 + _WaterCol ("Water color", Color) = (0.03, 0.08, 0.12, 1.0) + _WaveStrength ("Wave scale", Range(0, 1)) = 1 + _WaveSpeed ("Wave speed", Range(0, 5)) = 1 + [NoScaleOffset] + _WaterNormal ("Surface Normal", 2D) = "white" {} + [Header(Debug)] + _Grid ("Grid visibility", Range(0, 1)) = 0 + + } + SubShader + { + Tags { "RenderType"="Opaque" } + LOD 100 + Cull front + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + + int _MaxSteps; + float _MaxDist; + float _SurfDist; + #define MAX_STEPS 512 + #define MAX_DIST _MaxDist + #define SURF_DIST _SurfDist + + #define LIGHT_FN lighting + #define SCENE_FN main + #define REFLECTIONS 3 + #define SCENE_SCALE 0.025 + #define LIMIT_DEPTH_TO_MESH + + #include "lib/libgarbage.cginc" + + #define PI 3.1416f + #define WHITE 1 + #define UP float3(0, 1, 0) + + sampler2D _NoiseTex; + float3 _SkyCol; + float _HorizonTint; + + float _StarsMissing; + float _StarDensity; + float _StarRandom; + + float _StarSize; + float _StarSizeRandom; + float _StarTint; + + float3 _SunCol; + float _SunAngle; + float _SunRadius; + float _SunCutoff; + + sampler2D _WaterNormal; + // sampler2D _WaterHeight; + // sampler2D _WaterAO; + float3 _WaterCol; + float _HeightOffset; + float _WaveStrength; + float _WaveSpeed; + + float _Grid; + + float3 get_water_normal(float2 pos) { + pos *= 0.5; + float time = _Time.x * _WaveSpeed + 5; // offset is to make it look better at frame 0 + float t1 = time * 0.18; + float3 normal = (tex2D(_WaterNormal, pos + float2(t1, -t1 * 0.5)) - 0.5) * 0.5; + float t2 = time * 0.37; + normal += (tex2D(_WaterNormal, pos * 0.276 + float2(t2 * 0.8, t2)) - 0.5); + float t3 = time * 0.08; + normal += (tex2D(_WaterNormal, pos * 0.07 + float2(t3 * 0.8, -t3)) - 0.5); + // normal = normalize(normal.zxy); // normal map import settings + normal = normalize(normal.rbg) * float3(-1, 1, -1); // standard import settings + + // normal = normalize(normal); + + // return UP; + return lerp(UP, normal, _WaveStrength); + } + + + float3 sun(float3 base_col, float3 dir, float3 sun_dir) { + float alignment = min(acos(dot(dir, sun_dir)), 1); + float sun_amount = smax(min(_SunRadius / alignment, 5) - _SunCutoff, 0, 0.15); + return lerp(base_col, _SunCol, sun_amount); + } + + float3 sky(float3 dir, float3 sun_dir) { + float theta = atan2(dir.x, dir.z); // latitude + float phi = asin(dir.y); // longitude + /// background + float factor = smoothstep(0, 0.5, dir.y + 0.2); + float3 horizon_col = lerp(_SkyCol, _SunCol, _HorizonTint); + float3 col = lerp(horizon_col, _SkyCol, factor); + + /// stars + float2 cells = float2(-1, floor(_StarDensity)); + float cell_x_base = floor(cells.y * PI); + float celly = phi * cells.y; + // cells per ring depend on y pos, to reduce warping around the poles: + cells.x = floor(cos(floor(celly) / _StarDensity) * cell_x_base); + float cellx = (theta / PI * cells.x); + + float2 pos = float2(cellx, celly); // cell-space pos of this pixel + float2 cell_pos = float2(floor(cellx), floor(celly)); // position of this cell + float2 cell_center = cell_pos + 0.5; + + float2 star_pos = cell_center + (tex2D(_NoiseTex, cell_pos / cells + float2(0, 0.1)) - 0.5) * _StarRandom; + + /// star color + float3 r = tex2D(_NoiseTex, cell_pos / cells); + float rnum = frac((r.r + r.g - r.b) * 10); + float rnum2 = frac((r.r - r.g + r.b) * 10); + + float star_size = _StarSize * (rnum * _StarSizeRandom + (1 - _StarSizeRandom)); + + float distance = length(pos - star_pos); + float star_strength = max(min(star_size / distance * 0.5, 1.25) - 0.25, 0); // star glow + + star_strength *= clamp(sin(phi * 2) - 0.1, 0, 1); // fade stars near/under horizon + star_strength *= length(r) / 2; // fade stars + star_strength *= rnum2 > _StarsMissing; // remove stars + + float3 star_col = lerp(WHITE, r, _StarTint); + + col = lerp(col, star_col, star_strength); + + col = sun(col, dir, sun_dir); + /// debug grid + col = lerp(col, WHITE, _Grid * ( + pow(frac( cellx), 20) + + pow(frac( celly), 20) + + pow(frac(-cellx), 20) + + pow(frac(-celly), 20) + )); + + return col; + } + + float3 sunset_env(float3 dir, float3 ray_origin) { + ray_origin = 0; + + // float3 horizon_col = lerp(_SkyCol, _SunCol, _HorizonTint); + float3 origin = mul(unity_ObjectToWorld, float4(0, 0, 0, 1)); + origin = 0; + float3 sun_dir = float3(sin(_SunAngle), 0.0, cos(_SunAngle)); + + float3 col; + + if (dir.y < 0) { + origin.y += _HeightOffset; + float3 camera_local_pos = ray_origin; + camera_local_pos.y = max(camera_local_pos.y, 0.01); // don't allow looking under water surface; it renders backwards. + float3 surface_pos = float3 ( + camera_local_pos.x - camera_local_pos.y / (dir.y / dir.x), + 0, + camera_local_pos.z - camera_local_pos.y / (dir.y / dir.z) + ); + float3 water_normal = get_water_normal(surface_pos.xz); + + float3 reflected_dir = reflect(dir, water_normal); + float3 sky_reflection = sky(reflected_dir, sun_dir) ; + + float3 water_col = lerp(_SkyCol, _SunCol, 0.01) * _WaterCol; + float3 refracted_dir = normalize(refract(dir, water_normal, 1/1.333)); + float subsurf = (refracted_dir.y + 1); + + col = water_col * max(subsurf * 12 - 2, 0.7); + + float diffuse = max(dot(sun_dir, water_normal), 0); + col += water_col * _SunCol * diffuse * 10; + + // float3 water_ao = get_ao(surface_pos.xz); + // col = water_col * lerp(0.1, water_ao, _WaveStrength) * 7; + + float hit_angle = dot(dir, -water_normal); + col = lerp(sky_reflection, col, hit_angle); + + // col = sky_reflection; + // col *= pow(dot(UP, water_normal), 512); // EVIL in the water + // col = pow((tex2D(_WaterNormal, surface_pos.xz).zxy), 2); + // col = tex2D(_WaterAO, surface_pos.xz); + + // float distance = length(surface_pos - camera_local_pos); + // float fog_factor = smoothstep(10, 70, distance) * 0.4; + // col = lerp(col, horizon_col, fog_factor); + } + else { + col = sky(dir, sun_dir); + } + return col; + } + + 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 metal = mat(1, 1); + Material blue = mat(float3(0.5, 0.6, 1), 0); + + 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); + + 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; + // d = qUnion(d, mPlaneY(p, h - snoise(p / 10 + _Time.xyz * 0.2) * 0.2, water)); + 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; + } + + float3 lighting(Ray ray) { + if (ray.missed) { + return sunset_env(ray.dir, ray.start / SCENE_SCALE); + } + + 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; + } + ENDCG + } + } +} diff --git a/Assets/raymarched/Spinny_Sunset.shader.meta b/Assets/raymarched/Spinny_Sunset.shader.meta new file mode 100644 index 0000000..6ff309f --- /dev/null +++ b/Assets/raymarched/Spinny_Sunset.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: bf32a865560b32c028bf9030b99bb087 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/distortion.shader b/Assets/raymarched/distortion.shader new file mode 100644 index 0000000..911f755 --- /dev/null +++ b/Assets/raymarched/distortion.shader @@ -0,0 +1,131 @@ +Shader "CrispyPin/Distortion" +{ + 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 3 + + #define LIGHT_FN lighting + #define SCENE_FN main + + // #define SEPARATE_MATERIAL_AND_DIST_FUNCTIONS + // #define SCENE_FN separate_mat + // #define DISTANCE_FN separate_dist + + // #define DISABLE_DEPTH + // #define DISCARD_ON_MISS + // #define USE_WORLD_SPACE + #define STEP_MULTIPLIER 0.5 + #define SCENE_SCALE 0.2 + #define LIMIT_DEPTH_TO_MESH + #include "lib/libgarbage.cginc" + + float3 distort(float3 p) { + p = rotY(p, sin(length(p.xz) * 0.2) * 0.2); + p.x += smoothstep(0, 0.5, fmod(_Time.x, 1)) * 2; + p.z += smoothstep(0.5, 1, fmod(_Time.x, 1)) * 2; + return p; + } + + 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) { + // oscillating warp + // p = rotY(p, length(p.xz)*0.03*sin(_Time.y) + _Time.y*0.1); + // constant movement with warped grid + // p = rotY(p, sin(length(p.xz) * 0.2) * 0.2); + // p.x += fmod(_Time.y, 4); + // + // p.x += smoothstep(0, 0.5, fmod(_Time.y, 1)) * 2; + // p.z += smoothstep(0.5, 1, fmod(_Time.y, 1)) * 2; + return lerp(0.08, + checkers(p - 1, 0.06, 0.12, 2), + smoothstep(64, 0, length(p)) + ); + } + + SurfacePoint main(float3 p) { + float3 twistp = rotY(p, sin(length(p.xz) * 0.2) * 0.2); + + p = distort(p); + Material floor = mat(floor_col(p)); + + p.y += 2.5; + + Material black = mat(0.05); + + SurfacePoint d; + // d = mSphere(p - float3(0, -1, 0), 0.1); + d = mPlaneY(p, 0, floor); + d = qIntersect(d, mSphere(p, 20, d.mat)); + float3 rp = repXZ(p, 2, 2); + float h = sin(twistp.x - rp.x) + 2 + sin((twistp.z - rp.z)* 0.17); + d = qUnion(d, mBox(rp - float3(0, h*0.5, 0), float3(0.5, h, 0.5), black)); + + return d; + } + + float3 lighting(Ray ray) { + 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(distort(surface_pos)); + return col * (lSky(float3(0,1,0)) + lSun(float3(0,1,0), sun_dir)); + } + } + + 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; + } + + ENDCG + } + } +} diff --git a/Assets/raymarched/distortion.shader.meta b/Assets/raymarched/distortion.shader.meta new file mode 100644 index 0000000..c4ef3fb --- /dev/null +++ b/Assets/raymarched/distortion.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ebb4c5ee330ee4a57bf8516adc9a7828 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/nut.shader b/Assets/raymarched/nut.shader new file mode 100644 index 0000000..fcce730 --- /dev/null +++ b/Assets/raymarched/nut.shader @@ -0,0 +1,158 @@ +Shader "CrispyPin/Nut" +{ + 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 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.8 + + // #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) { + 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(float3 p) { + return lerp(0.15, + checkers(p - 1, 0.10, 0.18, .2), + smoothstep(16, 0, length(p)) + ); + } + + SurfacePoint mRoundedHex(float3 p, float girth, float height) { + SurfacePoint d; + d = qRound(mHexPrism(p, girth, height), 0.01); + float rounding = 3; + d = qIntersect(d, mSphere(p - float3(0, -rounding + height, 0), rounding), 0.01); + d = qIntersect(d, mSphere(p + float3(0, -rounding + height, 0), rounding), 0.01); + return d; + } + + SurfacePoint main(float3 p) { + float girth = 0.3; + float height = 0.1; + float inner_radius = 0.18; + float thread = 0.013; + // float thread = 0.01 + sin(_Time.x * 8) * 0.01 + 0.01; + SurfacePoint d; + + float3 rp = rotY(p, _Time.y); + rp = rotX(rp, _Time.x); + // nut + d = mRoundedHex(rp, girth, height); + d = qSub(d, mInfCylinder(rp, float3(0, 0, inner_radius)), 0.02); + d = qSub(d, mHelix(rp - float3(0, -1, 0), inner_radius, thread, thread/2), 0.003); + + // bolt + SurfacePoint bolt_thread = mInfCylinder(rp, float3(0, 0, inner_radius + 0.3)); + bolt_thread = qSub(bolt_thread, mInfCylinder(rp, float3(0, 0, inner_radius)), 0.02); + bolt_thread = qSub(bolt_thread, mHelix(rp - float3(0, -1, 0), inner_radius, thread, thread/2), 0.03); + + + // d = qUnion(d, bolt_thread); + float h = sin(_Time.y) * 0.15 + 0.2; + float3 bp = rotY(rp, sin(_Time.y) * UNITY_PI * 4); + 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)); + bolt = qUnion(bolt, mCylinder(bp - float3(0, -0.17, 0), inner_radius , 0.1), 0.05); + Material metal1 = mat(float3(0.5, 0.3, 0.1), 1); + Material metal2 = mat(float3(0.3, 0.3, 0.5), 1); + d.mat = metal1; + bolt.mat = metal2; + + // cube + // float3 cp = rotX(bp - float3(0, -0.32, 0), _Time.w * 5); + // bolt = qUnion(bolt, mBox(cp, 0.1, mat(float3(0,1,1))),.1); + + d = qUnion(d, bolt); + + // floor + + // d = qUnion(d, mPlaneY(p, -0.5, mat(floor_col, 0)), 0.01); + // d = qIntersect(d, mPlaneY(-p, 0.6, mat(floor_col, 0)), 0.01); + d = qUnion(d, mBox(p - float3(0, -0.6, 0), float3(6, 0.05, 6), mat(floor(p), 0))); + + // d = qUnion(d, mSphere(p - float3(0, -0.5, 1), 0.4)); + return d; + } + + float3 lighting(Ray ray) { + float3 sun_dir = normalize(float3(4, 2, 1)); + + if (ray.missed) { + if (ray.dir.y >= 0) { + return lRenderSky(ray.dir, sun_dir); + } + else { + float3 cam = ray.start; + cam.y += 0.6 - 0.0275; + 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 = 1; + col = floor(surface_pos); + return col * (lSky(float3(0,1,0)) + lSun(float3(0,1,0), sun_dir)); + } + } + 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); + // float3(0.5, 0.8, 0.9); + // col = ray.mat.col; + + return col*ray.mat.col; + } + + + ENDCG + } + } +} diff --git a/Assets/raymarched/nut.shader.meta b/Assets/raymarched/nut.shader.meta new file mode 100644 index 0000000..1f0429b --- /dev/null +++ b/Assets/raymarched/nut.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4ba2b5d5658a2f257b227615f65e87f6 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/spinny.shader b/Assets/raymarched/spinny.shader new file mode 100644 index 0000000..13416e1 --- /dev/null +++ b/Assets/raymarched/spinny.shader @@ -0,0 +1,92 @@ +Shader "CrispyPin/LibGarbageSpinny" +{ + 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 3 + + #define LIGHT_FN lighting + #define SCENE_FN main + + // #define SEPARATE_MATERIAL_AND_DIST_FUNCTIONS + // #define SCENE_FN separate_mat + // #define DISTANCE_FN separate_dist + + // #define DISABLE_DEPTH + #define DISCARD_ON_MISS + // #define USE_WORLD_SPACE + #define SCENE_SCALE 0.05 + #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 metal = mat(1, 1); + Material blue = mat(float3(0.5, 0.6, 1), 0); + + 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); + 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(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); + + return col * ray.mat.col; + } + + ENDCG + } + } +} diff --git a/Assets/raymarched/spinny.shader.meta b/Assets/raymarched/spinny.shader.meta new file mode 100644 index 0000000..5b31c31 --- /dev/null +++ b/Assets/raymarched/spinny.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 0779c46007e531d31b99fa29d899e9ab +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: