├── ProjectSettings ├── ProjectVersion.txt ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── TagManager.asset ├── TimeManager.asset ├── EditorSettings.asset ├── NetworkManager.asset ├── DynamicsManager.asset ├── GraphicsSettings.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── Assets ├── Scenes │ ├── Cube.unity │ ├── Room.unity │ ├── Tours.unity │ ├── Repetition.unity │ ├── Fractal Brownian Motion.unity │ ├── Cube.unity.meta │ ├── Room.unity.meta │ ├── Tours.unity.meta │ ├── Repetition.unity.meta │ └── Fractal Brownian Motion.unity.meta ├── Materials │ ├── Room.mat │ ├── Tour.mat │ ├── Repetition.mat │ ├── Raymarching.mat │ ├── Fractal Brownian Motion.mat │ ├── Raymarching room with reflections.mat │ ├── Room.mat.meta │ ├── Tour.mat.meta │ ├── Raymarching.mat.meta │ ├── Repetition.mat.meta │ ├── Fractal Brownian Motion.mat.meta │ └── Raymarching room with reflections.mat.meta ├── Shaders │ ├── Raymarching │ │ ├── Ocean.mat │ │ ├── FBM.shader.meta │ │ ├── Cube.shader.meta │ │ ├── Room.shader.meta │ │ ├── Tours.shader.meta │ │ ├── rhodium.shader.meta │ │ ├── Repetition.shader.meta │ │ ├── Repetition2.shader.meta │ │ ├── metaballs.shader.meta │ │ ├── oren_nayar.shader.meta │ │ ├── sierpinski.shader.meta │ │ ├── voxel_torus.shader.meta │ │ ├── Ocean.mat.meta │ │ ├── Room_Reflection.shader.meta │ │ ├── Shape_blending.shader.meta │ │ ├── orthogonal_sphere.shader.meta │ │ ├── raymarched_plasma.shader.meta │ │ ├── sample_texture.shader.meta │ │ ├── sphere_mapping.shader.meta │ │ ├── terrain_procedural.shader.meta │ │ ├── volumetric_bunny.shader.meta │ │ ├── volumetric_clouds.shader.meta │ │ ├── raycasting_cylinder.shader.meta │ │ ├── terrain_with_heigthmap.shader.meta │ │ ├── shape_blending_with_penumbra.shader.meta │ │ ├── Tours.shader │ │ ├── raymarched_plasma.shader │ │ ├── Repetition.shader │ │ ├── Cube.shader │ │ ├── Repetition2.shader │ │ ├── orthogonal_sphere.shader │ │ ├── terrain_with_heigthmap.shader │ │ ├── raycasting_cylinder.shader │ │ ├── metaballs.shader │ │ ├── Shape_blending.shader │ │ ├── sphere_mapping.shader │ │ ├── terrain_procedural.shader │ │ ├── sample_texture.shader │ │ ├── volumetric_clouds.shader │ │ ├── shape_blending_with_penumbra.shader │ │ ├── voxel_torus.shader │ │ ├── oren_nayar.shader │ │ ├── sierpinski.shader │ │ ├── Room.shader │ │ ├── FBM.shader │ │ ├── Room_Reflection.shader │ │ ├── rhodium.shader │ │ └── volumetric_bunny.shader │ ├── Includes │ │ ├── Math.cginc │ │ ├── Math.cginc.meta │ │ ├── Noise.cginc.meta │ │ ├── Shapes.cginc.meta │ │ ├── Raymarching.cginc.meta │ │ ├── SimpleRaymarching.cginc.meta │ │ ├── SimpleRaymarching.cginc │ │ ├── Noise.cginc │ │ ├── Raymarching.cginc │ │ └── Shapes.cginc │ ├── Includes.meta │ ├── Pattern.meta │ ├── Raymarching.meta │ └── Pattern │ │ ├── voronoi_pattern.shader.meta │ │ └── voronoi_pattern.shader ├── Materials.meta ├── Scenes.meta ├── Scripts.meta ├── Shaders.meta └── Scripts │ ├── GhostCamera.meta │ └── GhostCamera │ ├── GhostFreeRoamCamera.cs.meta │ └── GhostFreeRoamCamera.cs ├── .gitignore ├── .vscode └── settings.json └── README.md /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.6.0f3 2 | -------------------------------------------------------------------------------- /Assets/Scenes/Cube.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Scenes/Cube.unity -------------------------------------------------------------------------------- /Assets/Scenes/Room.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Scenes/Room.unity -------------------------------------------------------------------------------- /Assets/Materials/Room.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Materials/Room.mat -------------------------------------------------------------------------------- /Assets/Materials/Tour.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Materials/Tour.mat -------------------------------------------------------------------------------- /Assets/Scenes/Tours.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Scenes/Tours.unity -------------------------------------------------------------------------------- /Assets/Materials/Repetition.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Materials/Repetition.mat -------------------------------------------------------------------------------- /Assets/Scenes/Repetition.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Scenes/Repetition.unity -------------------------------------------------------------------------------- /Assets/Materials/Raymarching.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Materials/Raymarching.mat -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Ocean.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Shaders/Raymarching/Ocean.mat -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Assets/Materials/Fractal Brownian Motion.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Materials/Fractal Brownian Motion.mat -------------------------------------------------------------------------------- /Assets/Scenes/Fractal Brownian Motion.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Scenes/Fractal Brownian Motion.unity -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/Materials/Raymarching room with reflections.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smkplus/UnityRayMarching/HEAD/Assets/Materials/Raymarching room with reflections.mat -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Math.cginc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // Rotation Matrix 5 | float2x2 rotate(float a) { 6 | return float2x2( cos(a), sin(a), -sin(a), cos(a) ); 7 | } -------------------------------------------------------------------------------- /Assets/Scenes/Cube.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc43be9e574c22f45bb43e05fec2cf4e 3 | timeCreated: 1511007595 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/Room.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77fa0380fabedac4a9ded5293801c446 3 | timeCreated: 1512410948 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/Tours.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad1fab50f3122de48ba9b8899382d43d 3 | timeCreated: 1511164460 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/Repetition.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 48ced4be03350824aa784c1a38e9854f 3 | timeCreated: 1511164460 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 85411fc0f9a93a44982d609a204d7e52 3 | folderAsset: yes 4 | timeCreated: 1511012365 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6180d30bc19d12a4ab145c877f4aeafb 3 | folderAsset: yes 4 | timeCreated: 1511012371 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes/Fractal Brownian Motion.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfd87c5fda19fc543a673ef9e90af58c 3 | timeCreated: 1511164460 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 70701d0f348fea14f9d58dcd443d9867 3 | folderAsset: yes 4 | timeCreated: 1511012226 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7582a4aef57a47940ba37b6f53853579 3 | folderAsset: yes 4 | timeCreated: 1511012226 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/GhostCamera.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74eaf9eaa7c9a6649aebc412c7c759e1 3 | folderAsset: yes 4 | timeCreated: 1511012225 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Includes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ab822e53e14d49439c6c4d88fbff893 3 | folderAsset: yes 4 | timeCreated: 1511323972 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Pattern.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9b77228f5013c64ab935d3f3baa3c83 3 | folderAsset: yes 4 | timeCreated: 1512412662 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bff981f8b5c74f147a9fa11c56e61a5b 3 | folderAsset: yes 4 | timeCreated: 1511408338 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Room.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0faa2a3a360004e4eae1ef4bf6c58921 3 | timeCreated: 1512410981 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Tour.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44a3557dc778b164c9ea7a50525a5aa9 3 | timeCreated: 1511189997 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Math.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 48e5217f3156b20459a74357084197ba 3 | timeCreated: 1511321125 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Noise.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13bdd861a5e229d4f9ab928793fef50d 3 | timeCreated: 1511321125 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Shapes.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f68a0b858b9eb9428170898adce76e7 3 | timeCreated: 1511321125 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/FBM.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 139a1609902a4534bb4f8c5321358612 3 | timeCreated: 1511408416 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Raymarching.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: daaf69bc29369a94e8b22922bec52ad7 3 | timeCreated: 1511321125 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Cube.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f794b8e5990c2348bf96e73319a8401 3 | timeCreated: 1510914667 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Room.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5b558dff95025a4b90fac75af1c27d8 3 | timeCreated: 1512411558 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Tours.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ae72e4577e6533140a94554bcb3af193 3 | timeCreated: 1511164512 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/rhodium.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58cc3473d3370d34297efe210456e8f4 3 | timeCreated: 1512412968 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Raymarching.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c713d7c55840bff419c366f2369a23b1 3 | timeCreated: 1510988636 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Repetition.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d61f5026ff42cc34eb5ad62f7a8797ac 3 | timeCreated: 1511189997 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Includes/SimpleRaymarching.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5116bef8b66e5a145b51de2568d21554 3 | timeCreated: 1511321125 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Pattern/voronoi_pattern.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29f7cb1e9f696d049b62b8eb69ab8cb1 3 | timeCreated: 1512412632 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Repetition.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59df0340bf707744685371f25ed53457 3 | timeCreated: 1511291441 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Repetition2.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 515d938e9f5b92443844b41f4a16b136 3 | timeCreated: 1511291441 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/metaballs.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 918c3160b371475428f4e307ed3ee50c 3 | timeCreated: 1512413477 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/oren_nayar.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b37ed27688b08ad4bbf79c1e0d5fdb23 3 | timeCreated: 1512413298 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/sierpinski.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 359688fef45c40b449c40b470c1beb64 3 | timeCreated: 1512412398 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/voxel_torus.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bca14731354e48649a258f5c754ef4df 3 | timeCreated: 1512412679 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Ocean.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8132006092220e34794e63db9c58ce72 3 | timeCreated: 1512413276 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Room_Reflection.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3972f48041a2581448265bac19ebfbb3 3 | timeCreated: 1512411681 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Shape_blending.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80e7e3b88488da645be9d86c9abe3bf0 3 | timeCreated: 1512411762 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/orthogonal_sphere.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b8092932edc0d94792b4ffeb41c7b09 3 | timeCreated: 1512413405 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/raymarched_plasma.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d0601e4ffcd70b46a619e1e622e33b3 3 | timeCreated: 1512413453 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/sample_texture.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 219bbadc973ff6a4fa64986db34dc74c 3 | timeCreated: 1512413041 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/sphere_mapping.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1b2f98543e6efd4f96f3fef5e9b0f1a 3 | timeCreated: 1512412433 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/terrain_procedural.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 229d2465efa8e1745a50aa01b96c5f02 3 | timeCreated: 1512412884 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/volumetric_bunny.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82d9ab8ef738b174c809dba2b563b327 3 | timeCreated: 1512412523 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/volumetric_clouds.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 08369dacd7a02454592a7105b5da6d01 3 | timeCreated: 1512412537 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Fractal Brownian Motion.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 028772cb39f9924488274713766c2e8c 3 | timeCreated: 1511164793 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/raycasting_cylinder.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 176383c9307045740b653417950b92e9 3 | timeCreated: 1512413079 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/terrain_with_heigthmap.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e4608dfda2a9f6a4abf03f4c1999dc63 3 | timeCreated: 1512412856 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/shape_blending_with_penumbra.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6727b517dc52b1748bdbd4b718195a22 3 | timeCreated: 1512412393 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Raymarching room with reflections.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 416d0493d1cccd347a9c117d5272a696 3 | timeCreated: 1512411698 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/GhostCamera/GhostFreeRoamCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 436275a13d4459746955fc6db5953473 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.pidb.meta 28 | 29 | # Unity3D Generated File On Crash Reports 30 | sysinfo.txt 31 | 32 | # Builds 33 | *.apk 34 | *.unitypackage 35 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Tours.shader: -------------------------------------------------------------------------------- 1 | 2 | 3 | Shader "Abstract" 4 | { 5 | Properties{ 6 | _MinDistance("Min Distance",Float) = 0 7 | } 8 | Subshader 9 | { 10 | 11 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } 12 | Blend SrcAlpha OneMinusSrcAlpha 13 | Pass 14 | { 15 | CGPROGRAM 16 | #pragma vertex vertex_shader 17 | #pragma fragment pixel_shader 18 | 19 | struct custom_type 20 | { 21 | float4 screen_vertex : SV_POSITION; 22 | float3 world_vertex : TEXCOORD1; 23 | }; 24 | #define DISTANCE_FUNCTION DistanceFunction 25 | #include "Assets/Shaders/Includes/Shapes.cginc" 26 | 27 | float DistanceFunction (float3 p) 28 | { 29 | return sdTorus(p,float2(1.0,0.5)); 30 | } 31 | 32 | #include "Assets/Shaders/Includes/Raymarching.cginc" 33 | 34 | ENDCG 35 | 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/raymarched_plasma.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | // source: https://www.shadertoy.com/view/ldSfzm 3 | Shader "Raymarched plasma" 4 | { 5 | Subshader 6 | { 7 | Pass 8 | { 9 | CGPROGRAM 10 | #pragma vertex vertex_shader 11 | #pragma fragment pixel_shader 12 | #pragma target 2.0 13 | 14 | struct custom_type 15 | { 16 | float4 vertex : SV_POSITION; 17 | float2 uv : TEXCOORD0; 18 | }; 19 | 20 | float m(float3 p) 21 | { 22 | p.z+=5.*_Time.g; 23 | return length(.2*sin(p.x-p.y)+cos(p/3.)-.1*sin(1.5*p.x))-.8; 24 | } 25 | 26 | custom_type vertex_shader (float4 vertex : POSITION, float2 uv : TEXCOORD0) 27 | { 28 | custom_type vs; 29 | vs.vertex = UnityObjectToClipPos (vertex); 30 | vs.uv=uv; 31 | return vs; 32 | } 33 | 34 | float4 pixel_shader (custom_type ps) : SV_TARGET 35 | { 36 | float2 u = ps.uv.xy; 37 | float3 d=.5-float3(u,0),o=d; 38 | for(int i=0;i<64;i++) o+=m(o)*d; 39 | return float4(abs(m(o+d)*float3(.3,.15,.1)+m(o*.5)*float3(.1,.05,0))*(8.-o.x/2.),1.0); 40 | } 41 | ENDCG 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Assets/Shaders/Includes/SimpleRaymarching.cginc: -------------------------------------------------------------------------------- 1 | //Raymarching CGINCLUDE 2 | 3 | #include "UnityCG.cginc" 4 | 5 | // Constants 6 | #define STEPS 64 7 | #define MIN_DISTANCE 0.01 8 | 9 | #ifndef DISTANCE_FUNCTION 10 | inline float _DefaultDistanceFunction(float3 pos) 11 | { 12 | return pos; 13 | } 14 | #define DISTANCE_FUNCTION _DefaultDistanceFunction 15 | #endif 16 | 17 | inline float _DistanceFunction(float3 pos) 18 | { 19 | return DISTANCE_FUNCTION(pos); 20 | } 21 | 22 | fixed4 raymarch (float3 position, float3 direction) 23 | { 24 | // Loop do raymarcher. 25 | for (int i = 0; i < STEPS; i++) 26 | { 27 | float distance = _DistanceFunction(position); 28 | if (distance < 0.01) 29 | return i / (float) STEPS; 30 | 31 | position += distance * direction; 32 | } 33 | return 0; 34 | } 35 | 36 | // Vertex function 37 | v2f vert (appdata_full v) 38 | { 39 | v2f o; 40 | o.pos = UnityObjectToClipPos(v.vertex); 41 | o.wPos = mul(unity_ObjectToWorld, v.vertex).xyz; 42 | return o; 43 | } 44 | 45 | 46 | 47 | // Fragment function 48 | fixed4 frag (v2f i) : SV_Target 49 | { 50 | float3 worldPosition = i.wPos; 51 | float3 viewDirection = normalize(i.wPos - _WorldSpaceCameraPos); 52 | return raymarch (worldPosition, viewDirection) * float4(1,1,1,10); 53 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Repetition.shader: -------------------------------------------------------------------------------- 1 | // Created by Seyed Morteza Kamaly - SMK/2017 2 | 3 | //http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm 4 | 5 | Shader "Smkgames/Repetition" 6 | { 7 | Properties 8 | { 9 | _Size("Size",Float) = 15 10 | } 11 | SubShader 12 | { 13 | // No culling 14 | Blend SrcAlpha OneMinusSrcAlpha 15 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } 16 | Pass 17 | { 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | 22 | #include "UnityCG.cginc" 23 | #include "Assets/Shaders/Includes/Shapes.cginc" 24 | #include "Assets/Shaders/Includes/Math.cginc" 25 | 26 | 27 | struct v2f { 28 | float4 pos : SV_POSITION; // Clip space 29 | float3 wPos : TEXCOORD1; // World position 30 | }; 31 | #define DISTANCE_FUNCTION DistanceFunction 32 | // Constants 33 | #define STEPS 64 34 | #define MIN_DISTANCE 1.0 35 | 36 | // Variables 37 | float _Size; 38 | 39 | // Function of distance. 40 | fixed DistanceFunction( fixed3 p ) { 41 | p += fixed3(0,-1,0); 42 | //p.xz = mul(p.xz,rotate(_Time.y)); 43 | return sdBox(opRep(p,fixed3(20.0,20.0,20.0)),fixed3(1.1,1.1,1.1)); 44 | } 45 | #include "Assets/Shaders/Includes/SimpleRaymarching.cginc" 46 | 47 | ENDCG 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Cube.shader: -------------------------------------------------------------------------------- 1 | // Created by Seyed Morteza Kamaly - SMK/2017 2 | 3 | //http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm 4 | 5 | Shader "Smkgames/Raymarcher" 6 | { 7 | Properties 8 | { 9 | _Size("Size",Float) = 15 10 | } 11 | SubShader 12 | { 13 | // No culling 14 | Cull Off ZTest Always 15 | Blend SrcAlpha OneMinusSrcAlpha 16 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } 17 | Pass 18 | { 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | 23 | #include "UnityCG.cginc" 24 | #include "Assets/Shaders/Includes/Shapes.cginc" 25 | #include "Assets/Shaders/Includes/Math.cginc" 26 | 27 | struct v2f { 28 | float4 pos : SV_POSITION; // Clip space 29 | float3 wPos : TEXCOORD1; // World position 30 | }; 31 | 32 | // Variables 33 | float _Size; 34 | 35 | #define DISTANCE_FUNCTION DistanceFunction 36 | // Function of distance. 37 | float DistanceFunction( fixed3 p ) { 38 | p += float3(0,-1,0); 39 | p.xz = mul(p.xz,rotate(_Time.y)); 40 | float Sphere = sdSphere(p,_Size*1.2); 41 | float Box = sdBox(p,float3(_Size,_Size,_Size)); 42 | return opS(Sphere,Box) ; 43 | } 44 | 45 | #include "Assets/Shaders/Includes/SimpleRaymarching.cginc" 46 | 47 | ENDCG 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Noise.cginc: -------------------------------------------------------------------------------- 1 | fixed hash( fixed n ) { return frac(sin(n)*753.5453123); } 2 | 3 | 4 | //--------------------------------------------------------------- 5 | // value noise, and its analytical derivatives 6 | //--------------------------------------------------------------- 7 | 8 | fixed4 noised( in fixed3 x ) 9 | { 10 | fixed3 p = floor(x); 11 | fixed3 w = frac(x); 12 | fixed3 u = w*w*(3.0-2.0*w); 13 | fixed3 du = 6.0*w*(1.0-w); 14 | 15 | fixed n = p.x + p.y*157.0 + 113.0*p.z; 16 | 17 | fixed a = hash(n+ 0.0); 18 | fixed b = hash(n+ 1.0); 19 | fixed c = hash(n+157.0); 20 | fixed d = hash(n+158.0); 21 | fixed e = hash(n+113.0); 22 | fixed f = hash(n+114.0); 23 | fixed g = hash(n+270.0); 24 | fixed h = hash(n+271.0); 25 | 26 | fixed k0 = a; 27 | fixed k1 = b - a; 28 | fixed k2 = c - a; 29 | fixed k3 = e - a; 30 | fixed k4 = a - b - c + d; 31 | fixed k5 = a - c - e + g; 32 | fixed k6 = a - b - e + f; 33 | fixed k7 = - a + b + c - d + e - f - g + h; 34 | 35 | return fixed4( k0 + k1*u.x + k2*u.y + k3*u.z + k4*u.x*u.y + k5*u.y*u.z + k6*u.z*u.x + k7*u.x*u.y*u.z, 36 | du * (fixed3(k1,k2,k3) + u.yzx*fixed3(k4,k5,k6) + u.zxy*fixed3(k6,k4,k5) + k7*u.yzx*u.zxy )); 37 | } 38 | 39 | //--------------------------------------------------------------- 40 | -------------------------------------------------------------------------------- /Assets/Shaders/Pattern/voronoi_pattern.shader: -------------------------------------------------------------------------------- 1 | //source: https://www.shadertoy.com/view/MslGD8 2 | Shader "Voronoi Pattern" 3 | { 4 | Subshader 5 | { 6 | Pass 7 | { 8 | CGPROGRAM 9 | #pragma vertex vertex_shader 10 | #pragma fragment pixel_shader 11 | #pragma target 3.0 12 | 13 | struct custom_type 14 | { 15 | float4 vertex : SV_POSITION; 16 | float2 uv : TEXCOORD0; 17 | }; 18 | 19 | float2 hash (float2 p) 20 | { 21 | p=float2(dot(p,float2(127.1,311.7)),dot(p,float2(269.5,183.3))); 22 | return frac(sin(p)*18.5453); 23 | } 24 | 25 | float2 voronoi (float2 x) 26 | { 27 | float2 n = floor(x); 28 | float2 f = frac(x); 29 | float3 m = float3(8,8,8); 30 | for( int j=-1; j<=1; j++ ) 31 | for( int i=-1; i<=1; i++ ) 32 | { 33 | float2 g = float2( float(i), float(j) ); 34 | float2 o = hash( n + g ); 35 | float2 r = g - f + (0.5+0.5*sin(6.2831*o)); 36 | float d = dot( r, r ); 37 | if( d100.0 || ro.x<-100.0 || ro.z>100.0 || ro.z<-100.0) break; 39 | if ( t<0.0001 && ro.y<6.0) return float4(0.0,0.0,1.0-1.0/ro.y,1.0); 40 | if ( t<0.0001 && ro.y>=6.0) return float4(3.0/ro.y,0.0,0.0,1.0); 41 | ro+=t*rd; 42 | } 43 | return float4(0.0,0.0,0.0,0.0); 44 | } 45 | 46 | custom_type vertex_shader (float4 vertex : POSITION) 47 | { 48 | custom_type vs; 49 | vs.screen_vertex = UnityObjectToClipPos (vertex); 50 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 51 | return vs; 52 | } 53 | 54 | float4 pixel_shader (custom_type ps ) : SV_TARGET 55 | { 56 | float3 worldPosition = ps.world_vertex; 57 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 58 | return raymarch (worldPosition,viewDirection); 59 | } 60 | 61 | ENDCG 62 | 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/raycasting_cylinder.shader: -------------------------------------------------------------------------------- 1 | Shader "Raycasting cylinder" 2 | { 3 | Subshader 4 | { 5 | Tags {"Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent"} 6 | ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off 7 | Pass 8 | { 9 | CGPROGRAM 10 | #pragma vertex vertex_shader 11 | #pragma fragment pixel_shader 12 | #pragma target 4.0 13 | 14 | struct custom_type 15 | { 16 | float4 screen_vertex : SV_POSITION; 17 | float3 world_vertex : TEXCOORD1; 18 | }; 19 | 20 | float4 cylinder(float3 ro,float3 rd, float3 pa,float3 pb, float ra) 21 | { 22 | float3 cc = 0.5*(pa+pb); 23 | float ch = length(pb-pa); 24 | float3 ca = (pb-pa)/ch; 25 | ch *= 0.5; 26 | float3 oc = ro - cc; 27 | float card = dot(ca,rd); 28 | float caoc = dot(ca,oc); 29 | float a = 1.0 - card*card; 30 | float b = dot( oc, rd) - caoc*card; 31 | float c = dot( oc, oc) - caoc*caoc - ra*ra; 32 | float h = b*b - a*c; 33 | if( h<0.0 ) return float4(-1,-1,-1,-1); 34 | h = sqrt(h); 35 | float t1 = (-b-h)/a; 36 | float y = caoc + t1*card; 37 | if( abs(y)0.0 ) 49 | { 50 | float3 pos = ro + t*rd; 51 | float3 nor = tnor.yzw; 52 | float dif = clamp( dot(nor,float3(0.57703,0.57703,0.57703)), 0.0, 1.0 ); 53 | float amb = 0.5 + 0.5*dot(nor,float3(0.0,1.0,0.0)); 54 | return float4(sqrt(float3(0.2,0.3,0.4)*amb+float3(0.8,0.7,0.5)*dif),1.0); 55 | } 56 | else return float4(0,0,0,0); 57 | } 58 | 59 | custom_type vertex_shader (float4 vertex : POSITION) 60 | { 61 | custom_type vs; 62 | vs.screen_vertex = UnityObjectToClipPos (vertex); 63 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 64 | return vs; 65 | } 66 | 67 | float4 pixel_shader (custom_type ps ) : SV_TARGET 68 | { 69 | float3 worldPosition = ps.world_vertex; 70 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 71 | return raycast (worldPosition,viewDirection); 72 | } 73 | 74 | ENDCG 75 | 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/metaballs.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | //usage: like other examples... 5 | Shader "Metaballs" 6 | { 7 | Subshader 8 | { 9 | Tags {"Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent"} 10 | ZWrite Off Blend SrcAlpha OneMinusSrcAlpha 11 | Pass 12 | { 13 | CGPROGRAM 14 | #pragma vertex vertex_shader 15 | #pragma fragment pixel_shader 16 | #pragma target 3.0 17 | 18 | struct custom_type 19 | { 20 | float4 screen_vertex : SV_POSITION; 21 | float3 world_vertex : TEXCOORD1; 22 | }; 23 | 24 | float sphere (float3 p,float3 c,float r) 25 | { 26 | return length (p-c)-r; 27 | } 28 | 29 | float metaballs(float a,float b) 30 | { 31 | float k = 3; 32 | return -log(exp(-k*a)+exp(-k*b))/k; 33 | } 34 | 35 | float map(float3 p) 36 | { 37 | float a = sphere(p,float3(0,0,0),1.0); 38 | float b = sphere(p,float3(3.0*sin(_Time.g),0,0),1.0); 39 | return metaballs(a,b); 40 | } 41 | 42 | float3 set_normal (float3 p) 43 | { 44 | float3 x = float3 (0.01,0.00,0.00); 45 | float3 y = float3 (0.00,0.01,0.00); 46 | float3 z = float3 (0.00,0.00,0.01); 47 | return normalize(float3(map(p+x)-map(p-x),map(p+y)-map(p-y),map(p+z)-map(p-z))); 48 | } 49 | 50 | float4 lighting (float3 p) 51 | { 52 | float3 AmbientLight = float3(0.1,0,0); 53 | float3 LightDirection = normalize(float3(10,55,-30)); 54 | float3 LightColor = float3(1,0,0); 55 | float3 NormalDirection = set_normal(p); 56 | return float4(max(dot(LightDirection, NormalDirection),0.0)*LightColor+AmbientLight,1.0); 57 | } 58 | 59 | float4 raymarch (float3 ro, float3 rd) 60 | { 61 | for (int i=0; i<128; i++) 62 | { 63 | float t = map(ro); 64 | if (t < 0.01) return lighting(ro); 65 | ro+=t*rd; 66 | } 67 | return 0; 68 | } 69 | 70 | custom_type vertex_shader (float4 vertex : POSITION) 71 | { 72 | custom_type vs; 73 | vs.screen_vertex = UnityObjectToClipPos (vertex); 74 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 75 | return vs; 76 | } 77 | 78 | float4 pixel_shader (custom_type ps ) : SV_TARGET 79 | { 80 | float3 worldPosition = ps.world_vertex; 81 | float3 viewDirection = normalize(ps.world_vertex-_WorldSpaceCameraPos.xyz); 82 | return raymarch (worldPosition,viewDirection); 83 | } 84 | 85 | ENDCG 86 | 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Raymarching.cginc: -------------------------------------------------------------------------------- 1 | //Raymarching CGINCLUDE 2 | 3 | #include "UnityCG.cginc" 4 | 5 | float _Limit = 1; 6 | float _MinDistance = 0.001; 7 | 8 | #ifndef DISTANCE_FUNCTION 9 | inline float _DefaultDistanceFunction(float3 pos) 10 | { 11 | return pos; 12 | } 13 | #define DISTANCE_FUNCTION _DefaultDistanceFunction 14 | #endif 15 | 16 | inline float _DistanceFunction(float3 pos) 17 | { 18 | return DISTANCE_FUNCTION(pos); 19 | } 20 | 21 | float ambient_occlusion( float3 pos, float3 nor ) 22 | { 23 | float occ = 0.0; 24 | float sca = 1.0; 25 | for( int i=0; i<5; i++ ) 26 | { 27 | float hr = 0.01 + 0.12*float(i)/4.0; 28 | float3 aopos = nor * hr + pos; 29 | float dd = _DistanceFunction( aopos ); 30 | occ += -(dd-hr)*sca; 31 | sca *= 0.95; 32 | } 33 | return clamp( 1.0 - 3.0*occ, 0.0, 1.0 ); 34 | } 35 | 36 | float3 set_normal (float3 p) 37 | { 38 | float3 x = float3 (0.001,0.00,0.00); 39 | float3 y = float3 (0.00,0.001,0.00); 40 | float3 z = float3 (0.00,0.00,0.001); 41 | return normalize(float3(_DistanceFunction(p+x)-_DistanceFunction(p-x), _DistanceFunction(p+y)-_DistanceFunction(p-y), _DistanceFunction(p+z)-_DistanceFunction(p-z))); 42 | } 43 | 44 | float3 lighting (float3 p) 45 | { 46 | float3 AmbientLight = float3 (0.1,0.1,0.1); 47 | float3 LightDirection = normalize(float3 (4.0,10.0,-10.0)); 48 | float3 LightColor = float3 (1.0,1.0,1.0); 49 | float3 NormalDirection = set_normal(p); 50 | return (max(dot(LightDirection, NormalDirection),0.0) * LightColor + AmbientLight)*ambient_occlusion(p,NormalDirection); 51 | } 52 | 53 | float4 raymarch (float3 ro, float3 rd) 54 | { 55 | for (int i=0; i<128; i++) 56 | { 57 | float ray = _DistanceFunction(ro); 58 | if(_Limit != 0){ 59 | if (distance(ro,ray*rd)>250) break; 60 | } 61 | if (ray < _MinDistance) return float4 (lighting(ro)*float3(1.0,0.0,0.0),1.0); else ro+=ray*rd; 62 | } 63 | return float4 (0.0,0.0,0.0,0.0); 64 | } 65 | 66 | custom_type vertex_shader (float4 vertex : POSITION) 67 | { 68 | custom_type vs; 69 | vs.screen_vertex = UnityObjectToClipPos (vertex); 70 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 71 | return vs; 72 | } 73 | 74 | float4 pixel_shader (custom_type ps ) : SV_TARGET 75 | { 76 | float3 worldPosition = ps.world_vertex; 77 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 78 | return raymarch (worldPosition,viewDirection); 79 | } 80 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Shape_blending.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | //In Unity3D editor, add 3D Object/Quad to Main Camera, then bind material with shader to the quad. Set quad position at (x=0 ; y=0; z=0.4;). Play. 5 | Shader "Shape blending" 6 | { 7 | Subshader 8 | { 9 | Pass 10 | { 11 | CGPROGRAM 12 | #pragma vertex vertex_shader 13 | #pragma fragment pixel_shader 14 | #pragma target 3.0 15 | 16 | static float time = abs(sin(_Time.g)); 17 | struct custom_type 18 | { 19 | float4 screen_vertex : SV_POSITION; 20 | float3 world_vertex : TEXCOORD1; 21 | }; 22 | 23 | float sphere (float3 p,float3 c,float r) 24 | { 25 | return length (p-c)-r; 26 | } 27 | 28 | float cuboid (float3 p,float3 c,float3 s) 29 | { 30 | float3 d = abs(p-c)-s; 31 | return max(max(d.x,d.y),d.z); 32 | } 33 | 34 | float4 rasterize (float3 p) 35 | { 36 | float3 x = float3 (0.01,0.00,0.00); 37 | float3 y = float3 (0.00,0.01,0.00); 38 | float3 z = float3 (0.00,0.00,0.01); 39 | float4 AmbientLight = float4 (1.0,0.0,0.0,0.0); 40 | float4 LightDirection = normalize(float4 (4.0,10.0,-10.0,1.0)); 41 | float4 LightColor = float4 (0.0,1.0,1.0,1.0); 42 | float3 NormalDirection = normalize(float3( 43 | lerp(sphere(p+x,0,1),cuboid(p+x,0,1),time) - lerp(sphere(p-x,0,1),cuboid(p-x,0,1),time), 44 | lerp(sphere(p+y,0,1),cuboid(p+y,0,1),time) - lerp(sphere(p-y,0,1),cuboid(p-y,0,1),time), 45 | lerp(sphere(p+z,0,1),cuboid(p+z,0,1),time) - lerp(sphere(p-z,0,1),cuboid(p-z,0,1),time))); 46 | float4 DiffuseColor = saturate (dot(LightDirection, NormalDirection)) * LightColor + AmbientLight; 47 | return DiffuseColor; 48 | } 49 | 50 | float4 raymarch (float3 ro, float3 rd) 51 | { 52 | for (int i=0; i<128; i++) 53 | { 54 | float t = lerp (sphere(ro,0,1),cuboid(ro,0,1),time); 55 | if (t < 0.01) return rasterize (ro); 56 | ro+=t*rd; 57 | } 58 | return 0; 59 | } 60 | 61 | custom_type vertex_shader (float4 vertex : POSITION) 62 | { 63 | custom_type vs; 64 | vs.screen_vertex = UnityObjectToClipPos (vertex); 65 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 66 | return vs; 67 | } 68 | 69 | float4 pixel_shader (custom_type ps ) : SV_TARGET 70 | { 71 | float3 worldPosition = ps.world_vertex; 72 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos); 73 | return raymarch (worldPosition,viewDirection); 74 | } 75 | 76 | ENDCG 77 | 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/sphere_mapping.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | Shader "Sphere Mapping" 5 | { 6 | Properties 7 | { 8 | _MainTex ("Texture", 2D) = "white" {} 9 | X("UV.X scale",Range(0.00,2.0)) = 1.0 10 | Y("UV.Y scale",Range(0.00,2.0)) = 1.0 11 | } 12 | Subshader 13 | { 14 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } 15 | Pass 16 | { 17 | ZWrite Off 18 | Blend SrcAlpha OneMinusSrcAlpha 19 | CGPROGRAM 20 | #pragma vertex vertex_shader 21 | #pragma fragment pixel_shader 22 | #pragma target 3.0 23 | 24 | float4 _LightColor0; 25 | sampler2D _MainTex; 26 | float X,Y; 27 | 28 | struct custom_type 29 | { 30 | float4 screen_vertex : SV_POSITION; 31 | float3 world_vertex : TEXCOORD1; 32 | }; 33 | 34 | float4 sphere (float3 p,float3 c,float r) 35 | { 36 | return length(p-c)-r; 37 | } 38 | 39 | float map (float3 p) 40 | { 41 | return sphere(p,float3(0,0,0),1.0); 42 | } 43 | 44 | float3 set_normal (float3 p) 45 | { 46 | float3 x = float3 (0.01,0.00,0.00); 47 | float3 y = float3 (0.00,0.01,0.00); 48 | float3 z = float3 (0.00,0.00,0.01); 49 | return normalize(float3(map(p+x)-map(p-x),map(p+y)-map(p-y),map(p+z)-map(p-z))); 50 | } 51 | 52 | float3 set_texture( float3 d, float3 nor ) 53 | { 54 | float2 p = float2(acos(d.y/length(d)), atan2(d.z,d.x))*float2(X,Y); 55 | return tex2Dlod(_MainTex,float4(p,0,0)).xyz; 56 | } 57 | 58 | float3 lighting (float3 p) 59 | { 60 | float3 AmbientLight = UNITY_LIGHTMODEL_AMBIENT; 61 | float3 LightDirection = normalize(_WorldSpaceLightPos0.xyz); 62 | float3 LightColor = _LightColor0.xyz; 63 | float3 NormalDirection = set_normal(p); 64 | return (max(dot(LightDirection, NormalDirection),0.0) * LightColor + AmbientLight)*set_texture(p,NormalDirection);; 65 | } 66 | 67 | float4 raymarch (float3 ro, float3 rd) 68 | { 69 | for (int i=0; i<128; i++) 70 | { 71 | float t = map(ro); 72 | if (distance(ro,t*rd)>250) break; 73 | if (t < 0.001) return float4 (lighting(ro),1.0); 74 | ro+=t*rd; 75 | } 76 | return float4(0.0,0.0,0.0,0.0); 77 | } 78 | 79 | custom_type vertex_shader (float4 vertex : POSITION) 80 | { 81 | custom_type vs; 82 | vs.screen_vertex = UnityObjectToClipPos (vertex); 83 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 84 | return vs; 85 | } 86 | 87 | float4 pixel_shader (custom_type ps ) : SV_TARGET 88 | { 89 | float3 worldPosition = ps.world_vertex; 90 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 91 | return raymarch (worldPosition,viewDirection); 92 | } 93 | 94 | ENDCG 95 | 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/terrain_procedural.shader: -------------------------------------------------------------------------------- 1 | // Set Main Camera to following position (0,50,0). 2 | Shader "Terrain procedural" 3 | { 4 | 5 | Subshader 6 | { 7 | Pass 8 | { 9 | CGPROGRAM 10 | #pragma vertex vertex_shader 11 | #pragma fragment pixel_shader 12 | #pragma target 3.0 13 | 14 | struct custom_type 15 | { 16 | float4 screen_vertex : SV_POSITION; 17 | float3 world_vertex : TEXCOORD1; 18 | }; 19 | 20 | float noise (float3 n) 21 | { 22 | return frac(sin(dot(n, float3(95.43583, 93.323197, 94.993431))) * 65536.32); 23 | } 24 | 25 | float perlin_a (float3 n) 26 | { 27 | float3 base = floor(n * 64.0) * 0.015625; 28 | float3 dd = float3(0.015625, 0.0, 0.0); 29 | float a = noise(base); 30 | float b = noise(base + dd.xyy); 31 | float c = noise(base + dd.yxy); 32 | float d = noise(base + dd.xxy); 33 | float3 p = (n - base) * 64.0; 34 | float t = lerp(a, b, p.x); 35 | float tt = lerp(c, d, p.x); 36 | return lerp(t, tt, p.y); 37 | } 38 | 39 | float perlin_b (float3 n) 40 | { 41 | float3 base = float3(n.x, n.y, floor(n.z * 64.0) * 0.015625); 42 | float3 dd = float3(0.015625, 0.0, 0.0); 43 | float3 p = (n - base) * 64.0; 44 | float front = perlin_a(base + dd.yyy); 45 | float back = perlin_a(base + dd.yyx); 46 | return lerp(front, back, p.z); 47 | } 48 | 49 | float fbm(float3 n) 50 | { 51 | float total = 0.0; 52 | float m1 = 1.0; 53 | float m2 = 0.1; 54 | for (int i = 0; i < 5; i++) 55 | { 56 | total += perlin_b(n * m1) * m2; 57 | m2 *= 2.0; 58 | m1 *= 0.5; 59 | } 60 | return total; 61 | } 62 | 63 | float3 heightmap (float3 n) 64 | { 65 | return float3(fbm((5.0 * n) + fbm((5.0 * n) * 3.0 - 1000.0) * 0.05),0,0); 66 | } 67 | 68 | float map (float3 p) 69 | { 70 | return p.y-32.0*float4(float3((heightmap(float3(p.xz*0.005,1.0)*0.1)-1.0)),1.0).r; 71 | } 72 | 73 | float4 raymarch (float3 ro, float3 rd) 74 | { 75 | for (int i=0; i<512; i++) 76 | { 77 | float t = map(ro); 78 | if (ro.x>300.0 || ro.x<-300.0 || ro.z>300.0 || ro.z<-300.0) break; 79 | if ( t<0.0001 ) return float4(5.0/ro.y,0.0,0.0,1.0); 80 | ro+=t*rd; 81 | } 82 | return float4(0.0,0.0,0.0,0.0); 83 | } 84 | 85 | custom_type vertex_shader (float4 vertex : POSITION) 86 | { 87 | custom_type vs; 88 | vs.screen_vertex = UnityObjectToClipPos (vertex); 89 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 90 | return vs; 91 | } 92 | 93 | float4 pixel_shader (custom_type ps ) : SV_TARGET 94 | { 95 | float3 worldPosition = ps.world_vertex; 96 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 97 | return raymarch (worldPosition,viewDirection); 98 | } 99 | 100 | ENDCG 101 | 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /Assets/Scripts/GhostCamera/GhostFreeRoamCamera.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | [RequireComponent(typeof(Camera))] 4 | public class GhostFreeRoamCamera : MonoBehaviour 5 | { 6 | public float initialSpeed = 10f; 7 | public float increaseSpeed = 1.25f; 8 | 9 | public bool allowMovement = true; 10 | public bool allowRotation = true; 11 | 12 | public KeyCode forwardButton = KeyCode.W; 13 | public KeyCode backwardButton = KeyCode.S; 14 | public KeyCode rightButton = KeyCode.D; 15 | public KeyCode leftButton = KeyCode.A; 16 | 17 | public float cursorSensitivity = 0.025f; 18 | public bool cursorToggleAllowed = true; 19 | public KeyCode cursorToggleButton = KeyCode.Escape; 20 | 21 | private float currentSpeed = 0f; 22 | private bool moving = false; 23 | private bool togglePressed = false; 24 | 25 | private void OnEnable() 26 | { 27 | if (cursorToggleAllowed) 28 | { 29 | Screen.lockCursor = true; 30 | Cursor.visible = false; 31 | } 32 | } 33 | 34 | private void Update() 35 | { 36 | if (allowMovement) 37 | { 38 | bool lastMoving = moving; 39 | Vector3 deltaPosition = Vector3.zero; 40 | 41 | if (moving) 42 | currentSpeed += increaseSpeed * Time.deltaTime; 43 | 44 | moving = false; 45 | 46 | CheckMove(forwardButton, ref deltaPosition, transform.forward); 47 | CheckMove(backwardButton, ref deltaPosition, -transform.forward); 48 | CheckMove(rightButton, ref deltaPosition, transform.right); 49 | CheckMove(leftButton, ref deltaPosition, -transform.right); 50 | 51 | if (moving) 52 | { 53 | if (moving != lastMoving) 54 | currentSpeed = initialSpeed; 55 | 56 | transform.position += deltaPosition * currentSpeed * Time.deltaTime; 57 | } 58 | else currentSpeed = 0f; 59 | } 60 | 61 | if (allowRotation) 62 | { 63 | Vector3 eulerAngles = transform.eulerAngles; 64 | eulerAngles.x += -Input.GetAxis("Mouse Y") * 359f * cursorSensitivity; 65 | eulerAngles.y += Input.GetAxis("Mouse X") * 359f * cursorSensitivity; 66 | transform.eulerAngles = eulerAngles; 67 | } 68 | 69 | if (cursorToggleAllowed) 70 | { 71 | if (Input.GetKey(cursorToggleButton)) 72 | { 73 | if (!togglePressed) 74 | { 75 | togglePressed = true; 76 | Screen.lockCursor = !Screen.lockCursor; 77 | Cursor.visible = !Cursor.visible; 78 | } 79 | } 80 | else togglePressed = false; 81 | } 82 | else 83 | { 84 | togglePressed = false; 85 | Cursor.visible = false; 86 | } 87 | } 88 | 89 | private void CheckMove(KeyCode keyCode, ref Vector3 deltaPosition, Vector3 directionVector) 90 | { 91 | if (Input.GetKey(keyCode)) 92 | { 93 | moving = true; 94 | deltaPosition += directionVector; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/sample_texture.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | Shader "Sample Texture" 5 | { 6 | Properties 7 | { 8 | _MainTex ("Texture", 2D) = "white" {} 9 | } 10 | Subshader 11 | { 12 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } 13 | Pass 14 | { 15 | ZWrite Off 16 | Blend SrcAlpha OneMinusSrcAlpha 17 | CGPROGRAM 18 | #pragma vertex vertex_shader 19 | #pragma fragment pixel_shader 20 | #pragma target 3.0 21 | 22 | float4 _LightColor0; 23 | sampler2D _MainTex; 24 | 25 | struct custom_type 26 | { 27 | float4 screen_vertex : SV_POSITION; 28 | float3 world_vertex : TEXCOORD1; 29 | }; 30 | 31 | float3x3 rotation( float x ) 32 | { 33 | return float3x3 34 | ( 35 | 1.0,0.0,0.0, 36 | 0.0,cos(x),-sin(x), 37 | 0.0,sin(x),cos(x) 38 | ); 39 | } 40 | 41 | float cuboid (float3 p,float3 c,float3 s) 42 | { 43 | float3 d = abs(p-c)-s; 44 | return float(max(max(d.x,d.y),d.z)); 45 | } 46 | 47 | float map (float3 p) 48 | { 49 | p = mul(rotation(_Time.g ),p); 50 | return cuboid(p,float3(0.0,0.0,0.0),float3(1.0,1.0,1.0)); 51 | } 52 | 53 | float3 set_normal (float3 p) 54 | { 55 | float3 x = float3 (0.01,0.00,0.00); 56 | float3 y = float3 (0.00,0.01,0.00); 57 | float3 z = float3 (0.00,0.00,0.01); 58 | return normalize(float3(map(p+x)-map(p-x),map(p+y)-map(p-y),map(p+z)-map(p-z))); 59 | } 60 | 61 | float3 set_texture( float3 pos, float3 nor ) 62 | { 63 | float3 w = nor*nor; 64 | return (w.x*tex2Dlod(_MainTex,float4(pos.yz,0.0,0.0) ) + w.y*tex2Dlod(_MainTex,float4(pos.zx,0.0,0.0))+ w.z*tex2Dlod(_MainTex,float4(pos.xy,0.0,0.0)) / (w.x+w.y+w.z)); 65 | } 66 | 67 | float3 lighting (float3 p) 68 | { 69 | float3 AmbientLight = UNITY_LIGHTMODEL_AMBIENT; 70 | float3 LightDirection = normalize(_WorldSpaceLightPos0.xyz); 71 | float3 LightColor = _LightColor0.xyz; 72 | float3 NormalDirection = set_normal(p); 73 | return (max(dot(LightDirection, NormalDirection),0.0) * LightColor + AmbientLight)*set_texture(p,NormalDirection);; 74 | } 75 | 76 | float4 raymarch (float3 ro, float3 rd) 77 | { 78 | for (int i=0; i<128; i++) 79 | { 80 | float t = map(ro); 81 | if (distance(ro,t*rd)>250) break; 82 | if (t < 0.001) return float4 (lighting(ro),1.0); 83 | ro+=t*rd; 84 | } 85 | return float4(0.0,0.0,0.0,0.0); 86 | } 87 | 88 | custom_type vertex_shader (float4 vertex : POSITION) 89 | { 90 | custom_type vs; 91 | vs.screen_vertex = UnityObjectToClipPos (vertex); 92 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 93 | return vs; 94 | } 95 | 96 | float4 pixel_shader (custom_type ps ) : SV_TARGET 97 | { 98 | float3 worldPosition = ps.world_vertex; 99 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 100 | return raymarch (worldPosition,viewDirection); 101 | } 102 | 103 | ENDCG 104 | 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/volumetric_clouds.shader: -------------------------------------------------------------------------------- 1 | // source: https://www.shadertoy.com/view/4sSBDG and https://www.shadertoy.com/view/XslGRr 2 | //In Unity3D editor, add quad to Main Camera. Bind material with shader to the quad. Set quad position at (0.0,0.0,0.4) and camera position at (0.0,0.0,30.0). Play. 3 | Shader "Volumetric clouds" 4 | { 5 | 6 | Subshader 7 | { 8 | Tags {"Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent"} 9 | ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off 10 | Pass 11 | { 12 | CGPROGRAM 13 | #pragma vertex vertex_shader 14 | #pragma fragment pixel_shader 15 | #pragma target 5.0 16 | 17 | struct custom_type 18 | { 19 | float4 screen_vertex : SV_POSITION; 20 | float3 world_vertex : TEXCOORD1; 21 | }; 22 | 23 | float hash( float n ) 24 | { 25 | return frac(sin(n)*43758.5453); 26 | } 27 | 28 | float noise( in float3 x ) 29 | { 30 | float3 p = floor(x); 31 | float3 f = frac(x); 32 | f = f*f*(3.0-2.0*f); 33 | float n = p.x + p.y * 57.0 + 113.0 * p.z; 34 | float res = lerp(lerp(lerp( hash(n+ 0.0), hash(n+ 1.0),f.x), 35 | lerp( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), 36 | lerp(lerp( hash(n+113.0), hash(n+114.0),f.x), 37 | lerp( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z); 38 | return res; 39 | } 40 | 41 | float fbm( float3 p ) 42 | { 43 | float3 q = p - float3(0.0,0.1,1.0)*_Time.g*0.2; 44 | float f; 45 | f = 0.50000*noise( q ); q = q*2.02; 46 | f += 0.25000*noise( q ); q = q*2.03; 47 | f += 0.12500*noise( q ); q = q*2.01; 48 | f += 0.06250*noise( q ); q = q*2.02; 49 | f += 0.03125*noise( q ); 50 | return clamp( 1.5 - p.y - 2.0 + 1.75*f, 0.0, 30.0 ); 51 | } 52 | 53 | float scene(float3 p) 54 | { 55 | return 0.2 - length(p) * .05 + fbm(p*.3); 56 | } 57 | 58 | custom_type vertex_shader (float4 vertex : POSITION) 59 | { 60 | custom_type vs; 61 | vs.screen_vertex = UnityObjectToClipPos (vertex); 62 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 63 | return vs; 64 | } 65 | 66 | float4 pixel_shader (custom_type ps ) : SV_TARGET 67 | { 68 | float4 color = float4(0,0,0,0); 69 | float3 dir = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 70 | const int nbSample = 128; 71 | const int nbSampleLight = 6; 72 | float zMax = 160.0; 73 | float step = zMax/float(nbSample); 74 | float zMaxl = 20.0; 75 | float stepl = zMaxl/float(nbSampleLight); 76 | float3 p = ps.world_vertex; 77 | float T = 1.0; 78 | float absorption = 100.0; 79 | float3 sun_direction = normalize( float3(0.0,1.0,-1.0) ); 80 | for(int i=0; i0.0) 84 | { 85 | float tmp = density / float(nbSample); 86 | T *= 1. - tmp * absorption; 87 | if( T <= 0.01) break; 88 | float Tl = 1.0; 89 | for(int j=0; j < nbSampleLight; j++) 90 | { 91 | float densityLight = scene( p + normalize(sun_direction) * float(j) * stepl); 92 | if(densityLight > 0.0) Tl *= 1.0-densityLight*absorption/float(nbSample); 93 | if (Tl <= 0.01) break; 94 | } 95 | color += 50. * tmp * T + 80. * tmp * T * Tl; 96 | } 97 | p += dir * step; 98 | } 99 | return color; 100 | } 101 | 102 | ENDCG 103 | 104 | } 105 | } 106 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/shape_blending_with_penumbra.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | Shader "Shape Blending with Penumbra" 5 | { 6 | Subshader 7 | { 8 | Pass 9 | { 10 | CGPROGRAM 11 | #pragma vertex vertex_shader 12 | #pragma fragment pixel_shader 13 | #pragma target 3.0 14 | 15 | struct custom_type 16 | { 17 | float4 screen_vertex : SV_POSITION; 18 | float3 world_vertex : TEXCOORD1; 19 | }; 20 | 21 | float remap (float x, float a, float b, float c, float d) 22 | { 23 | return (x-a)/(b-a)*(d-c) + c; 24 | } 25 | 26 | static float time = remap(sin(_Time.g),-1.0,1.0,0.0,1.0); 27 | 28 | float plane(float3 p) 29 | { 30 | return p.y + 12.0f; 31 | } 32 | 33 | float sphere (float3 p,float3 c,float r) 34 | { 35 | return length (p-c)-r; 36 | } 37 | 38 | float cuboid (float3 p,float3 c,float3 s) 39 | { 40 | float3 d = abs(p-c)-s; 41 | return max(max(d.x,d.y),d.z); 42 | } 43 | 44 | float map (float3 p) 45 | { 46 | return lerp (min(sphere(p,0,1),plane(p)),min(cuboid(p,0,1),plane(p)),time) ; 47 | } 48 | 49 | float3 set_normal (float3 p) 50 | { 51 | float3 x = float3 (0.01,0.00,0.00); 52 | float3 y = float3 (0.00,0.01,0.00); 53 | float3 z = float3 (0.00,0.00,0.01); 54 | return normalize(float3(map(p+x)-map(p-x),map(p+y)-map(p-y),map(p+z)-map(p-z))); 55 | } 56 | 57 | float soft_shadow ( float3 ro, float3 rd, float mint, float maxt, float k ) 58 | { 59 | float t = mint; 60 | float res = 1.0; 61 | for ( int i = 0; i < 128; ++i ) 62 | { 63 | float h = map(ro + rd * t); 64 | if ( h < 0.001 ) return 0.0; 65 | res = min( res, k * h / t ); 66 | t += h; 67 | if ( t > maxt ) break; 68 | } 69 | return res; 70 | } 71 | 72 | float3 lighting (float3 p) 73 | { 74 | float3 LightPosition = float3( 94.0, 15.0, -50.0 ); 75 | LightPosition .x = cos( _Time.g * 0.5 ) * 8.0; 76 | LightPosition .z = sin( _Time.g * 0.5 ) * 8.0; 77 | float3 LightDirection = LightPosition - p; 78 | float LightDistance= length( LightDirection ); 79 | LightDirection = normalize( LightDirection ); 80 | float Shadow = soft_shadow( p, LightDirection , 0.0625, LightDistance,64.0); 81 | float3 AmbientLight = float3 (0.0,0.0,0.0); 82 | float3 LightColor = float3 (1.0,1.0,1.0); 83 | float3 NormalDirection = set_normal(p); 84 | return (saturate (dot(LightDirection , NormalDirection)) * LightColor + AmbientLight) * Shadow; 85 | } 86 | 87 | float4 raymarch (float3 ro, float3 rd) 88 | { 89 | for (int i=0; i<128; i++) 90 | { 91 | float t = map(ro); 92 | if (distance(ro,t*rd)>250) break; 93 | if (t < 0.001) return float4 (lighting(ro),1.0); 94 | ro+=t*rd; 95 | } 96 | return float4(0.0,0.0,0.0,1.0); 97 | } 98 | 99 | custom_type vertex_shader (float4 vertex : POSITION) 100 | { 101 | custom_type vs; 102 | vs.screen_vertex = UnityObjectToClipPos (vertex); 103 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 104 | return vs; 105 | } 106 | 107 | float4 pixel_shader (custom_type ps ) : SV_TARGET 108 | { 109 | float3 worldPosition = ps.world_vertex; 110 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 111 | return raymarch (worldPosition,viewDirection); 112 | } 113 | 114 | ENDCG 115 | 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/voxel_torus.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | //In Unity3D editor, add 3D Object/Quad to Main Camera, then bind material with shader to the quad. Set quad position at (x=0 ; y=0; z=0.4;). 5 | //Set camera position (0,0,-10). Apply fly script to the camera. Play. 6 | Shader "Voxel torus" 7 | { 8 | Subshader 9 | { 10 | Tags {"Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent"} 11 | ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off 12 | Pass 13 | { 14 | CGPROGRAM 15 | #pragma vertex vertex_shader 16 | #pragma fragment pixel_shader 17 | #pragma target 3.0 18 | 19 | struct custom_type 20 | { 21 | float4 screen_vertex : SV_POSITION; 22 | float3 world_vertex : TEXCOORD1; 23 | }; 24 | 25 | static const float voxel_size = 0.1; 26 | 27 | float torus (float3 p, float2 t) //torus signed distance field function 28 | { 29 | float2 q = float2(length(p.xz)-t.x,p.y); 30 | return length(q)-t.y; 31 | } 32 | 33 | float map (float3 p) //scene geometry 34 | { 35 | return torus(p-float3(4,4,4),float2(2.0,0.6)); 36 | } 37 | 38 | float4 lighting (float3 p, float3 normal) //surface color 39 | { 40 | float3 voxel = fmod(p, voxel_size) / voxel_size; 41 | float3 a = max(abs(normal), smoothstep(0.0, 0.1, voxel)); 42 | float3 b = max(abs(normal), smoothstep(0.0, 0.1, 1.0 - voxel)); 43 | float Line = a.x * a.y * a.z *b.x * b.y * b.z; 44 | float4 AmbientLight = float4 (0.2,0.2,0.2,1.0); 45 | float3 LightDirection = normalize(float3(1,1,-20)); 46 | float3 NormalDirection = normal; 47 | float4 LightColor = float4(0.7,0.7,0.7,1.0) ; 48 | float4 Lambert = max(dot(LightDirection,NormalDirection),0.0)*LightColor+AmbientLight; 49 | return lerp(float4(0,0,1,1.0), Lambert, Line); 50 | } 51 | 52 | float4 raymarch (float3 ro, float3 rd) //renderer 53 | { 54 | float3 voxel = floor(ro / voxel_size); 55 | float3 next = ((voxel + max(sign(rd), 0.0)) * voxel_size - ro) / rd; 56 | float3 step = sign(rd); 57 | float3 delta = voxel_size / abs(rd); 58 | float3 normal; 59 | float t = 0.0; 60 | for(int i = 0; i < 256; i++) 61 | { 62 | float d = map(voxel * voxel_size); 63 | if (d < 0.0001) 64 | { 65 | ro += rd*t*(1.0-abs(normal)); 66 | return lighting(ro,normal); 67 | } 68 | if(next.x < next.y && next.x < next.z) 69 | { 70 | voxel.x += step.x; 71 | t = next.x; 72 | next.x += delta.x; 73 | normal = float3(-step.x, 0.0, 0.0); 74 | } 75 | else if(next.y < next.x && next.y < next.z) 76 | { 77 | voxel.y += step.y; 78 | t = next.y; 79 | next.y += delta.y; 80 | normal = float3(0.0, -step.y, 0.0); 81 | } 82 | else if(next.z < next.x && next.z < next.y) 83 | { 84 | voxel.z += step.z; 85 | t = next.z; 86 | next.z += delta.z; 87 | normal = float3(0.0, 0.0, -step.z); 88 | } 89 | } 90 | return float4(0,0,0,0); 91 | } 92 | 93 | custom_type vertex_shader (float4 vertex:POSITION) //vertex shader 94 | { 95 | custom_type vs; 96 | vs.screen_vertex = UnityObjectToClipPos (vertex); 97 | vs.world_vertex = mul(unity_ObjectToWorld,vertex); 98 | return vs; 99 | } 100 | 101 | float4 pixel_shader (custom_type ps ):SV_TARGET //fragment shader 102 | { 103 | float3 worldPosition = ps.world_vertex; 104 | float3 viewDirection = normalize(ps.world_vertex-_WorldSpaceCameraPos.xyz); 105 | return raymarch(worldPosition,viewDirection); 106 | } 107 | 108 | ENDCG 109 | 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/oren_nayar.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | //In Unity3D editor, add 3D Object/Quad to Main Camera, then bind material with shader to the quad. Set quad position at (x=0 ; y=0; z=0.4;). Apply fly script to the camera. Play. 5 | Shader "Oren-Nayar lightmodel" 6 | { 7 | Properties 8 | { 9 | roughness("Roughness",Range(0.0,1.0)) = 0.5 10 | } 11 | Subshader 12 | { 13 | Tags {"Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent"} 14 | ZWrite Off Blend SrcAlpha OneMinusSrcAlpha 15 | Pass 16 | { 17 | CGPROGRAM 18 | #pragma vertex vertex_shader 19 | #pragma fragment pixel_shader 20 | #pragma target 3.0 21 | 22 | float roughness; 23 | 24 | struct custom_type 25 | { 26 | float4 screen_vertex : SV_POSITION; 27 | float3 world_vertex : TEXCOORD1; 28 | }; 29 | 30 | float4 cuboid (float3 p,float3 c,float3 s) 31 | { 32 | float3 m = float3(1.0,1.0,0.0); 33 | float3 d = abs(p-c)-s; 34 | return float4(m,max(max(d.x,d.y),d.z)); 35 | } 36 | 37 | float substraction( float d1, float d2 ) 38 | { 39 | return max(-d1,d2); 40 | } 41 | 42 | float4 map (float3 p) 43 | { 44 | float solid=substraction(cuboid(p,float3(0.0,0.0,0.0),float3(1.0,1.0,6.0)).w,cuboid(p,float3(0.0,0.0,0.0),float3(2.0,2.0,2.0)).w); 45 | solid=substraction(cuboid(p,float3(0.0,0.0,0.0),float3(1.0,6.0,1.0)).w,solid); 46 | solid=substraction(cuboid(p,float3(0.0,0.0,0.0),float3(6.0,1.0,1.0)).w,solid); 47 | return float4(float3(1.0,0.0,0.0),solid); 48 | } 49 | 50 | float3 set_normal (float3 p) 51 | { 52 | float3 x = float3 (0.01,0.00,0.00); 53 | float3 y = float3 (0.00,0.01,0.00); 54 | float3 z = float3 (0.00,0.00,0.01); 55 | return normalize(float3(map(p+x).w-map(p-x).w, map(p+y).w-map(p-y).w, map(p+z).w-map(p-z).w)); 56 | } 57 | 58 | float3 oren_nayar(float3 rd, float3 ld, float3 n) 59 | { 60 | float3 col = float3(0.0,0.0,0.0); 61 | float NdotL = dot(n, ld); 62 | float NdotV = dot(-rd, n); 63 | float angleVN = acos(NdotV); 64 | float angleLN = acos(NdotL); 65 | float mu = roughness; 66 | float A = 1.0-0.5*mu*mu/(mu*mu+0.57); 67 | float B = 0.45*mu*mu/(mu*mu+0.09); 68 | float alpha = max(angleVN, angleLN); 69 | float beta = min(angleVN, angleLN); 70 | float gamma = dot(-rd -(n * NdotV), ld - (n * NdotL)); 71 | float albedo = 1.1; 72 | float e0 = 3.1; 73 | float L1 = max(0.0, NdotL) * (A + B * max(0.0, gamma) * sin(alpha) * tan(beta)); 74 | return float3(1.0,1.0,1.0) * L1; 75 | } 76 | 77 | float3 lighting (float3 p, float3 rd) 78 | { 79 | float3 AmbientLight = float3 (0.5,0.5,0.5); 80 | float3 LightDirection = normalize(float3 (4.0,10.0,-10.0)); 81 | float3 LightColor = float3 (0.0,0.0,1.0); 82 | float3 NormalDirection = set_normal(p); 83 | return oren_nayar (rd,LightDirection,NormalDirection); 84 | } 85 | 86 | float4 raymarch (float3 ro, float3 rd) 87 | { 88 | for (int i=0; i<128; i++) 89 | { 90 | float ray = map(ro).w; 91 | float3 material = map(ro).xyz; 92 | if (ray < 0.001) return float4 (lighting(ro,rd)*material,1.0); else ro+=ray*rd; 93 | } 94 | return float4 (0.0,0.0,0.0,0.0); 95 | } 96 | 97 | custom_type vertex_shader (float4 vertex : POSITION) 98 | { 99 | custom_type vs; 100 | vs.screen_vertex = UnityObjectToClipPos (vertex); 101 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 102 | return vs; 103 | } 104 | 105 | float4 pixel_shader (custom_type ps ) : SV_TARGET 106 | { 107 | float3 worldPosition = ps.world_vertex; 108 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 109 | return raymarch (worldPosition,viewDirection); 110 | } 111 | 112 | ENDCG 113 | 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/sierpinski.shader: -------------------------------------------------------------------------------- 1 | //In Unity3D editor, add quad to Main Camera. Set quad position (0.0;0.0;0.4) and camera position(0,0,-2). Bind material with shader to the quad. Add fly script to the camera. Play. 2 | //source : https://www.shadertoy.com/view/4dl3Wl 3 | Shader "Sierpinski" 4 | { 5 | Subshader 6 | { 7 | Pass 8 | { 9 | CGPROGRAM 10 | #pragma vertex vertex_shader 11 | #pragma fragment pixel_shader 12 | #pragma target 3.0 13 | 14 | static const float3 va = float3( 0.0, 0.57735, 0.0 ); 15 | static const float3 vb = float3( 0.0, -1.0, 1.15470 ); 16 | static const float3 vc = float3( 1.0, -1.0, -0.57735 ); 17 | static const float3 vd = float3( -1.0, -1.0, -0.57735 ); 18 | static const float precis = 0.0002; 19 | 20 | struct custom_type 21 | { 22 | float4 screen_vertex : SV_POSITION; 23 | float3 world_vertex : TEXCOORD1; 24 | }; 25 | 26 | float2 map( float3 p ) 27 | { 28 | float a = 0.0; 29 | float s = 1.0; 30 | float r = 1.0; 31 | float dm; 32 | float3 v; 33 | for( int i=0; i<8; i++ ) 34 | { 35 | float d, t; 36 | d = dot(p-va,p-va); v=va; dm=d; t=0.0; 37 | d = dot(p-vb,p-vb); if( dmaxd ) break; 58 | m = r.y; 59 | t += r.x; 60 | } 61 | if( t0.5 ) 94 | { 95 | float3 pos = ro + tm.x*rd; 96 | float3 nor = calcNormal( pos ); 97 | float3 maa = float3( 0.0,0.0,0.0 ); 98 | maa = 0.5 + 0.5*cos( 6.2831*tm.z + float3(0.0,1.0,2.0) ); 99 | float occ = calcOcclusion( pos, nor ); 100 | float amb = (0.5 + 0.5*nor.y); 101 | float dif = max(dot(nor,lig),0.0); 102 | float3 lin = 1.5*amb*float3(1.0,1.0,1.0) * occ; 103 | col = maa * lin; 104 | } 105 | return col; 106 | } 107 | 108 | custom_type vertex_shader (float4 vertex : POSITION) 109 | { 110 | custom_type vs; 111 | vs.screen_vertex = UnityObjectToClipPos (vertex); 112 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 113 | return vs; 114 | } 115 | 116 | float4 pixel_shader (custom_type ps ) : SV_TARGET 117 | { 118 | float3 worldPosition = ps.world_vertex; 119 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 120 | return float4(render (worldPosition,viewDirection),1.0); 121 | } 122 | 123 | ENDCG 124 | 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Room.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | Shader "Raymarching room" 5 | { 6 | Subshader 7 | { 8 | Pass 9 | { 10 | CGPROGRAM 11 | #pragma vertex vertex_shader 12 | #pragma fragment pixel_shader 13 | #pragma target 3.0 14 | 15 | struct custom_type 16 | { 17 | float4 screen_vertex : SV_POSITION; 18 | float3 world_vertex : TEXCOORD1; 19 | }; 20 | 21 | static float time = sin(_Time.g)*0.5+0.5; 22 | 23 | float4 plane (float3 p, float4 n, float3 m) 24 | { 25 | return float4(m,dot(p,n.xyz) + n.w); 26 | } 27 | 28 | float4 sphere (float3 p,float3 c,float r, float3 m) 29 | { 30 | return float4(m,length (p-c)-r); 31 | } 32 | 33 | float4 map (float3 p) 34 | { 35 | float4 up = plane (p,float4(0.0,-1.0,0.0,20.0),float3(0.0,0.5,0.0)); 36 | float4 down = plane (p,float4(0.0,1.0,0.0,10.0),float3(0.0,0.5,0.0)); 37 | float4 left = plane(p,float4(1.0,0.0,0.0,20.0),float3(1.0,1.0,0.0)); 38 | float4 right = plane (p,float4(-1.0,0.0,0.0,20.0),float3(1.0,1.0,0.0)); 39 | float4 front = plane(p,float4(0.0,0.0,1.0,20.0),float3(0.0,0.0,1.0)); 40 | float4 back = plane(p,float4(0.0,0.0,-1.0,20.0),float3(0.0,0.0,1.0)); 41 | float4 room = lerp(up,down,step(down.w,up.w)); 42 | room = lerp (room,left,step(left.w,room.w)); 43 | room = lerp (room,right,step(right.w,room.w)); 44 | room = lerp (room,front,step(front.w,room.w)); 45 | room = lerp (room,back,step(back.w,room.w)); 46 | return lerp (room,sphere(p,float3(0.0,0.0,0.0),2.0,float3(1.0,1.0,1.0)),step(sphere(p,float3(0.0,0.0,0.0),2.0,float3(1.0,1.0,1.0)).w,room.w)); 47 | } 48 | 49 | float3 set_normal (float3 p) 50 | { 51 | float3 x = float3 (0.01,0.00,0.00); 52 | float3 y = float3 (0.00,0.01,0.00); 53 | float3 z = float3 (0.00,0.00,0.01); 54 | return normalize(float3(map(p+x).w-map(p-x).w,map(p+y).w-map(p-y).w,map(p+z).w-map(p-z).w)); 55 | } 56 | 57 | float soft_shadow ( float3 ro, float3 rd, float mint, float maxt, float k ) 58 | { 59 | float t = mint; 60 | float res = 1.0; 61 | for ( int i = 0; i < 128; ++i ) 62 | { 63 | float h = map(ro + rd * t).w; 64 | if ( h < 0.001 ) return 0.0; 65 | res = min( res, k * h / t ); 66 | t += h; 67 | if ( t > maxt ) break; 68 | } 69 | return res; 70 | } 71 | 72 | float3 lighting (float3 p, float3 ViewDirection) 73 | { 74 | float3 Material = map(p).xyz; 75 | float3 LightPosition = float3( 4.0, 5.0, -10.0 ); 76 | LightPosition .x = cos( _Time.g * 0.5 ) * 8.0; 77 | LightPosition .z = sin( _Time.g * 0.5 ) * 8.0; 78 | float3 LightDirection = LightPosition - p; 79 | float LightDistance= length( LightDirection ); 80 | LightDirection = normalize( LightDirection ); 81 | float Shadow = soft_shadow( p, LightDirection , 0.0625, LightDistance,32.0); 82 | float3 AmbientDiffuseLight = float3 (0.0,0.0,0.0); 83 | float3 AmbientSpecularLight = float3 (0.1,0.1,0.1); 84 | float3 LightColor = float3 (1.0,1.0,1.0); 85 | float3 SpecularBase = float3 (1.0,1.0,1.0); 86 | float SpecularSpread = 50.0; 87 | float SpecularPower = 1.0; 88 | float3 NormalDirection = set_normal(p); 89 | float3 HalfVector = normalize(LightDirection-ViewDirection); 90 | float3 DiffuseColor = max (dot(LightDirection , NormalDirection),0.0) * LightColor * Material; 91 | float3 SpecularColor = pow(clamp (dot(HalfVector, NormalDirection),0.0,1.0),SpecularSpread) * SpecularPower * SpecularBase; 92 | return lerp((DiffuseColor+SpecularColor+AmbientSpecularLight),(DiffuseColor+AmbientDiffuseLight)*Shadow,step(dot(Material,Material),2.99)); 93 | } 94 | 95 | float4 raymarch (float3 ro, float3 rd) 96 | { 97 | for (int i=0; i<128; i++) 98 | { 99 | float ray = map(ro).w; 100 | if (distance(ro,ray*rd)>50) break; 101 | if (ray < 0.001) return float4(lighting(ro,rd),1.0); else ro+=ray*rd; 102 | } 103 | clip(-1); 104 | return float4(0.0,0.0,0.0,1.0); 105 | } 106 | 107 | custom_type vertex_shader (float4 vertex : POSITION) 108 | { 109 | custom_type vs; 110 | vs.screen_vertex = UnityObjectToClipPos (vertex); 111 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 112 | return vs; 113 | } 114 | 115 | float4 pixel_shader (custom_type ps ) : SV_TARGET 116 | { 117 | float3 worldPosition = ps.world_vertex; 118 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 119 | return raymarch (worldPosition,viewDirection); 120 | } 121 | 122 | ENDCG 123 | 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/FBM.shader: -------------------------------------------------------------------------------- 1 | // Created by Seyed Morteza Kamaly - SMK/2017 2 | 3 | //http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm 4 | //http://www.iquilezles.org/www/articles/morenoise/morenoise.htm 5 | //https://www.shadertoy.com/view/XttSz2 6 | 7 | Shader "Smkgames/Abstract/FractalBrownianMotion" 8 | { 9 | Subshader 10 | { 11 | // No culling 12 | Cull Off 13 | Blend SrcAlpha OneMinusSrcAlpha 14 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } 15 | Pass 16 | { 17 | CGPROGRAM 18 | #pragma vertex vertex_shader 19 | #pragma fragment pixel_shader 20 | #pragma target 3.0 21 | 22 | #include "UnityCG.cginc" 23 | 24 | struct VertexInput{ 25 | float2 uv:TEXCOORD0; 26 | float4 vertex:POSITION; 27 | }; 28 | 29 | struct VertexOutput 30 | { 31 | float2 uv : TEXCOORD0; 32 | float4 screen_vertex : SV_POSITION; 33 | float3 world_vertex : TEXCOORD1; 34 | }; 35 | 36 | fixed2x2 rotate(fixed a) { 37 | return fixed2x2( cos(a), sin(a), -sin(a), cos(a) ); 38 | } 39 | 40 | 41 | #include "Assets/Shaders/Includes/Noise.cginc" 42 | #include "Assets/Shaders/Includes/Shapes.cginc" 43 | 44 | 45 | fixed4 sdBox( fixed3 p, fixed3 b ) // distance and normal 46 | { 47 | fixed3 d = abs(p) - b; 48 | fixed x = min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0)); 49 | fixed3 n = step(d.yzx,d.xyz)*step(d.zxy,d.xyz)*sign(p); 50 | return fixed4( x, n ); 51 | } 52 | 53 | 54 | fixed4 fbmd( in fixed3 x ) 55 | { 56 | const fixed scale = 1.5; 57 | 58 | fixed a = 0.0; 59 | fixed b = 0.5; 60 | fixed f = 1.0; 61 | fixed3 d = fixed3(0.0,0.0,0.0); 62 | [unroll(100)] 63 | for( int i=0; i<8; i++ ) 64 | { 65 | fixed4 n = noised(f*x*scale); 66 | a += b*n.x; // accumulate values 67 | d += b*n.yzw*f*scale; // accumulate derivatives 68 | b *= 0.5; // amplitude decrease 69 | f *= 1.8; // frequency increase 70 | } 71 | 72 | return fixed4( a, d ); 73 | } 74 | 75 | // Function of distance. 76 | fixed map( in fixed3 p ) 77 | { 78 | fixed4 d1 = fbmd( p ); 79 | d1.x -= 0.37; 80 | d1.x *= 0.7; 81 | d1.yzw = normalize(d1.yzw); 82 | 83 | // clip to box 84 | fixed4 d2 = sdBox( p, fixed3(1.5,1.5,1.5) ); 85 | return (d1.x>d2.x) ? d1 : d2; 86 | } 87 | 88 | sampler2D _MainTex; 89 | float4 _MainTex_ST; 90 | 91 | 92 | float ambient_occlusion( float3 pos, float3 nor ) 93 | { 94 | float occ = 0.0; 95 | float sca = 1.0; 96 | for( int i=0; i<5; i++ ) 97 | { 98 | float hr = 0.01 + 0.12*float(i)/4.0; 99 | float3 aopos = nor * hr + pos; 100 | float dd = map( aopos ); 101 | occ += -(dd-hr)*sca; 102 | sca *= 0.95; 103 | } 104 | return clamp( 1.0 - 3.0*occ, 0.0, 1.0 ); 105 | } 106 | 107 | float3 set_normal (float3 p) 108 | { 109 | float3 x = float3 (0.001,0.00,0.00); 110 | float3 y = float3 (0.00,0.001,0.00); 111 | float3 z = float3 (0.00,0.00,0.001); 112 | return normalize(float3(map(p+x)-map(p-x), map(p+y)-map(p-y), map(p+z)-map(p-z))); 113 | } 114 | 115 | float3 lighting (float3 p) 116 | { 117 | float3 AmbientLight = float3 (0.1,0.1,0.1); 118 | float3 LightDirection = normalize(float3 (4.0,10.0,-10.0)); 119 | float3 LightColor = float3 (1.0,1.0,1.0); 120 | float3 NormalDirection = set_normal(p); 121 | return (max(dot(LightDirection, NormalDirection),0.0) * LightColor + AmbientLight)*ambient_occlusion(p,NormalDirection); 122 | } 123 | 124 | float4 raymarch (float3 ro, float3 rd) 125 | { 126 | for (int i=0; i<64; i++) 127 | { 128 | float ray = map(ro); 129 | if (distance(ro,ray*rd)>250) break; 130 | if (ray < 0.001) return float4 (lighting(ro),1.0); else ro+=ray*rd; 131 | } 132 | return float4 (0.0,0.0,0.0,0.0); 133 | } 134 | 135 | VertexOutput vertex_shader (VertexInput v) 136 | { 137 | VertexOutput o; 138 | o.screen_vertex = UnityObjectToClipPos (v.vertex); 139 | o.world_vertex = mul (unity_ObjectToWorld, v.vertex); 140 | o.uv = TRANSFORM_TEX (v.uv, _MainTex); 141 | return o; 142 | } 143 | 144 | float4 pixel_shader (VertexOutput i) : SV_TARGET 145 | { 146 | float3 worldPosition = i.world_vertex; 147 | float3 viewDirection = normalize(i.world_vertex - _WorldSpaceCameraPos.xyz); 148 | float4 tex = tex2D(_MainTex,i.uv); 149 | return raymarch (worldPosition,viewDirection); 150 | } 151 | 152 | ENDCG 153 | 154 | } 155 | } 156 | } 157 | 158 | -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/Room_Reflection.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | //In Unity3D editor, add 3D Object/Quad to Main Camera, then bind material with shader to the quad. 5 | //Set quad position at (x=0 ; y=0; z=0.4;) and camera position at (x=0 ; y=0; z=-10;). Apply fly script to the camera. Play. 6 | Shader "Raymarching room with reflections" 7 | { 8 | Subshader 9 | { 10 | Pass 11 | { 12 | CGPROGRAM 13 | #pragma vertex vertex_shader 14 | #pragma fragment pixel_shader 15 | #pragma target 3.0 16 | 17 | struct custom_type 18 | { 19 | float4 screen_vertex : SV_POSITION; 20 | float3 world_vertex : TEXCOORD1; 21 | }; 22 | 23 | float4 plane (float3 p, float4 n, float3 m) 24 | { 25 | return float4(m,dot(p,n.xyz) + n.w); 26 | } 27 | 28 | float4 sphere (float3 p,float3 c,float r, float3 m) 29 | { 30 | return float4(m,length (p-c)-r); 31 | } 32 | 33 | float4 map (float3 p) 34 | { 35 | float4 up = plane (p,float4(0.0,-1.0,0.0,20.0),float3(1.0,0.0,0.0)); 36 | float4 down = plane (p,float4(0.0,1.0,0.0,10.0),float3(0.0,0.5,0.0)); 37 | float4 left = plane(p,float4(1.0,0.0,0.0,20.0),float3(0.7,0.7,0.7)); 38 | float4 right = plane (p,float4(-1.0,0.0,0.0,20.0),float3(1.0,1.0,0.0)); 39 | float4 front = plane(p,float4(0.0,0.0,1.0,20.0),float3(0.1,0.1,0.5)); 40 | float4 back = plane(p,float4(0.0,0.0,-1.0,20.0),float3(0.0,0.0,1.0)); 41 | float4 room = lerp(up,down,step(down.w,up.w)); 42 | room = lerp (room,left,step(left.w,room.w)); 43 | room = lerp (room,right,step(right.w,room.w)); 44 | room = lerp (room,front,step(front.w,room.w)); 45 | room = lerp (room,back,step(back.w,room.w)); 46 | return lerp (room,sphere(p,float3(0.0,0.0,0.0),2.0,float3(1.0,1.0,1.0)),step(sphere(p,float3(0.0,0.0,0.0),2.0,float3(1.0,1.0,1.0)).w,room.w)); 47 | } 48 | 49 | float3 set_normal (float3 p) 50 | { 51 | float3 x = float3 (0.01,0.00,0.00); 52 | float3 y = float3 (0.00,0.01,0.00); 53 | float3 z = float3 (0.00,0.00,0.01); 54 | return normalize(float3(map(p+x).w-map(p-x).w,map(p+y).w-map(p-y).w,map(p+z).w-map(p-z).w)); 55 | } 56 | 57 | float soft_shadow ( float3 ro, float3 rd, float mint, float maxt, float k ) 58 | { 59 | float t = mint; 60 | float res = 1.0; 61 | for ( int i = 0; i < 128; ++i ) 62 | { 63 | float h = map(ro + rd * t).w; 64 | if ( h < 0.001 ) return 0.0; 65 | res = min( res, k * h / t ); 66 | t += h; 67 | if ( t > maxt ) break; 68 | } 69 | return res; 70 | } 71 | 72 | float3 raymarch( float3 ro, float3 rd, float h) 73 | { 74 | for (int i = 0; i < 128; i++) 75 | { 76 | float t = map(ro + h*rd).w; 77 | if (t<0.0001) return ro + h*rd; else h += t; 78 | } 79 | return ro + h*rd; 80 | } 81 | 82 | float3 lambert (float3 p, float3 ViewDirection) 83 | { 84 | float3 Material = map(p).xyz; 85 | float3 LightPosition = float3( 4.0, 5.0, -10.0 ); 86 | LightPosition .x = cos( _Time.g * 0.5 ) * 8.0; 87 | LightPosition .z = sin( _Time.g * 0.5 ) * 8.0; 88 | float3 LightDirection = LightPosition - p; 89 | float LightDistance= length( LightDirection ); 90 | LightDirection = normalize( LightDirection ); 91 | float Shadow = soft_shadow( p, LightDirection , 0.0625, LightDistance,32.0); 92 | float3 AmbientDiffuseLight = float3 (0.0,0.0,0.0); 93 | float3 LightColor = float3 (1.0,1.0,1.0); 94 | float3 NormalDirection = set_normal(p); 95 | float3 DiffuseColor = max (dot(LightDirection , NormalDirection),0.0) * LightColor * Material; 96 | return (DiffuseColor+AmbientDiffuseLight)*Shadow; 97 | } 98 | 99 | float3 blinn_phong (float3 p, float3 ViewDirection) 100 | { 101 | float3 Material = map(p).xyz; 102 | float3 LightPosition = float3( 4.0, 5.0, -10.0 ); 103 | LightPosition .x = cos( _Time.g * 0.5 ) * 8.0; 104 | LightPosition .z = sin( _Time.g * 0.5 ) * 8.0; 105 | float3 LightDirection = normalize(LightPosition - p); 106 | float3 AmbientDiffuseLight = float3 (0.0,0.0,0.0); 107 | float3 AmbientSpecularLight = float3 (0.1,0.1,0.1); 108 | float3 LightColor = float3 (1.0,1.0,1.0); 109 | float3 SpecularBase = float3 (1.0,1.0,1.0); 110 | float SpecularSpread = 50.0; 111 | float SpecularPower = 1.0; 112 | float3 NormalDirection = set_normal(p); 113 | float3 HalfVector = normalize(LightDirection-ViewDirection); 114 | float3 DiffuseColor = max (dot(LightDirection , NormalDirection),0.0) * LightColor * Material; 115 | float3 SpecularColor = (pow(clamp (dot(HalfVector, NormalDirection),0.0,1.0),SpecularSpread) * SpecularPower * SpecularBase); 116 | return (DiffuseColor+SpecularColor+AmbientSpecularLight); 117 | } 118 | 119 | float3 reflection (float3 ro, float3 rd) 120 | { 121 | float3 t = raymarch(ro, rd, 0.01); 122 | float3 ReflectionDirection = reflect(rd, set_normal(t)); 123 | float3 ReflectionPosition = raymarch(t, ReflectionDirection, 0.01); 124 | return lambert(ReflectionPosition, ReflectionDirection); 125 | } 126 | 127 | float3 lighting (float3 ro, float3 rd) 128 | { 129 | float3 t = raymarch(ro,rd,0.0001); 130 | float3 Material = map(t).xyz; 131 | return lerp(blinn_phong(t,rd)*reflection(ro,rd),lambert(t,rd),step(dot(Material,Material),2.99)); 132 | } 133 | 134 | custom_type vertex_shader (float4 vertex : POSITION) 135 | { 136 | custom_type vs; 137 | vs.screen_vertex = UnityObjectToClipPos (vertex); 138 | vs.world_vertex = mul (unity_ObjectToWorld, vertex); 139 | return vs; 140 | } 141 | 142 | float4 pixel_shader (custom_type ps ) : SV_TARGET 143 | { 144 | float3 worldPosition = ps.world_vertex; 145 | float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz); 146 | return float4(lighting(worldPosition,viewDirection),1.0); 147 | } 148 | 149 | ENDCG 150 | 151 | } 152 | } 153 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/rhodium.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | // Original source https://www.shadertoy.com/view/llK3Dy 4 | // Translated from GLSL to CG by Przemyslaw Zaworski 5 | 6 | Shader "Rhodium" 7 | { 8 | Subshader 9 | { 10 | Tags { "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector"="True" } 11 | Pass 12 | { 13 | CGPROGRAM 14 | #pragma vertex vertex_shader 15 | #pragma fragment pixel_shader 16 | #pragma target 4.0 17 | 18 | struct v2f 19 | { 20 | float4 clip_space_position : SV_POSITION; 21 | }; 22 | 23 | static float time = _Time.g; 24 | 25 | float sdBox(float3 p,float3 b) 26 | { 27 | float3 d=abs(p)-b; 28 | return min(max(d.x,max(d.y,d.z)),0.0)+length(max(d,0.0)); 29 | } 30 | 31 | void pR(inout float2 p,float a) 32 | { 33 | p=cos(a)*p+sin(a)*float2(p.y,-p.x); 34 | } 35 | 36 | float noise(float3 p) 37 | { 38 | float3 ip=floor(p); 39 | p-=ip; 40 | float3 s=float3(7,157,113); 41 | float4 h=float4(0.0,s.yz,s.y+s.z)+dot(ip,s); 42 | p=p*p*(3.0-2.0*p); 43 | h=lerp(frac(sin(h)*43758.5),frac(sin(h+s.x)*43758.5),p.x); 44 | h.xy=lerp(h.xz,h.yw,p.y); 45 | return lerp(h.x,h.y,p.z); 46 | } 47 | 48 | float map(float3 p) 49 | { 50 | p.z-=1.0; 51 | p*=0.9; 52 | pR(p.yz,abs(frac(0.05*time)-0.5)*20.0*1.0+0.4*p.x); 53 | return sdBox(p+float3(0,sin(1.6*time),0),float3(20.0, 0.05, 1.2))-0.4*noise(8.0*p+3.0*abs(frac(0.05*time)-0.5)*20.0); 54 | } 55 | 56 | float3 calcNormal(float3 pos) 57 | { 58 | float eps=0.0001; 59 | float d=map(pos); 60 | return normalize(float3(map(pos+float3(eps,0,0))-d,map(pos+float3(0,eps,0))-d,map(pos+float3(0,0,eps))-d)); 61 | } 62 | 63 | 64 | float castRayx(float3 ro,float3 rd) 65 | { 66 | float function_sign=(map(ro)<0.0)?-1.0:1.0; 67 | float precis=0.0001; 68 | float h=precis*2.0; 69 | float t=0.; 70 | for(int i=0;i<120;i++) 71 | { 72 | if(abs(h)12.0)break; 73 | h=function_sign*map(ro+rd*t); 74 | t+=h; 75 | } 76 | return t; 77 | } 78 | 79 | float refr(float3 pos,float3 lig,float3 dir,float3 nor,float angle,out float t2, out float3 nor2) 80 | { 81 | float h=0.0; 82 | t2=2.0; 83 | float3 dir2=refract(dir,nor,angle); 84 | for(int i=0;i<50;i++) 85 | { 86 | if(abs(h)>3.0) break; 87 | h=map(pos+dir2*t2); 88 | t2-=h; 89 | } 90 | nor2=calcNormal(pos+dir2*t2); 91 | return(0.5*clamp(dot(-lig,nor2),0.0,1.0)+pow(max(dot(reflect(dir2,nor2),lig),0.0),8.0)); 92 | } 93 | 94 | float softshadow(float3 ro,float3 rd) 95 | { 96 | float sh=1.0; 97 | float t=0.02; 98 | float h=0.0; 99 | for(int i=0;i<22;i++) 100 | { 101 | if(t>20.0)continue; 102 | h=map(ro+rd*t); 103 | sh=min(sh,4.0*h/t); 104 | t+=h; 105 | } 106 | return sh; 107 | } 108 | 109 | v2f vertex_shader (float4 local_vertex:position) 110 | { 111 | v2f o; 112 | o.clip_space_position = UnityObjectToClipPos(local_vertex); 113 | return o; 114 | } 115 | 116 | float4 pixel_shader (v2f i) : SV_TARGET 117 | { 118 | float2 uv=i.clip_space_position.xy/_ScreenParams.xy; 119 | float2 p=uv*2.-1.; 120 | p.y=-1.0*p.y; 121 | float wobble=(frac(0.1*(time-1.0))>=0.9)?frac(-time)*0.1*sin(30.0*time):0.0; 122 | float3 dir = normalize(float3(2.0*i.clip_space_position.xy -_ScreenParams.xy, _ScreenParams.y)); 123 | float3 org = float3(0,2.*wobble,-3.0); 124 | float3 color = float3(0.0,0.0,0.0); 125 | float3 color2 =float3(0.0,0.0,0.0); 126 | float t=castRayx(org,dir); 127 | float3 pos=org+dir*t; 128 | float3 nor=calcNormal(pos); 129 | float3 lig=normalize(float3(0.2,6.0,0.5)); 130 | float depth=clamp((1.0-0.09*t),0.0,1.0); 131 | float3 pos2 = float3(0.0,0.0,0.0); 132 | float3 nor2 = float3(0.0,0.0,0.0); 133 | if(t<12.0) 134 | { 135 | float cc = pow(max(dot(reflect(dir,nor),lig),0.0),16.0); 136 | color2 = float3(max(dot(lig,nor),0.) + float3(cc,cc,cc)); 137 | color2 *=clamp(softshadow(pos,lig),0.0,1.0); 138 | float t2; 139 | color2.rgb +=refr(pos,lig,dir,nor,0.9, t2, nor2)*depth; 140 | color2-=clamp(0.1*t2,0.0,1.0); 141 | 142 | } 143 | float tmp = 0.; 144 | float T = 1.0; 145 | float intensity = 0.1*-sin(0.209*time+1.0)+0.05; 146 | for(int i=0; i<128; i++) 147 | { 148 | float density = 0.0; 149 | float nebula = noise(org+abs(frac(0.05*time)-.5)*20.0); 150 | density=intensity-map(org+.5*nor2)*nebula; 151 | if(density>0.) 152 | { 153 | tmp = density / 128.; 154 | T *= 1. -tmp * 100.; 155 | if( T <= 0.) break; 156 | } 157 | org += dir*0.078; 158 | } 159 | float3 basecol=float3(1./1. , 1./4. , 1./16.); 160 | T=clamp(T,0.0,1.5); 161 | color += basecol* exp(4.0*(0.5-T) - 0.8); 162 | color2*=depth; 163 | color2+= (1.0-depth)*noise(6.0*dir+0.3*time)*0.1; 164 | return float4(float3(1.*color+0.8*color2)*1.3,abs(0.67-depth)*2.+4.*wobble); 165 | } 166 | 167 | ENDCG 168 | } 169 | 170 | GrabPass { "_bufferA" } 171 | Pass 172 | { 173 | CGPROGRAM 174 | #pragma vertex vertex_shader 175 | #pragma fragment pixel_shader 176 | #pragma target 4.0 177 | 178 | struct v2f 179 | { 180 | float4 clip_space_position : SV_POSITION; 181 | }; 182 | 183 | sampler2D _bufferA; 184 | float GA =2.399; 185 | static float2x2 rot = float2x2(cos(GA),sin(GA),-sin(GA),cos(GA)); 186 | 187 | float3 dof(sampler2D tex,float2 uv,float rad) 188 | { 189 | float3 acc=float3(0.0,0.0,0.0); 190 | float2 angle = float2(0.0,rad); 191 | float2 pixel=float2(0.002*_ScreenParams.y/_ScreenParams.x,0.002); 192 | rad=1.0; 193 | for (int j=0;j<80;j++) 194 | { 195 | rad += 1./rad; 196 | angle=mul(angle,rot); 197 | float4 col=tex2D(tex,uv+pixel*(rad-1.0)*angle); 198 | acc+=col.xyz; 199 | } 200 | return acc/80.0; 201 | } 202 | 203 | 204 | v2f vertex_shader (float4 local_vertex:position) 205 | { 206 | v2f o; 207 | o.clip_space_position = UnityObjectToClipPos(local_vertex); 208 | return o; 209 | } 210 | 211 | float4 pixel_shader (v2f i) : SV_TARGET 212 | { 213 | float2 uv = i.clip_space_position.xy / _ScreenParams.xy; 214 | return float4 (dof(_bufferA,uv,tex2D(_bufferA,uv).w),1.0); 215 | } 216 | 217 | ENDCG 218 | } 219 | } 220 | } -------------------------------------------------------------------------------- /Assets/Shaders/Raymarching/volumetric_bunny.shader: -------------------------------------------------------------------------------- 1 | //source: https://www.shadertoy.com/view/ls2BRt 2 | //In Unity3D editor, add quad to Main Camera. Bind material with shader to the quad. Set quad position at (0.0,0.0,0.4) and camera position at (0.0,0.0,0.0). Play. 3 | Shader "Volumetric Bunny" 4 | { 5 | Subshader 6 | { 7 | Tags {"Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent"} 8 | ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off 9 | Pass 10 | { 11 | CGPROGRAM 12 | 13 | #pragma vertex vertex_shader 14 | #pragma fragment pixel_shader 15 | #pragma target 5.0 16 | 17 | static const uint packedBunny[1024] = 18 | {0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,917504u,917504u,917504u,0u,0u,0u,0u,0u,0u,0u,0u, 19 | 0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,1966080u,12531712u,16742400u,16742400u, 20 | 16723968u,16711680u,8323072u,4128768u,2031616u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u, 21 | 0u,0u,0u,0u,6144u,2063360u,16776704u,33553920u,33553920u,33553920u,33553920u,33520640u,16711680u, 22 | 8323072u,8323072u,2031616u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,268435456u,402653184u,134217728u,201326592u, 23 | 67108864u,0u,0u,7168u,2031104u,16776960u,33554176u,33554176u,33554304u,33554176u,33554176u,33554176u, 24 | 33553920u,16744448u,8323072u,4128768u,1572864u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,805306368u,939524096u,402653184u, 25 | 478150656u,260046848u,260046848u,260046848u,125832192u,130055680u,67108608u,33554304u,33554304u,33554304u, 26 | 33554304u,33554304u,33554304u,33554304u,33554176u,16776704u,8355840u,4128768u,917504u,0u,0u,0u,0u,0u,0u,0u,0u, 27 | 0u,805306368u,1056964608u,1056964608u,528482304u,528482304u,260046848u,260046848u,260046848u,130039296u, 28 | 130154240u,67108739u,67108807u,33554375u,33554375u,33554370u,33554368u,33554368u,33554304u,33554304u,16776960u, 29 | 8330240u,4128768u,393216u,0u,0u,0u,0u,0u,0u,0u,0u,939524096u,1040187392u,1040187392u,520093696u,251658240u, 30 | 251658240u,260046848u,125829120u,125829120u,130088704u,63045504u,33554375u,33554375u,33554375u,33554407u, 31 | 33554407u,33554370u,33554370u,33554374u,33554310u,16776966u,4144642u,917504u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u, 32 | 0u,0u,0u,0u,0u,0u,15360u,130816u,262017u,4194247u,33554383u,67108847u,33554415u,33554407u,33554407u,33554375u, 33 | 33554375u,33554318u,2031502u,32262u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,31744u,130816u,262019u, 34 | 2097151u,134217727u,134217727u,67108863u,33554415u,33554407u,33554415u,33554383u,2097102u,982926u,32262u,0u,0u, 35 | 0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,31744u,130816u,524263u,117964799u,127926271u,134217727u,67108863u, 36 | 16777215u,4194303u,4194303u,2097151u,1048574u,65422u,16134u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u, 37 | 3u,31751u,130951u,524287u,252182527u,261095423u,261095423u,59768830u,2097150u,1048574u,1048575u,262143u,131070u, 38 | 65534u,16134u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,7u,31751u,130959u,503840767u,520617982u, 39 | 529530879u,261095423u,1048575u,1048574u,1048574u,524286u,524287u,131070u,65534u,16134u,0u,0u,0u,0u,0u,0u,0u,0u, 40 | 0u,0u,0u,0u,0u,0u,0u,0u,3u,1799u,32527u,134348750u,1040449534u,1057488894u,520617982u,51380223u,1048575u,1048575u, 41 | 524287u,524287u,524287u,131070u,65534u,15886u,6u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,1536u,3968u,8175u, 42 | 65535u,1006764030u,1040449534u,1057488894u,50855934u,524286u,524286u,524287u,524287u,524286u,262142u,131070u, 43 | 65534u,32270u,14u,6u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,3968u,8160u,8191u,805371903u,2080505854u,2114191358u, 44 | 101187582u,34078718u,524286u,524286u,524286u,524286u,524286u,524286u,262142u,131070u,32766u,8078u,3590u,0u,0u,0u, 45 | 0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,8128u,8176u,16383u,2013331455u,2080505854u,235143166u,101187582u,524286u,1048574u, 46 | 1048574u,1048574u,1048574u,524286u,524286u,262142u,131070u,32766u,16382u,8070u,1024u,0u,0u,0u,0u,0u,0u,0u,0u,0u, 47 | 0u,0u,0u,8160u,8184u,1879064574u,2013331455u,470024190u,67371006u,524286u,1048574u,1048574u,1048574u,1048574u, 48 | 1048574u,1048574u,524286u,524286u,262142u,65534u,16382u,8160u,1024u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,8128u, 49 | 8184u,805322750u,402718719u,134479870u,524286u,524286u,1048574u,1048574u,1048574u,1048574u,1048574u,1048574u, 50 | 1048574u,524286u,262142u,65534u,16382u,16368u,1792u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,3968u,8184u,16382u,131071u, 51 | 262142u,524286u,1048574u,1048574u,1048574u,1048574u,1048574u,1048574u,1048574u,1048574u,524286u,262142u,65534u, 52 | 16382u,16368u,1792u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,1792u,8184u,16380u,65535u,262143u,524286u,524286u, 53 | 1048574u,1048574u,1048575u,1048574u,1048574u,1048574u,1048574u,524286u,262142u,65534u,16376u,16368u,1792u,0u, 54 | 0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,8176u,16376u,32767u,262143u,524286u,1048574u,1048574u,1048575u,1048575u, 55 | 1048575u,1048575u,1048574u,1048574u,524286u,262142u,32766u,16376u,8176u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u, 56 | 0u,0u,4032u,8184u,32766u,262142u,524286u,524286u,1048575u,1048574u,1048574u,1048574u,1048574u,1048574u, 57 | 1048574u,524286u,262142u,32766u,16376u,8176u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,384u,8184u,32766u, 58 | 131070u,262142u,524286u,1048575u,1048574u,1048574u,1048574u,1048574u,1048574u,524286u,524286u,131070u,32766u, 59 | 16368u,1920u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,4080u,32764u,65534u,262142u,524286u,524286u,524286u, 60 | 1048574u,1048574u,524286u,524286u,524286u,262142u,131070u,32764u,8160u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u, 61 | 0u,0u,0u,256u,16376u,32760u,131068u,262140u,262142u,524286u,524286u,524286u,524286u,524286u,262142u,131070u,65532u, 62 | 16368u,3840u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,3968u,32752u,65528u,131068u,262142u,262142u, 63 | 262142u,262142u,262142u,262142u,262140u,131064u,32752u,7936u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u, 64 | 0u,0u,0u,8064u,32736u,65528u,131070u,131070u,131070u,131070u,131070u,131070u,65532u,32752u,8160u,0u,0u,0u,0u, 65 | 0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,3456u,16376u,32764u,65534u,65534u,65534u,32766u,32764u,16380u, 66 | 4048u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,48u,2680u,8188u,8188u,8188u,8188u,4092u, 67 | 120u,16u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,120u,248u,508u,508u,508u,248u, 68 | 240u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,96u,240u,504u,504u,504u,240u,96u, 69 | 0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,0u,224u,224u,224u,0u,0u,0u,0u,0u, 70 | 0u,0u,0u,0u,0u,0u,0u,0u,0u,0u}; 71 | 72 | float voxelB(float x,float y,float z) 73 | { 74 | return float((packedBunny[int(x)+int(y)*32 ] >> int(z) ) % 2u ); 75 | } 76 | 77 | #define rot(a) float2x2(cos(a),-sin(a),sin(a),cos(a)) 78 | 79 | float voxel(float x, float y, float z) 80 | { 81 | int ix = int(x), iy = int(y), iz = int(z); 82 | if (min(ix,min(iy,iz)) < 0 || max(ix,max(iy,iz)) > 30 ) return 0.0; 83 | return lerp( lerp( lerp( voxelB(ix,iy ,iz ), voxelB(ix+1,iy,iz), frac(x)), 84 | lerp( voxelB(ix,iy+1,iz ), voxelB(ix+1,iy+1,iz ), frac(x) ), frac(y)), 85 | lerp( lerp( voxelB(ix,iy ,iz+1), voxelB(ix+1,iy ,iz+1), frac(x)), 86 | lerp( voxelB(ix,iy+1,iz+1),voxelB(ix+1,iy+1,iz+1),frac(x)),frac(y)),frac(z)); 87 | } 88 | 89 | float4 vertex_shader (float4 vertex : POSITION) : SV_POSITION 90 | { 91 | return UnityObjectToClipPos (vertex); 92 | } 93 | 94 | float4 pixel_shader (float4 vertex:SV_POSITION) : SV_TARGET 95 | { 96 | float2 V = 1.7* ((2.0*vertex.xy - _ScreenParams.xy) / _ScreenParams.y); 97 | float4 O = float4(0,0,0,0); 98 | for (float i=-1.; i<1.; i+=1./16.) 99 | { 100 | float3 P = float3( V, i); 101 | P.yz = mul(rot(.78),P.yz); 102 | P.xz = mul(rot(-_Time.g),P.xz); 103 | float3 A = abs(P); 104 | if (max(A.x,max(A.y,A.z))>1.) continue; 105 | P = 16.*(P+1.); 106 | O +=(1.-O.a)*voxel(P.x,P.z,P.y)*float4(float3(.5-.5*i,.5-.5*i,.5-.5*i),1); 107 | } 108 | return O; 109 | } 110 | ENDCG 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /Assets/Shaders/Includes/Shapes.cginc: -------------------------------------------------------------------------------- 1 | //http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm 2 | 3 | //Intro 4 | //After having posted about the basics of distance functions in several places (pouet, my blog, shadertoy, private emails, etc), I thought it might make sense to put these together in centralized place. Here you will find the distance functions for basic primitives, plus the formulas for combining them together for building more complex shapes, as well as some distortion functions that you can use to shape your objects. Hopefully this will be usefull for those rendering scenes with raymarching. You can see some of the results you can get by using these techniques in the raymarching distance fields article. Lastly, this article doesn't include lighting tricks, nor marching acceleartion tricks or more advanced techniques as recursive primitives or fractals. 5 | 6 | //Lengths 7 | float length2( float2 p ) // sqrt(x^2+y^2) 8 | { 9 | return sqrt( p.x*p.x + p.y*p.y ); 10 | } 11 | 12 | float length6( float2 p ) // (x^6+y^6)^(1/6) 13 | { 14 | p = p*p*p; 15 | p = p*p; 16 | return pow( p.x + p.y, 1.0/6.0 ); 17 | } 18 | 19 | float length8( float2 p ) // (x^8+y^8)^(1/8) 20 | { 21 | p = p*p; 22 | p = p*p; 23 | p = p*p; 24 | return pow( p.x + p.y, 1.0/8.0 ); 25 | } 26 | 27 | //primitives 28 | //All primitives are centered at the origin. You will have to transform the point to get arbitrarily rotated, translated and scaled objects (see below). 29 | 30 | 31 | //Sphere - signed - exact 32 | 33 | float sdSphere( float3 p, float s ) 34 | { 35 | return length(p)-s; 36 | } 37 | 38 | 39 | //Box - unsigned - exact 40 | 41 | float udBox( float3 p, float3 b ) 42 | { 43 | return length(max(abs(p)-b,0.0)); 44 | } 45 | 46 | 47 | //Round Box - unsigned - exact 48 | 49 | float udRoundBox( float3 p, float3 b, float r ) 50 | { 51 | return length(max(abs(p)-b,0.0))-r; 52 | } 53 | 54 | 55 | //Box - signed - exact 56 | 57 | float sdBox( float3 p, float3 b ) 58 | { 59 | float3 d = abs(p) - b; 60 | return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0)); 61 | } 62 | 63 | 64 | //Torus - signed - exact 65 | 66 | float sdTorus( float3 p, float2 t ) 67 | { 68 | float2 q = float2(length(p.xz)-t.x,p.y); 69 | return length(q)-t.y; 70 | } 71 | 72 | 73 | //Cylinder - signed - exact 74 | 75 | float sdCylinder( float3 p, float3 c ) 76 | { 77 | return length(p.xz-c.xy)-c.z; 78 | } 79 | 80 | 81 | //Cone - signed - exact 82 | 83 | float sdCone( float3 p, float2 c ) 84 | { 85 | // c must be normalized 86 | float q = length(p.xy); 87 | return dot(c,float2(q,p.z)); 88 | } 89 | 90 | 91 | //Plane - signed - exact 92 | 93 | float sdPlane( float3 p, float4 n ) 94 | { 95 | // n must be normalized 96 | return dot(p,n.xyz) + n.w; 97 | } 98 | 99 | 100 | //Hexagonal Prism - signed - exact 101 | 102 | float sdHexPrism( float3 p, float2 h ) 103 | { 104 | float3 q = abs(p); 105 | return max(q.z-h.y,max((q.x*0.866025+q.y*0.5),q.y)-h.x); 106 | } 107 | 108 | 109 | //Triangular Prism - signed - exact 110 | 111 | float sdTriPrism( float3 p, float2 h ) 112 | { 113 | float3 q = abs(p); 114 | return max(q.z-h.y,max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5); 115 | } 116 | 117 | 118 | //Capsule / Line - signed - exact 119 | 120 | float sdCapsule( float3 p, float3 a, float3 b, float r ) 121 | { 122 | float3 pa = p - a, ba = b - a; 123 | float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); 124 | return length( pa - ba*h ) - r; 125 | } 126 | 127 | 128 | // Capped cylinder - signed - exact 129 | 130 | float sdCappedCylinder( float3 p, float2 h ) 131 | { 132 | float2 d = abs(float2(length(p.xz),p.y)) - h; 133 | return min(max(d.x,d.y),0.0) + length(max(d,0.0)); 134 | } 135 | 136 | 137 | // Capped Cone - signed - bound 138 | 139 | float sdCappedCone( in float3 p, in float3 c ) 140 | { 141 | float2 q = float2( length(p.xz), p.y ); 142 | float2 v = float2( c.z*c.y/c.x, -c.z ); 143 | float2 w = v - q; 144 | float2 vv = float2( dot(v,v), v.x*v.x ); 145 | float2 qv = float2( dot(v,w), v.x*w.x ); 146 | float2 d = max(qv,0.0)*qv/vv; 147 | return sqrt( dot(w,w) - max(d.x,d.y) ) * sign(max(q.y*v.x-q.x*v.y,w.y)); 148 | } 149 | 150 | 151 | // Ellipsoid - signed - bound 152 | 153 | float sdEllipsoid( in float3 p, in float3 r ) 154 | { 155 | return (length( p/r ) - 1.0) * min(min(r.x,r.y),r.z); 156 | } 157 | 158 | 159 | // Triangle - unsigned - exact 160 | float dot2( in float3 v ) { return dot(v,v); } 161 | 162 | float udTriangle( float3 p, float3 a, float3 b, float3 c ) 163 | { 164 | float3 ba = b - a; float3 pa = p - a; 165 | float3 cb = c - b; float3 pb = p - b; 166 | float3 ac = a - c; float3 pc = p - c; 167 | float3 nor = cross( ba, ac ); 168 | 169 | return sqrt( 170 | (sign(dot(cross(ba,nor),pa)) + 171 | sign(dot(cross(cb,nor),pb)) + 172 | sign(dot(cross(ac,nor),pc))<2.0) 173 | ? 174 | min( min( 175 | dot2(ba*clamp(dot(ba,pa)/dot2(ba),0.0,1.0)-pa), 176 | dot2(cb*clamp(dot(cb,pb)/dot2(cb),0.0,1.0)-pb) ), 177 | dot2(ac*clamp(dot(ac,pc)/dot2(ac),0.0,1.0)-pc) ) 178 | : 179 | dot(nor,pa)*dot(nor,pa)/dot2(nor) ); 180 | } 181 | 182 | 183 | // Quad - unsigned - exact 184 | 185 | float udQuad( float3 p, float3 a, float3 b, float3 c, float3 d ) 186 | { 187 | float3 ba = b - a; float3 pa = p - a; 188 | float3 cb = c - b; float3 pb = p - b; 189 | float3 dc = d - c; float3 pc = p - c; 190 | float3 ad = a - d; float3 pd = p - d; 191 | float3 nor = cross( ba, ad ); 192 | 193 | return sqrt( 194 | (sign(dot(cross(ba,nor),pa)) + 195 | sign(dot(cross(cb,nor),pb)) + 196 | sign(dot(cross(dc,nor),pc)) + 197 | sign(dot(cross(ad,nor),pd))<3.0) 198 | ? 199 | min( min( min( 200 | dot2(ba*clamp(dot(ba,pa)/dot2(ba),0.0,1.0)-pa), 201 | dot2(cb*clamp(dot(cb,pb)/dot2(cb),0.0,1.0)-pb) ), 202 | dot2(dc*clamp(dot(dc,pc)/dot2(dc),0.0,1.0)-pc) ), 203 | dot2(ad*clamp(dot(ad,pd)/dot2(ad),0.0,1.0)-pd) ) 204 | : 205 | dot(nor,pa)*dot(nor,pa)/dot2(nor) ); 206 | } 207 | 208 | 209 | 210 | 211 | // Most of these functions can be modified to use other norms than the euclidean. By replacing length(p), which computes (x^2+y^2+z^2)^(1/2) by (x^n+y^n+z^n)^(1/n) one can get variations of the basic primitives that have rounded edges rather than sharp ones. 212 | 213 | 214 | //Torus82 - signed 215 | 216 | float sdTorus82( float3 p, float2 t ) 217 | { 218 | float2 q = float2(length2(p.xz)-t.x,p.y); 219 | return length8(q)-t.y; 220 | } 221 | 222 | 223 | //Torus88 - signed 224 | 225 | float sdTorus88( float3 p, float2 t ) 226 | { 227 | float2 q = float2(length8(p.xz)-t.x,p.y); 228 | return length8(q)-t.y; 229 | } 230 | 231 | 232 | // distance operations 233 | // The d1 and d2 parameters in the following functions are the distance to the two distance fields to combine together. 234 | 235 | 236 | //Union 237 | 238 | float opU( float d1, float d2 ) 239 | { 240 | return min(d1,d2); 241 | } 242 | 243 | 244 | //Substraction 245 | 246 | float opS( float d1, float d2 ) 247 | { 248 | return max(-d1,d2); 249 | } 250 | 251 | 252 | //Intersection 253 | 254 | float opI( float d1, float d2 ) 255 | { 256 | return max(d1,d2); 257 | } 258 | 259 | 260 | 261 | 262 | 263 | // domain operations 264 | // Where "primitive", in the examples below, is any distance formula really (one of the basic primitives above, a combination, or a complex distance field). 265 | 266 | 267 | //Repetition 268 | 269 | float3 opRep( float3 p, float3 c ) 270 | { 271 | float3 q = fmod(p,c)-0.5*c; 272 | return q; 273 | } 274 | 275 | 276 | //Rotation/Translation 277 | 278 | // float3 opTx( float3 p, float4x4 m ) 279 | // { 280 | // float3 q = invert(m)*p; 281 | // return primitive(q); 282 | // } 283 | 284 | 285 | //Scale 286 | 287 | // float opScale( float3 p, float s ) 288 | // { 289 | // return primitive(p/s)*s; 290 | // } 291 | 292 | 293 | 294 | 295 | 296 | //distance deformations 297 | //You must be carefull when using distance transformation functions, as the field created might not be a real distance function anymore. You will probably need to decrease your step size, if you are using a raymarcher to sample this. The displacement example below is using sin(20*p.x)*sin(20*p.y)*sin(20*p.z) as displacement pattern, but you can of course use anything you might imagine. As for smin() function in opBlend(), please read the smooth minimum article in this same site. 298 | 299 | 300 | //Displacement 301 | 302 | // float opDisplace( float3 p ) 303 | // { 304 | // float d1 = primitive(p); 305 | // float d2 = displacement(p); 306 | // return d1+d2; 307 | // } 308 | 309 | 310 | //Blend 311 | 312 | // float opBlend( float3 p ) 313 | // { 314 | // float d1 = primitiveA(p); 315 | // float d2 = primitiveB(p); 316 | // return smin( d1, d2 ); 317 | // } 318 | 319 | 320 | 321 | 322 | 323 | // domain deformations 324 | // Domain deformation functions do not preserve distances neither. You must decrease your marching step to properly sample these functions (proportionally to the maximun derivative of the domain distortion function). Of course, any distortion function can be used, from twists, bends, to random noise driven deformations. 325 | 326 | 327 | //Twist 328 | 329 | // float opTwist( float3 p ) 330 | // { 331 | // float c = cos(20.0*p.y); 332 | // float s = sin(20.0*p.y); 333 | // float2x2 m = float2x2(c,-s,s,c); 334 | // float3 q = float3(mul(m,p.xz),p.y); 335 | // return primitive(q); 336 | // } 337 | 338 | 339 | //Cheap Bend 340 | 341 | // float opCheapBend( float3 p ) 342 | // { 343 | // float c = cos(20.0*p.y); 344 | // float s = sin(20.0*p.y); 345 | // float2x2 m = float2x2(c,-s,s,c); 346 | // float3 q = float3(mul(m,p.xz),p.z); 347 | // return primitive(q); 348 | // } 349 | 350 | --------------------------------------------------------------------------------