├── .gitignore ├── LICENSE ├── README.md ├── img ├── heat-maps.gif ├── interactive-game-objects.gif └── smooth-sphere-union.gif └── unity-ray-marching ├── Assets ├── Scenes.meta ├── Scenes │ ├── AABB Tree Stress Test.meta │ ├── AABB Tree Stress Test │ │ ├── AABB Tree Stress Test.unity │ │ └── AABB Tree Stress Test.unity.meta │ ├── Game Object Ray Marcher.meta │ ├── Game Object Ray Marcher │ │ ├── Game Object Ray Marcher.unity │ │ └── Game Object Ray Marcher.unity.meta │ ├── Primitives.meta │ ├── Primitives │ │ ├── Primitives.shader │ │ ├── Primitives.shader.meta │ │ ├── Primitives.unity │ │ └── Primitives.unity.meta │ ├── Spheres.meta │ └── Spheres │ │ ├── Spheres.shader │ │ ├── Spheres.shader.meta │ │ ├── Spheres.unity │ │ └── Spheres.unity.meta ├── Script.meta ├── Script │ ├── PostProcessingBase.cs │ ├── PostProcessingBase.cs.meta │ ├── PostProcessingBlit.cs │ ├── PostProcessingBlit.cs.meta │ ├── PostProcessingCompute.cs │ ├── PostProcessingCompute.cs.meta │ ├── Ray Marching.meta │ ├── Ray Marching │ │ ├── AabbTree.cs │ │ ├── AabbTree.cs.meta │ │ ├── GameObjectRayMarcher.cs │ │ ├── GameObjectRayMarcher.cs.meta │ │ ├── RayMarchedShape.cs │ │ ├── RayMarchedShape.cs.meta │ │ ├── RayMarchedSphere.cs │ │ ├── RayMarchedSphere.cs.meta │ │ ├── SdfShape.cs │ │ └── SdfShape.cs.meta │ ├── Util.meta │ └── Util │ │ ├── ConditionalFieldAttribute.cs │ │ ├── ConditionalFieldAttribute.cs.meta │ │ ├── ConditionalFieldAttributeDrawer.cs │ │ ├── ConditionalFieldAttributeDrawer.cs.meta │ │ ├── MathUtil.cs │ │ ├── MathUtil.cs.meta │ │ ├── QuaternionUtil.cs │ │ ├── QuaternionUtil.cs.meta │ │ ├── VectorUtil.cs │ │ └── VectorUtil.cs.meta ├── Shader.meta └── Shader │ ├── Math.meta │ ├── Math │ ├── CatmullRom.cginc │ ├── CatmullRom.cginc.meta │ ├── Color.cginc │ ├── Color.cginc.meta │ ├── Math.cginc │ ├── Math.cginc.meta │ ├── Quaternion.cginc │ ├── Quaternion.cginc.meta │ ├── Vector.cginc │ └── Vector.cginc.meta │ ├── Noise.meta │ ├── Noise │ ├── ClassicNoise2D.cginc │ ├── ClassicNoise2D.cginc.meta │ ├── ClassicNoise3D.cginc │ ├── ClassicNoise3D.cginc.meta │ ├── Noise.cginc │ ├── Noise.cginc.meta │ ├── NoiseCommon.cginc │ ├── NoiseCommon.cginc.meta │ ├── RandomNoise.cginc │ ├── RandomNoise.cginc.meta │ ├── Resources.meta │ ├── Resources │ │ ├── ClassicNoiseCs.compute │ │ ├── ClassicNoiseCs.compute.meta │ │ ├── ClassicNoisePeriodicCs.compute │ │ ├── ClassicNoisePeriodicCs.compute.meta │ │ ├── RandomNoiseCs.compute │ │ ├── RandomNoiseCs.compute.meta │ │ ├── RandomNoiseVectorCs.compute │ │ ├── RandomNoiseVectorCs.compute.meta │ │ ├── SimplexNoiseCs.compute │ │ ├── SimplexNoiseCs.compute.meta │ │ ├── SimplexNoiseGradientCs.compute │ │ └── SimplexNoiseGradientCs.compute.meta │ ├── SimplexNoise2D.cginc │ ├── SimplexNoise2D.cginc.meta │ ├── SimplexNoise3D.cginc │ └── SimplexNoise3D.cginc.meta │ ├── Ray Marching.meta │ └── Ray Marching │ ├── Resources.meta │ ├── Resources │ ├── AabbTree.cginc │ ├── AabbTree.cginc.meta │ ├── RayMarcherCs.compute │ └── RayMarcherCs.compute.meta │ ├── SDF.meta │ └── SDF │ ├── Normal.cginc │ ├── Normal.cginc.meta │ ├── Operators.cginc │ ├── Operators.cginc.meta │ ├── Primitives.cginc │ ├── Primitives.cginc.meta │ ├── SDF.cginc │ ├── SDF.cginc.meta │ ├── Shapes.cginc │ ├── Shapes.cginc.meta │ ├── Util.cginc │ └── Util.cginc.meta ├── Packages └── manifest.json └── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── Physics2DSettings.asset ├── PresetManager.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityConnectSettings.asset ├── VFXManager.asset └── XRSettings.asset /.gitignore: -------------------------------------------------------------------------------- 1 | unity-ray-marching/[Ll]ibrary/ 2 | unity-ray-marching/[Dd]ebug/ 3 | unity-ray-marching/[Tt]emp/ 4 | unity-ray-marching/[Oo]bj/ 5 | unity-ray-marching/[Bb]uild/ 6 | unity-ray-marching/[Bb]uilds/ 7 | unity-ray-marching/.vs/ 8 | bin/ 9 | 10 | # Autogenerated VS/MD/Consulo solution and project files 11 | ExportedObj/ 12 | .consulo/ 13 | *.csproj 14 | *.unityproj 15 | *.sln 16 | *.suo 17 | *.tmp 18 | *.user 19 | *.userprefs 20 | *.pidb 21 | *.booproj 22 | *.svd 23 | *.pdb 24 | 25 | # Unity3D generated meta files 26 | *.pidb.meta 27 | 28 | # Unity3D Generated File On Crash Reports 29 | sysinfo.txt 30 | 31 | # Builds 32 | *.unitypackage 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Ming-Lun "Allen" Chou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Unity Ray Marching - My Sandbox for Learning Ray Marching 2 | by **Ming-Lun "Allen" Chou** / [AllenChou.net](http://AllenChou.net) / [@TheAllenChou](http://twitter.com/TheAllenChou) / [Patreon](https://www.patreon.com/TheAllenChou) 3 | 4 | This project has been forked into [MudBun](http://longbunnylabs.com/mudbun/), a volumetric VFX tool for Unity inspired by [Clayxels](https://andrea-intg.itch.io/clayxels). 5 | 6 | ![](/img/smooth-sphere-union.gif) ![](/img/interactive-game-objects.gif) ![](/img/heat-maps.gif) 7 | 8 | ## Features 9 | * Smooth Boolean operations: union, subtraction, intersection. 10 | * Heat maps: number of ray steps & number of SDF evaluations. 11 | * Final rendered image entirely generated using compute shader. 12 | 13 | ## Optimization Techniques 14 | * Bounding volume hierarchy (BVH) using dynamic AABB trees. 15 | * AABB query & ray query against AABB trees on GPU. 16 | 17 | ## References & Resources 18 | * [How Ray Marching & Signed Distance Fields (SDF) Work](http://www.michaelwalczyk.com/blog/2017/5/25/ray-marching) 19 | * [Smooth SDF Unions](http://www.iquilezles.org/www/articles/smin/smin.htm) 20 | * [SDF Normals](http://www.iquilezles.org/www/articles/normalsSDF/normalsSDF.htm) 21 | * [Shadertoy](http://shadertoy.com) 22 | * [Dynamic Bounding Volume Hierarchies (GDC 2019)](https://box2d.org/files/ErinCatto_DynamicBVH_GDC2019.pdf) 23 | * [Box2D](https://github.com/erincatto/box2d) 24 | -------------------------------------------------------------------------------- /img/heat-maps.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAllenChou/unity-ray-marching/8c584a834348c31cc98d20c853d43dc1b8c5237f/img/heat-maps.gif -------------------------------------------------------------------------------- /img/interactive-game-objects.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAllenChou/unity-ray-marching/8c584a834348c31cc98d20c853d43dc1b8c5237f/img/interactive-game-objects.gif -------------------------------------------------------------------------------- /img/smooth-sphere-union.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAllenChou/unity-ray-marching/8c584a834348c31cc98d20c853d43dc1b8c5237f/img/smooth-sphere-union.gif -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 865d41909afd7b34c9b262076a972a21 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/AABB Tree Stress Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38416bedd4b88144f84a50806dc4bbd2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/AABB Tree Stress Test/AABB Tree Stress Test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2cb5d603f12a331478b7e554e172ceeb 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Game Object Ray Marcher.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f17b9c3ff1d350a4c945049a1f7356e7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Game Object Ray Marcher/Game Object Ray Marcher.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: feed9cf56bd271742be8855bdb453c17 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Primitives.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0138a61cb73dd504f810141270a8375a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Primitives/Primitives.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | Shader "Hidden/Primitives" 14 | { 15 | Properties 16 | { 17 | _MainTex ("Texture", 2D) = "white" {} 18 | } 19 | SubShader 20 | { 21 | Cull Off ZWrite Off ZTest Always 22 | 23 | Pass 24 | { 25 | CGPROGRAM 26 | #pragma vertex vert 27 | #pragma fragment frag 28 | 29 | #include "UnityCG.cginc" 30 | #include "../../Shader/Math/Math.cginc" 31 | #include "../../Shader/Ray Marching/SDF/SDF.cginc" 32 | 33 | struct appdata 34 | { 35 | float4 vertex : POSITION; 36 | float2 uv : TEXCOORD0; 37 | }; 38 | 39 | struct v2f 40 | { 41 | float2 uv : TEXCOORD0; 42 | float4 vertex : SV_POSITION; 43 | float3 view : TEXCOORD1; 44 | }; 45 | 46 | sampler2D _MainTex; 47 | sampler2D _CameraDepthTexture; 48 | 49 | float map(float3 p) 50 | { 51 | const float3 kSphereCenter = float3(0.0f, 0.0f, 5.0f); 52 | const float3 kSphereRadius = 1.0f; 53 | const float t = _Time.y; 54 | 55 | const float a = sdf_sphere(p, kSphereCenter, kSphereRadius); 56 | const float b = sdf_sphere(p, kSphereCenter - float3(2.0f * sin(2.0f * t), 0.0f, 0.0f), 0.7f * kSphereRadius * (0.8f * abs(sin(2.0f * t)) + 0.2f)); 57 | const float c = sdf_sphere(p, kSphereCenter - float3(0.0f, 2.0f * cos(2.0f * t), 0.0f), 0.7f * kSphereRadius * (0.8f * abs(cos(2.0f * t)) + 0.2f)); 58 | const float d = sdf_box(p, float3(0.0f, 0.0f, 3.0f), float3(1.0f, 0.5f, 0.5f), quat_euler(float3(0.0f, kSixthPi, kFifthPi))); 59 | const float e = sdf_capsule(p, float3(1.0f, 1.0f, 2.0f), float3(-1.0f, -1.0f, 2.5f), 0.3f); 60 | const float f = sdf_cylinder(p, float3(-1.0f, 1.0f, 0.0f), float3(1.0f, -1.0f, 0.5f), 0.3f); 61 | 62 | float k = 0.5f; 63 | float res = sdf_uni_smooth(a, b, k); 64 | res = sdf_uni_smooth(c, res, k); 65 | res = sdf_uni_smooth(d, res, k); 66 | res = sdf_uni_smooth(e, res, k); 67 | res = sdf_uni_smooth(f, res, k); 68 | 69 | return res; 70 | } 71 | 72 | float3 normal(float3 p) 73 | { 74 | return sdf_normal(p, map, 0.01f); 75 | } 76 | 77 | float3 march(float3 ro, float3 rd) 78 | { 79 | const int kMaxSteps = 256; 80 | const float kHitDist = 0.005f; 81 | const float kMaxDist = 1000.0f; 82 | const float3 kBackground = float3(0.0f, 0.07f, 0.15f); 83 | const float3 kDiffuse = float3(1.0f, 0.65f, 0.05f); 84 | const float3 kAmbient = 0.1f * kDiffuse; 85 | const float t = _Time.y; 86 | 87 | float dist = 0.0f; 88 | for (int i = 0; i < kMaxSteps; ++i) 89 | { 90 | float3 p = ro + dist * rd; 91 | float d = map(p); 92 | 93 | if (d < kHitDist) 94 | { 95 | float3 n = normal(p); 96 | float3 lightPos = ro + float3(5.0f * sin(2.0f * t), 5.0f * cos(2.0f * t), 0.0f); 97 | float3 lightDir = normalize(p - lightPos); 98 | float3 shaded = max(pow(dot(n, -lightDir), 1.0f), kAmbient) * kDiffuse; 99 | float3 fresnel = 0.3f * pow(saturate(1.0f - dot(n, -rd)), 2.0f); 100 | float3 specular = 0.2f * pow(saturate(dot(n, -normalize(rd + lightDir))), 100.0f); 101 | return shaded + fresnel + specular; 102 | } 103 | 104 | if (dist > kMaxDist) 105 | return kBackground; 106 | 107 | dist += d; 108 | } 109 | 110 | return float3(1.0f, 0.0f, 0.0f); 111 | } 112 | 113 | v2f vert(appdata v) 114 | { 115 | v2f o; 116 | o.vertex = UnityObjectToClipPos(v.vertex); 117 | o.uv = v.uv; 118 | 119 | // Camera space matches OpenGL convention where cam forward is -z. In unity forward is positive z. 120 | // (https://docs.unity3d.com/ScriptReference/Camera-cameraToWorldMatrix.html) 121 | float3 view = mul(unity_CameraInvProjection, float4(v.uv * 2.0f - 1.0f, 0.0f, -1.0f)); 122 | o.view = mul(unity_CameraToWorld, float4(view, 0.0f)); 123 | 124 | return o; 125 | } 126 | 127 | fixed4 frag(v2f i) : SV_Target 128 | { 129 | fixed4 col = tex2D(_MainTex, i.uv); 130 | 131 | float3 ro = _WorldSpaceCameraPos; 132 | float3 rd = normalize(i.view); 133 | 134 | col.rgb = march(ro, rd); 135 | 136 | return col; 137 | } 138 | ENDCG 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Primitives/Primitives.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b559e008daad4d344ab0b473b0e8e622 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Primitives/Primitives.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 11 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 512 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 256 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 1 83 | m_PVRDenoiserTypeDirect: 1 84 | m_PVRDenoiserTypeIndirect: 1 85 | m_PVRDenoiserTypeAO: 1 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 1 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_UseShadowmask: 1 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | debug: 122 | m_Flags: 0 123 | m_NavMeshData: {fileID: 0} 124 | --- !u!1 &397912282 125 | GameObject: 126 | m_ObjectHideFlags: 0 127 | m_CorrespondingSourceObject: {fileID: 0} 128 | m_PrefabInstance: {fileID: 0} 129 | m_PrefabAsset: {fileID: 0} 130 | serializedVersion: 6 131 | m_Component: 132 | - component: {fileID: 397912284} 133 | - component: {fileID: 397912283} 134 | m_Layer: 0 135 | m_Name: Directional Light 136 | m_TagString: Untagged 137 | m_Icon: {fileID: 0} 138 | m_NavMeshLayer: 0 139 | m_StaticEditorFlags: 0 140 | m_IsActive: 1 141 | --- !u!108 &397912283 142 | Light: 143 | m_ObjectHideFlags: 0 144 | m_CorrespondingSourceObject: {fileID: 0} 145 | m_PrefabInstance: {fileID: 0} 146 | m_PrefabAsset: {fileID: 0} 147 | m_GameObject: {fileID: 397912282} 148 | m_Enabled: 1 149 | serializedVersion: 10 150 | m_Type: 1 151 | m_Shape: 0 152 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 153 | m_Intensity: 1 154 | m_Range: 10 155 | m_SpotAngle: 30 156 | m_InnerSpotAngle: 21.80208 157 | m_CookieSize: 10 158 | m_Shadows: 159 | m_Type: 2 160 | m_Resolution: -1 161 | m_CustomResolution: -1 162 | m_Strength: 1 163 | m_Bias: 0.05 164 | m_NormalBias: 0.4 165 | m_NearPlane: 0.2 166 | m_CullingMatrixOverride: 167 | e00: 1 168 | e01: 0 169 | e02: 0 170 | e03: 0 171 | e10: 0 172 | e11: 1 173 | e12: 0 174 | e13: 0 175 | e20: 0 176 | e21: 0 177 | e22: 1 178 | e23: 0 179 | e30: 0 180 | e31: 0 181 | e32: 0 182 | e33: 1 183 | m_UseCullingMatrixOverride: 0 184 | m_Cookie: {fileID: 0} 185 | m_DrawHalo: 0 186 | m_Flare: {fileID: 0} 187 | m_RenderMode: 0 188 | m_CullingMask: 189 | serializedVersion: 2 190 | m_Bits: 4294967295 191 | m_RenderingLayerMask: 1 192 | m_Lightmapping: 4 193 | m_LightShadowCasterMode: 0 194 | m_AreaSize: {x: 1, y: 1} 195 | m_BounceIntensity: 1 196 | m_ColorTemperature: 6570 197 | m_UseColorTemperature: 0 198 | m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} 199 | m_UseBoundingSphereOverride: 0 200 | m_ShadowRadius: 0 201 | m_ShadowAngle: 0 202 | --- !u!4 &397912284 203 | Transform: 204 | m_ObjectHideFlags: 0 205 | m_CorrespondingSourceObject: {fileID: 0} 206 | m_PrefabInstance: {fileID: 0} 207 | m_PrefabAsset: {fileID: 0} 208 | m_GameObject: {fileID: 397912282} 209 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 210 | m_LocalPosition: {x: 0, y: 3, z: 0} 211 | m_LocalScale: {x: 1, y: 1, z: 1} 212 | m_Children: [] 213 | m_Father: {fileID: 0} 214 | m_RootOrder: 1 215 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 216 | --- !u!1 &954908092 217 | GameObject: 218 | m_ObjectHideFlags: 0 219 | m_CorrespondingSourceObject: {fileID: 0} 220 | m_PrefabInstance: {fileID: 0} 221 | m_PrefabAsset: {fileID: 0} 222 | serializedVersion: 6 223 | m_Component: 224 | - component: {fileID: 954908095} 225 | - component: {fileID: 954908094} 226 | - component: {fileID: 954908093} 227 | - component: {fileID: 954908096} 228 | m_Layer: 0 229 | m_Name: Main Camera 230 | m_TagString: MainCamera 231 | m_Icon: {fileID: 0} 232 | m_NavMeshLayer: 0 233 | m_StaticEditorFlags: 0 234 | m_IsActive: 1 235 | --- !u!81 &954908093 236 | AudioListener: 237 | m_ObjectHideFlags: 0 238 | m_CorrespondingSourceObject: {fileID: 0} 239 | m_PrefabInstance: {fileID: 0} 240 | m_PrefabAsset: {fileID: 0} 241 | m_GameObject: {fileID: 954908092} 242 | m_Enabled: 1 243 | --- !u!20 &954908094 244 | Camera: 245 | m_ObjectHideFlags: 0 246 | m_CorrespondingSourceObject: {fileID: 0} 247 | m_PrefabInstance: {fileID: 0} 248 | m_PrefabAsset: {fileID: 0} 249 | m_GameObject: {fileID: 954908092} 250 | m_Enabled: 1 251 | serializedVersion: 2 252 | m_ClearFlags: 1 253 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 254 | m_projectionMatrixMode: 1 255 | m_GateFitMode: 2 256 | m_FOVAxisMode: 0 257 | m_SensorSize: {x: 36, y: 24} 258 | m_LensShift: {x: 0, y: 0} 259 | m_FocalLength: 50 260 | m_NormalizedViewPortRect: 261 | serializedVersion: 2 262 | x: 0 263 | y: 0 264 | width: 1 265 | height: 1 266 | near clip plane: 0.3 267 | far clip plane: 1000 268 | field of view: 60 269 | orthographic: 0 270 | orthographic size: 5 271 | m_Depth: -1 272 | m_CullingMask: 273 | serializedVersion: 2 274 | m_Bits: 4294967295 275 | m_RenderingPath: -1 276 | m_TargetTexture: {fileID: 0} 277 | m_TargetDisplay: 0 278 | m_TargetEye: 3 279 | m_HDR: 1 280 | m_AllowMSAA: 1 281 | m_AllowDynamicResolution: 0 282 | m_ForceIntoRT: 0 283 | m_OcclusionCulling: 1 284 | m_StereoConvergence: 10 285 | m_StereoSeparation: 0.022 286 | --- !u!4 &954908095 287 | Transform: 288 | m_ObjectHideFlags: 0 289 | m_CorrespondingSourceObject: {fileID: 0} 290 | m_PrefabInstance: {fileID: 0} 291 | m_PrefabAsset: {fileID: 0} 292 | m_GameObject: {fileID: 954908092} 293 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 294 | m_LocalPosition: {x: 0, y: 0, z: -5} 295 | m_LocalScale: {x: 1, y: 1, z: 1} 296 | m_Children: [] 297 | m_Father: {fileID: 0} 298 | m_RootOrder: 0 299 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 300 | --- !u!114 &954908096 301 | MonoBehaviour: 302 | m_ObjectHideFlags: 0 303 | m_CorrespondingSourceObject: {fileID: 0} 304 | m_PrefabInstance: {fileID: 0} 305 | m_PrefabAsset: {fileID: 0} 306 | m_GameObject: {fileID: 954908092} 307 | m_Enabled: 1 308 | m_EditorHideFlags: 0 309 | m_Script: {fileID: 11500000, guid: 530b9ca09b259de41aecc7ea3e363242, type: 3} 310 | m_Name: 311 | m_EditorClassIdentifier: 312 | ApplyToSceneCamera: 1 313 | PostProcessingShader: {fileID: 4800000, guid: b559e008daad4d344ab0b473b0e8e622, 314 | type: 3} 315 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Primitives/Primitives.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9505b0e9844b1142911bf52e3a1083d 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Spheres.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73d694c43c459e8439bab662d4f5c864 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Spheres/Spheres.shader: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | Shader "Hidden/Spheres" 14 | { 15 | Properties 16 | { 17 | _MainTex ("Texture", 2D) = "white" {} 18 | } 19 | SubShader 20 | { 21 | Cull Off ZWrite Off ZTest Always 22 | 23 | Pass 24 | { 25 | CGPROGRAM 26 | #pragma vertex vert 27 | #pragma fragment frag 28 | 29 | #include "UnityCG.cginc" 30 | #include "../../Shader/Math/Math.cginc" 31 | #include "../../Shader/Ray Marching/SDF/SDF.cginc" 32 | 33 | struct appdata 34 | { 35 | float4 vertex : POSITION; 36 | float2 uv : TEXCOORD0; 37 | }; 38 | 39 | struct v2f 40 | { 41 | float2 uv : TEXCOORD0; 42 | float4 vertex : SV_POSITION; 43 | float3 view : TEXCOORD1; 44 | }; 45 | 46 | sampler2D _MainTex; 47 | sampler2D _CameraDepthTexture; 48 | 49 | float map(float3 p, int userData) 50 | { 51 | const float3 kSphereCenter = float3(0.0f, 0.0f, 5.0f); 52 | const float3 kSphereRadius = 1.0f; 53 | const float t = _Time.y; 54 | 55 | const float a = sdf_sphere(p, kSphereCenter, kSphereRadius); 56 | const float b = sdf_sphere(p, kSphereCenter - float3(2.0f * sin(2.0f * t), 0.0f, 0.0f), 0.7f * kSphereRadius * (0.8f * abs(sin(2.0f * t)) + 0.2f)); 57 | const float c = sdf_sphere(p, kSphereCenter - float3(0.0f, 2.0f * cos(2.0f * t), 0.0f), 0.7f * kSphereRadius * (0.8f * abs(cos(2.0f * t)) + 0.2f)); 58 | 59 | float k = 0.5f; 60 | float res = sdf_uni_smooth(a, b, k); 61 | res = sdf_uni_smooth(c, res, k); 62 | 63 | return res; 64 | } 65 | 66 | 67 | float3 normal(float3 p) 68 | { 69 | return sdf_normal(p, map, 0.01f); 70 | } 71 | 72 | float3 march(float3 ro, float3 rd) 73 | { 74 | const int kMaxSteps = 256; 75 | const float kHitDist = 0.005f; 76 | const float kMaxDist = 1000.0f; 77 | const float3 kBackground = float3(0.0f, 0.07f, 0.15f); 78 | const float3 kDiffuse = float3(1.0f, 0.65f, 0.05f); 79 | const float3 kAmbient = 0.1f * kDiffuse; 80 | const float t = _Time.y; 81 | 82 | float dist = 0.0f; 83 | for (int i = 0; i < kMaxSteps; ++i) 84 | { 85 | float3 p = ro + dist * rd; 86 | float d = map(p); 87 | 88 | if (d < kHitDist) 89 | { 90 | float3 n = normal(p); 91 | float3 lightPos = ro + float3(5.0f * sin(2.0f * t), 5.0f * cos(2.0f * t), 0.0f); 92 | float3 lightDir = normalize(p - lightPos); 93 | float3 shaded = max(pow(dot(n, -lightDir), 1.0f), kAmbient) * kDiffuse; 94 | float3 fresnel = 0.3f * pow(saturate(1.0f - dot(n, -rd)), 2.0f); 95 | float3 specular = 0.2f * pow(saturate(dot(n, -normalize(rd + lightDir))), 100.0f); 96 | return shaded + fresnel + specular; 97 | } 98 | 99 | if (dist > kMaxDist) 100 | return kBackground; 101 | 102 | dist += d; 103 | } 104 | 105 | return float3(1.0f, 0.0f, 0.0f); 106 | } 107 | 108 | v2f vert(appdata v) 109 | { 110 | v2f o; 111 | o.vertex = UnityObjectToClipPos(v.vertex); 112 | o.uv = v.uv; 113 | 114 | // Camera space matches OpenGL convention where cam forward is -z. In unity forward is positive z. 115 | // (https://docs.unity3d.com/ScriptReference/Camera-cameraToWorldMatrix.html) 116 | float3 view = mul(unity_CameraInvProjection, float4(v.uv * 2.0f - 1.0f, 0.0f, -1.0f)); 117 | o.view = mul(unity_CameraToWorld, float4(view, 0.0f)); 118 | 119 | return o; 120 | } 121 | 122 | fixed4 frag(v2f i) : SV_Target 123 | { 124 | fixed4 col = tex2D(_MainTex, i.uv); 125 | 126 | float3 ro = _WorldSpaceCameraPos; 127 | float3 rd = normalize(i.view); 128 | 129 | col.rgb = march(ro, rd); 130 | 131 | return col; 132 | } 133 | ENDCG 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Spheres/Spheres.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c81371aa634cf774fb5d9e4922721b23 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Spheres/Spheres.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 11 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 512 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 256 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 1 83 | m_PVRDenoiserTypeDirect: 1 84 | m_PVRDenoiserTypeIndirect: 1 85 | m_PVRDenoiserTypeAO: 1 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 1 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_UseShadowmask: 1 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | debug: 122 | m_Flags: 0 123 | m_NavMeshData: {fileID: 0} 124 | --- !u!1 &563885889 125 | GameObject: 126 | m_ObjectHideFlags: 0 127 | m_CorrespondingSourceObject: {fileID: 0} 128 | m_PrefabInstance: {fileID: 0} 129 | m_PrefabAsset: {fileID: 0} 130 | serializedVersion: 6 131 | m_Component: 132 | - component: {fileID: 563885892} 133 | - component: {fileID: 563885891} 134 | - component: {fileID: 563885890} 135 | - component: {fileID: 563885893} 136 | m_Layer: 0 137 | m_Name: Main Camera 138 | m_TagString: MainCamera 139 | m_Icon: {fileID: 0} 140 | m_NavMeshLayer: 0 141 | m_StaticEditorFlags: 0 142 | m_IsActive: 1 143 | --- !u!81 &563885890 144 | AudioListener: 145 | m_ObjectHideFlags: 0 146 | m_CorrespondingSourceObject: {fileID: 0} 147 | m_PrefabInstance: {fileID: 0} 148 | m_PrefabAsset: {fileID: 0} 149 | m_GameObject: {fileID: 563885889} 150 | m_Enabled: 1 151 | --- !u!20 &563885891 152 | Camera: 153 | m_ObjectHideFlags: 0 154 | m_CorrespondingSourceObject: {fileID: 0} 155 | m_PrefabInstance: {fileID: 0} 156 | m_PrefabAsset: {fileID: 0} 157 | m_GameObject: {fileID: 563885889} 158 | m_Enabled: 1 159 | serializedVersion: 2 160 | m_ClearFlags: 1 161 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 162 | m_projectionMatrixMode: 1 163 | m_GateFitMode: 2 164 | m_FOVAxisMode: 0 165 | m_SensorSize: {x: 36, y: 24} 166 | m_LensShift: {x: 0, y: 0} 167 | m_FocalLength: 50 168 | m_NormalizedViewPortRect: 169 | serializedVersion: 2 170 | x: 0 171 | y: 0 172 | width: 1 173 | height: 1 174 | near clip plane: 0.3 175 | far clip plane: 1000 176 | field of view: 60 177 | orthographic: 0 178 | orthographic size: 5 179 | m_Depth: -1 180 | m_CullingMask: 181 | serializedVersion: 2 182 | m_Bits: 4294967295 183 | m_RenderingPath: -1 184 | m_TargetTexture: {fileID: 0} 185 | m_TargetDisplay: 0 186 | m_TargetEye: 3 187 | m_HDR: 1 188 | m_AllowMSAA: 1 189 | m_AllowDynamicResolution: 0 190 | m_ForceIntoRT: 0 191 | m_OcclusionCulling: 1 192 | m_StereoConvergence: 10 193 | m_StereoSeparation: 0.022 194 | --- !u!4 &563885892 195 | Transform: 196 | m_ObjectHideFlags: 0 197 | m_CorrespondingSourceObject: {fileID: 0} 198 | m_PrefabInstance: {fileID: 0} 199 | m_PrefabAsset: {fileID: 0} 200 | m_GameObject: {fileID: 563885889} 201 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 202 | m_LocalPosition: {x: 0, y: 0, z: 0} 203 | m_LocalScale: {x: 1, y: 1, z: 1} 204 | m_Children: [] 205 | m_Father: {fileID: 0} 206 | m_RootOrder: 0 207 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 208 | --- !u!114 &563885893 209 | MonoBehaviour: 210 | m_ObjectHideFlags: 0 211 | m_CorrespondingSourceObject: {fileID: 0} 212 | m_PrefabInstance: {fileID: 0} 213 | m_PrefabAsset: {fileID: 0} 214 | m_GameObject: {fileID: 563885889} 215 | m_Enabled: 1 216 | m_EditorHideFlags: 0 217 | m_Script: {fileID: 11500000, guid: 530b9ca09b259de41aecc7ea3e363242, type: 3} 218 | m_Name: 219 | m_EditorClassIdentifier: 220 | ApplyToSceneCamera: 1 221 | PostProcessingShader: {fileID: 4800000, guid: c81371aa634cf774fb5d9e4922721b23, 222 | type: 3} 223 | --- !u!1 &1815280917 224 | GameObject: 225 | m_ObjectHideFlags: 0 226 | m_CorrespondingSourceObject: {fileID: 0} 227 | m_PrefabInstance: {fileID: 0} 228 | m_PrefabAsset: {fileID: 0} 229 | serializedVersion: 6 230 | m_Component: 231 | - component: {fileID: 1815280919} 232 | - component: {fileID: 1815280918} 233 | m_Layer: 0 234 | m_Name: Directional Light 235 | m_TagString: Untagged 236 | m_Icon: {fileID: 0} 237 | m_NavMeshLayer: 0 238 | m_StaticEditorFlags: 0 239 | m_IsActive: 1 240 | --- !u!108 &1815280918 241 | Light: 242 | m_ObjectHideFlags: 0 243 | m_CorrespondingSourceObject: {fileID: 0} 244 | m_PrefabInstance: {fileID: 0} 245 | m_PrefabAsset: {fileID: 0} 246 | m_GameObject: {fileID: 1815280917} 247 | m_Enabled: 1 248 | serializedVersion: 10 249 | m_Type: 1 250 | m_Shape: 0 251 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 252 | m_Intensity: 1 253 | m_Range: 10 254 | m_SpotAngle: 30 255 | m_InnerSpotAngle: 21.80208 256 | m_CookieSize: 10 257 | m_Shadows: 258 | m_Type: 2 259 | m_Resolution: -1 260 | m_CustomResolution: -1 261 | m_Strength: 1 262 | m_Bias: 0.05 263 | m_NormalBias: 0.4 264 | m_NearPlane: 0.2 265 | m_CullingMatrixOverride: 266 | e00: 1 267 | e01: 0 268 | e02: 0 269 | e03: 0 270 | e10: 0 271 | e11: 1 272 | e12: 0 273 | e13: 0 274 | e20: 0 275 | e21: 0 276 | e22: 1 277 | e23: 0 278 | e30: 0 279 | e31: 0 280 | e32: 0 281 | e33: 1 282 | m_UseCullingMatrixOverride: 0 283 | m_Cookie: {fileID: 0} 284 | m_DrawHalo: 0 285 | m_Flare: {fileID: 0} 286 | m_RenderMode: 0 287 | m_CullingMask: 288 | serializedVersion: 2 289 | m_Bits: 4294967295 290 | m_RenderingLayerMask: 1 291 | m_Lightmapping: 4 292 | m_LightShadowCasterMode: 0 293 | m_AreaSize: {x: 1, y: 1} 294 | m_BounceIntensity: 1 295 | m_ColorTemperature: 6570 296 | m_UseColorTemperature: 0 297 | m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} 298 | m_UseBoundingSphereOverride: 0 299 | m_ShadowRadius: 0 300 | m_ShadowAngle: 0 301 | --- !u!4 &1815280919 302 | Transform: 303 | m_ObjectHideFlags: 0 304 | m_CorrespondingSourceObject: {fileID: 0} 305 | m_PrefabInstance: {fileID: 0} 306 | m_PrefabAsset: {fileID: 0} 307 | m_GameObject: {fileID: 1815280917} 308 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 309 | m_LocalPosition: {x: 0, y: 3, z: 0} 310 | m_LocalScale: {x: 1, y: 1, z: 1} 311 | m_Children: [] 312 | m_Father: {fileID: 0} 313 | m_RootOrder: 1 314 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 315 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Scenes/Spheres/Spheres.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f8545089f598fd4aa4cdba8e6735fe6 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2460c116f61f3174e92f093527e6d3a1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/PostProcessingBase.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | #if UNITY_EDITOR 15 | using UnityEditor; 16 | #endif 17 | 18 | [RequireComponent(typeof(Camera))] 19 | [ExecuteInEditMode] 20 | public class PostProcessingBase : MonoBehaviour 21 | { 22 | public bool ApplyToSceneCamera = true; 23 | 24 | #if UNITY_EDITOR 25 | private Camera m_sceneCamera; 26 | private PostProcessingBase m_postProcessing; 27 | private bool m_appliedToSceneCamera = false; 28 | private bool m_attachedToSceneCamera = false; 29 | #endif 30 | 31 | private void DisposeSceneCamera() 32 | { 33 | if (m_postProcessing != null) 34 | { 35 | DestroyImmediate(m_postProcessing); 36 | } 37 | 38 | m_sceneCamera = null; 39 | m_postProcessing = null; 40 | m_appliedToSceneCamera = false; 41 | } 42 | 43 | private void Update() 44 | { 45 | #if UNITY_EDITOR 46 | UpdateSceneCamera(); 47 | #endif 48 | } 49 | 50 | protected virtual void OnValidate() 51 | { 52 | #if UNITY_EDITOR 53 | // reboot component copy to scene camera if changed in editor 54 | m_appliedToSceneCamera = false; 55 | #endif 56 | } 57 | 58 | #if UNITY_EDITOR 59 | private void UpdateSceneCamera() 60 | { 61 | if (m_attachedToSceneCamera) 62 | return; 63 | 64 | if (!ApplyToSceneCamera) 65 | { 66 | DisposeSceneCamera(); 67 | return; 68 | } 69 | 70 | if (m_appliedToSceneCamera) 71 | return; 72 | 73 | var window = EditorWindow.GetWindow(false, "", false); 74 | var camera = window ? window.camera : null; 75 | if (m_sceneCamera && m_sceneCamera != camera) 76 | { 77 | DisposeSceneCamera(); 78 | } 79 | m_sceneCamera = camera; 80 | 81 | if (camera == null) 82 | return; 83 | 84 | var pp = (PostProcessingBase) camera.GetComponent(GetType()); 85 | if (pp && pp != m_postProcessing) 86 | { 87 | DestroyImmediate(pp); 88 | pp = null; 89 | } 90 | 91 | if (pp == null) 92 | { 93 | pp = (PostProcessingBase) camera.gameObject.AddComponent(GetType()); 94 | pp.m_attachedToSceneCamera = true; 95 | } 96 | 97 | EditorUtility.CopySerialized(this, pp); 98 | m_postProcessing = pp; 99 | 100 | m_appliedToSceneCamera = true; 101 | } 102 | #endif 103 | } 104 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/PostProcessingBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0acce6fa5b66f84e872645bb39ffca3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/PostProcessingBlit.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | [RequireComponent(typeof(Camera))] 15 | [ExecuteInEditMode] 16 | public class PostProcessingBlit : PostProcessingBase 17 | { 18 | public Shader PostProcessingShader; 19 | 20 | private Material m_material; 21 | 22 | private void OnRenderImage(RenderTexture src, RenderTexture dst) 23 | { 24 | if (PostProcessingShader == null) 25 | { 26 | Debug.LogWarning("Shader is not assigned for post processing."); 27 | return; 28 | } 29 | 30 | if (PostProcessingShader != null) 31 | { 32 | if (m_material == null) 33 | { 34 | m_material = new Material(PostProcessingShader); 35 | } 36 | 37 | if (m_material.shader != PostProcessingShader) 38 | { 39 | m_material.shader = PostProcessingShader; 40 | } 41 | } 42 | 43 | Graphics.Blit(src, dst, m_material); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/PostProcessingBlit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 530b9ca09b259de41aecc7ea3e363242 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/PostProcessingCompute.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | [RequireComponent(typeof(Camera))] 15 | [ExecuteInEditMode] 16 | public class PostProcessingCompute : PostProcessingBase 17 | { 18 | public ComputeShader Compute; 19 | private ComputeShader m_compute; 20 | private RenderTexture m_renderTarget; 21 | 22 | protected virtual void Init(ComputeShader compute) { } 23 | protected virtual void Dispose(ComputeShader compute) { } 24 | protected virtual void OnPreRenderImage(ComputeShader compute, RenderTexture src, RenderTexture dst) { } 25 | protected virtual void Dispatch(ComputeShader compute, RenderTexture src, RenderTexture dst) { } 26 | protected virtual void OnPostRenderImage(ComputeShader compute, RenderTexture src, RenderTexture dst) { } 27 | 28 | private void OnDisable() 29 | { 30 | if (m_compute == null) 31 | return; 32 | 33 | Dispose(m_compute); 34 | m_compute = null; 35 | } 36 | 37 | private void OnRenderImage(RenderTexture src, RenderTexture dst) 38 | { 39 | if (Compute != m_compute) 40 | { 41 | if (m_compute != null) 42 | { 43 | Dispose(m_compute); 44 | m_compute = null; 45 | } 46 | 47 | if (Compute != null) 48 | { 49 | m_compute = Compute; 50 | Init(m_compute); 51 | } 52 | } 53 | 54 | if (m_compute == null) 55 | { 56 | Debug.LogWarning("Compute shader is not assigned for post processing."); 57 | return; 58 | } 59 | 60 | if (m_renderTarget == null 61 | || m_renderTarget.width != src.width 62 | || m_renderTarget.height != src.height) 63 | { 64 | if (m_renderTarget != null) 65 | { 66 | DestroyImmediate(m_renderTarget); 67 | m_renderTarget = null; 68 | } 69 | 70 | m_renderTarget = new RenderTexture(src.width, src.height, 0); 71 | m_renderTarget.enableRandomWrite = true; 72 | m_renderTarget.Create(); 73 | } 74 | 75 | OnPreRenderImage(m_compute, src, m_renderTarget); 76 | Dispatch(m_compute, src, m_renderTarget); 77 | Graphics.Blit(m_renderTarget, dst); 78 | OnPostRenderImage(m_compute, src, m_renderTarget); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/PostProcessingCompute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abde3e9da58da63419f8889e4332b75a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bef8deda301ea2f468d4a2de50868c77 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/AabbTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a8a0dbeb130cbd4b8f67fca1fa2d462 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/GameObjectRayMarcher.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using System.Collections.Generic; 13 | 14 | using UnityEngine; 15 | 16 | #if UNITY_EDITOR 17 | using UnityEditor; 18 | #endif 19 | 20 | [RequireComponent(typeof(Camera))] 21 | [ExecuteInEditMode] 22 | public class GameObjectRayMarcher : PostProcessingCompute 23 | { 24 | private static readonly int TileSize = 8; 25 | 26 | public enum HeatMapModeEnum 27 | { 28 | None, 29 | StepCountPerThread, 30 | StepCountPerTile, 31 | ShapeCountPerThread, 32 | ShapeCountPerTile, 33 | } 34 | 35 | [Header("Ray Marching")] 36 | public float BlendDistance = 0.5f; 37 | public Color BackgroundColor = new Color(0.0f, 0.07f, 0.15f); 38 | public Color MissColor = new Color(1.0f, 0.0f, 0.0f); 39 | [Range(1, 256)] 40 | public int MaxRaySteps = 128; 41 | public float RayHitThreshold = 0.005f; 42 | public float MaxRayDistance = 1000.0f; 43 | 44 | [Header("Bounding Volume Hierarchy")] 45 | [ConditionalField(Label = "Use BVH")] 46 | public bool UseBoundingVolumes = true; 47 | public bool DrawBoundingVolumes = false; 48 | [ConditionalField(Label = " Isolate BVH Depth", Min = -1, Max = 16)] 49 | public int IsolateBoundingVolumeDepth = -1; 50 | [ConditionalField(Label = "Test BVH Bounds Query")] 51 | public bool TestBvhBoundsQuery = false; 52 | [ConditionalField(Label = "Test BVH Ray Cast")] 53 | public bool TestBvhRayCast = false; 54 | 55 | [Header("Heat Map")] 56 | public HeatMapModeEnum HeatMapMode = HeatMapModeEnum.None; 57 | [ConditionalField("HeatMapMode", HeatMapModeEnum.StepCountPerThread, HeatMapModeEnum.StepCountPerTile, Min = 1, Max = 256)] 58 | public int MaxStepCountBudget = 64; 59 | [ConditionalField("HeatMapMode", HeatMapModeEnum.ShapeCountPerThread, HeatMapModeEnum.ShapeCountPerTile, Min = 1, Max = 64)] 60 | public int MaxShapeCountBudget = 16; 61 | public Color HeatColorCool = new Color(0.0f, 1.0f, 0.0f); 62 | public Color HeatColorMedium = new Color(1.0f, 1.0f, 0.0f); 63 | public Color HeatColorHot = new Color(1.0f, 0.0f, 0.0f); 64 | [Range(0.0f, 1.0f)] 65 | public float HeatAlpha = 0.5f; 66 | 67 | private struct ShaderConstants 68 | { 69 | public ICollection Kernels; 70 | public int MainKernel; 71 | public int StepCountKernelPerThread; 72 | public int StepCountKernelPerTile; 73 | public int ShapeCountKernelPerThread; 74 | public int ShapeCountKernelPerTile; 75 | 76 | public int Src; 77 | public int Dst; 78 | 79 | public int CameraInverseProjection; 80 | public int CameraToWorld; 81 | public int CameraPosition; 82 | public int ScreenSize; 83 | 84 | public int SdfShapes; 85 | public int NumSdfShapes; 86 | public int TempBuffer; 87 | 88 | public int BlendDistance; 89 | public int RayMarchParams; 90 | 91 | public int BackgroundColor; 92 | public int MissColor; 93 | 94 | public int UseAabbTree; 95 | public int AabbTree; 96 | public int AabbTreeRoot; 97 | 98 | public int HeatMap; 99 | public int HeatColorCool; 100 | public int HeatColorMedium; 101 | public int HeatColorHot; 102 | public int HeatAlpha; 103 | 104 | public int MaxCountBudget; 105 | } 106 | 107 | private ShaderConstants m_const; 108 | private ComputeBuffer m_shapes; 109 | private RenderTexture m_tempBuffer; 110 | private ComputeBuffer m_aabbTree; 111 | private RenderTexture m_heatMap; 112 | 113 | protected override void OnValidate() 114 | { 115 | base.OnValidate(); 116 | 117 | BlendDistance = Mathf.Max(0.0f, BlendDistance); 118 | RayHitThreshold = Mathf.Max(0.0f, RayHitThreshold); 119 | MaxRayDistance = Mathf.Max(0.0f, MaxRayDistance); 120 | 121 | IsolateBoundingVolumeDepth = Mathf.Max(-1, IsolateBoundingVolumeDepth); 122 | } 123 | 124 | protected override void Init(ComputeShader compute) 125 | { 126 | InitShaderConstants(); 127 | } 128 | 129 | private void InitShaderConstants() 130 | { 131 | m_const.Kernels = 132 | new int[] 133 | { 134 | m_const.MainKernel = Compute.FindKernel("Main"), 135 | m_const.StepCountKernelPerThread = Compute.FindKernel("StepCountPerThread"), 136 | m_const.StepCountKernelPerTile = Compute.FindKernel("StepCountPerTile"), 137 | m_const.ShapeCountKernelPerThread = Compute.FindKernel("ShapeCountPerThread"), 138 | m_const.ShapeCountKernelPerTile = Compute.FindKernel("ShapeCountPerTile"), 139 | }; 140 | 141 | m_const.Src = Shader.PropertyToID("src"); 142 | m_const.Dst = Shader.PropertyToID("dst"); 143 | 144 | m_const.CameraInverseProjection = Shader.PropertyToID("cameraInvProj"); 145 | m_const.CameraToWorld = Shader.PropertyToID("cameraToWorld"); 146 | m_const.CameraPosition = Shader.PropertyToID("cameraPos"); 147 | m_const.ScreenSize = Shader.PropertyToID("screenSize"); 148 | 149 | m_const.SdfShapes = Shader.PropertyToID("aSdfShape"); 150 | m_const.NumSdfShapes = Shader.PropertyToID("numSdfShapes"); 151 | m_const.TempBuffer = Shader.PropertyToID("tempBuffer"); 152 | 153 | m_const.RayMarchParams = Shader.PropertyToID("rayMarchParams"); 154 | m_const.BlendDistance = Shader.PropertyToID("blendDist"); 155 | 156 | m_const.BackgroundColor = Shader.PropertyToID("backgroundColor"); 157 | m_const.MissColor = Shader.PropertyToID("missColor"); 158 | 159 | m_const.UseAabbTree = Shader.PropertyToID("useAabbTree"); 160 | m_const.AabbTree = Shader.PropertyToID("aabbTree"); 161 | m_const.AabbTreeRoot = Shader.PropertyToID("aabbTreeRoot"); 162 | 163 | m_const.HeatMap = Shader.PropertyToID("heatMap"); 164 | m_const.HeatColorCool = Shader.PropertyToID("heatColorCool"); 165 | m_const.HeatColorMedium = Shader.PropertyToID("heatColorMedium"); 166 | m_const.HeatColorHot = Shader.PropertyToID("heatColorHot"); 167 | m_const.HeatAlpha = Shader.PropertyToID("heatAlpha"); 168 | 169 | m_const.MaxCountBudget = Shader.PropertyToID("maxCountBudget"); 170 | } 171 | 172 | protected override void Dispose(ComputeShader compute) 173 | { 174 | if (m_shapes != null) 175 | { 176 | m_shapes.Dispose(); 177 | m_shapes = null; 178 | } 179 | 180 | if (m_heatMap != null) 181 | { 182 | DestroyImmediate(m_heatMap); 183 | m_heatMap = null; 184 | } 185 | } 186 | 187 | protected override void OnPreRenderImage(ComputeShader compute, RenderTexture src, RenderTexture dst) 188 | { 189 | // validate SDF shapes buffer 190 | var sdfShapes = RayMarchedShape.GetShapes(); 191 | int numShapes = sdfShapes.Count; 192 | if (m_shapes == null 193 | || m_shapes.count != numShapes) 194 | { 195 | if (m_shapes != null) 196 | { 197 | m_shapes.Dispose(); 198 | m_shapes = null; 199 | } 200 | 201 | m_shapes = new ComputeBuffer(Mathf.Max(1, numShapes), SdfShape.Stride); 202 | } 203 | 204 | // validate SDF temp buffer 205 | if (m_tempBuffer == null 206 | || m_tempBuffer.width != src.width 207 | || m_tempBuffer.height != src.height) 208 | { 209 | if (m_tempBuffer != null) 210 | { 211 | DestroyImmediate(m_tempBuffer); 212 | m_tempBuffer = null; 213 | } 214 | 215 | m_tempBuffer = new RenderTexture(src.width, src.height, 0, RenderTextureFormat.ARGBFloat); 216 | m_tempBuffer.enableRandomWrite = true; 217 | m_tempBuffer.Create(); 218 | } 219 | 220 | // validate AABB tree buffer 221 | if (m_aabbTree == null 222 | || m_aabbTree.count != RayMarchedShape.AabbTreeCapacity) 223 | { 224 | if (m_aabbTree != null) 225 | { 226 | m_aabbTree.Dispose(); 227 | m_aabbTree = null; 228 | } 229 | 230 | m_aabbTree = new ComputeBuffer(RayMarchedShape.AabbTreeCapacity, AabbTree.NodePod.Stride); 231 | } 232 | 233 | // validate heat map buffer 234 | if (m_heatMap == null 235 | || m_heatMap.width != src.width 236 | || m_heatMap.height != src.height) 237 | { 238 | if (m_heatMap != null) 239 | { 240 | DestroyImmediate(m_heatMap); 241 | m_heatMap = null; 242 | } 243 | 244 | m_heatMap = new RenderTexture(src.width, src.height, 0, RenderTextureFormat.RFloat); 245 | m_heatMap.enableRandomWrite = true; 246 | m_heatMap.Create(); 247 | } 248 | 249 | // fill buffers 250 | m_shapes.SetData(sdfShapes); 251 | RayMarchedShape.FillAabbTree(m_aabbTree, AabbTree.FatBoundsRadius - BlendDistance); 252 | 253 | if (m_const.Kernels == null) 254 | { 255 | InitShaderConstants(); 256 | } 257 | 258 | foreach (int kernel in m_const.Kernels) 259 | { 260 | compute.SetTexture(kernel, m_const.Src, src); 261 | compute.SetTexture(kernel, m_const.Dst, dst); 262 | 263 | compute.SetBuffer(kernel, m_const.SdfShapes, m_shapes); 264 | compute.SetTexture(kernel, m_const.TempBuffer, m_tempBuffer); 265 | 266 | compute.SetBuffer(kernel, m_const.AabbTree, m_aabbTree); 267 | 268 | compute.SetTexture(kernel, m_const.HeatMap, m_heatMap); 269 | } 270 | 271 | var camera = GetComponent(); 272 | compute.SetMatrix(m_const.CameraInverseProjection, camera.projectionMatrix.inverse); 273 | compute.SetMatrix(m_const.CameraToWorld, camera.cameraToWorldMatrix); 274 | compute.SetVector(m_const.CameraPosition, camera.transform.position); 275 | compute.SetInts(m_const.ScreenSize, new int[] { camera.pixelWidth, camera.pixelHeight }); 276 | 277 | compute.SetInt(m_const.NumSdfShapes, numShapes); 278 | 279 | compute.SetVector(m_const.RayMarchParams, new Vector4(MaxRaySteps, RayHitThreshold, MaxRayDistance, Time.time)); 280 | compute.SetFloat(m_const.BlendDistance, BlendDistance); 281 | 282 | compute.SetVector(m_const.BackgroundColor, new Vector4(BackgroundColor.r, BackgroundColor.g, BackgroundColor.b, BackgroundColor.a)); 283 | compute.SetVector(m_const.MissColor, new Vector4(MissColor.r, MissColor.g, MissColor.b, MissColor.a)); 284 | 285 | compute.SetBool(m_const.UseAabbTree, UseBoundingVolumes); 286 | compute.SetInt(m_const.AabbTreeRoot, RayMarchedShape.AabbTreeRoot); 287 | 288 | compute.SetVector(m_const.HeatColorCool, new Vector4(HeatColorCool.r, HeatColorCool.g, HeatColorCool.b, HeatColorCool.a)); 289 | compute.SetVector(m_const.HeatColorMedium, new Vector4(HeatColorMedium.r, HeatColorMedium.g, HeatColorMedium.b, HeatColorMedium.a)); 290 | compute.SetVector(m_const.HeatColorHot, new Vector4(HeatColorHot.r, HeatColorHot.g, HeatColorHot.b, HeatColorHot.a)); 291 | compute.SetFloat(m_const.HeatAlpha, HeatAlpha); 292 | } 293 | 294 | protected override void Dispatch(ComputeShader compute, RenderTexture src, RenderTexture dst) 295 | { 296 | var camera = GetComponent(); 297 | 298 | int threadGroupSizeX = (camera.pixelWidth + TileSize - 1) / TileSize; 299 | int threadGroupSizeY = (camera.pixelHeight + TileSize - 1) / TileSize; 300 | 301 | compute.Dispatch(m_const.MainKernel, threadGroupSizeX, threadGroupSizeY, 1); 302 | 303 | switch (HeatMapMode) 304 | { 305 | case HeatMapModeEnum.StepCountPerThread: 306 | compute.SetInt(m_const.MaxCountBudget, MaxStepCountBudget); 307 | compute.Dispatch(m_const.StepCountKernelPerThread, threadGroupSizeX, threadGroupSizeY, 1); 308 | break; 309 | 310 | case HeatMapModeEnum.StepCountPerTile: 311 | compute.SetInt(m_const.MaxCountBudget, MaxStepCountBudget); 312 | compute.Dispatch(m_const.StepCountKernelPerTile, threadGroupSizeX, threadGroupSizeY, 1); 313 | break; 314 | 315 | case HeatMapModeEnum.ShapeCountPerThread: 316 | compute.SetInt(m_const.MaxCountBudget, MaxShapeCountBudget); 317 | compute.Dispatch(m_const.ShapeCountKernelPerThread, threadGroupSizeX, threadGroupSizeY, 1); 318 | break; 319 | 320 | case HeatMapModeEnum.ShapeCountPerTile: 321 | compute.SetInt(m_const.MaxCountBudget, MaxShapeCountBudget); 322 | compute.Dispatch(m_const.ShapeCountKernelPerTile, threadGroupSizeX, threadGroupSizeY, 1); 323 | break; 324 | } 325 | } 326 | 327 | private void OnDrawGizmos() 328 | { 329 | #if UNITY_EDITOR 330 | 331 | var camera = GetComponent(); 332 | 333 | if (DrawBoundingVolumes) 334 | { 335 | RayMarchedShape.DrawBoundingVolumeHierarchyGizmos(IsolateBoundingVolumeDepth); 336 | } 337 | 338 | if (TestBvhBoundsQuery) 339 | { 340 | Color prevColor = Handles.color; 341 | 342 | Aabb queryBounds = 343 | new Aabb 344 | ( 345 | camera.transform.position - 0.5f * Vector3.one, 346 | camera.transform.position + 0.5f * Vector3.one 347 | ); 348 | 349 | Handles.color = Color.yellow; 350 | Handles.DrawWireCube(queryBounds.Center, queryBounds.Extents); 351 | 352 | Handles.color = new Color(1.0f, 1.0f, 0.0f, 0.5f); 353 | RayMarchedShape.Query 354 | ( 355 | queryBounds, 356 | (RayMarchedShape shape) => 357 | { 358 | Handles.DrawWireCube(shape.Bounds.Center, shape.Bounds.Extents); 359 | return true; 360 | } 361 | ); 362 | 363 | Handles.color = prevColor; 364 | } 365 | 366 | if (TestBvhRayCast) 367 | { 368 | Color prevColor = Handles.color; 369 | 370 | Vector3 cameraFrom = camera.transform.position; 371 | Vector3 cameraTo = cameraFrom + 10.0f * camera.transform.forward; 372 | 373 | Handles.color = Color.yellow; 374 | Handles.DrawLine(cameraFrom, cameraTo); 375 | 376 | Handles.color = new Color(1.0f, 1.0f, 0.0f, 0.5f); 377 | RayMarchedShape.RayCast 378 | ( 379 | cameraFrom, 380 | cameraTo, 381 | (Vector3 from, Vector3 to, RayMarchedShape shape) => 382 | { 383 | Handles.DrawWireCube(shape.Bounds.Center, shape.Bounds.Extents); 384 | return 1.0f; 385 | } 386 | ); 387 | 388 | Handles.color = prevColor; 389 | } 390 | 391 | #endif 392 | } 393 | } 394 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/GameObjectRayMarcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9b8e551071a17b47a40a329dd62c816 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: 7 | - Compute: {fileID: 7200000, guid: 047befc0d8dd6384fae6798d673887f4, type: 3} 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/RayMarchedShape.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using System.Collections.Generic; 13 | 14 | using UnityEngine; 15 | 16 | [ExecuteInEditMode] 17 | public class RayMarchedShape : MonoBehaviour 18 | { 19 | private static AabbTree s_tree = new AabbTree(); 20 | private static List s_shapeComponents = new List(); 21 | private static List s_sdfShapes = new List(); 22 | public static List GetShapes() 23 | { 24 | if (s_sdfShapes.Capacity < s_shapeComponents.Count) 25 | { 26 | s_sdfShapes.Capacity = s_shapeComponents.Count; 27 | } 28 | s_sdfShapes.Clear(); 29 | 30 | foreach (var s in s_shapeComponents) 31 | { 32 | var sdfShape = s.Shape; 33 | sdfShape.Operator = (int) s.Operator; 34 | s_sdfShapes.Add(sdfShape); 35 | } 36 | 37 | return s_sdfShapes; 38 | } 39 | 40 | public static void Query(Aabb bounds, AabbTree.QueryCallbcak callback) 41 | { 42 | s_tree.Query(bounds, callback); 43 | } 44 | 45 | public static void RayCast(Vector3 from, Vector3 to, AabbTree.RayCastCallback callback) 46 | { 47 | s_tree.RayCast(from, to, callback); 48 | } 49 | 50 | public static int AabbTreeCapacity { get { return s_tree.Capacity; } } 51 | public static int AabbTreeRoot { get { return s_tree.Root; } } 52 | public static int FillAabbTree(ComputeBuffer buffer, float aabbTightenRadius = 0.0f) 53 | { 54 | SyncBounds(); 55 | 56 | int root = s_tree.Fill(buffer, aabbTightenRadius); 57 | return root; 58 | } 59 | 60 | public static void SyncBounds() 61 | { 62 | foreach (var s in s_shapeComponents) 63 | { 64 | s_tree.UpdateProxy(s.m_iProxy, s.Bounds); 65 | } 66 | } 67 | 68 | public static void DrawBoundingVolumeHierarchyGizmos(int isolateDepth = -1) 69 | { 70 | SyncBounds(); 71 | s_tree.DrwaGizmos(isolateDepth); 72 | } 73 | 74 | public enum OperatorEnum 75 | { 76 | Union, 77 | Subtraction, 78 | Intersection 79 | } 80 | 81 | public OperatorEnum Operator = OperatorEnum.Union; 82 | private int m_shapeIndex = -1; 83 | private int m_iProxy = AabbTree.Null; 84 | 85 | public int ShapeIndex { get { return m_shapeIndex; } } 86 | 87 | private void OnEnable() 88 | { 89 | m_shapeIndex = s_shapeComponents.Count; 90 | s_shapeComponents.Add(this); 91 | 92 | m_iProxy = s_tree.CreateProxy(Bounds, this); 93 | } 94 | 95 | private void OnDisable() 96 | { 97 | s_shapeComponents[m_shapeIndex] = s_shapeComponents[s_shapeComponents.Count - 1]; 98 | s_shapeComponents[m_shapeIndex].m_shapeIndex = m_shapeIndex; 99 | s_shapeComponents.RemoveAt(s_shapeComponents.Count - 1); 100 | m_shapeIndex = -1; 101 | 102 | s_tree.DestroyProxy(m_iProxy); 103 | m_iProxy = AabbTree.Null; 104 | } 105 | 106 | protected virtual void OnValidate() { } 107 | 108 | protected virtual SdfShape Shape { get { return SdfShape.Dummy(); } } 109 | public virtual Aabb Bounds { get { return Aabb.Empty; } } 110 | } 111 | 112 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/RayMarchedShape.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1e03a64795bff742a82a78ad0c2487f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/RayMarchedSphere.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | [ExecuteInEditMode] 15 | public class RayMarchedSphere : RayMarchedShape 16 | { 17 | public float Radius = 0.5f; 18 | 19 | protected override SdfShape Shape 20 | { 21 | get 22 | { 23 | return SdfShape.Sphere(transform.position, Radius); 24 | } 25 | } 26 | 27 | public override Aabb Bounds 28 | { 29 | get 30 | { 31 | return 32 | new Aabb 33 | ( 34 | transform.position - Radius * Vector3.one, 35 | transform.position + Radius * Vector3.one 36 | ); 37 | } 38 | } 39 | 40 | protected override void OnValidate() 41 | { 42 | base.OnValidate(); 43 | 44 | Radius = Mathf.Max(0.0f, Radius); 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/RayMarchedSphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1916e7949e870644986a29ca93f913c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/SdfShape.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using System.Runtime.InteropServices; 13 | 14 | using UnityEngine; 15 | 16 | [StructLayout(LayoutKind.Sequential, Pack = 0)] 17 | public struct SdfShape 18 | { 19 | public static readonly int Stride = 4 * sizeof(int) + 12 * sizeof(float); 20 | 21 | public enum TypeEnum 22 | { 23 | Sphere, 24 | Box, 25 | Capsule, 26 | Cylinder, 27 | } 28 | 29 | public int Type; 30 | public int Operator; 31 | public int Padding1; 32 | public int Padding2; 33 | 34 | public Vector4 Data0; 35 | public Vector4 Data1; 36 | public Vector4 Data2; 37 | 38 | private static void WarningSuppression() 39 | { 40 | SdfShape shape; 41 | shape.Type = shape.Padding2 = 0; 42 | shape.Padding2 = shape.Type = 0; 43 | } 44 | 45 | public static SdfShape Dummy() 46 | { 47 | SdfShape shape; 48 | shape.Type = 0; 49 | shape.Operator = 0; 50 | shape.Padding1 = 0; 51 | shape.Padding2 = 0; 52 | 53 | shape.Data0 = Vector4.zero; 54 | shape.Data1 = Vector4.zero; 55 | shape.Data2 = Vector4.zero; 56 | 57 | return shape; 58 | } 59 | 60 | public static SdfShape Sphere(Vector3 center, float radius) 61 | { 62 | SdfShape shape; 63 | shape.Type = 0; 64 | shape.Operator = shape.Padding1 = shape.Padding2 = 0; 65 | 66 | shape.Data0 = new Vector4(center.x, center.y, center.z, radius); 67 | shape.Data1 = Vector4.zero; 68 | shape.Data2 = Vector4.zero; 69 | 70 | return shape; 71 | } 72 | 73 | public static SdfShape Box(Vector3 center, Vector3 halfExtents, Quaternion rotation, float radius = 0.0f) 74 | { 75 | SdfShape shape; 76 | shape.Type = 1; 77 | shape.Operator = shape.Padding1 = shape.Padding2 = 0; 78 | 79 | shape.Data0 = new Vector4(center.x, center.y, center.z, radius); 80 | shape.Data1 = new Vector4(halfExtents.x, halfExtents.y, halfExtents.z); 81 | shape.Data2 = new Vector4(rotation.x, rotation.y, rotation.z, rotation.w); 82 | 83 | return shape; 84 | } 85 | 86 | public static SdfShape Capsule(Vector3 a, Vector3 b, float radius) 87 | { 88 | SdfShape shape; 89 | shape.Type = 2; 90 | shape.Operator = shape.Padding1 = shape.Padding2 = 0; 91 | 92 | shape.Data0 = new Vector4(a.x, a.y, a.z, radius); 93 | shape.Data1 = new Vector4(b.x, b.y, b.z); 94 | shape.Data2 = Vector4.zero; 95 | 96 | return shape; 97 | } 98 | 99 | public static SdfShape Cylinder(Vector3 a, Vector3 b, float radius) 100 | { 101 | SdfShape shape; 102 | shape.Type = 3; 103 | shape.Operator = shape.Padding1 = shape.Padding2 = 0; 104 | 105 | shape.Data0 = new Vector4(a.x, a.y, a.z, radius); 106 | shape.Data1 = new Vector4(b.x, b.y, b.z); 107 | shape.Data2 = Vector4.zero; 108 | 109 | return shape; 110 | } 111 | } -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Ray Marching/SdfShape.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d871bab018e391e4dbb1a2eff56dba5d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 42808b11ec400f34db1f71436cb70e31 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/ConditionalFieldAttribute.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Modified from project "MyBox" by Andrew Rumak. 11 | License : Copyright (C) 2018 Andrew Rumak. 12 | Distributed under the MIT License. See LICENSE file. 13 | https://github.com/Deadcows/MyBox 14 | */ 15 | /******************************************************************************/ 16 | 17 | using System; 18 | using UnityEngine; 19 | 20 | [AttributeUsage(AttributeTargets.Field)] 21 | public class ConditionalFieldAttribute : PropertyAttribute 22 | { 23 | public bool ShowRange { get { return Min != Max; } } 24 | 25 | public string PropertyToCheck; 26 | public object CompareValue; 27 | public object CompareValue2; 28 | public object CompareValue3; 29 | public object CompareValue4; 30 | public object CompareValue5; 31 | public object CompareValue6; 32 | public string Label; 33 | public string Tooltip; 34 | public float Min; 35 | public float Max; 36 | 37 | public ConditionalFieldAttribute 38 | ( 39 | string propertyToCheck = null, 40 | object compareValue = null, 41 | object compareValue2 = null, 42 | object compareValue3 = null, 43 | object compareValue4 = null, 44 | object compareValue5 = null, 45 | object compareValue6 = null 46 | ) 47 | { 48 | PropertyToCheck = propertyToCheck; 49 | CompareValue = compareValue; 50 | CompareValue2 = compareValue2; 51 | CompareValue3 = compareValue3; 52 | CompareValue4 = compareValue4; 53 | CompareValue5 = compareValue5; 54 | CompareValue6 = compareValue6; 55 | Label = ""; 56 | Tooltip = ""; 57 | Min = 0.0f; 58 | Max = 0.0f; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/ConditionalFieldAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 818a0fa987056af47b5b73549bd92298 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/ConditionalFieldAttributeDrawer.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Modified from project "MyBox" by Andrew Rumak. 11 | License : Copyright (C) 2018 Andrew Rumak. 12 | Distributed under the MIT License. See LICENSE file. 13 | https://github.com/Deadcows/MyBox 14 | */ 15 | /******************************************************************************/ 16 | 17 | #if UNITY_EDITOR 18 | 19 | using System; 20 | using UnityEngine; 21 | using UnityEditor; 22 | 23 | [CustomPropertyDrawer(typeof(ConditionalFieldAttribute))] 24 | public class ConditionalFieldAttributeDrawer : PropertyDrawer 25 | { 26 | public static string AsStringValue(SerializedProperty property) 27 | { 28 | switch (property.propertyType) 29 | { 30 | case SerializedPropertyType.String: 31 | return property.stringValue; 32 | 33 | case SerializedPropertyType.Character: 34 | case SerializedPropertyType.Integer: 35 | if (property.type == "char") return System.Convert.ToChar(property.intValue).ToString(); 36 | return property.intValue.ToString(); 37 | 38 | case SerializedPropertyType.ObjectReference: 39 | return property.objectReferenceValue != null ? property.objectReferenceValue.ToString() : "null"; 40 | 41 | case SerializedPropertyType.Boolean: 42 | return property.boolValue.ToString(); 43 | 44 | case SerializedPropertyType.Enum: 45 | return property.enumNames[property.enumValueIndex]; 46 | 47 | default: 48 | return string.Empty; 49 | } 50 | } 51 | 52 | private ConditionalFieldAttribute Attribute 53 | { 54 | get 55 | { 56 | return _attribute ?? (_attribute = attribute as ConditionalFieldAttribute); 57 | } 58 | } 59 | 60 | private string PropertyToCheck { get { return Attribute != null ? _attribute.PropertyToCheck : null; } } 61 | private object CompareValue { get { return Attribute != null ? _attribute.CompareValue : null; } } 62 | private object CompareValue2 { get { return Attribute != null ? _attribute.CompareValue2 : null; } } 63 | private object CompareValue3 { get { return Attribute != null ? _attribute.CompareValue3 : null; } } 64 | private object CompareValue4 { get { return Attribute != null ? _attribute.CompareValue4 : null; } } 65 | private object CompareValue5 { get { return Attribute != null ? _attribute.CompareValue5 : null; } } 66 | private object CompareValue6 { get { return Attribute != null ? _attribute.CompareValue6 : null; } } 67 | 68 | private ConditionalFieldAttribute _attribute; 69 | 70 | private bool ShouldShow(SerializedProperty property) 71 | { 72 | if (PropertyToCheck != null && !PropertyToCheck.Equals("")) 73 | { 74 | var conditionProperty = FindPropertyRelative(property, PropertyToCheck); 75 | if (conditionProperty != null) 76 | { 77 | 78 | var aCompVal = new object[] 79 | { 80 | CompareValue, 81 | CompareValue2, 82 | CompareValue3, 83 | CompareValue4, 84 | CompareValue5, 85 | CompareValue6, 86 | }; 87 | 88 | bool matched = false; 89 | foreach (object compVal in aCompVal) 90 | { 91 | if (compVal == null) 92 | continue; 93 | 94 | bool isBoolMatch = conditionProperty.propertyType == SerializedPropertyType.Boolean && conditionProperty.boolValue; 95 | string compareStringValue = compVal != null ? compVal.ToString().ToUpper() : "NULL"; 96 | if (isBoolMatch && compareStringValue == "FALSE") isBoolMatch = false; 97 | 98 | string conditionPropertyStringValue = AsStringValue(conditionProperty).ToUpper(); 99 | bool objectMatch = compareStringValue == conditionPropertyStringValue; 100 | 101 | if (!isBoolMatch && !objectMatch) 102 | continue; 103 | 104 | matched = true; 105 | break; 106 | } 107 | 108 | if (!matched) 109 | { 110 | return false; 111 | } 112 | } 113 | } 114 | 115 | return true; 116 | } 117 | 118 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) 119 | { 120 | return 121 | ShouldShow(property) 122 | ? EditorGUI.GetPropertyHeight(property) 123 | : 0.0f; 124 | } 125 | 126 | // TODO: Skip array fields 127 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent content) 128 | { 129 | if (!ShouldShow(property)) 130 | return; 131 | 132 | if (!Attribute.Label.Equals("")) 133 | content.text = Attribute.Label; 134 | 135 | if (!Attribute.Tooltip.Equals("")) 136 | content.tooltip = Attribute.Tooltip; 137 | 138 | if (Attribute.ShowRange) 139 | { 140 | if (property.propertyType == SerializedPropertyType.Float) 141 | EditorGUI.Slider(position, property, Attribute.Min, Attribute.Max, content); 142 | else if (property.propertyType == SerializedPropertyType.Integer) 143 | EditorGUI.IntSlider(position, property, Convert.ToInt32(Attribute.Min), Convert.ToInt32(Attribute.Max), content); 144 | else 145 | EditorGUI.LabelField(position, content.text, "Use Range with float or int."); 146 | } 147 | else 148 | { 149 | EditorGUI.PropertyField(position, property, content); 150 | } 151 | } 152 | 153 | private SerializedProperty FindPropertyRelative(SerializedProperty property, string toGet) 154 | { 155 | if (property.depth == 0) return property.serializedObject.FindProperty(toGet); 156 | 157 | var path = property.propertyPath.Replace(".Array.data[", "["); 158 | var elements = path.Split('.'); 159 | SerializedProperty parent = null; 160 | 161 | for (int i = 0; i < elements.Length - 1; i++) 162 | { 163 | var element = elements[i]; 164 | int index = -1; 165 | if (element.Contains("[")) 166 | { 167 | index = Convert.ToInt32(element.Substring(element.IndexOf("[", StringComparison.Ordinal)).Replace("[", "").Replace("]", "")); 168 | element = element.Substring(0, element.IndexOf("[", StringComparison.Ordinal)); 169 | } 170 | 171 | parent = i == 0 ? 172 | property.serializedObject.FindProperty(element) : 173 | parent.FindPropertyRelative(element); 174 | 175 | if (index >= 0) parent = parent.GetArrayElementAtIndex(index); 176 | } 177 | 178 | return parent.FindPropertyRelative(toGet); 179 | } 180 | } 181 | 182 | #endif 183 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/ConditionalFieldAttributeDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5d203bfa2c42624e8fef2207b690de1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/MathUtil.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | public class MathUtil 15 | { 16 | public static readonly float Pi = Mathf.PI; 17 | public static readonly float TwoPi = 2.0f * Mathf.PI; 18 | public static readonly float HalfPi = Mathf.PI / 2.0f; 19 | public static readonly float ThirdPi = Mathf.PI / 3.0f; 20 | public static readonly float QuarterPi = Mathf.PI / 4.0f; 21 | public static readonly float FifthPi = Mathf.PI / 5.0f; 22 | public static readonly float SixthPi = Mathf.PI / 6.0f; 23 | 24 | public static readonly float Sqrt2 = Mathf.Sqrt(2.0f); 25 | public static readonly float Sqrt2Inv = 1.0f / Mathf.Sqrt(2.0f); 26 | public static readonly float Sqrt3 = Mathf.Sqrt(3.0f); 27 | public static readonly float Sqrt3Inv = 1.0f / Mathf.Sqrt(3.0f); 28 | 29 | 30 | public static readonly float Epsilon = 1.0e-9f; 31 | public static readonly float EpsilonComp = 1.0f - Epsilon; 32 | public static readonly float Rad2Deg = 180.0f / Mathf.PI; 33 | public static readonly float Deg2Rad = Mathf.PI / 180.0f; 34 | 35 | public static float AsinSafe(float x) 36 | { 37 | return Mathf.Asin(Mathf.Clamp(x, -1.0f, 1.0f)); 38 | } 39 | 40 | public static float AcosSafe(float x) 41 | { 42 | return Mathf.Acos(Mathf.Clamp(x, -1.0f, 1.0f)); 43 | } 44 | 45 | public static float CatmullRom(float p0, float p1, float p2, float p3, float t) 46 | { 47 | float tt = t * t; 48 | return 49 | 0.5f 50 | * ((2.0f * p1) 51 | + (-p0 + p2) * t 52 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 53 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/MathUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2be06966b82829644aeea34af59922ab 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/QuaternionUtil.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | public class QuaternionUtil 15 | { 16 | // basic stuff 17 | // ------------------------------------------------------------------------ 18 | 19 | public static float Magnitude(Quaternion q) 20 | { 21 | return Mathf.Sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); 22 | } 23 | 24 | public static float MagnitudeSqr(Quaternion q) 25 | { 26 | return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w; 27 | } 28 | 29 | public static Quaternion Normalize(Quaternion q) 30 | { 31 | float magInv = 1.0f / Magnitude(q); 32 | return new Quaternion(magInv * q.x, magInv * q.y, magInv * q.z, magInv * q.w); 33 | } 34 | 35 | public static Quaternion AngularVector(Vector3 v) 36 | { 37 | float len = v.magnitude; 38 | if (len < MathUtil.Epsilon) 39 | return Quaternion.identity; 40 | 41 | v /= len; 42 | 43 | float h = 0.5f * len; 44 | float s = Mathf.Sin(h); 45 | float c = Mathf.Cos(h); 46 | 47 | return new Quaternion(s * v.x, s * v.y, s * v.z, c); 48 | } 49 | 50 | // axis must be normalized 51 | public static Quaternion AxisAngle(Vector3 axis, float angle) 52 | { 53 | float h = 0.5f * angle; 54 | float s = Mathf.Sin(h); 55 | float c = Mathf.Cos(h); 56 | 57 | return new Quaternion(s * axis.x, s * axis.y, s * axis.z, c); 58 | } 59 | 60 | public static Vector3 GetAxis(Quaternion q) 61 | { 62 | Vector3 v = new Vector3(q.x, q.y, q.z); 63 | float len = v.magnitude; 64 | if (len < MathUtil.Epsilon) 65 | return Vector3.left; 66 | 67 | return v / len; 68 | } 69 | 70 | public static float GetAngle(Quaternion q) 71 | { 72 | return 2.0f * Mathf.Acos(Mathf.Clamp(q.w, -1.0f, 1.0f)); 73 | } 74 | 75 | public static Quaternion Pow(Quaternion q, float exp) 76 | { 77 | Vector3 axis = GetAxis(q); 78 | float angle = GetAngle(q); 79 | return AxisAngle(axis, angle * exp); 80 | } 81 | 82 | // v: derivative of q 83 | public static Quaternion Integrate(Quaternion q, Quaternion v, float dt) 84 | { 85 | return Pow(v, dt) * q; 86 | } 87 | 88 | // omega: angular velocity (direction is axis, magnitude is angle) 89 | // https://www.ashwinnarayan.com/post/how-to-integrate-quaternions/ 90 | // https://gafferongames.com/post/physics_in_3d/ 91 | public static Quaternion Integrate(Quaternion q, Vector3 omega, float dt) 92 | { 93 | omega *= 0.5f; 94 | Quaternion p = (new Quaternion(omega.x, omega.y, omega.z, 0.0f)) * q; 95 | return Normalize(new Quaternion(q.x + p.x * dt, q.y + p.y * dt, q.z + p.z * dt, q.w + p.w * dt)); 96 | } 97 | 98 | public static Vector4 ToVector4(Quaternion q) 99 | { 100 | return new Vector4(q.x, q.y, q.z, q.w); 101 | } 102 | 103 | public static Quaternion FromVector4(Vector4 v, bool normalize = true) 104 | { 105 | if (normalize) 106 | { 107 | float magSqr = v.sqrMagnitude; 108 | if (magSqr < MathUtil.Epsilon) 109 | return Quaternion.identity; 110 | 111 | v /= Mathf.Sqrt(magSqr); 112 | } 113 | 114 | return new Quaternion(v.x, v.y, v.z, v.w); 115 | } 116 | 117 | // ------------------------------------------------------------------------ 118 | // end: basic stuff 119 | 120 | 121 | // swing-twist decomposition & interpolation 122 | // ------------------------------------------------------------------------ 123 | 124 | public static void DecomposeSwingTwist 125 | ( 126 | Quaternion q, 127 | Vector3 twistAxis, 128 | out Quaternion swing, 129 | out Quaternion twist 130 | ) 131 | { 132 | Vector3 r = new Vector3(q.x, q.y, q.z); // (rotaiton axis) * cos(angle / 2) 133 | 134 | // singularity: rotation by 180 degree 135 | if (r.sqrMagnitude < MathUtil.Epsilon) 136 | { 137 | Vector3 rotatedTwistAxis = q * twistAxis; 138 | Vector3 swingAxis = Vector3.Cross(twistAxis, rotatedTwistAxis); 139 | 140 | if (swingAxis.sqrMagnitude > MathUtil.Epsilon) 141 | { 142 | float swingAngle = Vector3.Angle(twistAxis, rotatedTwistAxis); 143 | swing = Quaternion.AngleAxis(swingAngle, swingAxis); 144 | } 145 | else 146 | { 147 | // more singularity: rotation axis parallel to twist axis 148 | swing = Quaternion.identity; // no swing 149 | } 150 | 151 | // always twist 180 degree on singularity 152 | twist = Quaternion.AngleAxis(180.0f, twistAxis); 153 | return; 154 | } 155 | 156 | // formula & proof: 157 | // http://www.euclideanspace.com/maths/geometry/rotations/for/decomposition/ 158 | Vector3 p = Vector3.Project(r, twistAxis); 159 | twist = new Quaternion(p.x, p.y, p.z, q.w); 160 | twist = Normalize(twist); 161 | swing = q * Quaternion.Inverse(twist); 162 | } 163 | 164 | public enum SterpMode 165 | { 166 | // non-constant angular velocity, faster 167 | // use if interpolating across small angles or constant angular velocity is not important 168 | Nlerp, 169 | 170 | // constant angular velocity, slower 171 | // use if interpolating across large angles and constant angular velocity is important 172 | Slerp, 173 | }; 174 | 175 | // same swing & twist parameters 176 | public static Quaternion Sterp 177 | ( 178 | Quaternion a, 179 | Quaternion b, 180 | Vector3 twistAxis, 181 | float t, 182 | SterpMode mode = SterpMode.Slerp 183 | ) 184 | { 185 | Quaternion swing; 186 | Quaternion twist; 187 | return Sterp(a, b, twistAxis, t, out swing, out twist, mode); 188 | } 189 | 190 | // same swing & twist parameters with individual interpolated swing & twist outputs 191 | public static Quaternion Sterp 192 | ( 193 | Quaternion a, 194 | Quaternion b, 195 | Vector3 twistAxis, 196 | float t, 197 | out Quaternion swing, 198 | out Quaternion twist, 199 | SterpMode mode = SterpMode.Slerp 200 | ) 201 | { 202 | return Sterp(a, b, twistAxis, t, t, out swing, out twist, mode); 203 | } 204 | 205 | // different swing & twist parameters 206 | public static Quaternion Sterp 207 | ( 208 | Quaternion a, 209 | Quaternion b, 210 | Vector3 twistAxis, 211 | float tSwing, 212 | float tTwist, 213 | SterpMode mode = SterpMode.Slerp 214 | ) 215 | { 216 | Quaternion swing; 217 | Quaternion twist; 218 | return Sterp(a, b, twistAxis, tSwing, tTwist, out swing, out twist, mode); 219 | } 220 | 221 | // master sterp function 222 | public static Quaternion Sterp 223 | ( 224 | Quaternion a, 225 | Quaternion b, 226 | Vector3 twistAxis, 227 | float tSwing, 228 | float tTwist, 229 | out Quaternion swing, 230 | out Quaternion twist, 231 | SterpMode mode 232 | ) 233 | { 234 | Quaternion q = b * Quaternion.Inverse(a); 235 | Quaternion swingFull; 236 | Quaternion twistFull; 237 | QuaternionUtil.DecomposeSwingTwist(q, twistAxis, out swingFull, out twistFull); 238 | 239 | switch (mode) 240 | { 241 | default: 242 | case SterpMode.Nlerp: 243 | swing = Quaternion.Lerp(Quaternion.identity, swingFull, tSwing); 244 | twist = Quaternion.Lerp(Quaternion.identity, twistFull, tTwist); 245 | break; 246 | case SterpMode.Slerp: 247 | swing = Quaternion.Slerp(Quaternion.identity, swingFull, tSwing); 248 | twist = Quaternion.Slerp(Quaternion.identity, twistFull, tTwist); 249 | break; 250 | } 251 | 252 | return twist * swing; 253 | } 254 | 255 | // ------------------------------------------------------------------------ 256 | // end: swing-twist decomposition & interpolation 257 | } 258 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/QuaternionUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a2b208716778704fbe087c0565379bb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/VectorUtil.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | using UnityEngine; 13 | 14 | public class VectorUtil 15 | { 16 | public static Vector3 Rotate2D(Vector3 v, float deg) 17 | { 18 | Vector3 results = v; 19 | float cos = Mathf.Cos(MathUtil.Deg2Rad * deg); 20 | float sin = Mathf.Sin(MathUtil.Deg2Rad * deg); 21 | results.x = cos * v.x - sin * v.y; 22 | results.y = sin * v.x + cos * v.y; 23 | return results; 24 | } 25 | 26 | public static Vector3 NormalizeSafe(Vector3 v, Vector3 fallback) 27 | { 28 | return 29 | v.sqrMagnitude > MathUtil.Epsilon 30 | ? v.normalized 31 | : fallback; 32 | } 33 | 34 | // Returns a vector orthogonal to given vector. 35 | // If the given vector is a unit vector, the returned vector will also be a unit vector. 36 | public static Vector3 FindOrthogonal(Vector3 v) 37 | { 38 | if (v.x >= MathUtil.Sqrt3Inv) 39 | return new Vector3(v.y, -v.x, 0.0f); 40 | else 41 | return new Vector3(0.0f, v.z, -v.y); 42 | } 43 | 44 | // Yields two extra vectors that form an orthogonal basis with the given vector. 45 | // If the given vector is a unit vector, the returned vectors will also be unit vectors. 46 | public static void FormOrthogonalBasis(Vector3 v, out Vector3 a, out Vector3 b) 47 | { 48 | a = FindOrthogonal(v); 49 | b = Vector3.Cross(a, v); 50 | } 51 | 52 | // Both vectors must be unit vectors. 53 | public static Vector3 Slerp(Vector3 a, Vector3 b, float t) 54 | { 55 | float dot = Vector3.Dot(a, b); 56 | 57 | if (dot > 0.99999f) 58 | { 59 | // singularity: two vectors point in the same direction 60 | return Vector3.Lerp(a, b, t); 61 | } 62 | else if (dot < -0.99999f) 63 | { 64 | // singularity: two vectors point in the opposite direction 65 | Vector3 axis = FindOrthogonal(a); 66 | return Quaternion.AngleAxis(180.0f * t, axis) * a; 67 | } 68 | 69 | float rad = MathUtil.AcosSafe(dot); 70 | return (Mathf.Sin((1.0f - t) * rad) * a + Mathf.Sin(t * rad) * b) / Mathf.Sin(rad); 71 | } 72 | 73 | public static Vector3 CatmullRom(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) 74 | { 75 | float tt = t * t; 76 | return 77 | 0.5f 78 | * ((2.0f * p1) 79 | + (-p0 + p2) * t 80 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 81 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 82 | ); 83 | } 84 | 85 | public static Vector3 Abs(Vector3 v) 86 | { 87 | return new Vector3(Mathf.Abs(v.x), Mathf.Abs(v.y), Mathf.Abs(v.z)); 88 | } 89 | 90 | public static Vector3 Min(Vector3 a, Vector3 b) 91 | { 92 | return new Vector3(Mathf.Min(a.x, b.x), Mathf.Min(a.y, b.y), Mathf.Min(a.z, b.z)); 93 | } 94 | 95 | public static Vector3 Max(Vector3 a, Vector3 b) 96 | { 97 | return new Vector3(Mathf.Max(a.x, b.x), Mathf.Max(a.y, b.y), Mathf.Max(a.z, b.z)); 98 | } 99 | 100 | public static float GetComopnent(Vector3 v, int i) 101 | { 102 | switch (i) 103 | { 104 | case 0: return v.x; 105 | case 1: return v.y; 106 | case 2: return v.z; 107 | } 108 | 109 | return float.MinValue; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Script/Util/VectorUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 746b9536107568b4b8f3748a67cfe4a7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2fa710f532831d469ec88e6820b3604 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a883fb640ccceab4fa6798fae4d5dbef 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/CatmullRom.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef RAY_MARCHING_CATMULL_ROM 13 | #define RAY_MARCHING_CATMULL_ROM 14 | 15 | inline float catmullRom(float p0, float p1, float p2, float p3, float t) 16 | { 17 | float tt = t * t; 18 | return 19 | 0.5f 20 | * ((2.0f * p1) 21 | + (-p0 + p2) * t 22 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 23 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 24 | ); 25 | } 26 | 27 | inline float2 catmullRom(float2 p0, float2 p1, float2 p2, float2 p3, float t) 28 | { 29 | float tt = t * t; 30 | return 31 | 0.5f 32 | * ((2.0f * p1) 33 | + (-p0 + p2) * t 34 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 35 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 36 | ); 37 | } 38 | 39 | inline float3 catmullRom(float3 p0, float3 p1, float3 p2, float3 p3, float t) 40 | { 41 | float tt = t * t; 42 | return 43 | 0.5f 44 | * ((2.0f * p1) 45 | + (-p0 + p2) * t 46 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 47 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 48 | ); 49 | } 50 | 51 | inline float4 catmullRom(float4 p0, float4 p1, float4 p2, float4 p3, float t) 52 | { 53 | float tt = t * t; 54 | return 55 | 0.5f 56 | * ((2.0f * p1) 57 | + (-p0 + p2) * t 58 | + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * tt 59 | + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * tt * t 60 | ); 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/CatmullRom.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8faf7cc0acb5fcb4f8f2344c07918c16 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Color.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef RAY_MARCHING_COLOR 13 | #define RAY_MARCHING_COLOR 14 | 15 | float3 hsv2rgb(float3 hsv) 16 | { 17 | hsv.x = hsv.x - floor(hsv.x); 18 | int h = ((int) (hsv.x * 6)); 19 | float f = hsv.x * 6.0 - h; 20 | float p = hsv.z * (1.0 - hsv.y); 21 | float q = hsv.z * (1.0 - f * hsv.y); 22 | float t = hsv.z * (1.0 - (1.0 - f) * hsv.y); 23 | 24 | switch (h) 25 | { 26 | default: 27 | case 0: return float3(hsv.z, t, p); 28 | case 1: return float3(q, hsv.z, p); 29 | case 2: return float3(p, hsv.z, t); 30 | case 3: return float3(p, q, hsv.z); 31 | case 4: return float3(t, p, hsv.z); 32 | case 5: return float3(hsv.z, p, q); 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Color.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d29168bdf7611fb43ae31c32f099264e 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Math.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef RAY_MARCHING_MATH 13 | #define RAY_MARCHING_MATH 14 | 15 | #define kPi (3.1415926535) 16 | #define kTwoPi (6.2831853071) 17 | #define kHalfPi (1.5707963267) 18 | #define kThirdPi (1.0471975511) 19 | #define kQuarterPi (0.7853981633) 20 | #define kFifthPi (0.6283185307) 21 | #define kSixthPi (0.5235987755) 22 | 23 | #define kSqrt2 (1.4142135623) 24 | #define kSqrt3 (1.7320508075) 25 | #define kSqrt2Inv (0.7071067811) 26 | #define kSqrt3Inv (0.5773502691) 27 | 28 | #define kEpsilon (1e-16f) 29 | #define kEpsilonComp (1.0f - kEpsilon) 30 | 31 | #define kRad2Deg (57.295779513) 32 | #define kDeg2Rad (0.0174532925) 33 | 34 | #include "Color.cginc" 35 | #include "Vector.cginc" 36 | #include "Quaternion.cginc" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Math.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cbc2d2d27ca839e4a9a2e5662fd714ad 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Quaternion.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef RAY_MARCHING_QUATERNION 13 | #define RAY_MARCHING_QUATERNION 14 | 15 | #include "Math.cginc" 16 | #include "Vector.cginc" 17 | 18 | #define kQuatIdentity (float4(0.0f, 0.0f, 0.0f, 1.0f)) 19 | 20 | inline float4 quat_conj(float4 q) 21 | { 22 | return float4(-q.xyz, q.w); 23 | } 24 | 25 | inline float4 quat_inv(float4 q) 26 | { 27 | return quat_conj(q); 28 | } 29 | 30 | // q must be unit quaternion 31 | inline float4 quat_pow(float4 q, float p) 32 | { 33 | float r = length(q.xyz); 34 | if (r < kEpsilon) 35 | return kQuatIdentity; 36 | 37 | float t = p * atan2(q.w, r); 38 | 39 | return float4(sin(t) * q.xyz / r, cos(t)); 40 | } 41 | 42 | inline float3 quat_rot(float4 q, float3 v) 43 | { 44 | return 45 | dot(q.xyz, v) * q.xyz 46 | + q.w * q.w * v 47 | + 2.0 * q.w * cross(q.xyz, v) 48 | - cross(cross(q.xyz, v), q.xyz); 49 | } 50 | 51 | inline float4 quat_axis_angle(float3 v, float a) 52 | { 53 | float h = 0.5 * a; 54 | return float4(sin(h) * normalize(v), cos(h)); 55 | } 56 | 57 | inline float4 quat_from_to(float3 from, float3 to) 58 | { 59 | float3 c = cross(from, to); 60 | float cc = dot(c, c); 61 | 62 | if (cc < kEpsilon) 63 | return kQuatIdentity; 64 | 65 | float3 axis = c / sqrt(cc); 66 | float angle = acos(clamp(dot(from, to), -1.0f, 1.0f)); 67 | return quat_axis_angle(axis, angle); 68 | } 69 | 70 | inline float3 quat_get_axis(float4 q) 71 | { 72 | float d = dot(q.xyz, q.xyz); 73 | return 74 | d > kEpsilon 75 | ? q.xyz / sqrt(d) 76 | : float3(0.0f, 0.0f, 1.0f); 77 | } 78 | 79 | inline float3 quat_get_angle(float4 q) 80 | { 81 | return 2.0f * acos(clamp(q.w, -1.0f, 1.0f)); 82 | } 83 | 84 | inline float4 quat_mul(float4 q1, float4 q2) 85 | { 86 | return 87 | float4 88 | ( 89 | q1.w * q2.xyz + q2.w * q1.xyz + cross(q1.xyz, q2.xyz), 90 | q1.w * q2.w - dot(q1.xyz, q2.xyz) 91 | ); 92 | } 93 | 94 | inline float4 quat_mat(float3x3 m) 95 | { 96 | float tr = m._m00 + m._m11 + m._m22; 97 | if (tr > 0.0f) { 98 | float s = sqrt(tr + 1.0f) * 2.0f; 99 | float sInv = 1.0f / s; 100 | return 101 | float4 102 | ( 103 | (m._m21 - m._m12) * sInv, 104 | (m._m02 - m._m20) * sInv, 105 | (m._m10 - m._m01) * sInv, 106 | 0.25 * s 107 | ); 108 | } 109 | else if ((m._m00 > m._m11) && (m._m00 > m._m22)) 110 | { 111 | float s = sqrt(1.0f + m._m00 - m._m11 - m._m22) * 2.0f; 112 | float sInv = 1.0f / s; 113 | return 114 | float4 115 | ( 116 | 0.25f * s, 117 | (m._m01 + m._m10) * sInv, 118 | (m._m02 + m._m20) * sInv, 119 | (m._m21 - m._m12) * sInv 120 | ); 121 | } 122 | else if (m._m11 > m._m22) 123 | { 124 | float s = sqrt(1.0f + m._m11 - m._m00 - m._m22) * 2.0f; 125 | float sInv = 1.0f / s; 126 | return 127 | float4 128 | ( 129 | (m._m01 + m._m10) * sInv, 130 | 0.25 * s, 131 | (m._m12 + m._m21) * sInv, 132 | (m._m02 - m._m20) * sInv 133 | ); 134 | } 135 | else { 136 | float s = sqrt(1.0f + m._m22 - m._m00 - m._m11) * 2.0f; 137 | float sInv = 1.0f / s; 138 | return 139 | float4 140 | ( 141 | (m._m02 + m._m20) * sInv, 142 | (m._m12 + m._m21) * sInv, 143 | 0.25 * s, 144 | (m._m10 - m._m01) * sInv 145 | ); 146 | } 147 | } 148 | 149 | inline float4 quat_look_at(float3 dir, float3 up) 150 | { 151 | return quat_mat(mat_look_at(dir, up)); 152 | } 153 | 154 | // order: ZXY 155 | inline float4 quat_euler(float3 rot) 156 | { 157 | return 158 | quat_mul 159 | ( 160 | quat_mul 161 | ( 162 | quat_axis_angle(kUnitY, rot.x), 163 | quat_axis_angle(kUnitX, rot.y) 164 | ), 165 | quat_axis_angle(kUnitZ, rot.z) 166 | ); 167 | } 168 | 169 | inline float4 slerp(float4 a, float4 b, float t) 170 | { 171 | float d = dot(normalize(a), normalize(b)); 172 | if (d > kEpsilonComp) 173 | { 174 | return lerp(a, b, t); 175 | } 176 | 177 | float r = acos(clamp(d, -1.0f, 1.0f)); 178 | return (sin((1.0 - t) * r) * a + sin(t * r) * b) / sin(r); 179 | } 180 | 181 | inline float4 nlerp(float4 a, float b, float t) 182 | { 183 | return normalize(lerp(a, b, t)); 184 | } 185 | 186 | #endif 187 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Quaternion.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e4acf9f8acb3a9b408dcca8bc0f064ff 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Vector.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #ifndef RAY_MARCHING_VECTOR 13 | #define RAY_MARCHING_VECTOR 14 | 15 | #include "Math.cginc" 16 | 17 | #define kUnitX (float3(1.0f, 0.0f, 0.0f)) 18 | #define kUnitY (float3(0.0f, 1.0f, 0.0f)) 19 | #define kUnitZ (float3(0.0f, 0.0f, 1.0f)) 20 | 21 | inline float3 normalize_safe(float3 v, float3 fallback) 22 | { 23 | float vv = dot(v, v); 24 | return vv > kEpsilon ? v / sqrt(vv) : fallback; 25 | } 26 | 27 | inline float3 normalize_safe(float3 v) 28 | { 29 | return normalize_safe(v, kUnitZ); 30 | } 31 | 32 | inline float3 project_vec(float3 v, float3 onto) 33 | { 34 | onto = normalize(onto); 35 | return dot(v, onto) * onto; 36 | } 37 | 38 | inline float3 project_plane(float3 v, float3 n) 39 | { 40 | return v - project_vec(v, n); 41 | } 42 | 43 | inline float3 limit_length(float3 v, float maxLen) 44 | { 45 | return min(maxLen, length(v)) * normalize_safe(v, 0.0f); 46 | } 47 | 48 | inline float3 find_ortho(float3 v) 49 | { 50 | if (v.x >= kSqrt3Inv) 51 | return float3(v.y, -v.x, 0.0); 52 | else 53 | return float3(0.0, v.z, -v.y); 54 | } 55 | 56 | inline float3 slerp(float3 a, float3 b, float t) 57 | { 58 | float d = dot(normalize(a), normalize(b)); 59 | if (d > kEpsilonComp) 60 | { 61 | return lerp(a, b, t); 62 | } 63 | 64 | float r = acos(clamp(d, -1.0f, 1.0f)); 65 | return (sin((1.0 - t) * r) * a + sin(t * r) * b) / sin(r); 66 | } 67 | 68 | inline float3 nlerp(float3 a, float b, float t) 69 | { 70 | return normalize(lerp(a, b, t)); 71 | } 72 | 73 | inline float3x3 mat_basis(float3 xAxis, float3 yAxis, float3 zAxis) 74 | { 75 | return transpose(float3x3(xAxis, yAxis, zAxis)); 76 | } 77 | 78 | inline float3x3 mat_look_at(float3 dir, float3 up) 79 | { 80 | float3 zAxis = normalize_safe(dir, kUnitZ); 81 | float3 xAxis = normalize_safe(cross(up, zAxis), kUnitX); 82 | float3 yAxis = cross(zAxis, xAxis); 83 | return mat_basis(xAxis, yAxis, zAxis); 84 | } 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Math/Vector.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa89081643259a543bf0f9f2dc1300cc 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 326d4c9b941056c43ac1e7237fe69bde 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/ClassicNoise2D.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on project "webgl-noise" by Ashima Arts. 11 | Description : Array and textureless GLSL 2D simplex noise function. 12 | Author : Ian McEwan, Ashima Arts. 13 | Maintainer : ijm 14 | Lastmod : 20110822 (ijm) 15 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 16 | Distributed under the MIT License. See LICENSE file. 17 | https://github.com/ashima/webgl-noise 18 | */ 19 | /******************************************************************************/ 20 | 21 | 22 | #ifndef RAY_MARCHING_CLASSIC_NOISE_2D 23 | #define RAY_MARCHING_CLASSIC_NOISE_2D 24 | 25 | #include "NoiseCommon.cginc" 26 | 27 | // classic Perlin noise 28 | // single octave 29 | float cnoise(float2 P) 30 | { 31 | float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0); 32 | float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0); 33 | Pi = mod289(Pi); // To avoid truncation effects in permutation 34 | float4 ix = Pi.xzxz; 35 | float4 iy = Pi.yyww; 36 | float4 fx = Pf.xzxz; 37 | float4 fy = Pf.yyww; 38 | 39 | float4 i = permute(permute(ix) + iy); 40 | 41 | float4 gx = frac(i / 41.0) * 2.0 - 1.0 ; 42 | float4 gy = abs(gx) - 0.5 ; 43 | float4 tx = floor(gx + 0.5); 44 | gx = gx - tx; 45 | 46 | float2 g00 = float2(gx.x,gy.x); 47 | float2 g10 = float2(gx.y,gy.y); 48 | float2 g01 = float2(gx.z,gy.z); 49 | float2 g11 = float2(gx.w,gy.w); 50 | 51 | float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); 52 | g00 *= norm.x; 53 | g01 *= norm.y; 54 | g10 *= norm.z; 55 | g11 *= norm.w; 56 | 57 | float n00 = dot(g00, float2(fx.x, fy.x)); 58 | float n10 = dot(g10, float2(fx.y, fy.y)); 59 | float n01 = dot(g01, float2(fx.z, fy.z)); 60 | float n11 = dot(g11, float2(fx.w, fy.w)); 61 | 62 | float2 fade_xy = fade(Pf.xy); 63 | float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x); 64 | float n_xy = lerp(n_x.x, n_x.y, fade_xy.y); 65 | return 2.3 * n_xy; 66 | } 67 | 68 | // multiple octaves 69 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(cnoise, float, float2, 0.5); 70 | 71 | // classic Perlin noise, periodic variant 72 | // single octave 73 | float pnoise(float2 P, float2 rep) 74 | { 75 | float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0); 76 | float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0); 77 | Pi = mod(Pi, rep.xyxy); // To create noise with explicit period 78 | Pi = mod289(Pi); // To avoid truncation effects in permutation 79 | float4 ix = Pi.xzxz; 80 | float4 iy = Pi.yyww; 81 | float4 fx = Pf.xzxz; 82 | float4 fy = Pf.yyww; 83 | 84 | float4 i = permute(permute(ix) + iy); 85 | 86 | float4 gx = frac(i / 41.0) * 2.0 - 1.0 ; 87 | float4 gy = abs(gx) - 0.5 ; 88 | float4 tx = floor(gx + 0.5); 89 | gx = gx - tx; 90 | 91 | float2 g00 = float2(gx.x,gy.x); 92 | float2 g10 = float2(gx.y,gy.y); 93 | float2 g01 = float2(gx.z,gy.z); 94 | float2 g11 = float2(gx.w,gy.w); 95 | 96 | float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); 97 | g00 *= norm.x; 98 | g01 *= norm.y; 99 | g10 *= norm.z; 100 | g11 *= norm.w; 101 | 102 | float n00 = dot(g00, float2(fx.x, fy.x)); 103 | float n10 = dot(g10, float2(fx.y, fy.y)); 104 | float n01 = dot(g01, float2(fx.z, fy.z)); 105 | float n11 = dot(g11, float2(fx.w, fy.w)); 106 | 107 | float2 fade_xy = fade(Pf.xy); 108 | float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x); 109 | float n_xy = lerp(n_x.x, n_x.y, fade_xy.y); 110 | return 2.3 * n_xy; 111 | } 112 | 113 | // multiple octave 114 | DEFINE_PERIODIC_NOISE_FUNC_MULTIPLE_OCTAVES(pnoise, float, float2); 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/ClassicNoise2D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a0a039eee7b0d048a94b088878a737a 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/ClassicNoise3D.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on project "webgl-noise" by Ashima Arts. 11 | Description : Array and textureless GLSL 2D simplex noise function. 12 | Author : Ian McEwan, Ashima Arts. 13 | Maintainer : ijm 14 | Lastmod : 20110822 (ijm) 15 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 16 | Distributed under the MIT License. See LICENSE file. 17 | https://github.com/ashima/webgl-noise 18 | */ 19 | /******************************************************************************/ 20 | 21 | #ifndef RAY_MARCHING_CLASSIC_NOISE_3D 22 | #define RAY_MARCHING_CLASSIC_NOISE_3D 23 | 24 | #include "NoiseCommon.cginc" 25 | 26 | // classic Perlin noise 27 | // single octave 28 | float cnoise(float3 P) 29 | { 30 | float3 Pi0 = floor(P); // Integer part for indexing 31 | float3 Pi1 = Pi0 + (float3)1.0; // Integer part + 1 32 | Pi0 = mod289(Pi0); 33 | Pi1 = mod289(Pi1); 34 | float3 Pf0 = frac(P); // Fractional part for interpolation 35 | float3 Pf1 = Pf0 - (float3)1.0; // Fractional part - 1.0 36 | float4 ix = float4(Pi0.x, Pi1.x, Pi0.x, Pi1.x); 37 | float4 iy = float4(Pi0.y, Pi0.y, Pi1.y, Pi1.y); 38 | float4 iz0 = (float4)Pi0.z; 39 | float4 iz1 = (float4)Pi1.z; 40 | 41 | float4 ixy = permute(permute(ix) + iy); 42 | float4 ixy0 = permute(ixy + iz0); 43 | float4 ixy1 = permute(ixy + iz1); 44 | 45 | float4 gx0 = ixy0 / 7.0; 46 | float4 gy0 = frac(floor(gx0) / 7.0) - 0.5; 47 | gx0 = frac(gx0); 48 | float4 gz0 = (float4)0.5 - abs(gx0) - abs(gy0); 49 | float4 sz0 = step(gz0, (float4)0.0); 50 | gx0 -= sz0 * (step((float4)0.0, gx0) - 0.5); 51 | gy0 -= sz0 * (step((float4)0.0, gy0) - 0.5); 52 | 53 | float4 gx1 = ixy1 / 7.0; 54 | float4 gy1 = frac(floor(gx1) / 7.0) - 0.5; 55 | gx1 = frac(gx1); 56 | float4 gz1 = (float4)0.5 - abs(gx1) - abs(gy1); 57 | float4 sz1 = step(gz1, (float4)0.0); 58 | gx1 -= sz1 * (step((float4)0.0, gx1) - 0.5); 59 | gy1 -= sz1 * (step((float4)0.0, gy1) - 0.5); 60 | 61 | float3 g000 = float3(gx0.x,gy0.x,gz0.x); 62 | float3 g100 = float3(gx0.y,gy0.y,gz0.y); 63 | float3 g010 = float3(gx0.z,gy0.z,gz0.z); 64 | float3 g110 = float3(gx0.w,gy0.w,gz0.w); 65 | float3 g001 = float3(gx1.x,gy1.x,gz1.x); 66 | float3 g101 = float3(gx1.y,gy1.y,gz1.y); 67 | float3 g011 = float3(gx1.z,gy1.z,gz1.z); 68 | float3 g111 = float3(gx1.w,gy1.w,gz1.w); 69 | 70 | float4 norm0 = taylorInvSqrt(float4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); 71 | g000 *= norm0.x; 72 | g010 *= norm0.y; 73 | g100 *= norm0.z; 74 | g110 *= norm0.w; 75 | 76 | float4 norm1 = taylorInvSqrt(float4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); 77 | g001 *= norm1.x; 78 | g011 *= norm1.y; 79 | g101 *= norm1.z; 80 | g111 *= norm1.w; 81 | 82 | float n000 = dot(g000, Pf0); 83 | float n100 = dot(g100, float3(Pf1.x, Pf0.y, Pf0.z)); 84 | float n010 = dot(g010, float3(Pf0.x, Pf1.y, Pf0.z)); 85 | float n110 = dot(g110, float3(Pf1.x, Pf1.y, Pf0.z)); 86 | float n001 = dot(g001, float3(Pf0.x, Pf0.y, Pf1.z)); 87 | float n101 = dot(g101, float3(Pf1.x, Pf0.y, Pf1.z)); 88 | float n011 = dot(g011, float3(Pf0.x, Pf1.y, Pf1.z)); 89 | float n111 = dot(g111, Pf1); 90 | 91 | float3 fade_xyz = fade(Pf0); 92 | float4 n_z = lerp(float4(n000, n100, n010, n110), float4(n001, n101, n011, n111), fade_xyz.z); 93 | float2 n_yz = lerp(n_z.xy, n_z.zw, fade_xyz.y); 94 | float n_xyz = lerp(n_yz.x, n_yz.y, fade_xyz.x); 95 | return 2.2 * n_xyz; 96 | } 97 | 98 | // multiple octave 99 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(cnoise, float, float3, 0.5); 100 | 101 | // classic Perlin noise, periodic variant 102 | // single octave 103 | float pnoise(float3 P, float3 rep) 104 | { 105 | float3 Pi0 = mod(floor(P), rep); // Integer part, modulo period 106 | float3 Pi1 = mod(Pi0 + (float3)1.0, rep); // Integer part + 1, mod period 107 | Pi0 = mod289(Pi0); 108 | Pi1 = mod289(Pi1); 109 | float3 Pf0 = frac(P); // Fractional part for interpolation 110 | float3 Pf1 = Pf0 - (float3)1.0; // Fractional part - 1.0 111 | float4 ix = float4(Pi0.x, Pi1.x, Pi0.x, Pi1.x); 112 | float4 iy = float4(Pi0.y, Pi0.y, Pi1.y, Pi1.y); 113 | float4 iz0 = (float4)Pi0.z; 114 | float4 iz1 = (float4)Pi1.z; 115 | 116 | float4 ixy = permute(permute(ix) + iy); 117 | float4 ixy0 = permute(ixy + iz0); 118 | float4 ixy1 = permute(ixy + iz1); 119 | 120 | float4 gx0 = ixy0 / 7.0; 121 | float4 gy0 = frac(floor(gx0) / 7.0) - 0.5; 122 | gx0 = frac(gx0); 123 | float4 gz0 = (float4)0.5 - abs(gx0) - abs(gy0); 124 | float4 sz0 = step(gz0, (float4)0.0); 125 | gx0 -= sz0 * (step((float4)0.0, gx0) - 0.5); 126 | gy0 -= sz0 * (step((float4)0.0, gy0) - 0.5); 127 | 128 | float4 gx1 = ixy1 / 7.0; 129 | float4 gy1 = frac(floor(gx1) / 7.0) - 0.5; 130 | gx1 = frac(gx1); 131 | float4 gz1 = (float4)0.5 - abs(gx1) - abs(gy1); 132 | float4 sz1 = step(gz1, (float4)0.0); 133 | gx1 -= sz1 * (step((float4)0.0, gx1) - 0.5); 134 | gy1 -= sz1 * (step((float4)0.0, gy1) - 0.5); 135 | 136 | float3 g000 = float3(gx0.x,gy0.x,gz0.x); 137 | float3 g100 = float3(gx0.y,gy0.y,gz0.y); 138 | float3 g010 = float3(gx0.z,gy0.z,gz0.z); 139 | float3 g110 = float3(gx0.w,gy0.w,gz0.w); 140 | float3 g001 = float3(gx1.x,gy1.x,gz1.x); 141 | float3 g101 = float3(gx1.y,gy1.y,gz1.y); 142 | float3 g011 = float3(gx1.z,gy1.z,gz1.z); 143 | float3 g111 = float3(gx1.w,gy1.w,gz1.w); 144 | 145 | float4 norm0 = taylorInvSqrt(float4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); 146 | g000 *= norm0.x; 147 | g010 *= norm0.y; 148 | g100 *= norm0.z; 149 | g110 *= norm0.w; 150 | float4 norm1 = taylorInvSqrt(float4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); 151 | g001 *= norm1.x; 152 | g011 *= norm1.y; 153 | g101 *= norm1.z; 154 | g111 *= norm1.w; 155 | 156 | float n000 = dot(g000, Pf0); 157 | float n100 = dot(g100, float3(Pf1.x, Pf0.y, Pf0.z)); 158 | float n010 = dot(g010, float3(Pf0.x, Pf1.y, Pf0.z)); 159 | float n110 = dot(g110, float3(Pf1.x, Pf1.y, Pf0.z)); 160 | float n001 = dot(g001, float3(Pf0.x, Pf0.y, Pf1.z)); 161 | float n101 = dot(g101, float3(Pf1.x, Pf0.y, Pf1.z)); 162 | float n011 = dot(g011, float3(Pf0.x, Pf1.y, Pf1.z)); 163 | float n111 = dot(g111, Pf1); 164 | 165 | float3 fade_xyz = fade(Pf0); 166 | float4 n_z = lerp(float4(n000, n100, n010, n110), float4(n001, n101, n011, n111), fade_xyz.z); 167 | float2 n_yz = lerp(n_z.xy, n_z.zw, fade_xyz.y); 168 | float n_xyz = lerp(n_yz.x, n_yz.y, fade_xyz.x); 169 | return 2.2 * n_xyz; 170 | } 171 | 172 | // multiple octaves 173 | DEFINE_PERIODIC_NOISE_FUNC_MULTIPLE_OCTAVES(pnoise, float, float3); 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/ClassicNoise3D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3bb8e11abde62a34e9b3c23f1b163708 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Noise.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef NOISE 14 | #define NOISE 15 | 16 | #include "ClassicNoise2D.cginc" 17 | #include "ClassicNoise3D.cginc" 18 | #include "SimplexNoise2D.cginc" 19 | #include "SimplexNoise3D.cginc" 20 | 21 | #include "RandomNoise.cginc" 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Noise.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5428bc95309813640956652494e668d1 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/NoiseCommon.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | 13 | #ifndef RAY_MARCHING_NOISE_COMMON 14 | #define RAY_MARCHING_NOISE_COMMON 15 | 16 | float mod(float x, float y) 17 | { 18 | return x - y * floor(x / y); 19 | } 20 | 21 | float2 mod(float2 x, float2 y) 22 | { 23 | return x - y * floor(x / y); 24 | } 25 | 26 | float3 mod(float3 x, float3 y) 27 | { 28 | return x - y * floor(x / y); 29 | } 30 | 31 | float4 mod(float4 x, float4 y) 32 | { 33 | return x - y * floor(x / y); 34 | } 35 | 36 | float2 mod289(float2 x) 37 | { 38 | return x - floor(x / 289.0) * 289.0; 39 | } 40 | 41 | float3 mod289(float3 x) 42 | { 43 | return x - floor(x / 289.0) * 289.0; 44 | } 45 | 46 | float4 mod289(float4 x) 47 | { 48 | return x - floor(x / 289.0) * 289.0; 49 | } 50 | 51 | float3 permute(float3 x) 52 | { 53 | return mod289((x * 34.0 + 1.0) * x); 54 | } 55 | 56 | float4 permute(float4 x) 57 | { 58 | return mod289((x * 34.0 + 1.0) * x); 59 | } 60 | 61 | float3 taylorInvSqrt(float3 r) 62 | { 63 | return 1.79284291400159 - 0.85373472095314 * r; 64 | } 65 | 66 | float4 taylorInvSqrt(float4 r) 67 | { 68 | return 1.79284291400159 - 0.85373472095314 * r; 69 | } 70 | 71 | float2 fade(float2 t) 72 | { 73 | return t * t * t * (t * (t * 6.0 - 15.0) + 10.0); 74 | } 75 | 76 | float3 fade(float3 t) 77 | { 78 | return t * t * t * (t * (t * 6.0 - 15.0) + 10.0); 79 | } 80 | 81 | int index(int3 id, int3 dimension) 82 | { 83 | return ((id.z * dimension.z + id.y) * dimension.y) + id.x; 84 | } 85 | 86 | 87 | #define DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(NOISE_FUNC, RET_TYPE, PARAM_TYPE, CENTER) \ 88 | RET_TYPE NOISE_FUNC \ 89 | ( \ 90 | PARAM_TYPE s, \ 91 | PARAM_TYPE offset, \ 92 | int numOctaves, \ 93 | float octaveOffsetFactor \ 94 | ) \ 95 | { \ 96 | RET_TYPE o = 0.0; \ 97 | float w = 0.5; \ 98 | float wTotal = 0.0; \ 99 | int i = 0; \ 100 | do \ 101 | { \ 102 | o += w * NOISE_FUNC(s - offset); \ 103 | wTotal += w; \ 104 | offset *= 2.0 * octaveOffsetFactor; \ 105 | s *= 2.0; \ 106 | w *= 0.5; \ 107 | } while (++i < numOctaves); \ 108 | o *= 0.5 / wTotal; \ 109 | o += CENTER; \ 110 | return o; \ 111 | } 112 | 113 | #define DEFINE_PERIODIC_NOISE_FUNC_MULTIPLE_OCTAVES(NOISE_FUNC, RET_TYPE, PARAM_TYPE) \ 114 | RET_TYPE NOISE_FUNC \ 115 | ( \ 116 | PARAM_TYPE s, \ 117 | PARAM_TYPE offset, \ 118 | PARAM_TYPE period, \ 119 | int numOctaves, \ 120 | float octaveOffsetFactor \ 121 | ) \ 122 | { \ 123 | RET_TYPE o = 0.0; \ 124 | float w = 0.5; \ 125 | float wTotal = 0.0; \ 126 | int i = 0; \ 127 | do \ 128 | { \ 129 | o += w * NOISE_FUNC(s - offset, period); \ 130 | wTotal += w; \ 131 | offset *= 2.0 * octaveOffsetFactor; \ 132 | period *= 2.0; \ 133 | s *= 2.0; \ 134 | w *= 0.5; \ 135 | } while (++i < numOctaves); \ 136 | o *= 0.5 / wTotal; \ 137 | o += 0.5; \ 138 | return o; \ 139 | } 140 | 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/NoiseCommon.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d888eae3bfbc1b44dadb3c139a77443a 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/RandomNoise.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on an Andy Gryc's version of the common one-line shader random noise 11 | http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand/ 12 | 13 | */ 14 | /******************************************************************************/ 15 | 16 | 17 | #ifndef RAY_MARCHING_RANDOM_NOISE 18 | #define RAY_MARCHING_RANDOM_NOISE 19 | 20 | #include "NoiseCommon.cginc" 21 | 22 | float rand(float s) 23 | { 24 | return frac(sin(mod(s, 6.2831853)) * 43758.5453123); 25 | } 26 | 27 | 28 | float rand(float2 s) 29 | { 30 | float d = dot(s + 0.1234567, float2(1111112.9819837, 78.237173)); 31 | float m = mod(d, 6.2831853); 32 | return frac(sin(m) * 43758.5453123); 33 | } 34 | 35 | float rand(float3 s) 36 | { 37 | float d = dot(s + 0.1234567, float3(11112.9819837, 378.237173, 3971977.9173179)); 38 | float m = mod(d, 6.2831853); 39 | return frac(sin(m) * 43758.5453123); 40 | } 41 | 42 | float rand_range(float s, float a, float b) 43 | { 44 | return a + (b - a) * rand(s); 45 | } 46 | 47 | float2 rand_range(float2 s, float2 a, float2 b) 48 | { 49 | return a + (b - a) * rand(s); 50 | } 51 | 52 | float3 rand_range(float3 s, float3 a, float3 b) 53 | { 54 | return a + (b - a) * rand(s); 55 | } 56 | 57 | float2 rand_uvec(float2 s) 58 | { 59 | return normalize(float2(rand(s), rand(s * 1.23456789)) - 0.5); 60 | } 61 | 62 | float3 rand_uvec(float3 s) 63 | { 64 | return normalize(float3(rand(s), rand(s * 1.23456789), rand(s * 9876.54321)) - 0.5); 65 | } 66 | 67 | float2 rand_vec(float2 s) 68 | { 69 | return rand_uvec(s) * rand(s * 9876.54321); 70 | } 71 | 72 | float3 rand_vec(float3 s) 73 | { 74 | return rand_uvec(s) * rand(s * 1357975.31313); 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/RandomNoise.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6d41152c5085d749b5d5d890fa0dc81 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1fd5ac2c904801a478dcc3481cdc9ce4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/ClassicNoiseCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel ClassicGrid2 13 | #pragma kernel ClassicGrid3 14 | #pragma kernel ClassicCustom2 15 | #pragma kernel ClassicCustom3 16 | 17 | #include "../ClassicNoise2D.cginc" 18 | #include "../ClassicNoise3D.cginc" 19 | #include "../RandomNoise.cginc" 20 | 21 | RWStructuredBuffer input2; 22 | RWStructuredBuffer input3; 23 | RWStructuredBuffer output; 24 | 25 | int3 dimension; 26 | float3 scale; 27 | float3 offset; 28 | int numOctaves; 29 | float octaveOffsetFactor; 30 | 31 | [numthreads(1, 1, 1)] 32 | void ClassicGrid2(uint3 id : SV_DispatchThreadID) 33 | { 34 | float2 s = id.xy / scale.xy; 35 | output[index(id, dimension)] = 36 | cnoise(s, offset.xy, numOctaves, octaveOffsetFactor); 37 | } 38 | 39 | [numthreads(1, 1, 1)] 40 | void ClassicGrid3(uint3 id : SV_DispatchThreadID) 41 | { 42 | float3 s = id / scale; 43 | output[index(id, dimension)] = 44 | cnoise(s, offset, numOctaves, octaveOffsetFactor); 45 | } 46 | 47 | [numthreads(1, 1, 1)] 48 | void ClassicCustom2(uint3 id : SV_DispatchThreadID) 49 | { 50 | float2 s = input2[id.x] / scale.xy; 51 | output[id.x] = 52 | cnoise(s, offset.xy, numOctaves, octaveOffsetFactor); 53 | } 54 | 55 | [numthreads(1, 1, 1)] 56 | void ClassicCustom3(uint3 id : SV_DispatchThreadID) 57 | { 58 | float3 s = input3[id.x] / scale; 59 | output[id.x] = 60 | cnoise(s, offset, numOctaves, octaveOffsetFactor); 61 | } 62 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/ClassicNoiseCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d47a6b2a48ecf647875c4bedbc8d0c2 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/ClassicNoisePeriodicCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel ClassicPeriodicGrid2 13 | #pragma kernel ClassicPeriodicGrid3 14 | #pragma kernel ClassicPeriodicCustom2 15 | #pragma kernel ClassicPeriodicCustom3 16 | 17 | #include "../ClassicNoise2D.cginc" 18 | #include "../ClassicNoise3D.cginc" 19 | 20 | RWStructuredBuffer input2; 21 | RWStructuredBuffer input3; 22 | RWStructuredBuffer output; 23 | 24 | int3 dimension; 25 | float3 scale; 26 | float3 offset; 27 | float3 period; 28 | int numOctaves; 29 | float octaveOffsetFactor; 30 | 31 | [numthreads(1, 1, 1)] 32 | void ClassicPeriodicGrid2(uint3 id : SV_DispatchThreadID) 33 | { 34 | float2 s = id.xy / scale.xy; 35 | output[index(id, dimension)] = 36 | pnoise(s, offset.xy, period.xy, numOctaves, octaveOffsetFactor); 37 | } 38 | 39 | [numthreads(1, 1, 1)] 40 | void ClassicPeriodicGrid3(uint3 id : SV_DispatchThreadID) 41 | { 42 | float3 s = id / scale; 43 | output[index(id, dimension)] = 44 | pnoise(s, offset, period, numOctaves, octaveOffsetFactor); 45 | } 46 | 47 | [numthreads(1, 1, 1)] 48 | void ClassicPeriodicCustom2(uint3 id : SV_DispatchThreadID) 49 | { 50 | float2 s = input2[id.x] / scale.xy; 51 | output[id.x] = 52 | pnoise(s, offset.xy, period.xy, numOctaves, octaveOffsetFactor); 53 | } 54 | 55 | [numthreads(1, 1, 1)] 56 | void ClassicPeriodicCustom3(uint3 id : SV_DispatchThreadID) 57 | { 58 | float3 s = input3[id.x] / scale; 59 | output[id.x] = 60 | pnoise(s, offset, period, numOctaves, octaveOffsetFactor); 61 | } 62 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/ClassicNoisePeriodicCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: afe6add88b0b89d448b26e6e3dc5f59b 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/RandomNoiseCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel RandomGrid1 13 | #pragma kernel RandomGrid2 14 | #pragma kernel RandomGrid3 15 | 16 | #include "../RandomNoise.cginc" 17 | 18 | RWStructuredBuffer output; 19 | 20 | float seed; 21 | int3 dimension; 22 | 23 | [numthreads(1, 1, 1)] 24 | void RandomGrid1(uint3 id : SV_DispatchThreadID) 25 | { 26 | output[index(id, dimension)] = rand(seed + id.x); 27 | } 28 | 29 | [numthreads(1, 1, 1)] 30 | void RandomGrid2(uint3 id : SV_DispatchThreadID) 31 | { 32 | output[index(id, dimension)] = rand(seed + id.xy); 33 | } 34 | 35 | [numthreads(1, 1, 1)] 36 | void RandomGrid3(uint3 id : SV_DispatchThreadID) 37 | { 38 | output[index(id, dimension)] = rand(seed + id.xyz); 39 | } 40 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/RandomNoiseCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17f67342dcf81694fbd8e72def0acced 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/RandomNoiseVectorCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel RandomVec2 13 | #pragma kernel RandomVec3 14 | 15 | #include "../RandomNoise.cginc" 16 | 17 | RWStructuredBuffer output2; 18 | RWStructuredBuffer output3; 19 | 20 | float seed; 21 | int3 dimension; 22 | 23 | [numthreads(1, 1, 1)] 24 | void RandomVec2(uint3 id : SV_DispatchThreadID) 25 | { 26 | output2[index(id, dimension)] = rand_vec(seed + id.xy); 27 | } 28 | 29 | [numthreads(1, 1, 1)] 30 | void RandomVec3(uint3 id : SV_DispatchThreadID) 31 | { 32 | output3[index(id, dimension)] = rand_vec(seed + id.xyz); 33 | } -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/RandomNoiseVectorCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db6578c993355594ba41b3c1335a9adf 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/SimplexNoiseCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | #pragma kernel SimplexGrid2 13 | #pragma kernel SimplexGrid3 14 | #pragma kernel SimplexCustom2 15 | #pragma kernel SimplexCustom3 16 | 17 | #include "../SimplexNoise2D.cginc" 18 | #include "../SimplexNoise3D.cginc" 19 | #include "../RandomNoise.cginc" 20 | 21 | RWStructuredBuffer input2; 22 | RWStructuredBuffer input3; 23 | RWStructuredBuffer output; 24 | 25 | int3 dimension; 26 | float3 scale; 27 | float3 offset; 28 | int numOctaves; 29 | float octaveOffsetFactor; 30 | 31 | [numthreads(1, 1, 1)] 32 | void SimplexGrid2(uint3 id : SV_DispatchThreadID) 33 | { 34 | float2 s = id.xy / scale.xy; 35 | output[index(id, dimension)] = 36 | snoise(s, offset.xy, numOctaves, octaveOffsetFactor); 37 | } 38 | 39 | [numthreads(1, 1, 1)] 40 | void SimplexGrid3(uint3 id : SV_DispatchThreadID) 41 | { 42 | float3 s = id / scale; 43 | output[index(id, dimension)] = 44 | snoise(s, offset, numOctaves, octaveOffsetFactor); 45 | } 46 | 47 | [numthreads(1, 1, 1)] 48 | void SimplexCustom2(uint3 id : SV_DispatchThreadID) 49 | { 50 | float2 s = input2[id.x] / scale.xy; 51 | output[id.x] = 52 | snoise(s, offset.xy, numOctaves, octaveOffsetFactor); 53 | } 54 | 55 | [numthreads(1, 1, 1)] 56 | void SimplexCustom3(uint3 id : SV_DispatchThreadID) 57 | { 58 | float3 s = input3[id.x] / scale; 59 | output[id.x] = 60 | snoise(s, offset, numOctaves, octaveOffsetFactor); 61 | } 62 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/SimplexNoiseCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4eb8152e697df05409038674dbc8bb4b 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/SimplexNoiseGradientCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | */ 10 | /******************************************************************************/ 11 | 12 | 13 | #pragma kernel SimplexGradientGrid2 14 | #pragma kernel SimplexGradientGrid3 15 | #pragma kernel SimplexGradientCustom2 16 | #pragma kernel SimplexGradientCustom3 17 | 18 | #include "../SimplexNoise2D.cginc" 19 | #include "../SimplexNoise3D.cginc" 20 | 21 | RWStructuredBuffer input2; 22 | RWStructuredBuffer input3; 23 | RWStructuredBuffer output2; 24 | RWStructuredBuffer output3; 25 | 26 | int3 dimension; 27 | float3 scale; 28 | float3 offset; 29 | int numOctaves; 30 | float octaveOffsetFactor; 31 | 32 | // grid sample points 33 | [numthreads(1, 1, 1)] 34 | void SimplexGradientGrid2(uint3 id : SV_DispatchThreadID) 35 | { 36 | float2 s = id.xy / scale.xy; 37 | output2[index(id, dimension)] = 38 | snoise_grad(s, offset.xy, numOctaves, octaveOffsetFactor).xy; 39 | } 40 | 41 | // grid sample points 42 | [numthreads(1, 1, 1)] 43 | void SimplexGradientGrid3(uint3 id : SV_DispatchThreadID) 44 | { 45 | float3 s = id / scale; 46 | output3[index(id, dimension)] = 47 | snoise_grad(s, offset, numOctaves, octaveOffsetFactor).xyz; 48 | } 49 | 50 | // custom sample points 51 | [numthreads(1, 1, 1)] 52 | void SimplexGradientCustom2(uint3 id : SV_DispatchThreadID) 53 | { 54 | float2 s = input2[id.x] / scale.xy; 55 | output2[id.x] = 56 | snoise_grad(s, offset.xy, numOctaves, octaveOffsetFactor).xy; 57 | } 58 | 59 | // custom sample points 60 | [numthreads(1, 1, 1)] 61 | void SimplexGradientCustom3(uint3 id : SV_DispatchThreadID) 62 | { 63 | float3 s = input3[id.x] / scale; 64 | output3[id.x] = 65 | snoise_grad(s, offset, numOctaves, octaveOffsetFactor).xyz; 66 | } 67 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/Resources/SimplexNoiseGradientCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7957dd6eaa0f4074383bdba2b668fe69 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/SimplexNoise2D.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on project "webgl-noise" by Ashima Arts. 11 | Description : Array and textureless GLSL 2D simplex noise function. 12 | Author : Ian McEwan, Ashima Arts. 13 | Maintainer : ijm 14 | Lastmod : 20110822 (ijm) 15 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 16 | Distributed under the MIT License. See LICENSE file. 17 | https://github.com/ashima/webgl-noise 18 | */ 19 | /******************************************************************************/ 20 | 21 | #ifndef RAY_MARCHING_SIMPLEX_NOISE_2D 22 | #define RAY_MARCHING_SIMPLEX_NOISE_2D 23 | 24 | #include "NoiseCommon.cginc" 25 | 26 | // single octave 27 | float snoise(float2 v) 28 | { 29 | const float4 C = float4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0 30 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 31 | -0.577350269189626, // -1.0 + 2.0 * C.x 32 | 0.024390243902439); // 1.0 / 41.0 33 | // First corner 34 | float2 i = floor(v + dot(v, C.yy)); 35 | float2 x0 = v - i + dot(i, C.xx); 36 | 37 | // Other corners 38 | float2 i1; 39 | i1.x = step(x0.y, x0.x); 40 | i1.y = 1.0 - i1.x; 41 | 42 | // x1 = x0 - i1 + 1.0 * C.xx; 43 | // x2 = x0 - 1.0 + 2.0 * C.xx; 44 | float2 x1 = x0 + C.xx - i1; 45 | float2 x2 = x0 + C.zz; 46 | 47 | // Permutations 48 | i = mod289(i); // Avoid truncation effects in permutation 49 | float3 p = 50 | permute(permute(i.y + float3(0.0, i1.y, 1.0)) 51 | + i.x + float3(0.0, i1.x, 1.0)); 52 | 53 | float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); 54 | m = m * m; 55 | m = m * m; 56 | 57 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 58 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 59 | float3 x = 2.0 * frac(p * C.www) - 1.0; 60 | float3 h = abs(x) - 0.5; 61 | float3 ox = floor(x + 0.5); 62 | float3 a0 = x - ox; 63 | 64 | // Normalise gradients implicitly by scaling m 65 | m *= taylorInvSqrt(a0 * a0 + h * h); 66 | 67 | // Compute final noise value at P 68 | float3 g; 69 | g.x = a0.x * x0.x + h.x * x0.y; 70 | g.y = a0.y * x1.x + h.y * x1.y; 71 | g.z = a0.z * x2.x + h.z * x2.y; 72 | return 130.0 * dot(m, g); 73 | } 74 | 75 | // multiple octaves 76 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(snoise, float, float2, 0.5); 77 | 78 | // single octave 79 | float3 snoise_grad(float2 v) 80 | { 81 | const float4 C = float4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0 82 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 83 | -0.577350269189626, // -1.0 + 2.0 * C.x 84 | 0.024390243902439); // 1.0 / 41.0 85 | // First corner 86 | float2 i = floor(v + dot(v, C.yy)); 87 | float2 x0 = v - i + dot(i, C.xx); 88 | 89 | // Other corners 90 | float2 i1; 91 | i1.x = step(x0.y, x0.x); 92 | i1.y = 1.0 - i1.x; 93 | 94 | // x1 = x0 - i1 + 1.0 * C.xx; 95 | // x2 = x0 - 1.0 + 2.0 * C.xx; 96 | float2 x1 = x0 + C.xx - i1; 97 | float2 x2 = x0 + C.zz; 98 | 99 | // Permutations 100 | i = mod289(i); // Avoid truncation effects in permutation 101 | float3 p = 102 | permute(permute(i.y + float3(0.0, i1.y, 1.0)) 103 | + i.x + float3(0.0, i1.x, 1.0)); 104 | 105 | float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); 106 | float3 m2 = m * m; 107 | float3 m3 = m2 * m; 108 | float3 m4 = m2 * m2; 109 | 110 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 111 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 112 | float3 x = 2.0 * frac(p * C.www) - 1.0; 113 | float3 h = abs(x) - 0.5; 114 | float3 ox = floor(x + 0.5); 115 | float3 a0 = x - ox; 116 | 117 | // Normalise gradients 118 | float3 norm = taylorInvSqrt(a0 * a0 + h * h); 119 | float2 g0 = float2(a0.x, h.x) * norm.x; 120 | float2 g1 = float2(a0.y, h.y) * norm.y; 121 | float2 g2 = float2(a0.z, h.z) * norm.z; 122 | 123 | // Compute noise and gradient at P 124 | float2 grad = 125 | -6.0 * m3.x * x0 * dot(x0, g0) + m4.x * g0 + 126 | -6.0 * m3.y * x1 * dot(x1, g1) + m4.y * g1 + 127 | -6.0 * m3.z * x2 * dot(x2, g2) + m4.z * g2; 128 | float3 px = float3(dot(x0, g0), dot(x1, g1), dot(x2, g2)); 129 | return 130.0 * float3(grad, dot(m4, px)); 130 | } 131 | 132 | // multiple octaves 133 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(snoise_grad, float3, float2, 0.0); 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/SimplexNoise2D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c05b16f88a1d0ba419095712496e35e6 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/SimplexNoise3D.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | Based on project "webgl-noise" by Ashima Arts. 11 | Description : Array and textureless GLSL 2D simplex noise function. 12 | Author : Ian McEwan, Ashima Arts. 13 | Maintainer : ijm 14 | Lastmod : 20110822 (ijm) 15 | License : Copyright (C) 2011 Ashima Arts. All rights reserved. 16 | Distributed under the MIT License. See LICENSE file. 17 | https://github.com/ashima/webgl-noise 18 | */ 19 | /******************************************************************************/ 20 | 21 | #ifndef RAY_MARCHING_SIMPLEX_NOISE_3D 22 | #define RAY_MARCHING_SIMPLEX_NOISE_3D 23 | 24 | #include "NoiseCommon.cginc" 25 | 26 | // single octave 27 | float snoise(float3 v) 28 | { 29 | const float2 C = float2(1.0 / 6.0, 1.0 / 3.0); 30 | 31 | // First corner 32 | float3 i = floor(v + dot(v, C.yyy)); 33 | float3 x0 = v - i + dot(i, C.xxx); 34 | 35 | // Other corners 36 | float3 g = step(x0.yzx, x0.xyz); 37 | float3 l = 1.0 - g; 38 | float3 i1 = min(g.xyz, l.zxy); 39 | float3 i2 = max(g.xyz, l.zxy); 40 | 41 | // x1 = x0 - i1 + 1.0 * C.xxx; 42 | // x2 = x0 - i2 + 2.0 * C.xxx; 43 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 44 | float3 x1 = x0 - i1 + C.xxx; 45 | float3 x2 = x0 - i2 + C.yyy; 46 | float3 x3 = x0 - 0.5; 47 | 48 | // Permutations 49 | i = mod289(i); // Avoid truncation effects in permutation 50 | float4 p = 51 | permute(permute(permute(i.z + float4(0.0, i1.z, i2.z, 1.0)) 52 | + i.y + float4(0.0, i1.y, i2.y, 1.0)) 53 | + i.x + float4(0.0, i1.x, i2.x, 1.0)); 54 | 55 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 56 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 57 | float4 j = p - 49.0 * floor(p / 49.0); // mod(p,7*7) 58 | 59 | float4 x_ = floor(j / 7.0); 60 | float4 y_ = floor(j - 7.0 * x_); // mod(j,N) 61 | 62 | float4 x = (x_ * 2.0 + 0.5) / 7.0 - 1.0; 63 | float4 y = (y_ * 2.0 + 0.5) / 7.0 - 1.0; 64 | 65 | float4 h = 1.0 - abs(x) - abs(y); 66 | 67 | float4 b0 = float4(x.xy, y.xy); 68 | float4 b1 = float4(x.zw, y.zw); 69 | 70 | //float4 s0 = float4(lessThan(b0, 0.0)) * 2.0 - 1.0; 71 | //float4 s1 = float4(lessThan(b1, 0.0)) * 2.0 - 1.0; 72 | float4 s0 = floor(b0) * 2.0 + 1.0; 73 | float4 s1 = floor(b1) * 2.0 + 1.0; 74 | float4 sh = -step(h, 0.0); 75 | 76 | float4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; 77 | float4 a1 = b1.xzyw + s1.xzyw * sh.zzww; 78 | 79 | float3 g0 = float3(a0.xy, h.x); 80 | float3 g1 = float3(a0.zw, h.y); 81 | float3 g2 = float3(a1.xy, h.z); 82 | float3 g3 = float3(a1.zw, h.w); 83 | 84 | // Normalise gradients 85 | float4 norm = taylorInvSqrt(float4(dot(g0, g0), dot(g1, g1), dot(g2, g2), dot(g3, g3))); 86 | g0 *= norm.x; 87 | g1 *= norm.y; 88 | g2 *= norm.z; 89 | g3 *= norm.w; 90 | 91 | // Mix final noise value 92 | float4 m = max(0.6 - float4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0); 93 | m = m * m; 94 | m = m * m; 95 | 96 | float4 px = float4(dot(x0, g0), dot(x1, g1), dot(x2, g2), dot(x3, g3)); 97 | return 42.0 * dot(m, px); 98 | } 99 | 100 | // multiple octaves 101 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(snoise, float, float3, 0.5); 102 | 103 | // single octave 104 | float4 snoise_grad(float3 v) 105 | { 106 | const float2 C = float2(1.0 / 6.0, 1.0 / 3.0); 107 | 108 | // First corner 109 | float3 i = floor(v + dot(v, C.yyy)); 110 | float3 x0 = v - i + dot(i, C.xxx); 111 | 112 | // Other corners 113 | float3 g = step(x0.yzx, x0.xyz); 114 | float3 l = 1.0 - g; 115 | float3 i1 = min(g.xyz, l.zxy); 116 | float3 i2 = max(g.xyz, l.zxy); 117 | 118 | // x1 = x0 - i1 + 1.0 * C.xxx; 119 | // x2 = x0 - i2 + 2.0 * C.xxx; 120 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 121 | float3 x1 = x0 - i1 + C.xxx; 122 | float3 x2 = x0 - i2 + C.yyy; 123 | float3 x3 = x0 - 0.5; 124 | 125 | // Permutations 126 | i = mod289(i); // Avoid truncation effects in permutation 127 | float4 p = 128 | permute(permute(permute(i.z + float4(0.0, i1.z, i2.z, 1.0)) 129 | + i.y + float4(0.0, i1.y, i2.y, 1.0)) 130 | + i.x + float4(0.0, i1.x, i2.x, 1.0)); 131 | 132 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 133 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 134 | float4 j = p - 49.0 * floor(p / 49.0); // mod(p,7*7) 135 | 136 | float4 x_ = floor(j / 7.0); 137 | float4 y_ = floor(j - 7.0 * x_); // mod(j,N) 138 | 139 | float4 x = (x_ * 2.0 + 0.5) / 7.0 - 1.0; 140 | float4 y = (y_ * 2.0 + 0.5) / 7.0 - 1.0; 141 | 142 | float4 h = 1.0 - abs(x) - abs(y); 143 | 144 | float4 b0 = float4(x.xy, y.xy); 145 | float4 b1 = float4(x.zw, y.zw); 146 | 147 | //float4 s0 = float4(lessThan(b0, 0.0)) * 2.0 - 1.0; 148 | //float4 s1 = float4(lessThan(b1, 0.0)) * 2.0 - 1.0; 149 | float4 s0 = floor(b0) * 2.0 + 1.0; 150 | float4 s1 = floor(b1) * 2.0 + 1.0; 151 | float4 sh = -step(h, 0.0); 152 | 153 | float4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; 154 | float4 a1 = b1.xzyw + s1.xzyw * sh.zzww; 155 | 156 | float3 g0 = float3(a0.xy, h.x); 157 | float3 g1 = float3(a0.zw, h.y); 158 | float3 g2 = float3(a1.xy, h.z); 159 | float3 g3 = float3(a1.zw, h.w); 160 | 161 | // Normalise gradients 162 | float4 norm = taylorInvSqrt(float4(dot(g0, g0), dot(g1, g1), dot(g2, g2), dot(g3, g3))); 163 | g0 *= norm.x; 164 | g1 *= norm.y; 165 | g2 *= norm.z; 166 | g3 *= norm.w; 167 | 168 | // Compute noise and gradient at P 169 | float4 m = max(0.6 - float4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0); 170 | float4 m2 = m * m; 171 | float4 m3 = m2 * m; 172 | float4 m4 = m2 * m2; 173 | float3 grad = 174 | -6.0 * m3.x * x0 * dot(x0, g0) + m4.x * g0 + 175 | -6.0 * m3.y * x1 * dot(x1, g1) + m4.y * g1 + 176 | -6.0 * m3.z * x2 * dot(x2, g2) + m4.z * g2 + 177 | -6.0 * m3.w * x3 * dot(x3, g3) + m4.w * g3; 178 | float4 px = float4(dot(x0, g0), dot(x1, g1), dot(x2, g2), dot(x3, g3)); 179 | return 42.0 * float4(grad, dot(m4, px)); 180 | } 181 | 182 | // multiple octaves 183 | DEFINE_NOISE_FUNC_MULTIPLE_OCTAVES(snoise_grad, float4, float3, 0.0); 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Noise/SimplexNoise3D.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c474d07a7f2949a45b86bf61f6a3fa29 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8b5370892ee4dda4d98899a7acc2cccd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a85763f85fa963d4dbf621a19e437035 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/Resources/AabbTree.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef RAY_MARCHING_AABB_TREE 14 | #define RAY_MARCHING_AABB_TREE 15 | 16 | struct Aabb 17 | { 18 | float4 boundsMin; 19 | float4 boundsMax; 20 | }; 21 | 22 | struct AabbNode 23 | { 24 | Aabb aabb; 25 | int parent; 26 | int childA; 27 | int childB; 28 | int shapeIndex; 29 | }; 30 | 31 | inline float3 aabb_center(Aabb aabb) 32 | { 33 | return 0.5f * (aabb.boundsMin.xyz + aabb.boundsMax.xyz); 34 | } 35 | 36 | inline float3 aabb_extents(Aabb aabb) 37 | { 38 | return aabb.boundsMax.xyz - aabb.boundsMin.xyz; 39 | } 40 | 41 | inline float3 aabb_half_extents(Aabb aabb) 42 | { 43 | return 0.5f * (aabb.boundsMax.xyz - aabb.boundsMin.xyz); 44 | } 45 | 46 | inline bool aabb_intersects(Aabb a, Aabb b) 47 | { 48 | return all(a.boundsMin <= b.boundsMax && a.boundsMax >= b.boundsMin); 49 | } 50 | 51 | float aabb_ray_cast(Aabb aabb, float3 from, float3 to) 52 | { 53 | float tMin = -kFltMax; 54 | float tMax = +kFltMax; 55 | 56 | float3 d = to - from; 57 | float3 absD = abs(d); 58 | 59 | if (any(absD < kEpsilon)) 60 | { 61 | // parallel? 62 | if (any(from < aabb.boundsMin.xyz) || any(aabb.boundsMax.xyz < from)) 63 | return -kFltMax; 64 | } 65 | else 66 | { 67 | float3 invD = 1.0f / d; 68 | float3 t1 = (aabb.boundsMin.xyz - from) * invD; 69 | float3 t2 = (aabb.boundsMax.xyz - from) * invD; 70 | float3 minComps = min(t1, t2); 71 | float3 maxComps = max(t1, t2); 72 | 73 | tMin = max(minComps.x, max(minComps.y, minComps.z)); 74 | tMax = min(maxComps.x, min(maxComps.y, maxComps.z)); 75 | } 76 | 77 | if (tMin > tMax) 78 | return -kFltMax; 79 | 80 | if (tMin < 0.0f) 81 | return -kFltMax; 82 | 83 | return tMin; 84 | } 85 | 86 | // stmt = statements processing shapeIndex of hit leaf AABB nodes 87 | #define aabb_tree_ray_cast(tree, root, rayFrom, rayTo, stackSize, stmt) \ 88 | { \ 89 | float3 rayDir = normalize(rayTo - rayFrom); \ 90 | float3 rayDirOrtho = normalize(find_ortho(rayDir)); \ 91 | float3 rayDirOrthoAbs = abs(rayDirOrtho); \ 92 | \ 93 | Aabb rayBounds; \ 94 | rayBounds.boundsMin = float4(min(rayFrom, rayTo), 0.0f); \ 95 | rayBounds.boundsMax = float4(max(rayFrom, rayTo), 0.0f); \ 96 | \ 97 | int stackTop = 0; \ 98 | int stack[stackSize]; \ 99 | stack[stackTop] = root; \ 100 | \ 101 | while (stackTop >= 0) \ 102 | { \ 103 | int index = stack[stackTop--]; \ 104 | if (index < 0) \ 105 | continue; \ 106 | \ 107 | if (!aabb_intersects(tree[index].aabb, rayBounds)) \ 108 | continue; \ 109 | \ 110 | float3 aabbCenter = aabb_center(tree[index].aabb); \ 111 | float3 aabbHalfExtents = aabb_half_extents(tree[index].aabb); \ 112 | float separation = \ 113 | abs(dot(rayDirOrtho, rayFrom - aabbCenter)) \ 114 | - dot(rayDirOrthoAbs, aabbHalfExtents); \ 115 | if (separation > 0.0f) \ 116 | continue; \ 117 | \ 118 | if (tree[index].childA < 0) \ 119 | { \ 120 | float t = aabb_ray_cast(tree[index].aabb, rayFrom, rayTo); \ 121 | if (t < 0.0f) \ 122 | continue; \ 123 | \ 124 | const int shapeIndex = tree[index].shapeIndex; \ 125 | \ 126 | stmt \ 127 | } \ 128 | else \ 129 | { \ 130 | stackTop = min(stackTop + 1, stackSize - 1); \ 131 | stack[stackTop] = tree[index].childA; \ 132 | stackTop = min(stackTop + 1, stackSize - 1); \ 133 | stack[stackTop] = tree[index].childB; \ 134 | } \ 135 | } \ 136 | } 137 | 138 | #endif 139 | 140 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/Resources/AabbTree.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7868d5de0115c5047b9adc8da3d8f19b 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/Resources/RayMarcherCs.compute: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #include "../SDF/SDF.cginc" 14 | #include "AabbTree.cginc" 15 | 16 | 17 | // constants & buffers 18 | //----------------------------------------------------------------------------- 19 | 20 | #define kTileSize (8) 21 | #define kMaxShapesPerRay (64) 22 | #define kAabbTreeStackSize (128) 23 | 24 | Texture2D src; 25 | RWTexture2D dst; 26 | RWTexture2D heatMap; 27 | 28 | float4x4 cameraInvProj; 29 | float4x4 cameraToWorld; 30 | float4 cameraPos; 31 | int2 screenSize; // width / height 32 | 33 | StructuredBuffer aSdfShape; 34 | int numSdfShapes; 35 | RWTexture2D tempBuffer; // scratch memory 36 | 37 | float4 rayMarchParams; // maxSteps, hitDist, maxDist, time 38 | float blendDist; 39 | 40 | float4 backgroundColor; 41 | float4 missColor; 42 | 43 | float4 heatColorCool; 44 | float4 heatColorMedium; 45 | float4 heatColorHot; 46 | float heatAlpha; 47 | 48 | int maxCountBudget; 49 | 50 | bool useAabbTree; 51 | StructuredBuffer aabbTree; 52 | int aabbTreeRoot; 53 | 54 | //----------------------------------------------------------------------------- 55 | // end: constants & buffers 56 | 57 | 58 | // ray marching 59 | //----------------------------------------------------------------------------- 60 | 61 | // no keyword variant support for compute shaders yet, sigh -_- 62 | #define kModeMain (0) 63 | #define kModeStepCount (1) 64 | #define kModeShapeCount (2) 65 | 66 | float ground_truth_sdf(float3 p) 67 | { 68 | if (numSdfShapes <= 0) 69 | return kInfinity; 70 | 71 | float3 opRes = kInfinity; 72 | 73 | for (int i = 0; i < numSdfShapes; ++i) 74 | { 75 | // why doesn't a switch statement work here? 76 | int op = aSdfShape[i].data0.y; 77 | if (op == kSdfUnion) 78 | { 79 | opRes.x = sdf_uni_smooth(opRes.x, sdf_shape(p, aSdfShape[i]), blendDist); 80 | } 81 | else if (op == kSdfSubtraction) 82 | { 83 | opRes.y = sdf_uni_smooth(opRes.y, sdf_shape(p, aSdfShape[i]), blendDist); 84 | } 85 | else if (op == kSdfIntersection) 86 | { 87 | opRes.z = sdf_uni_smooth(opRes.z, sdf_shape(p, aSdfShape[i]), blendDist); 88 | } 89 | } 90 | 91 | float res = sdf_sub_smooth(opRes.x, opRes.y, blendDist); 92 | if (opRes.z < kInfinity) 93 | res = sdf_int_smooth(res, opRes.z, blendDist); 94 | 95 | return res; 96 | } 97 | 98 | float3 heat_color(float t) 99 | { 100 | return 101 | t < 0.5f 102 | ? lerp(heatColorCool.rgb, heatColorMedium.rgb, t / 0.5f) 103 | : lerp(heatColorMedium.rgb, heatColorHot.rgb, (t - 0.5f) / 0.5f); 104 | } 105 | 106 | #define SDF_NEAR_SHAPES(res, p, aiNearShape, numNearShapes) \ 107 | { \ 108 | float3 opRes = kInfinity; \ 109 | for (int i = 0; i < numNearShapes; ++i) \ 110 | { \ 111 | const int iShape = aiNearShape[i]; \ 112 | const int op = aSdfShape[iShape].data0.y; \ 113 | if (op == kSdfUnion) \ 114 | { \ 115 | opRes.x = sdf_uni_smooth(opRes.x, sdf_shape(p, aSdfShape[iShape]), blendDist); \ 116 | } \ 117 | else if (op == kSdfSubtraction) \ 118 | { \ 119 | opRes.y = sdf_uni_smooth(opRes.y, sdf_shape(p, aSdfShape[iShape]), blendDist); \ 120 | } \ 121 | else if (op == kSdfIntersection) \ 122 | { \ 123 | opRes.z = sdf_uni_smooth(opRes.z, sdf_shape(p, aSdfShape[iShape]), blendDist); \ 124 | } \ 125 | } \ 126 | res = sdf_sub_smooth(opRes.x, opRes.y, blendDist); \ 127 | if (opRes.z < kInfinity) \ 128 | res = sdf_int_smooth(res, opRes.z, blendDist); \ 129 | } 130 | 131 | float4 march(int3 id, int mode) 132 | { 133 | // TODO: move hard-coded material out of here 134 | const float3 kDiffuse = float3(1.0f, 0.65f, 0.05f); 135 | const float3 kAmbient = 0.1f * kDiffuse; 136 | 137 | // set up ray 138 | const float2 uv = float2(id.xy) / screenSize; 139 | const float4 view = mul(cameraInvProj, float4(uv * 2.0f - 1.0f, 0.0f, 1.0f)); 140 | const float3 ro = cameraPos.xyz; 141 | const float3 rd = normalize(mul(cameraToWorld, float4(view.xyz, 0.0f)).xyz); 142 | 143 | // params 144 | const int maxSteps = int(rayMarchParams.x); 145 | const float hitDist = rayMarchParams.y; 146 | const float maxDist = rayMarchParams.z; 147 | 148 | // gather shapes around ray by casting it against AABB tree 149 | int aiNearShape[kMaxShapesPerRay]; 150 | int numNearShapes = 0; 151 | aabb_tree_ray_cast(aabbTree, aabbTreeRoot, ro, ro + maxDist * rd, kAabbTreeStackSize, 152 | numNearShapes = min(numNearShapes + 1, kMaxShapesPerRay); 153 | aiNearShape[numNearShapes - 1] = shapeIndex; 154 | ); 155 | 156 | // march ray 157 | float dist = 0.0f; 158 | for (int iStep = 0; iStep < maxSteps; ++iStep) 159 | { 160 | const float3 p = ro + dist * rd; 161 | 162 | // sample SDf 163 | float d = kInfinity; 164 | if (useAabbTree) 165 | { 166 | SDF_NEAR_SHAPES(d, p, aiNearShape, numNearShapes); 167 | } 168 | else 169 | { 170 | d = ground_truth_sdf(p); 171 | } 172 | 173 | // hit shape? 174 | if (d < hitDist) 175 | { 176 | // TODO: why doesn't a switch statement work here? 177 | if (mode == kModeMain) 178 | { 179 | // TODO: choose h to be proportional to pixel footprint 180 | // http://www.iquilezles.org/www/articles/normalsSDF/normalsSDF.htm 181 | const float h = 0.01f; 182 | 183 | // compute differential normal 184 | float3 n = 0.0f; 185 | if (useAabbTree) 186 | { 187 | float n0, n1, n2, n3; 188 | SDF_NEAR_SHAPES(n0, p + float3( (h), -(h), -(h)), aiNearShape, numNearShapes); 189 | SDF_NEAR_SHAPES(n1, p + float3(-(h), -(h), (h)), aiNearShape, numNearShapes); 190 | SDF_NEAR_SHAPES(n2, p + float3(-(h), (h), -(h)), aiNearShape, numNearShapes); 191 | SDF_NEAR_SHAPES(n3, p + float3( (h), (h), (h)), aiNearShape, numNearShapes); 192 | n = 193 | normalize 194 | ( 195 | float3( 1.0f, -1.0f, -1.0f) * n0 196 | + float3(-1.0f, -1.0f, 1.0f) * n1 197 | + float3(-1.0f, 1.0f, -1.0f) * n2 198 | + float3( 1.0f, 1.0f, 1.0f) * n3 199 | ); 200 | } 201 | else 202 | { 203 | n = sdf_normal(p, ground_truth_sdf, h); 204 | } 205 | 206 | const float3 lightPos = ro + float3(0.0f, 1.0f, 0.0f); 207 | const float3 lightDir = normalize(p - lightPos); 208 | const float3 shaded = max(pow(dot(n, -lightDir), 1.0f), kAmbient) * kDiffuse; 209 | const float3 fresnel = 0.3f * pow(saturate(1.0f - dot(n, -rd)), 2.0f); 210 | const float3 specular = 0.2f * pow(saturate(dot(n, -normalize(rd + lightDir))), 100.0f); 211 | 212 | return float4(shaded + fresnel + specular, d); 213 | } 214 | else if (mode == kModeStepCount) 215 | { 216 | return iStep; 217 | } 218 | else if (mode == kModeShapeCount) 219 | { 220 | return useAabbTree ? numNearShapes : numSdfShapes; 221 | } 222 | } 223 | 224 | // hit background? 225 | if (dist > maxDist) 226 | { 227 | if (mode == kModeMain) 228 | { 229 | return float4(backgroundColor.rgb, kInfinity); 230 | } 231 | else if (mode == kModeStepCount) 232 | { 233 | return iStep; 234 | } 235 | else if (mode == kModeShapeCount) 236 | { 237 | return useAabbTree ? numNearShapes : numSdfShapes; 238 | } 239 | } 240 | 241 | dist += d; 242 | } 243 | 244 | if (mode != kModeMain) 245 | return kInfinity; 246 | 247 | return float4(missColor.rgb, kInfinity); 248 | } 249 | 250 | //----------------------------------------------------------------------------- 251 | // end: ray marching 252 | 253 | 254 | // kernels 255 | //----------------------------------------------------------------------------- 256 | 257 | #pragma kernel Main 258 | #pragma kernel StepCountPerThread 259 | #pragma kernel StepCountPerTile 260 | #pragma kernel ShapeCountPerThread 261 | #pragma kernel ShapeCountPerTile 262 | 263 | [numthreads(kTileSize, kTileSize, 1)] 264 | void Main(int3 id : SV_DispatchThreadID) 265 | { 266 | if (any(id.xy > screenSize)) 267 | return; 268 | 269 | float4 res = march(id, kModeMain); 270 | float3 col = res.rgb; 271 | 272 | dst[id.xy] = float4(col, 1.0f); 273 | } 274 | 275 | [numthreads(kTileSize, kTileSize, 1)] 276 | void StepCountPerThread(int3 id : SV_DispatchThreadID) 277 | { 278 | if (any(id.xy >= screenSize)) 279 | return; 280 | 281 | float4 res = march(id, kModeStepCount); 282 | float heat = res.x / maxCountBudget; 283 | float3 col = heat_color(heat); 284 | 285 | dst[id.xy] = lerp(dst[id.xy], float4(col, 1.0f), heatAlpha); 286 | } 287 | 288 | [numthreads(kTileSize, kTileSize, 1)] 289 | void StepCountPerTile(int3 id : SV_DispatchThreadID) 290 | { 291 | float4 res = march(id, kModeStepCount); 292 | float heat = res.x / maxCountBudget; 293 | heatMap[id.xy] = heat; 294 | 295 | AllMemoryBarrierWithGroupSync(); 296 | 297 | if (any(id.xy >= screenSize)) 298 | return; 299 | 300 | int2 tileBaseId = kTileSize * (uint2(id.xy) / kTileSize); 301 | float maxHeat = 0.0f; 302 | for (int i = 0; i < kTileSize; ++i) 303 | for (int j = 0; j < kTileSize; ++j) 304 | maxHeat = max(maxHeat, heatMap[tileBaseId + int2(i, j)]); 305 | 306 | float3 col = heat_color(maxHeat); 307 | 308 | dst[id.xy] = lerp(dst[id.xy], float4(col, 1.0f), heatAlpha); 309 | } 310 | 311 | [numthreads(kTileSize, kTileSize, 1)] 312 | void ShapeCountPerThread(int3 id : SV_DispatchThreadID) 313 | { 314 | if (any(id.xy >= screenSize)) 315 | return; 316 | 317 | float4 res = march(id, kModeShapeCount); 318 | float heat = res.x / maxCountBudget; 319 | float3 col = heat_color(heat); 320 | 321 | dst[id.xy] = lerp(dst[id.xy], float4(col, 1.0f), heatAlpha); 322 | } 323 | 324 | [numthreads(kTileSize, kTileSize, 1)] 325 | void ShapeCountPerTile(int3 id : SV_DispatchThreadID) 326 | { 327 | float4 res = march(id, kModeShapeCount); 328 | float heat = res.x / maxCountBudget; 329 | heatMap[id.xy] = heat; 330 | 331 | AllMemoryBarrierWithGroupSync(); 332 | 333 | if (any(id.xy >= screenSize)) 334 | return; 335 | 336 | int2 tileBaseId = kTileSize * (uint2(id.xy) / kTileSize); 337 | float maxHeat = 0.0f; 338 | for (int i = 0; i < kTileSize; ++i) 339 | for (int j = 0; j < kTileSize; ++j) 340 | maxHeat = max(maxHeat, heatMap[tileBaseId + int2(i, j)]); 341 | 342 | float3 col = heat_color(maxHeat); 343 | 344 | dst[id.xy] = lerp(dst[id.xy], float4(col, 1.0f), heatAlpha); 345 | } 346 | 347 | //----------------------------------------------------------------------------- 348 | // end: kernels 349 | 350 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/Resources/RayMarcherCs.compute.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 047befc0d8dd6384fae6798d673887f4 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 4 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64378cb6cd7a85d448337b995e1b517a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Normal.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef RAY_MARCHING_SDF_NORMAL 14 | #define RAY_MARCHING_SDF_NORMAL 15 | 16 | // http://iquilezles.org/www/articles/normalsSDF/normalsSDF.htm 17 | 18 | // central differences 19 | #define sdf_normal_diff(p, sdf, h) \ 20 | normalize \ 21 | ( \ 22 | float3 \ 23 | ( \ 24 | sdf((p) + float3( (h), 0.0f, 0.0f))) - sdf((p) - float3( (h), 0.0f, 0.0f))), \ 25 | sdf((p) + float3(0.0f, (h), 0.0f))) - sdf((p) - float3(0.0f, (h), 0.0f))), \ 26 | sdf((p) + float3(0.0f, 0.0f, (h)))) - sdf((p) - float3(0.0f, 0.0f, (h)))) \ 27 | ) \ 28 | ) 29 | 30 | // tetrahedron technique 31 | #define sdf_normal_tetra(p, sdf, h) \ 32 | normalize \ 33 | ( \ 34 | float3( 1.0f, -1.0f, -1.0f) * sdf((p) + float3( (h), -(h), -(h))) \ 35 | + float3(-1.0f, -1.0f, 1.0f) * sdf((p) + float3(-(h), -(h), (h))) \ 36 | + float3(-1.0f, 1.0f, -1.0f) * sdf((p) + float3(-(h), (h), -(h))) \ 37 | + float3( 1.0f, 1.0f, 1.0f) * sdf((p) + float3( (h), (h), (h))) \ 38 | ) 39 | 40 | // use tetrahedron technique as default 41 | #define sdf_normal(p, sdf, h) sdf_normal_tetra(p, sdf, h) 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Normal.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9248e0b25fba6e34b94bcce062e06aff 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Operators.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef RAY_MARCHING_SDF_OPERATORS 14 | #define RAY_MARCHING_SDF_OPERATORS 15 | 16 | // http://www.iquilezles.org/www/articles/smin/smin.htm 17 | // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm 18 | 19 | 20 | // union 21 | //----------------------------------------------------------------------------- 22 | 23 | // raw union 24 | float sdf_uni(float a, float b) 25 | { 26 | return min(a, b); 27 | } 28 | 29 | // smooth quadratic polynomial union (C1 continuity, order-dependent concatenation) 30 | // k = 0.1f is a good default 31 | float sdf_uni_quad(float a, float b, float k) 32 | { 33 | float h = max(k - abs(a - b), 0.0f) / k; 34 | return min(a, b) - h * h * k * (1.0f / 4.0f); 35 | } 36 | 37 | // smooth cubic polynomial union (C2 continuity, order-dependent concatenation) 38 | // k = 0.1f is a good default 39 | float sdf_uni_cubic(float a, float b, float k) 40 | { 41 | float h = max(k - abs(a - b), 0.0f) / k; 42 | return min(a, b) - h * h * h * k * (1.0f / 6.0f); 43 | } 44 | 45 | // smooth exponential union (infinite continuity, order-independent concatenation) 46 | // k = 30.0f is a good default 47 | #define sdf_uni_exp_concat_term(x, k) (exp2(-(k) * (x))) 48 | #define sdf_uni_exp_concat_res(sum, k) (-log2(sum) / (k)) 49 | float sdf_uni_exp(float a, float b, float k) // 2-term concatenation 50 | { 51 | float sum = sdf_uni_exp_concat_term(a, k) + sdf_uni_exp_concat_term(b, k); 52 | return sdf_uni_exp_concat_res(sum, k); 53 | } 54 | 55 | // smooth power union (infinite continuity, order-independent concatenation) 56 | // k = 8.0f is a good default 57 | #define sdf_uni_pow_concat_term(x, k) (pow((x), (k))) 58 | #define sdf_uni_pow_concat_res(sum, prod, k) pow((prod) / (sum), 1.0f / (k)) 59 | float sdf_uni_pow(float a, float b, float k) // 2-term concatenation 60 | { 61 | a = sdf_uni_pow_concat_term(a, k); 62 | b = sdf_uni_pow_concat_term(b, k); 63 | return sdf_uni_pow_concat_res(a + b, a * b, k); 64 | } 65 | 66 | // use cubic polynomial union as default 67 | inline float sdf_uni_smooth(float a, float b, float h) 68 | { 69 | return sdf_uni_cubic(a, b, h); 70 | } 71 | 72 | //----------------------------------------------------------------------------- 73 | // end: union 74 | 75 | 76 | // subtraction 77 | //----------------------------------------------------------------------------- 78 | 79 | // raw subtraction 80 | float sdf_sub(float a, float b) 81 | { 82 | return max(a, -b); 83 | } 84 | 85 | // smooth quadratic polynomial subtraction (C1 continuity, order-dependent concatenation) 86 | // k = 0.1f is a good default 87 | float sdf_sub_quad(float a, float b, float k) 88 | { 89 | float h = max(k - abs(a + b), 0.0f) / k; 90 | return max(a, -b) + h * h * k * (1.0f / 4.0f); 91 | } 92 | 93 | // smooth cubic polynomial subtraction (C2 continuity, order-dependent concatenation) 94 | // k = 0.1f is a good default 95 | float sdf_sub_cubic(float a, float b, float k) 96 | { 97 | float h = max(k - abs(a + b), 0.0f) / k; 98 | return max(a, -b) + h * h * h * k * (1.0f / 6.0f); 99 | } 100 | 101 | // use cubic polynomial subtraction as default 102 | inline float sdf_sub_smooth(float a, float b, float h) 103 | { 104 | return sdf_sub_cubic(a, b, h); 105 | } 106 | 107 | //----------------------------------------------------------------------------- 108 | // end: subtraction 109 | 110 | 111 | // intersection 112 | //----------------------------------------------------------------------------- 113 | 114 | // raw intersection 115 | float sdf_int(float a, float b) 116 | { 117 | return max(a, b); 118 | } 119 | 120 | // smooth quadratic polynomial intersection (C1 continuity, order-dependent concatenation) 121 | // k = 0.1f is a good default 122 | float sdf_int_quad(float a, float b, float k) 123 | { 124 | float h = max(k - abs(a - b), 0.0f) / k; 125 | return max(a, b) + h * h * k * (1.0f / 4.0f); 126 | } 127 | 128 | // smooth cubic polynomial intersection (C2 continuity, order-dependent concatenation) 129 | // k = 0.1f is a good default 130 | float sdf_int_cubic(float a, float b, float k) 131 | { 132 | float h = max(k - abs(a - b), 0.0f) / k; 133 | return max(a, b) + h * h * h * k * (1.0f / 6.0f); 134 | } 135 | 136 | // use cubic polynomial intersection as default 137 | inline float sdf_int_smooth(float a, float b, float h) 138 | { 139 | return sdf_int_cubic(a, b, h); 140 | } 141 | 142 | //----------------------------------------------------------------------------- 143 | // end: intersection 144 | 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Operators.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d0f682991a1efe44b44a0cf8cfc9be6 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Primitives.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef RAY_MARCHING_SDF_PRIMITIVES 14 | #define RAY_MARCHING_SDF_PRIMITIVES 15 | 16 | #include "../../Math/Quaternion.cginc" 17 | #include "Util.cginc" 18 | 19 | // c: center 20 | // r: radius 21 | float sdf_sphere(float3 p, float3 c, float r) 22 | { 23 | p -= c; 24 | return length(p) - r; 25 | } 26 | 27 | // c: center 28 | // h: half extents 29 | // r: radius 30 | // q: rotation 31 | float sdf_box(float3 p, float3 c, float3 h, float4 q = kQuatIdentity, float r = 0.0f) 32 | { 33 | p = quat_rot(quat_inv(q), p - c); 34 | float3 d = abs(p) - h; 35 | return length(max(d, 0.0f)) + min(max_comp(d), 0.0f) - r; 36 | } 37 | 38 | // a: point A 39 | // b: point B 40 | // r: radius 41 | float sdf_capsule(float3 p, float3 a, float3 b, float r) 42 | { 43 | float3 ab = b - a; 44 | float3 ap = p - a; 45 | p -= a + saturate(dot(ap, ab) / dot(ab, ab)) * ab; 46 | return length(p) - r; 47 | } 48 | 49 | // a: point A 50 | // b: point B 51 | // r: radius 52 | float sdf_cylinder(float3 p, float3 a, float3 b, float r) 53 | { 54 | float3 ab = b - a; 55 | float3 ap = p - a; 56 | float t = dot(ap, ab) / dot(ab, ab); 57 | float3 q = a + saturate(t) * ab; 58 | 59 | if (t >= 0.0f && t <= 1.0f) 60 | return length(p - q) - r; 61 | 62 | float3 c = q + limit_length(project_plane(p - q, ab), r); 63 | return length(p - c); 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Primitives.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 72b5425ec4fa01045b01729011c72a72 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/SDF.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef RAY_MARCHING_SDF 14 | #define RAY_MARCHING_SDF 15 | 16 | #include "Primitives.cginc" 17 | #include "Operators.cginc" 18 | #include "Normal.cginc" 19 | #include "Shapes.cginc" 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/SDF.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c288864a6425b3438817ec4721b2251 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Shapes.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef RAY_MARCHING_SDF_SHAPES 14 | #define RAY_MARCHING_SDF_SHAPES 15 | 16 | #include "Primitives.cginc" 17 | 18 | #define kSdfSphere (0) 19 | #define kSdfBox (1) 20 | #define kSdfCapsule (2) 21 | #define kSdfCylinder (3) 22 | 23 | #define kSdfUnion (0) 24 | #define kSdfSubtraction (1) 25 | #define kSdfIntersection (2) 26 | 27 | #define kFltMax (1e32f) 28 | #define kInfinity kFltMax 29 | 30 | struct SdfShape 31 | { 32 | int4 data0; // type, operator 33 | // sphere box capsule cylinder 34 | float4 data1; // c.xyz, r c.xyz, r a.xyz, r a.xyz, r 35 | float4 data2; // h.xyz b.xyz b.xyz 36 | float4 data3; // q 37 | }; 38 | 39 | float sdf_shape(float3 p, SdfShape s) 40 | { 41 | // give ma a break DX11 warnings >:( 42 | // y u no like a switch statement here? 43 | if (s.data0.x == kSdfSphere) 44 | return sdf_sphere(p, s.data1.xyz, s.data1.w); 45 | else if (s.data0.x == kSdfBox) 46 | return sdf_box(p, s.data1.xyz, s.data2.xyz, s.data3, s.data1.w); 47 | else if (s.data0.x == kSdfCapsule) 48 | return sdf_capsule(p, s.data1.xyz, s.data2.xyz, s.data1.w); 49 | else if (s.data0.x == kSdfCylinder) 50 | return sdf_cylinder(p, s.data1.xyz, s.data2.xyz, s.data1.w); 51 | 52 | return kInfinity; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Shapes.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e964a60c868081e4bb2da0a5acd92213 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Util.cginc: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /* 3 | Project - Unity Ray Marching 4 | https://github.com/TheAllenChou/unity-ray-marching 5 | 6 | Author - Ming-Lun "Allen" Chou 7 | Web - http://AllenChou.net 8 | Twitter - @TheAllenChou 9 | 10 | */ 11 | /******************************************************************************/ 12 | 13 | #ifndef RAY_MARCHING_SDF_UTIL 14 | #define RAY_MARCHING_SDF_UTIL 15 | 16 | inline float min_comp(float3 v) 17 | { 18 | return min(v.x, min(v.y, v.z)); 19 | } 20 | 21 | inline float max_comp(float3 v) 22 | { 23 | return max(v.x, max(v.y, v.z)); 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /unity-ray-marching/Assets/Shader/Ray Marching/SDF/Util.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b6c5a40a5d31c0499d02275b38e0666 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /unity-ray-marching/Packages/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "com.unity.2d.sprite": "1.0.0", 4 | "com.unity.2d.tilemap": "1.0.0", 5 | "com.unity.ads": "3.4.4", 6 | "com.unity.analytics": "3.3.5", 7 | "com.unity.collab-proxy": "1.2.16", 8 | "com.unity.ide.rider": "1.1.4", 9 | "com.unity.ide.vscode": "1.1.4", 10 | "com.unity.multiplayer-hlapi": "1.0.4", 11 | "com.unity.purchasing": "2.0.6", 12 | "com.unity.test-framework": "1.1.13", 13 | "com.unity.textmeshpro": "2.0.1", 14 | "com.unity.timeline": "1.2.6", 15 | "com.unity.ugui": "1.0.0", 16 | "com.unity.xr.legacyinputhelpers": "1.3.11", 17 | "com.unity.modules.ai": "1.0.0", 18 | "com.unity.modules.androidjni": "1.0.0", 19 | "com.unity.modules.animation": "1.0.0", 20 | "com.unity.modules.assetbundle": "1.0.0", 21 | "com.unity.modules.audio": "1.0.0", 22 | "com.unity.modules.cloth": "1.0.0", 23 | "com.unity.modules.director": "1.0.0", 24 | "com.unity.modules.imageconversion": "1.0.0", 25 | "com.unity.modules.imgui": "1.0.0", 26 | "com.unity.modules.jsonserialize": "1.0.0", 27 | "com.unity.modules.particlesystem": "1.0.0", 28 | "com.unity.modules.physics": "1.0.0", 29 | "com.unity.modules.physics2d": "1.0.0", 30 | "com.unity.modules.screencapture": "1.0.0", 31 | "com.unity.modules.terrain": "1.0.0", 32 | "com.unity.modules.terrainphysics": "1.0.0", 33 | "com.unity.modules.tilemap": "1.0.0", 34 | "com.unity.modules.ui": "1.0.0", 35 | "com.unity.modules.uielements": "1.0.0", 36 | "com.unity.modules.umbra": "1.0.0", 37 | "com.unity.modules.unityanalytics": "1.0.0", 38 | "com.unity.modules.unitywebrequest": "1.0.0", 39 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0", 40 | "com.unity.modules.unitywebrequestaudio": "1.0.0", 41 | "com.unity.modules.unitywebrequesttexture": "1.0.0", 42 | "com.unity.modules.unitywebrequestwww": "1.0.0", 43 | "com.unity.modules.vehicles": "1.0.0", 44 | "com.unity.modules.video": "1.0.0", 45 | "com.unity.modules.vr": "1.0.0", 46 | "com.unity.modules.wind": "1.0.0", 47 | "com.unity.modules.xr": "1.0.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Volume: 1 8 | Rolloff Scale: 1 9 | Doppler Factor: 1 10 | Default Speaker Mode: 2 11 | m_SampleRate: 0 12 | m_DSPBufferSize: 1024 13 | m_VirtualVoiceCount: 512 14 | m_RealVoiceCount: 32 15 | m_SpatializerPlugin: 16 | m_AmbisonicDecoderPlugin: 17 | m_DisableAudio: 0 18 | m_VirtualizeEffects: 1 19 | m_RequestedDSPBufferSize: 0 20 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 10 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 0 23 | m_ReuseCollisionCallbacks: 0 24 | m_ClothInterCollisionSettingsToggle: 0 25 | m_ContactPairsMode: 0 26 | m_BroadphaseType: 0 27 | m_WorldBounds: 28 | m_Center: {x: 0, y: 0, z: 0} 29 | m_Extent: {x: 250, y: 250, z: 250} 30 | m_WorldSubdivisions: 8 31 | m_FrictionType: 0 32 | m_EnableEnhancedDeterminism: 0 33 | m_EnableUnifiedHeightmaps: 1 34 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: [] 8 | m_configObjects: {} 9 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 9 7 | m_ExternalVersionControlSupport: Hidden Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_PrefabRegularEnvironment: {fileID: 0} 12 | m_PrefabUIEnvironment: {fileID: 0} 13 | m_SpritePackerMode: 0 14 | m_SpritePackerPaddingPower: 1 15 | m_EtcTextureCompressorBehavior: 1 16 | m_EtcTextureFastCompressor: 1 17 | m_EtcTextureNormalCompressor: 2 18 | m_EtcTextureBestCompressor: 4 19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref 20 | m_ProjectGenerationRootNamespace: 21 | m_CollabEditorSettings: 22 | inProgressEnabled: 1 23 | m_EnableTextureStreamingInEditMode: 1 24 | m_EnableTextureStreamingInPlayMode: 1 25 | m_AsyncShaderCompilation: 1 26 | m_EnterPlayModeOptionsEnabled: 0 27 | m_EnterPlayModeOptions: 3 28 | m_ShowLightmapResolutionOverlay: 1 29 | m_UseLegacyProbeSampleCount: 1 30 | m_AssetPipelineMode: 1 31 | m_CacheServerMode: 0 32 | m_CacheServerEndpoint: 33 | m_CacheServerNamespacePrefix: default 34 | m_CacheServerEnableDownload: 1 35 | m_CacheServerEnableUpload: 1 36 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | - {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0} 39 | m_PreloadedShaders: [] 40 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 41 | type: 0} 42 | m_CustomRenderPipeline: {fileID: 0} 43 | m_TransparencySortMode: 0 44 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 45 | m_DefaultRenderingPath: 1 46 | m_DefaultMobileRenderingPath: 1 47 | m_TierSettings: [] 48 | m_LightmapStripping: 0 49 | m_FogStripping: 0 50 | m_InstancingStripping: 0 51 | m_LightmapKeepPlain: 1 52 | m_LightmapKeepDirCombined: 1 53 | m_LightmapKeepDynamicPlain: 1 54 | m_LightmapKeepDynamicDirCombined: 1 55 | m_LightmapKeepShadowMask: 1 56 | m_LightmapKeepSubtractive: 1 57 | m_FogKeepLinear: 1 58 | m_FogKeepExp: 1 59 | m_FogKeepExp2: 1 60 | m_AlbedoSwatchInfos: [] 61 | m_LightsUseLinearIntensity: 0 62 | m_LightsUseColorTemperature: 0 63 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!13 &1 4 | InputManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Axes: 8 | - serializedVersion: 3 9 | m_Name: Horizontal 10 | descriptiveName: 11 | descriptiveNegativeName: 12 | negativeButton: left 13 | positiveButton: right 14 | altNegativeButton: a 15 | altPositiveButton: d 16 | gravity: 3 17 | dead: 0.001 18 | sensitivity: 3 19 | snap: 1 20 | invert: 0 21 | type: 0 22 | axis: 0 23 | joyNum: 0 24 | - serializedVersion: 3 25 | m_Name: Vertical 26 | descriptiveName: 27 | descriptiveNegativeName: 28 | negativeButton: down 29 | positiveButton: up 30 | altNegativeButton: s 31 | altPositiveButton: w 32 | gravity: 3 33 | dead: 0.001 34 | sensitivity: 3 35 | snap: 1 36 | invert: 0 37 | type: 0 38 | axis: 0 39 | joyNum: 0 40 | - serializedVersion: 3 41 | m_Name: Fire1 42 | descriptiveName: 43 | descriptiveNegativeName: 44 | negativeButton: 45 | positiveButton: left ctrl 46 | altNegativeButton: 47 | altPositiveButton: mouse 0 48 | gravity: 1000 49 | dead: 0.001 50 | sensitivity: 1000 51 | snap: 0 52 | invert: 0 53 | type: 0 54 | axis: 0 55 | joyNum: 0 56 | - serializedVersion: 3 57 | m_Name: Fire2 58 | descriptiveName: 59 | descriptiveNegativeName: 60 | negativeButton: 61 | positiveButton: left alt 62 | altNegativeButton: 63 | altPositiveButton: mouse 1 64 | gravity: 1000 65 | dead: 0.001 66 | sensitivity: 1000 67 | snap: 0 68 | invert: 0 69 | type: 0 70 | axis: 0 71 | joyNum: 0 72 | - serializedVersion: 3 73 | m_Name: Fire3 74 | descriptiveName: 75 | descriptiveNegativeName: 76 | negativeButton: 77 | positiveButton: left shift 78 | altNegativeButton: 79 | altPositiveButton: mouse 2 80 | gravity: 1000 81 | dead: 0.001 82 | sensitivity: 1000 83 | snap: 0 84 | invert: 0 85 | type: 0 86 | axis: 0 87 | joyNum: 0 88 | - serializedVersion: 3 89 | m_Name: Jump 90 | descriptiveName: 91 | descriptiveNegativeName: 92 | negativeButton: 93 | positiveButton: space 94 | altNegativeButton: 95 | altPositiveButton: 96 | gravity: 1000 97 | dead: 0.001 98 | sensitivity: 1000 99 | snap: 0 100 | invert: 0 101 | type: 0 102 | axis: 0 103 | joyNum: 0 104 | - serializedVersion: 3 105 | m_Name: Mouse X 106 | descriptiveName: 107 | descriptiveNegativeName: 108 | negativeButton: 109 | positiveButton: 110 | altNegativeButton: 111 | altPositiveButton: 112 | gravity: 0 113 | dead: 0 114 | sensitivity: 0.1 115 | snap: 0 116 | invert: 0 117 | type: 1 118 | axis: 0 119 | joyNum: 0 120 | - serializedVersion: 3 121 | m_Name: Mouse Y 122 | descriptiveName: 123 | descriptiveNegativeName: 124 | negativeButton: 125 | positiveButton: 126 | altNegativeButton: 127 | altPositiveButton: 128 | gravity: 0 129 | dead: 0 130 | sensitivity: 0.1 131 | snap: 0 132 | invert: 0 133 | type: 1 134 | axis: 1 135 | joyNum: 0 136 | - serializedVersion: 3 137 | m_Name: Mouse ScrollWheel 138 | descriptiveName: 139 | descriptiveNegativeName: 140 | negativeButton: 141 | positiveButton: 142 | altNegativeButton: 143 | altPositiveButton: 144 | gravity: 0 145 | dead: 0 146 | sensitivity: 0.1 147 | snap: 0 148 | invert: 0 149 | type: 1 150 | axis: 2 151 | joyNum: 0 152 | - serializedVersion: 3 153 | m_Name: Horizontal 154 | descriptiveName: 155 | descriptiveNegativeName: 156 | negativeButton: 157 | positiveButton: 158 | altNegativeButton: 159 | altPositiveButton: 160 | gravity: 0 161 | dead: 0.19 162 | sensitivity: 1 163 | snap: 0 164 | invert: 0 165 | type: 2 166 | axis: 0 167 | joyNum: 0 168 | - serializedVersion: 3 169 | m_Name: Vertical 170 | descriptiveName: 171 | descriptiveNegativeName: 172 | negativeButton: 173 | positiveButton: 174 | altNegativeButton: 175 | altPositiveButton: 176 | gravity: 0 177 | dead: 0.19 178 | sensitivity: 1 179 | snap: 0 180 | invert: 1 181 | type: 2 182 | axis: 1 183 | joyNum: 0 184 | - serializedVersion: 3 185 | m_Name: Fire1 186 | descriptiveName: 187 | descriptiveNegativeName: 188 | negativeButton: 189 | positiveButton: joystick button 0 190 | altNegativeButton: 191 | altPositiveButton: 192 | gravity: 1000 193 | dead: 0.001 194 | sensitivity: 1000 195 | snap: 0 196 | invert: 0 197 | type: 0 198 | axis: 0 199 | joyNum: 0 200 | - serializedVersion: 3 201 | m_Name: Fire2 202 | descriptiveName: 203 | descriptiveNegativeName: 204 | negativeButton: 205 | positiveButton: joystick button 1 206 | altNegativeButton: 207 | altPositiveButton: 208 | gravity: 1000 209 | dead: 0.001 210 | sensitivity: 1000 211 | snap: 0 212 | invert: 0 213 | type: 0 214 | axis: 0 215 | joyNum: 0 216 | - serializedVersion: 3 217 | m_Name: Fire3 218 | descriptiveName: 219 | descriptiveNegativeName: 220 | negativeButton: 221 | positiveButton: joystick button 2 222 | altNegativeButton: 223 | altPositiveButton: 224 | gravity: 1000 225 | dead: 0.001 226 | sensitivity: 1000 227 | snap: 0 228 | invert: 0 229 | type: 0 230 | axis: 0 231 | joyNum: 0 232 | - serializedVersion: 3 233 | m_Name: Jump 234 | descriptiveName: 235 | descriptiveNegativeName: 236 | negativeButton: 237 | positiveButton: joystick button 3 238 | altNegativeButton: 239 | altPositiveButton: 240 | gravity: 1000 241 | dead: 0.001 242 | sensitivity: 1000 243 | snap: 0 244 | invert: 0 245 | type: 0 246 | axis: 0 247 | joyNum: 0 248 | - serializedVersion: 3 249 | m_Name: Submit 250 | descriptiveName: 251 | descriptiveNegativeName: 252 | negativeButton: 253 | positiveButton: return 254 | altNegativeButton: 255 | altPositiveButton: joystick button 0 256 | gravity: 1000 257 | dead: 0.001 258 | sensitivity: 1000 259 | snap: 0 260 | invert: 0 261 | type: 0 262 | axis: 0 263 | joyNum: 0 264 | - serializedVersion: 3 265 | m_Name: Submit 266 | descriptiveName: 267 | descriptiveNegativeName: 268 | negativeButton: 269 | positiveButton: enter 270 | altNegativeButton: 271 | altPositiveButton: space 272 | gravity: 1000 273 | dead: 0.001 274 | sensitivity: 1000 275 | snap: 0 276 | invert: 0 277 | type: 0 278 | axis: 0 279 | joyNum: 0 280 | - serializedVersion: 3 281 | m_Name: Cancel 282 | descriptiveName: 283 | descriptiveNegativeName: 284 | negativeButton: 285 | positiveButton: escape 286 | altNegativeButton: 287 | altPositiveButton: joystick button 1 288 | gravity: 1000 289 | dead: 0.001 290 | sensitivity: 1000 291 | snap: 0 292 | invert: 0 293 | type: 0 294 | axis: 0 295 | joyNum: 0 296 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_JobOptions: 23 | serializedVersion: 2 24 | useMultithreading: 0 25 | useConsistencySorting: 0 26 | m_InterpolationPosesPerJob: 100 27 | m_NewContactsPerJob: 30 28 | m_CollideContactsPerJob: 100 29 | m_ClearFlagsPerJob: 200 30 | m_ClearBodyForcesPerJob: 200 31 | m_SyncDiscreteFixturesPerJob: 50 32 | m_SyncContinuousFixturesPerJob: 50 33 | m_FindNearestContactsPerJob: 100 34 | m_UpdateTriggerContactsPerJob: 100 35 | m_IslandSolverCostThreshold: 100 36 | m_IslandSolverBodyCostScale: 1 37 | m_IslandSolverContactCostScale: 10 38 | m_IslandSolverJointCostScale: 10 39 | m_IslandSolverBodiesPerJob: 50 40 | m_IslandSolverContactsPerJob: 50 41 | m_AutoSimulation: 1 42 | m_QueriesHitTriggers: 1 43 | m_QueriesStartInColliders: 1 44 | m_CallbacksOnDisable: 1 45 | m_ReuseCollisionCallbacks: 0 46 | m_AutoSyncTransforms: 0 47 | m_AlwaysShowColliders: 0 48 | m_ShowColliderSleep: 1 49 | m_ShowColliderContacts: 0 50 | m_ShowColliderAABB: 0 51 | m_ContactArrowScale: 0.2 52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 57 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | m_DefaultList: [] 7 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2019.3.11f1 2 | m_EditorVersionWithRevision: 2019.3.11f1 (ceef2d848e70) 3 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 5 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | streamingMipmapsActive: 0 33 | streamingMipmapsAddAllCameras: 1 34 | streamingMipmapsMemoryBudget: 512 35 | streamingMipmapsRenderersPerFrame: 512 36 | streamingMipmapsMaxLevelReduction: 2 37 | streamingMipmapsMaxFileIORequests: 1024 38 | particleRaycastBudget: 4 39 | asyncUploadTimeSlice: 2 40 | asyncUploadBufferSize: 16 41 | asyncUploadPersistentBuffer: 1 42 | resolutionScalingFixedDPIFactor: 1 43 | excludedTargetPlatforms: [] 44 | - serializedVersion: 2 45 | name: Low 46 | pixelLightCount: 0 47 | shadows: 0 48 | shadowResolution: 0 49 | shadowProjection: 1 50 | shadowCascades: 1 51 | shadowDistance: 20 52 | shadowNearPlaneOffset: 3 53 | shadowCascade2Split: 0.33333334 54 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 55 | shadowmaskMode: 0 56 | blendWeights: 2 57 | textureQuality: 0 58 | anisotropicTextures: 0 59 | antiAliasing: 0 60 | softParticles: 0 61 | softVegetation: 0 62 | realtimeReflectionProbes: 0 63 | billboardsFaceCameraPosition: 0 64 | vSyncCount: 0 65 | lodBias: 0.4 66 | maximumLODLevel: 0 67 | streamingMipmapsActive: 0 68 | streamingMipmapsAddAllCameras: 1 69 | streamingMipmapsMemoryBudget: 512 70 | streamingMipmapsRenderersPerFrame: 512 71 | streamingMipmapsMaxLevelReduction: 2 72 | streamingMipmapsMaxFileIORequests: 1024 73 | particleRaycastBudget: 16 74 | asyncUploadTimeSlice: 2 75 | asyncUploadBufferSize: 16 76 | asyncUploadPersistentBuffer: 1 77 | resolutionScalingFixedDPIFactor: 1 78 | excludedTargetPlatforms: [] 79 | - serializedVersion: 2 80 | name: Medium 81 | pixelLightCount: 1 82 | shadows: 1 83 | shadowResolution: 0 84 | shadowProjection: 1 85 | shadowCascades: 1 86 | shadowDistance: 20 87 | shadowNearPlaneOffset: 3 88 | shadowCascade2Split: 0.33333334 89 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 90 | shadowmaskMode: 0 91 | blendWeights: 2 92 | textureQuality: 0 93 | anisotropicTextures: 1 94 | antiAliasing: 0 95 | softParticles: 0 96 | softVegetation: 0 97 | realtimeReflectionProbes: 0 98 | billboardsFaceCameraPosition: 0 99 | vSyncCount: 1 100 | lodBias: 0.7 101 | maximumLODLevel: 0 102 | streamingMipmapsActive: 0 103 | streamingMipmapsAddAllCameras: 1 104 | streamingMipmapsMemoryBudget: 512 105 | streamingMipmapsRenderersPerFrame: 512 106 | streamingMipmapsMaxLevelReduction: 2 107 | streamingMipmapsMaxFileIORequests: 1024 108 | particleRaycastBudget: 64 109 | asyncUploadTimeSlice: 2 110 | asyncUploadBufferSize: 16 111 | asyncUploadPersistentBuffer: 1 112 | resolutionScalingFixedDPIFactor: 1 113 | excludedTargetPlatforms: [] 114 | - serializedVersion: 2 115 | name: High 116 | pixelLightCount: 2 117 | shadows: 2 118 | shadowResolution: 1 119 | shadowProjection: 1 120 | shadowCascades: 2 121 | shadowDistance: 40 122 | shadowNearPlaneOffset: 3 123 | shadowCascade2Split: 0.33333334 124 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 125 | shadowmaskMode: 1 126 | blendWeights: 2 127 | textureQuality: 0 128 | anisotropicTextures: 1 129 | antiAliasing: 0 130 | softParticles: 0 131 | softVegetation: 1 132 | realtimeReflectionProbes: 1 133 | billboardsFaceCameraPosition: 1 134 | vSyncCount: 1 135 | lodBias: 1 136 | maximumLODLevel: 0 137 | streamingMipmapsActive: 0 138 | streamingMipmapsAddAllCameras: 1 139 | streamingMipmapsMemoryBudget: 512 140 | streamingMipmapsRenderersPerFrame: 512 141 | streamingMipmapsMaxLevelReduction: 2 142 | streamingMipmapsMaxFileIORequests: 1024 143 | particleRaycastBudget: 256 144 | asyncUploadTimeSlice: 2 145 | asyncUploadBufferSize: 16 146 | asyncUploadPersistentBuffer: 1 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Very High 151 | pixelLightCount: 3 152 | shadows: 2 153 | shadowResolution: 2 154 | shadowProjection: 1 155 | shadowCascades: 2 156 | shadowDistance: 70 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 2 164 | antiAliasing: 2 165 | softParticles: 1 166 | softVegetation: 1 167 | realtimeReflectionProbes: 1 168 | billboardsFaceCameraPosition: 1 169 | vSyncCount: 1 170 | lodBias: 1.5 171 | maximumLODLevel: 0 172 | streamingMipmapsActive: 0 173 | streamingMipmapsAddAllCameras: 1 174 | streamingMipmapsMemoryBudget: 512 175 | streamingMipmapsRenderersPerFrame: 512 176 | streamingMipmapsMaxLevelReduction: 2 177 | streamingMipmapsMaxFileIORequests: 1024 178 | particleRaycastBudget: 1024 179 | asyncUploadTimeSlice: 2 180 | asyncUploadBufferSize: 16 181 | asyncUploadPersistentBuffer: 1 182 | resolutionScalingFixedDPIFactor: 1 183 | excludedTargetPlatforms: [] 184 | - serializedVersion: 2 185 | name: Ultra 186 | pixelLightCount: 4 187 | shadows: 2 188 | shadowResolution: 2 189 | shadowProjection: 1 190 | shadowCascades: 4 191 | shadowDistance: 150 192 | shadowNearPlaneOffset: 3 193 | shadowCascade2Split: 0.33333334 194 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 195 | shadowmaskMode: 1 196 | blendWeights: 4 197 | textureQuality: 0 198 | anisotropicTextures: 2 199 | antiAliasing: 2 200 | softParticles: 1 201 | softVegetation: 1 202 | realtimeReflectionProbes: 1 203 | billboardsFaceCameraPosition: 1 204 | vSyncCount: 1 205 | lodBias: 2 206 | maximumLODLevel: 0 207 | streamingMipmapsActive: 0 208 | streamingMipmapsAddAllCameras: 1 209 | streamingMipmapsMemoryBudget: 512 210 | streamingMipmapsRenderersPerFrame: 512 211 | streamingMipmapsMaxLevelReduction: 2 212 | streamingMipmapsMaxFileIORequests: 1024 213 | particleRaycastBudget: 4096 214 | asyncUploadTimeSlice: 2 215 | asyncUploadBufferSize: 16 216 | asyncUploadPersistentBuffer: 1 217 | resolutionScalingFixedDPIFactor: 1 218 | excludedTargetPlatforms: [] 219 | m_PerPlatformDefaultQuality: 220 | Android: 2 221 | Lumin: 5 222 | Nintendo Switch: 5 223 | PS4: 5 224 | Standalone: 5 225 | WebGL: 3 226 | Windows Store Apps: 5 227 | XboxOne: 5 228 | iPhone: 2 229 | tvOS: 2 230 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.33333334 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 1 7 | m_Enabled: 0 8 | m_TestMode: 0 9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events 10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events 11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com 12 | m_TestInitMode: 0 13 | CrashReportingSettings: 14 | m_EventUrl: https://perf-events.cloud.unity3d.com 15 | m_Enabled: 0 16 | m_LogBufferSize: 10 17 | m_CaptureEditorExceptions: 1 18 | UnityPurchasingSettings: 19 | m_Enabled: 0 20 | m_TestMode: 0 21 | UnityAnalyticsSettings: 22 | m_Enabled: 0 23 | m_TestMode: 0 24 | m_InitializeOnStartup: 1 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/VFXManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!937362698 &1 4 | VFXManager: 5 | m_ObjectHideFlags: 0 6 | m_IndirectShader: {fileID: 0} 7 | m_CopyBufferShader: {fileID: 0} 8 | m_SortShader: {fileID: 0} 9 | m_RenderPipeSettingsPath: 10 | m_FixedTimeStep: 0.016666668 11 | m_MaxDeltaTime: 0.05 12 | -------------------------------------------------------------------------------- /unity-ray-marching/ProjectSettings/XRSettings.asset: -------------------------------------------------------------------------------- 1 | { 2 | "m_SettingKeys": [ 3 | "VR Device Disabled", 4 | "VR Device User Alert" 5 | ], 6 | "m_SettingValues": [ 7 | "False", 8 | "False" 9 | ] 10 | } --------------------------------------------------------------------------------