From 39d7353464caec6e51599b330a7e34eab7323767 Mon Sep 17 00:00:00 2001 From: Nadine Ganz Date: Wed, 10 Apr 2024 11:17:00 +0200 Subject: [PATCH] Add Depthkit packages and changed manifest file --- .../depthkit.core.shadergraph/CHANGELOG.md | 31 + .../CHANGELOG.md.meta | 7 + .../depthkit.core.shadergraph/Editor.meta | 8 + .../Editor/CoreShaderGraphLookGizmosDrawer.cs | 40 + .../CoreShaderGraphLookGizmosDrawer.cs.meta | 11 + .../Editor/CoreShaderGraphMenu.cs | 44 + .../Editor/CoreShaderGraphMenu.cs.meta | 11 + .../Depthkit.Core.ShaderGraph.Editor.asmdef | 18 + ...pthkit.Core.ShaderGraph.Editor.asmdef.meta | 7 + .../depthkit.core.shadergraph/LICENSE.md | 138 ++++ .../depthkit.core.shadergraph/LICENSE.md.meta | 7 + .../depthkit.core.shadergraph/README.md | 2 + .../depthkit.core.shadergraph/README.md.meta | 7 + .../depthkit.core.shadergraph/Runtime.meta | 8 + .../Runtime/Depthkit.Core.ShaderGraph.asmdef | 16 + .../Depthkit.Core.ShaderGraph.asmdef.meta | 7 + .../Runtime/Looks.meta | 8 + .../Runtime/Looks/CoreShaderGraphLook.cs | 63 ++ .../Runtime/Looks/CoreShaderGraphLook.cs.meta | 11 + .../Runtime/Resources.meta | 8 + .../Runtime/Resources/Shaders.meta | 8 + ...Depthkit Core Photo Look Unlit.shadergraph | 67 ++ ...kit Core Photo Look Unlit.shadergraph.meta | 10 + .../DepthkitCoreFragment.shadersubgraph | 146 ++++ .../DepthkitCoreFragment.shadersubgraph.meta | 10 + .../Shaders/DepthkitVertex.shadersubgraph | 55 ++ .../DepthkitVertex.shadersubgraph.meta | 10 + .../Runtime/Resources/Shaders/Includes.meta | 8 + .../DepthkitCoreSampleTriangleBuffer.hlsl | 15 + ...DepthkitCoreSampleTriangleBuffer.hlsl.meta | 9 + .../Includes/DepthkitCoreShaderGraph.hlsl | 53 ++ .../DepthkitCoreShaderGraph.hlsl.meta | 9 + .../Runtime/ShaderGraphLook.cs | 74 ++ .../Runtime/ShaderGraphLook.cs.meta | 11 + .../depthkit.core.shadergraph/package.json | 28 + .../package.json.meta | 7 + LocalPackages/depthkit.core/CHANGELOG.md | 77 ++ LocalPackages/depthkit.core/CHANGELOG.md.meta | 7 + LocalPackages/depthkit.core/Editor.meta | 8 + .../depthkit.core/Editor/ClipEditor.cs | 184 +++++ .../depthkit.core/Editor/ClipEditor.cs.meta | 11 + .../Editor/Depthkit.Core.Editor.asmdef | 17 + .../Editor/Depthkit.Core.Editor.asmdef.meta | 7 + .../depthkit.core/Editor/EditorUtil.cs | 44 + .../depthkit.core/Editor/EditorUtil.cs.meta | 11 + LocalPackages/depthkit.core/Editor/Looks.meta | 8 + .../Editor/Looks/CoreLookGizmosDrawer.cs | 40 + .../Editor/Looks/CoreLookGizmosDrawer.cs.meta | 11 + .../depthkit.core/Editor/PlayerProcessor.cs | 87 ++ .../Editor/PlayerProcessor.cs.meta | 11 + .../depthkit.core/Editor/Sources.meta | 8 + .../Editor/Sources/CoreMeshSourceEditor.cs | 233 ++++++ .../Sources/CoreMeshSourceEditor.cs.meta | 11 + .../Editor/Sources/MaskGeneratorGUI.cs | 214 +++++ .../Editor/Sources/MaskGeneratorGUI.cs.meta | 11 + .../Editor/depthkit-symbol-64.png | Bin 0 -> 5387 bytes .../Editor/depthkit-symbol-64.png.meta | 92 +++ LocalPackages/depthkit.core/LICENSE.md | 138 ++++ LocalPackages/depthkit.core/LICENSE.md.meta | 7 + LocalPackages/depthkit.core/README.md | 2 + LocalPackages/depthkit.core/README.md.meta | 7 + LocalPackages/depthkit.core/Runtime.meta | 8 + LocalPackages/depthkit.core/Runtime/Clip.cs | 761 ++++++++++++++++++ .../depthkit.core/Runtime/Clip.cs.meta | 11 + .../depthkit.core/Runtime/DataSource.meta | 8 + .../Runtime/DataSource/CoreMeshSource.cs | 495 ++++++++++++ .../Runtime/DataSource/CoreMeshSource.cs.meta | 11 + .../Runtime/DataSource/DataSource.cs | 323 ++++++++ .../Runtime/DataSource/DataSource.cs.meta | 11 + .../Runtime/DataSource/DataSourceEvents.cs | 103 +++ .../DataSource/DataSourceEvents.cs.meta | 11 + .../Runtime/DataSource/MaskGenerator.cs | 409 ++++++++++ .../Runtime/DataSource/MaskGenerator.cs.meta | 11 + .../Runtime/DataSource/MeshSource.cs | 497 ++++++++++++ .../Runtime/DataSource/MeshSource.cs.meta | 11 + .../Runtime/DataSource/SubMesh.cs | 200 +++++ .../Runtime/DataSource/SubMesh.cs.meta | 11 + .../Runtime/Depthkit.Core.asmdef | 14 + .../Runtime/Depthkit.Core.asmdef.meta | 7 + .../depthkit.core/Runtime/Interfaces.meta | 8 + .../Runtime/Interfaces/IPropertyTransfer.cs | 33 + .../Interfaces/IPropertyTransfer.cs.meta | 11 + .../depthkit.core/Runtime/Looks.meta | 8 + .../depthkit.core/Runtime/Looks/CoreLook.cs | 70 ++ .../Runtime/Looks/CoreLook.cs.meta | 11 + .../depthkit.core/Runtime/Looks/Look.cs | 238 ++++++ .../depthkit.core/Runtime/Looks/Look.cs.meta | 11 + .../Runtime/Looks/ProceduralLook.cs | 77 ++ .../Runtime/Looks/ProceduralLook.cs.meta | 11 + .../depthkit.core/Runtime/Players.meta | 8 + .../Runtime/Players/ClipPlayer.cs | 148 ++++ .../Runtime/Players/ClipPlayer.cs.meta | 11 + .../Runtime/Players/PlayerEvents.cs | 61 ++ .../Runtime/Players/PlayerEvents.cs.meta | 11 + .../Runtime/Players/UnityVideoPlayer.cs | 286 +++++++ .../Runtime/Players/UnityVideoPlayer.cs.meta | 11 + .../depthkit.core/Runtime/Resources.meta | 8 + .../Runtime/Resources/Shaders.meta | 8 + .../Runtime/Resources/Shaders/DataSource.meta | 8 + .../DataSource/DepthkitCoreMeshSource.compute | 57 ++ .../DepthkitCoreMeshSource.compute.meta | 8 + .../DepthkitCoreMeshSourceCommon.cginc | 96 +++ .../DepthkitCoreMeshSourceCommon.cginc.meta | 9 + .../Shaders/DataSource/GenerateNormals.cginc | 215 +++++ .../DataSource/GenerateNormals.cginc.meta | 9 + .../DataSource/GenerateTriangles.cginc | 176 ++++ .../DataSource/GenerateTriangles.cginc.meta | 9 + .../Shaders/DataSource/GenerateVertices.cginc | 227 ++++++ .../DataSource/GenerateVertices.cginc.meta | 9 + .../Runtime/Resources/Shaders/Includes.meta | 8 + .../Shaders/Includes/ColorCorrection.cginc | 81 ++ .../Includes/ColorCorrection.cginc.meta | 9 + .../Shaders/Includes/CoreTriangle.cginc | 50 ++ .../Shaders/Includes/CoreTriangle.cginc.meta | 9 + .../Shaders/Includes/CoreVertex.cginc | 45 ++ .../Shaders/Includes/CoreVertex.cginc.meta | 9 + .../Shaders/Includes/DebugCameraColors.cginc | 39 + .../Includes/DebugCameraColors.cginc.meta | 9 + .../Resources/Shaders/Includes/Defines.cginc | 33 + .../Shaders/Includes/Defines.cginc.meta | 9 + .../Resources/Shaders/Includes/Depthkit.cginc | 460 +++++++++++ .../Shaders/Includes/Depthkit.cginc.meta | 9 + .../Includes/DepthkitCoreUniforms.cginc | 41 + .../Includes/DepthkitCoreUniforms.cginc.meta | 9 + .../Includes/SampleCoreTriangles.cginc | 69 ++ .../Includes/SampleCoreTriangles.cginc.meta | 9 + .../Shaders/Includes/SampleEdgeMask.cginc | 106 +++ .../Includes/SampleEdgeMask.cginc.meta | 9 + .../Resources/Shaders/Includes/Types.cginc | 40 + .../Shaders/Includes/Types.cginc.meta | 9 + .../Resources/Shaders/Includes/Utils.cginc | 279 +++++++ .../Shaders/Includes/Utils.cginc.meta | 9 + .../Runtime/Resources/Shaders/Looks.meta | 8 + .../Shaders/Looks/DepthkitCorePhotoLook.cginc | 142 ++++ .../Looks/DepthkitCorePhotoLook.cginc.meta | 9 + .../Looks/DepthkitCoreShadowCaster.cginc | 75 ++ .../Looks/DepthkitCoreShadowCaster.cginc.meta | 9 + .../Looks/DepthkitPhotoLookBuiltInRP.shader | 129 +++ .../DepthkitPhotoLookBuiltInRP.shader.meta | 9 + .../Runtime/Resources/Shaders/Util.meta | 8 + .../Shaders/Util/GaussianBlurFilter.cginc | 84 ++ .../Util/GaussianBlurFilter.cginc.meta | 9 + .../Shaders/Util/GaussianBlurFilter.compute | 75 ++ .../Util/GaussianBlurFilter.compute.meta | 8 + .../Util/MinMaxDownscaleByHalf.compute | 61 ++ .../Util/MinMaxDownscaleByHalf.compute.meta | 8 + .../Shaders/Util/MipMapGaussianBlur.compute | 71 ++ .../Util/MipMapGaussianBlur.compute.meta | 9 + .../Shaders/Util/PrepareArgs.compute | 72 ++ .../Shaders/Util/PrepareArgs.compute.meta | 8 + .../Shaders/Util/PushPullMips.shader | 90 +++ .../Shaders/Util/PushPullMips.shader.meta | 10 + .../Resources/Shaders/Util/SobelFilter.cginc | 129 +++ .../Shaders/Util/SobelFilter.cginc.meta | 9 + .../Shaders/Util/SobelFilter.compute | 54 ++ .../Shaders/Util/SobelFilter.compute.meta | 8 + .../depthkit.core/Runtime/Utils.meta | 8 + .../Runtime/Utils/GaussianBlurFilter.cs | 180 +++++ .../Runtime/Utils/GaussianBlurFilter.cs.meta | 11 + .../depthkit.core/Runtime/Utils/Info.cs | 197 +++++ .../depthkit.core/Runtime/Utils/Info.cs.meta | 11 + .../depthkit.core/Runtime/Utils/Metadata.cs | 326 ++++++++ .../Runtime/Utils/Metadata.cs.meta | 11 + .../Runtime/Utils/PlatformValidator.cs | 41 + .../Runtime/Utils/PlatformValidator.cs.meta | 11 + .../Runtime/Utils/SetCaptureFrameRate.cs | 55 ++ .../Runtime/Utils/SetCaptureFrameRate.cs.meta | 11 + .../Runtime/Utils/SyncedStructuredBuffer.cs | 87 ++ .../Utils/SyncedStructuredBuffer.cs.meta | 11 + .../Runtime/Utils/TriangleMesh.cs | 404 ++++++++++ .../Runtime/Utils/TriangleMesh.cs.meta | 11 + .../depthkit.core/Runtime/Utils/Util.cs | 426 ++++++++++ .../depthkit.core/Runtime/Utils/Util.cs.meta | 11 + LocalPackages/depthkit.core/package.json | 29 + LocalPackages/depthkit.core/package.json.meta | 7 + Viagg-io/Packages/manifest.json | 4 +- Viagg-io/Packages/packages-lock.json | 4 +- 177 files changed, 11269 insertions(+), 4 deletions(-) create mode 100644 LocalPackages/depthkit.core.shadergraph/CHANGELOG.md create mode 100644 LocalPackages/depthkit.core.shadergraph/CHANGELOG.md.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Editor.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs create mode 100644 LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs create mode 100644 LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef create mode 100644 LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/LICENSE.md create mode 100644 LocalPackages/depthkit.core.shadergraph/LICENSE.md.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/README.md create mode 100644 LocalPackages/depthkit.core.shadergraph/README.md.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Looks.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs create mode 100644 LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs.meta create mode 100644 LocalPackages/depthkit.core.shadergraph/package.json create mode 100644 LocalPackages/depthkit.core.shadergraph/package.json.meta create mode 100644 LocalPackages/depthkit.core/CHANGELOG.md create mode 100644 LocalPackages/depthkit.core/CHANGELOG.md.meta create mode 100644 LocalPackages/depthkit.core/Editor.meta create mode 100644 LocalPackages/depthkit.core/Editor/ClipEditor.cs create mode 100644 LocalPackages/depthkit.core/Editor/ClipEditor.cs.meta create mode 100644 LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef create mode 100644 LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef.meta create mode 100644 LocalPackages/depthkit.core/Editor/EditorUtil.cs create mode 100644 LocalPackages/depthkit.core/Editor/EditorUtil.cs.meta create mode 100644 LocalPackages/depthkit.core/Editor/Looks.meta create mode 100644 LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs create mode 100644 LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs.meta create mode 100644 LocalPackages/depthkit.core/Editor/PlayerProcessor.cs create mode 100644 LocalPackages/depthkit.core/Editor/PlayerProcessor.cs.meta create mode 100644 LocalPackages/depthkit.core/Editor/Sources.meta create mode 100644 LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs create mode 100644 LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs.meta create mode 100644 LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs create mode 100644 LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs.meta create mode 100644 LocalPackages/depthkit.core/Editor/depthkit-symbol-64.png create mode 100644 LocalPackages/depthkit.core/Editor/depthkit-symbol-64.png.meta create mode 100644 LocalPackages/depthkit.core/LICENSE.md create mode 100644 LocalPackages/depthkit.core/LICENSE.md.meta create mode 100644 LocalPackages/depthkit.core/README.md create mode 100644 LocalPackages/depthkit.core/README.md.meta create mode 100644 LocalPackages/depthkit.core/Runtime.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Clip.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Clip.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource.meta create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs create mode 100644 LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef create mode 100644 LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Interfaces.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Looks.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Looks/Look.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Looks/Look.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Players.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute create mode 100644 LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/Info.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/Info.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs.meta create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/Util.cs create mode 100644 LocalPackages/depthkit.core/Runtime/Utils/Util.cs.meta create mode 100644 LocalPackages/depthkit.core/package.json create mode 100644 LocalPackages/depthkit.core/package.json.meta diff --git a/LocalPackages/depthkit.core.shadergraph/CHANGELOG.md b/LocalPackages/depthkit.core.shadergraph/CHANGELOG.md new file mode 100644 index 0000000..46b8322 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/CHANGELOG.md @@ -0,0 +1,31 @@ +## Changelog + +### 0.6.1 +* Update SDK license agreement + +### 0.6.0 +* Updated to Unity 2022.3 + +### 0.5.2 +* Updated assembly definitions. + +### 0.5.1 +* Updated com.unity.shadergraph dependency + +### 0.5.0 +* Updated to Unity 2020.3 +* Updated surface buffer capacity to be set as a percentage of the maximum triangles needed to render the lattice mesh at the set mesh density. + +### 0.4.0 +* compatibility with 0.11.0 + +### 0.3.0 +* Added support for material property blocks +* Moved common code to ShaderGraphLook base class +* Bug fixes + +### 0.2.2 +* Added depthkit icon to all depthkit components + +### 0.2.1 +* Bug fixes \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/CHANGELOG.md.meta b/LocalPackages/depthkit.core.shadergraph/CHANGELOG.md.meta new file mode 100644 index 0000000..85d59e1 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5b7ffb1510a7211428df971944eda351 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Editor.meta b/LocalPackages/depthkit.core.shadergraph/Editor.meta new file mode 100644 index 0000000..d21a513 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f9c6355c33d5da541a1eb187dfcdaa30 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs new file mode 100644 index 0000000..8cc15d6 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs @@ -0,0 +1,40 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Linq; +using System.Collections.Generic; +using System; + +namespace Depthkit +{ + public class CoreShaderGraphLookGizmosDrawer + { + [DrawGizmo(GizmoType.Selected | GizmoType.Active)] + static void DrawGizmosFor(Depthkit.CoreShaderGraphLook look, GizmoType gizmoType) + { + if (look.showCameraFrustums) + { + Depthkit.Util.RenderMetadataGizmos(look.depthkitClip.metadata, look.transform); + } + } + } +} diff --git a/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs.meta b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs.meta new file mode 100644 index 0000000..1d7d3bc --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphLookGizmosDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d27449979fb9b6246b129fb82af75c05 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs new file mode 100644 index 0000000..5d18284 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs @@ -0,0 +1,44 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; + +namespace Depthkit { + public class CoreShaderGraphMenu + { + [MenuItem ("Assets/Create/Shader/Depthkit/Core Look - Shader Graph")] + static void CreateDepthkitCoreSRPLookShaderGraph(MenuCommand menuCommand) + { + string filename; + if(Selection.assetGUIDs.Length > 0) + { + string clickedAssetGuid = Selection.assetGUIDs[0]; + string clickedPath = AssetDatabase.GUIDToAssetPath(clickedAssetGuid); + filename = Depthkit.Util.GetNextFileName(clickedPath + "/MyCoreLook", ".shadergraph"); + } + else + { + filename = Depthkit.Util.GetNextFileName("Assets/MyCoreLook", ".shadergraph"); + } + AssetDatabase.CopyAsset("Packages/nyc.scatter.depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph", filename); + } + } +} diff --git a/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs.meta b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs.meta new file mode 100644 index 0000000..4941ad5 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Editor/CoreShaderGraphMenu.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9efa5fe257de17f4b84e8be369eb5ef4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef b/LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef new file mode 100644 index 0000000..59cb6e8 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef @@ -0,0 +1,18 @@ +{ + "name": "Depthkit.Core.ShaderGraph.Editor", + "references": [ + "GUID:d757665d4a59fe94bab8bd5391e60e3d", + "GUID:3fcfa8946fa8f2b4bae0b88785a14d3e" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef.meta b/LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef.meta new file mode 100644 index 0000000..03220d7 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Editor/Depthkit.Core.ShaderGraph.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5272d745ea42c5743b70cb2d0f0ffbd2 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/LICENSE.md b/LocalPackages/depthkit.core.shadergraph/LICENSE.md new file mode 100644 index 0000000..4dac3aa --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/LICENSE.md @@ -0,0 +1,138 @@ +SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT + +The text of this license (this “License”) may be found at: www.depthkit.tv/license-agreement-v1 + +Thank you for your interest in using the Simile Inc dba Scatter ("Scatter") Software Development Kit (the "SDK"). +In order to obtain and use the SDK, you must first agree to the terms of this License. If you do not agree to the +terms of this License, then you may not use the SDK. + +SDK LICENSE +1. Subject to the terms and conditions of this License, Scatter hereby +grants to you a worldwide, non-exclusive, royalty-free, sublicenseable license to use, reproduce, modify, +embed and redistribute (subject to restrictions below) the software contained in the SDK, including, but +not limited to, the samples, headers, documentation and source code. This License is subject to the +following terms and conditions: +1.1 This license grants you the non-exclusive license and right to use the SDK to develop +methods to play back content produced in the software suite known as Depth Kit (such content referred +to as your “Content”) in the Unity game engine, as well as other features that may be added from time to +time by Scatter. You may not use the SDK to connect Depth Kit to any software platform or game engine +other than Unity. +1.2 For avoidance of doubt, when you use the SDK in or with your Content, you retain all +rights to your Content, and you have no obligations to share or license your Content (including your +source and object code) to Scatter or any third parties; provided, however, Scatter retains all rights to the +SDK and the headers, libraries and APIs of Depth Kit and other tools made available by Scatter, including +those that may be incorporated into your Content by virtue of your producing it through Depth Kit. +1.3 You agree not to commit any act intended to (a) interfere with the normal operation of +Depth Kit or the SDK, (b) provide software to Depth Kit users or developers that would induce breach of +any Scatter agreements, or (c) provide software to Scatter or Depth Kit users that contains malware, +viruses, hacks, bots, Trojan horses, or other malicious code. +1.4 You may not use the SDK for any purpose not expressly permitted by this License. You +may not: + +a. decompile; +b. reverse engineer; +c. disassemble; or +d. attempt to derive the source code of any part of the SDK where source code is +not directly provided to you, or any other software or firmware provided to you by Scatter in binary +form (except as and only to the extent any foregoing restriction is prohibited by applicable law). + +REDISTRIBUTION +2. Subject to the terms and conditions of this License, your license to redistribute and sublicense the SDK +is also expressly made subject to the following conditions: +2.1 You may sublicense and redistribute the binary or object code form of the SDK in whole +for no charge or as part of a for-charge piece of Content; provided, however, you may only license, +sublicense or redistribute the binary or object code of the SDK (and not the SDK’s source code) in its +entirety. The SDK, including its associated libraries, and your Content that includes any portion of the +SDK, may only be used with Depth Kit and may not be used, licensed, or sublicensed to interface with +software that is not authorized and approved by Scatter; +2.2 You must include with all such redistributed or sublicensed SDK code the following copyright +notice: “Copyright 2016-2024 Simile Inc dba Scatter. All rights reserved.”; +2.3 You must give any other recipients of the SDK a copy of this License as such recipients, +licensees or sublicensees may only use the SDK subject to the terms of this License and such recipient's, +licensee's or sublicensee's agreement to and acceptance of this License with Scatter; and +2.4 The SDK includes a “LICENSE” text file (the “License Notice”), and any SDK distribution that +you distribute must include a copy of this License with the License Notice. + +GENERAL PROVISIONS +3. Additional Materials +3.1 Scatter may include in this SDK additional content (e.g., samples) for demonstration, +references or other specific purposes. Such content will be clearly marked in the SDK and is subject to +any included terms and conditions. +3.2 Your use of third-party materials included in the SDK, or which the SDK may be dependent +upon (including without limitation Unity), may be subject to other terms and conditions typically found in +separate third-party license agreements or "READ ME" files included with such third-party materials. To +the extent such other terms and conditions conflict with the terms and conditions of this License, the +former will control with respect to the applicable third-party materials. The terms of licensing the Unity +game engine can be found here: https://unity3d.com/legal/terms-of-service/software. +4. THE SDK AND ANY COMPONENT THEREOF ARE PROVIDED “AS IS” AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL Scatter AS THE COPYRIGHT OWNER OR ITS CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SDK, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOME JURISDICTIONS DO NOT PERMIT THE +EXCLUSION OR LIMITATION OF IMPLIED WARRANTIES, SO YOU MAY HAVE ADDITIONAL +RIGHTS. +5. This License does not grant permission to use the trade names, trademarks, service marks, or product +names of Scatter, including without limitation “Depth Kit,” except as required for reasonable and customary +use in describing the origin of the SDK, and reproducing the content of the License Notice file. Scatter +reserves all rights not expressly granted to you under this License. Neither Scatter’s name nor the names +of Scatter’s contributors, licensors, employees, or contractors, may be used to endorse or promote +products developed using the SDK without specific prior written permission of Scatter. +6. You are responsible for ensuring that your use of the SDK and your Content complies with all +applicable laws (including privacy laws) wherever your Content is made available. You acknowledge and +agree that you are solely responsible for any health and safety issues arising from your Content. +7. Your acceptance of the terms and conditions of this License in and of itself and for all of your Content +may be evidenced by your usage of the SDK or acceptance of this License. As this License is updated for +future releases of the SDK, you agree to abide by and meet all requirements of future updates of this +License for those future SDK releases, with acceptance evidenced by usage of the SDK or any element +thereof and the future updates of this License will apply for your Content that may be developed for or +with that future SDK or any element thereof (i.e., you cannot sidestep out of the requirements of future +updates of the License by developing against an older release of the SDK or License). You acknowledge +that future versions of the SDK may be provided for a fee or otherwise under substantially different terms +from those provided hereunder. +8. Scatter reserves the right to terminate this License and all your rights hereunder immediately in the +event you materially breach this License. +9. Furthermore, Scatter also reserves the right to cancel or terminate this License for any of the following +reasons: +a. Intellectual property infringement by you for your Content that is used with or by +the SDK; +b. Content that violates applicable law; +c. Health and safety issues associated with your Content; +d. Use of the SDK with a commercial product other than Depth Kit and Unity; and +e. Failure to provide required notices as set forth above. +10. You agree to fully indemnify Scatter from any and all losses, costs, damages and expenses (including +reasonable attorney's fees) arising out of your Content or any breach of this License. +11. Scatter may discontinue or change functionality of Depth Kit or the SDK at any time, and your +continued use of Depth Kit or the SDK or use of any modified or additional services in connection +therewith is conditioned upon your adherence to the terms of this License, as modified by Scatter from +time to time, as well as any additional license agreements necessitated by additional features. +12. In the event any provision of this License is determined to be invalid, prohibited or unenforceable by a +court or other body of competent jurisdiction, this License shall be construed as if such invalid, prohibited +or unenforceable provision has been more narrowly drawn so as not to be invalid, prohibited or +unenforceable. +13. You may not assign any rights or obligations under this License without the advance written consent +of Scatter, which may be withheld in its sole discretion. Scatter may assign its rights or obligations under +this License in its sole discretion. +14. Failure of either party at any time to enforce any of the provisions of this License will not be construed +as a waiver of such provisions or in any way affect the validity of this License or parts thereof. +15. Your remedies under this License shall be limited to the right to collect money damages, if any, and +you hereby waive your right to injunctive or other equitable relief. +16. You will comply with all applicable export control laws of the United States and any other applicable +governmental authority, including without limitation, the U.S. Export Administration Regulations. You +agree that this License and the SDK and accompanying documentation are Scatter's confidential +information (and is not publicly available), and you will not use it, disclose it or make it available to others +except in accordance with the terms of this License. +17. This License shall be governed by the laws of the State of New York, without giving effect to choice of +law principles. All disputes relating to this License shall be resolved by binding non-appearance-based +arbitration before a single arbitrator in New York County, New York. The arbitration shall be conducted in +accordance with the rules and procedures of JAMS then in effect, and the judgment of the arbitrator shall +be final and capable of entry in any court of competent jurisdiction. You and Scatter agree to submit to the +personal jurisdiction of the courts located within New York County, New York in connection with any +entrance of an arbitrator’s judgment or decision or any dispute with respect to the arbitration process or +procedure or Scatter’s exercise of its equitable rights or remedies. + +Effective as of October 7, 2016 diff --git a/LocalPackages/depthkit.core.shadergraph/LICENSE.md.meta b/LocalPackages/depthkit.core.shadergraph/LICENSE.md.meta new file mode 100644 index 0000000..fe94200 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e30fdbafb6a3b4444852d807234af082 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/README.md b/LocalPackages/depthkit.core.shadergraph/README.md new file mode 100644 index 0000000..fc033a9 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/README.md @@ -0,0 +1,2 @@ +# Depthkit Core Shader Graph +Copyright 2021 Scatter All Rights reserved. diff --git a/LocalPackages/depthkit.core.shadergraph/README.md.meta b/LocalPackages/depthkit.core.shadergraph/README.md.meta new file mode 100644 index 0000000..6848f6c --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0d6f9fa8d2b16354b95d28638bd44eb9 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime.meta b/LocalPackages/depthkit.core.shadergraph/Runtime.meta new file mode 100644 index 0000000..fec58d5 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fbcbe8f39d8261c42b5d86fece785f5d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef b/LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef new file mode 100644 index 0000000..e9267a8 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef @@ -0,0 +1,16 @@ +{ + "name": "Depthkit.Core.ShaderGraph", + "rootNamespace": "", + "references": [ + "GUID:d757665d4a59fe94bab8bd5391e60e3d" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef.meta new file mode 100644 index 0000000..a9eb1d7 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Depthkit.Core.ShaderGraph.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3fcfa8946fa8f2b4bae0b88785a14d3e +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Looks.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Looks.meta new file mode 100644 index 0000000..c22e60c --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Looks.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 57fff10957385e04e8bfae0c20b2c47d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs b/LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs new file mode 100644 index 0000000..b6099d3 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs @@ -0,0 +1,63 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; + +namespace Depthkit +{ + [ExecuteInEditMode] + [AddComponentMenu("Depthkit/Core/Shader Graph/Depthkit Core Shader Graph Look")] + public class CoreShaderGraphLook : ShaderGraphLook + { + protected static Shader s_defaultUnlitPhotoLookShader = null; + protected static Material s_defaultUnlitPhotoLookMaterial = null; + + protected static Material GetDefaultMaterial() + { + if (s_defaultUnlitPhotoLookShader == null) + { + s_defaultUnlitPhotoLookShader = Shader.Find("Shader Graphs/Depthkit Core Photo Look Unlit"); + } + + if (s_defaultUnlitPhotoLookMaterial == null) + { + s_defaultUnlitPhotoLookMaterial = new Material(s_defaultUnlitPhotoLookShader); + } + return s_defaultUnlitPhotoLookMaterial; + } + + protected override Material GetDefaultShaderGraph() + { + return GetDefaultMaterial(); + } + + public override string GetLookName(){ return "Depthkit Core Shader Graph Look"; } + + protected override void SetDataSources() + { + if(meshSource == null) + { + meshSource = depthkitClip.GetDataSource(); + } + + if (!meshSource.useTriangleMesh) meshSource.useTriangleMesh = true; + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs.meta new file mode 100644 index 0000000..913c34a --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Looks/CoreShaderGraphLook.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 49f9b3a47303df142865cad5acebdb4d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 42c51ff9981f3e24b83cd7ad3c56e235, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources.meta new file mode 100644 index 0000000..39bb220 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6f54e2f05488f994b9935950d3a5d1f9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders.meta new file mode 100644 index 0000000..67e5723 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2e3afc07320a9f3489644400c10ca721 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph new file mode 100644 index 0000000..f39a27d --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph @@ -0,0 +1,67 @@ +{ + "m_SerializedProperties": [], + "m_SerializedKeywords": [], + "m_SerializableNodes": [ + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.UnlitMasterNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"d90de3fb-2d9f-4417-8d3d-feb8ecfd5ae6\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Unlit Master\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": false,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 211.0,\n \"y\": 29.0,\n \"width\": 200.0,\n \"height\": 197.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.PositionMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 9,\\n \\\"m_DisplayName\\\": \\\"Vertex Position\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Vertex Position\\\",\\n \\\"m_StageCapability\\\": 1,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_Space\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.NormalMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 10,\\n \\\"m_DisplayName\\\": \\\"Vertex Normal\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Vertex Normal\\\",\\n \\\"m_StageCapability\\\": 1,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_Space\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.TangentMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 11,\\n \\\"m_DisplayName\\\": \\\"Vertex Tangent\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Vertex Tangent\\\",\\n \\\"m_StageCapability\\\": 1,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_Space\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.ColorRGBMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"Color\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Color\\\",\\n \\\"m_StageCapability\\\": 2,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.7353569269180298,\\n \\\"y\\\": 0.7353569269180298,\\n \\\"z\\\": 0.7353569269180298\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_ColorMode\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 7,\\n \\\"m_DisplayName\\\": \\\"Alpha\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Alpha\\\",\\n \\\"m_StageCapability\\\": 2,\\n \\\"m_Value\\\": 1.0,\\n \\\"m_DefaultValue\\\": 1.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 8,\\n \\\"m_DisplayName\\\": \\\"AlphaClipThreshold\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"AlphaClipThreshold\\\",\\n \\\"m_StageCapability\\\": 2,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_DOTSInstancing\": false,\n \"m_SerializableSubShaders\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.Rendering.Universal.UniversalUnlitSubShader\"\n },\n \"JSONnodeData\": \"{}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.Rendering.HighDefinition.UnlitSubShader\"\n },\n \"JSONnodeData\": \"{}\"\n }\n ],\n \"m_ShaderGUIOverride\": \"\",\n \"m_OverrideEnabled\": false,\n \"m_SurfaceType\": 0,\n \"m_AlphaMode\": 0,\n \"m_TwoSided\": true,\n \"m_AddPrecomputedVelocity\": false\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.SubGraphNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"8a1e5229-af46-42b6-b4af-d6ff25109e2f\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"DepthkitVertex\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": -53.0,\n \"y\": 27.0,\n \"width\": 142.0,\n \"height\": 118.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"Object Position\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"ObjectPosition\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 2,\\n \\\"m_DisplayName\\\": \\\"Object Normal\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"ObjectNormal\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_SerializedSubGraph\": \"{\\n \\\"subGraph\\\": {\\n \\\"fileID\\\": -5475051401550479605,\\n \\\"guid\\\": \\\"4be5c3a372dc98742b91488a7f372740\\\",\\n \\\"type\\\": 3\\n }\\n}\",\n \"m_PropertyGuids\": [],\n \"m_PropertyIds\": []\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.SubGraphNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"6b674ade-4e27-4c04-83ff-3a90c2d85035\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"DepthkitCoreFragment\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": -99.0,\n \"y\": 154.0,\n \"width\": 191.0,\n \"height\": 166.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 4,\\n \\\"m_DisplayName\\\": \\\"Color\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Color\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"Alpha\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Alpha\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 3,\\n \\\"m_DisplayName\\\": \\\"Alpha Cliping Threshold\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"AlphaClipingThreshold\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector2MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 5,\\n \\\"m_DisplayName\\\": \\\"UV\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"UV\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_SerializedSubGraph\": \"{\\n \\\"subGraph\\\": {\\n \\\"fileID\\\": -5475051401550479605,\\n \\\"guid\\\": \\\"d8f155b222bf9234fab7df9371f4cff5\\\",\\n \\\"type\\\": 3\\n }\\n}\",\n \"m_PropertyGuids\": [],\n \"m_PropertyIds\": []\n}" + } + ], + "m_Groups": [], + "m_StickyNotes": [], + "m_SerializableEdges": [ + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 2,\n \"m_NodeGUIDSerialized\": \"8a1e5229-af46-42b6-b4af-d6ff25109e2f\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 10,\n \"m_NodeGUIDSerialized\": \"d90de3fb-2d9f-4417-8d3d-feb8ecfd5ae6\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 1,\n \"m_NodeGUIDSerialized\": \"6b674ade-4e27-4c04-83ff-3a90c2d85035\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 7,\n \"m_NodeGUIDSerialized\": \"d90de3fb-2d9f-4417-8d3d-feb8ecfd5ae6\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 3,\n \"m_NodeGUIDSerialized\": \"6b674ade-4e27-4c04-83ff-3a90c2d85035\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 8,\n \"m_NodeGUIDSerialized\": \"d90de3fb-2d9f-4417-8d3d-feb8ecfd5ae6\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 4,\n \"m_NodeGUIDSerialized\": \"6b674ade-4e27-4c04-83ff-3a90c2d85035\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"d90de3fb-2d9f-4417-8d3d-feb8ecfd5ae6\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 1,\n \"m_NodeGUIDSerialized\": \"8a1e5229-af46-42b6-b4af-d6ff25109e2f\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 9,\n \"m_NodeGUIDSerialized\": \"d90de3fb-2d9f-4417-8d3d-feb8ecfd5ae6\"\n }\n}" + } + ], + "m_PreviewData": { + "serializedMesh": { + "m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}", + "m_Guid": "" + } + }, + "m_Path": "Shader Graphs", + "m_ConcretePrecision": 0, + "m_ActiveOutputNodeGuidSerialized": "d90de3fb-2d9f-4417-8d3d-feb8ecfd5ae6" +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph.meta new file mode 100644 index 0000000..f644406 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Depthkit Core Photo Look Unlit.shadergraph.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: c87a04016ad3ac64fb8dabf413e1d1e3 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph new file mode 100644 index 0000000..685647e --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph @@ -0,0 +1,146 @@ +{ + "m_SerializedProperties": [], + "m_SerializedKeywords": [ + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.ShaderKeyword" + }, + "JSONnodeData": "{\n \"m_Guid\": {\n \"m_GuidSerialized\": \"6b098235-341a-4c3e-aa5e-5b9109b2aa9f\"\n },\n \"m_Name\": \"Debug Color\",\n \"m_DefaultReferenceName\": \"BOOLEAN_EC489DC2_ON\",\n \"m_OverrideReferenceName\": \"DK_USE_DEBUG_COLOR\",\n \"m_GeneratePropertyBlock\": true,\n \"m_KeywordType\": 0,\n \"m_KeywordDefinition\": 0,\n \"m_KeywordScope\": 0,\n \"m_Entries\": [],\n \"m_Value\": 0,\n \"m_IsEditable\": true,\n \"m_IsExposable\": true\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.ShaderKeyword" + }, + "JSONnodeData": "{\n \"m_Guid\": {\n \"m_GuidSerialized\": \"b557dc33-25bf-40d9-b247-d92ce948bb30\"\n },\n \"m_Name\": \"Use Edge Mask\",\n \"m_DefaultReferenceName\": \"BOOLEAN_91F67555_ON\",\n \"m_OverrideReferenceName\": \"DK_USE_EDGEMASK\",\n \"m_GeneratePropertyBlock\": true,\n \"m_KeywordType\": 0,\n \"m_KeywordDefinition\": 0,\n \"m_KeywordScope\": 0,\n \"m_Entries\": [],\n \"m_Value\": 0,\n \"m_IsEditable\": true,\n \"m_IsExposable\": true\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.ShaderKeyword" + }, + "JSONnodeData": "{\n \"m_Guid\": {\n \"m_GuidSerialized\": \"5ffa07f3-79f8-4553-9d34-428dee6ea182\"\n },\n \"m_Name\": \"Edge Dither\",\n \"m_DefaultReferenceName\": \"BOOLEAN_9DC7878D_ON\",\n \"m_OverrideReferenceName\": \"DK_SCREEN_DOOR_TRANSPARENCY\",\n \"m_GeneratePropertyBlock\": true,\n \"m_KeywordType\": 0,\n \"m_KeywordDefinition\": 0,\n \"m_KeywordScope\": 0,\n \"m_Entries\": [],\n \"m_Value\": 0,\n \"m_IsEditable\": true,\n \"m_IsExposable\": true\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.ShaderKeyword" + }, + "JSONnodeData": "{\n \"m_Guid\": {\n \"m_GuidSerialized\": \"ac3b8ff2-63e6-473e-900c-ef4fdec8728d\"\n },\n \"m_Name\": \"Debug Edge Mask\",\n \"m_DefaultReferenceName\": \"BOOLEAN_3523C1D0_ON\",\n \"m_OverrideReferenceName\": \"DK_DEBUG_EDGEMASK\",\n \"m_GeneratePropertyBlock\": true,\n \"m_KeywordType\": 0,\n \"m_KeywordDefinition\": 0,\n \"m_KeywordScope\": 0,\n \"m_Entries\": [],\n \"m_Value\": 0,\n \"m_IsEditable\": true,\n \"m_IsExposable\": true\n}" + } + ], + "m_SerializableNodes": [ + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.SubGraphOutputNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"85b26246-820d-4e5f-a250-9cbbfdd87a3e\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Output\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 1035.0,\n \"y\": -127.00000762939453,\n \"width\": 185.0,\n \"height\": 196.99998474121095\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 4,\\n \\\"m_DisplayName\\\": \\\"Color\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Color\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"Alpha\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Alpha\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 1.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 3,\\n \\\"m_DisplayName\\\": \\\"Alpha Cliping Threshold\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"AlphaClipingThreshold\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.9900000095367432,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector2MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 5,\\n \\\"m_DisplayName\\\": \\\"UV\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"UV\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.CustomFunctionNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"5874e62e-522a-46ad-849c-d89edbf593f3\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Custom Function\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 708.0,\n \"y\": -111.99999237060547,\n \"width\": 223.00001525878907,\n \"height\": 142.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 3,\\n \\\"m_DisplayName\\\": \\\"color\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"color\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 4,\\n \\\"m_DisplayName\\\": \\\"alpha\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"alpha\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector2MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 2,\\n \\\"m_DisplayName\\\": \\\"uv\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"uv\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 6,\\n \\\"m_DisplayName\\\": \\\"alphaclip\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"alphaclip\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 5,\\n \\\"m_DisplayName\\\": \\\"screenSpacePosition\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"screenSpacePosition\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"objectPositon\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"objectPositon\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_SourceType\": 0,\n \"m_FunctionName\": \"DepthkitCoreFragment\",\n \"m_FunctionSource\": \"54392f0b351a5bc418d0e506882a5db2\",\n \"m_FunctionBody\": \"Enter function body here...\"\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.PositionNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"5a218aff-39d0-47d0-bbf4-6e1f57a8db51\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Position\",\n \"m_NodeVersion\": 1,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 474.00006103515627,\n \"y\": 8.000011444091797,\n \"width\": 206.0,\n \"height\": 131.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"Out\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Out\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 1,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_Space\": 0\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.ScreenPositionNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"888980f8-c397-4e1c-9c5a-e34191713cda\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Screen Position\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 268.0000305175781,\n \"y\": -195.99998474121095,\n \"width\": 155.0,\n \"height\": 129.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector4MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"Out\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Out\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n }\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_ScreenSpaceType\": 0\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.ScreenNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"3934003e-9027-4844-874d-2d76211fe934\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Screen\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 161.0,\n \"y\": -70.99998474121094,\n \"width\": 103.0,\n \"height\": 101.00000762939453\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"Width\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Width\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"Height\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Height\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.Vector4Node" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"c5b8938c-3a1c-44d4-bff3-56870470b8f5\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Vector 4\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 280.0000305175781,\n \"y\": -54.00002670288086,\n \"width\": 140.0,\n \"height\": 149.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"X\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"X\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 2,\\n \\\"m_DisplayName\\\": \\\"Y\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Y\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"Y\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 3,\\n \\\"m_DisplayName\\\": \\\"Z\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Z\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 1.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 4,\\n \\\"m_DisplayName\\\": \\\"W\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"W\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 1.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"W\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector4MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"Out\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Out\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n }\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_Value\": {\n \"x\": 0.0,\n \"y\": 0.0,\n \"z\": 0.0,\n \"w\": 0.0\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.MultiplyNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"41bdc94d-dd22-492a-9281-e588817e73b3\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Multiply\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 474.00006103515627,\n \"y\": -146.00001525878907,\n \"width\": 135.0,\n \"height\": 117.99999237060547\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.DynamicValueMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"A\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"A\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"e00\\\": 0.0,\\n \\\"e01\\\": 0.0,\\n \\\"e02\\\": 0.0,\\n \\\"e03\\\": 0.0,\\n \\\"e10\\\": 0.0,\\n \\\"e11\\\": 0.0,\\n \\\"e12\\\": 0.0,\\n \\\"e13\\\": 0.0,\\n \\\"e20\\\": 0.0,\\n \\\"e21\\\": 0.0,\\n \\\"e22\\\": 0.0,\\n \\\"e23\\\": 0.0,\\n \\\"e30\\\": 0.0,\\n \\\"e31\\\": 0.0,\\n \\\"e32\\\": 0.0,\\n \\\"e33\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"e00\\\": 1.0,\\n \\\"e01\\\": 0.0,\\n \\\"e02\\\": 0.0,\\n \\\"e03\\\": 0.0,\\n \\\"e10\\\": 0.0,\\n \\\"e11\\\": 1.0,\\n \\\"e12\\\": 0.0,\\n \\\"e13\\\": 0.0,\\n \\\"e20\\\": 0.0,\\n \\\"e21\\\": 0.0,\\n \\\"e22\\\": 1.0,\\n \\\"e23\\\": 0.0,\\n \\\"e30\\\": 0.0,\\n \\\"e31\\\": 0.0,\\n \\\"e32\\\": 0.0,\\n \\\"e33\\\": 1.0\\n }\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.DynamicValueMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"B\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"B\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"e00\\\": 2.0,\\n \\\"e01\\\": 2.0,\\n \\\"e02\\\": 2.0,\\n \\\"e03\\\": 2.0,\\n \\\"e10\\\": 2.0,\\n \\\"e11\\\": 2.0,\\n \\\"e12\\\": 2.0,\\n \\\"e13\\\": 2.0,\\n \\\"e20\\\": 2.0,\\n \\\"e21\\\": 2.0,\\n \\\"e22\\\": 2.0,\\n \\\"e23\\\": 2.0,\\n \\\"e30\\\": 2.0,\\n \\\"e31\\\": 2.0,\\n \\\"e32\\\": 2.0,\\n \\\"e33\\\": 2.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"e00\\\": 1.0,\\n \\\"e01\\\": 0.0,\\n \\\"e02\\\": 0.0,\\n \\\"e03\\\": 0.0,\\n \\\"e10\\\": 0.0,\\n \\\"e11\\\": 1.0,\\n \\\"e12\\\": 0.0,\\n \\\"e13\\\": 0.0,\\n \\\"e20\\\": 0.0,\\n \\\"e21\\\": 0.0,\\n \\\"e22\\\": 1.0,\\n \\\"e23\\\": 0.0,\\n \\\"e30\\\": 0.0,\\n \\\"e31\\\": 0.0,\\n \\\"e32\\\": 0.0,\\n \\\"e33\\\": 1.0\\n }\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.DynamicValueMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 2,\\n \\\"m_DisplayName\\\": \\\"Out\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Out\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"e00\\\": 0.0,\\n \\\"e01\\\": 0.0,\\n \\\"e02\\\": 0.0,\\n \\\"e03\\\": 0.0,\\n \\\"e10\\\": 0.0,\\n \\\"e11\\\": 0.0,\\n \\\"e12\\\": 0.0,\\n \\\"e13\\\": 0.0,\\n \\\"e20\\\": 0.0,\\n \\\"e21\\\": 0.0,\\n \\\"e22\\\": 0.0,\\n \\\"e23\\\": 0.0,\\n \\\"e30\\\": 0.0,\\n \\\"e31\\\": 0.0,\\n \\\"e32\\\": 0.0,\\n \\\"e33\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"e00\\\": 1.0,\\n \\\"e01\\\": 0.0,\\n \\\"e02\\\": 0.0,\\n \\\"e03\\\": 0.0,\\n \\\"e10\\\": 0.0,\\n \\\"e11\\\": 1.0,\\n \\\"e12\\\": 0.0,\\n \\\"e13\\\": 0.0,\\n \\\"e20\\\": 0.0,\\n \\\"e21\\\": 0.0,\\n \\\"e22\\\": 1.0,\\n \\\"e23\\\": 0.0,\\n \\\"e30\\\": 0.0,\\n \\\"e31\\\": 0.0,\\n \\\"e32\\\": 0.0,\\n \\\"e33\\\": 1.0\\n }\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n }\n}" + } + ], + "m_Groups": [], + "m_StickyNotes": [], + "m_SerializableEdges": [ + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 2,\n \"m_NodeGUIDSerialized\": \"5874e62e-522a-46ad-849c-d89edbf593f3\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 5,\n \"m_NodeGUIDSerialized\": \"85b26246-820d-4e5f-a250-9cbbfdd87a3e\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 4,\n \"m_NodeGUIDSerialized\": \"5874e62e-522a-46ad-849c-d89edbf593f3\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 1,\n \"m_NodeGUIDSerialized\": \"85b26246-820d-4e5f-a250-9cbbfdd87a3e\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 3,\n \"m_NodeGUIDSerialized\": \"5874e62e-522a-46ad-849c-d89edbf593f3\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 4,\n \"m_NodeGUIDSerialized\": \"85b26246-820d-4e5f-a250-9cbbfdd87a3e\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"5a218aff-39d0-47d0-bbf4-6e1f57a8db51\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"5874e62e-522a-46ad-849c-d89edbf593f3\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 6,\n \"m_NodeGUIDSerialized\": \"5874e62e-522a-46ad-849c-d89edbf593f3\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 3,\n \"m_NodeGUIDSerialized\": \"85b26246-820d-4e5f-a250-9cbbfdd87a3e\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"c5b8938c-3a1c-44d4-bff3-56870470b8f5\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 1,\n \"m_NodeGUIDSerialized\": \"41bdc94d-dd22-492a-9281-e588817e73b3\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"888980f8-c397-4e1c-9c5a-e34191713cda\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"41bdc94d-dd22-492a-9281-e588817e73b3\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 2,\n \"m_NodeGUIDSerialized\": \"41bdc94d-dd22-492a-9281-e588817e73b3\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 5,\n \"m_NodeGUIDSerialized\": \"5874e62e-522a-46ad-849c-d89edbf593f3\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"3934003e-9027-4844-874d-2d76211fe934\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 1,\n \"m_NodeGUIDSerialized\": \"c5b8938c-3a1c-44d4-bff3-56870470b8f5\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 1,\n \"m_NodeGUIDSerialized\": \"3934003e-9027-4844-874d-2d76211fe934\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 2,\n \"m_NodeGUIDSerialized\": \"c5b8938c-3a1c-44d4-bff3-56870470b8f5\"\n }\n}" + } + ], + "m_PreviewData": { + "serializedMesh": { + "m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}", + "m_Guid": "" + } + }, + "m_Path": "Sub Graphs", + "m_ConcretePrecision": 0, + "m_ActiveOutputNodeGuidSerialized": "" +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph.meta new file mode 100644 index 0000000..bf71196 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitCoreFragment.shadersubgraph.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: d8f155b222bf9234fab7df9371f4cff5 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph new file mode 100644 index 0000000..3a92cdd --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph @@ -0,0 +1,55 @@ +{ + "m_SerializedProperties": [], + "m_SerializedKeywords": [], + "m_SerializableNodes": [ + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.SubGraphOutputNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"db251ffe-9a41-44bb-9a24-2c4e2335d61c\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Output\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 344.0,\n \"y\": -72.0,\n \"width\": 160.0,\n \"height\": 149.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"Object Position\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"ObjectPosition\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 2,\\n \\\"m_DisplayName\\\": \\\"Object Normal\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"ObjectNormal\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.CustomFunctionNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"9ab40ef9-5889-4e0c-9278-1f65e72b4622\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Custom Function\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 40.0,\n \"y\": -80.0,\n \"width\": 234.0,\n \"height\": 166.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector2MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"triangle uv\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"triangleuv\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector2MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"perspective uv\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"perspectiveuv\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 2,\\n \\\"m_DisplayName\\\": \\\"position\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"position\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector3MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 3,\\n \\\"m_DisplayName\\\": \\\"normal\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"normal\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 4,\\n \\\"m_DisplayName\\\": \\\"perspective\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"perspective\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_SourceType\": 0,\n \"m_FunctionName\": \"DepthkitCoreSampleTriangleBuffer\",\n \"m_FunctionSource\": \"9425010fadc863c47b5f8775a2f32428\",\n \"m_FunctionBody\": \"Enter function body here...\"\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.ShaderGraph.UVNode" + }, + "JSONnodeData": "{\n \"m_GuidSerialized\": \"c46bd900-8f26-4aa2-ab4c-3f9d4aeb0f40\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"UV\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": -173.75,\n \"y\": -70.50000762939453,\n \"width\": 144.99998474121095,\n \"height\": 128.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector4MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"Out\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Out\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n }\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": false,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_OutputChannel\": 0\n}" + } + ], + "m_Groups": [], + "m_StickyNotes": [], + "m_SerializableEdges": [ + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"c46bd900-8f26-4aa2-ab4c-3f9d4aeb0f40\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"9ab40ef9-5889-4e0c-9278-1f65e72b4622\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 2,\n \"m_NodeGUIDSerialized\": \"9ab40ef9-5889-4e0c-9278-1f65e72b4622\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 1,\n \"m_NodeGUIDSerialized\": \"db251ffe-9a41-44bb-9a24-2c4e2335d61c\"\n }\n}" + }, + { + "typeInfo": { + "fullName": "UnityEditor.Graphing.Edge" + }, + "JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 3,\n \"m_NodeGUIDSerialized\": \"9ab40ef9-5889-4e0c-9278-1f65e72b4622\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 2,\n \"m_NodeGUIDSerialized\": \"db251ffe-9a41-44bb-9a24-2c4e2335d61c\"\n }\n}" + } + ], + "m_PreviewData": { + "serializedMesh": { + "m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}", + "m_Guid": "" + } + }, + "m_Path": "Sub Graphs", + "m_ConcretePrecision": 0, + "m_ActiveOutputNodeGuidSerialized": "" +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph.meta new file mode 100644 index 0000000..33f27b6 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/DepthkitVertex.shadersubgraph.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 4be5c3a372dc98742b91488a7f372740 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes.meta new file mode 100644 index 0000000..d57a9ae --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: df8e8c109175b7b42a3e4d94c1d9e9aa +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl new file mode 100644 index 0000000..b661d4d --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl @@ -0,0 +1,15 @@ +#ifndef DEPTHKIT_SAMPLETRIANGLEBUFFER_HLSL_INCLUDE +#define DEPTHKIT_SAMPLETRIANGLEBUFFER_HLSL_INCLUDE + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc" + +void DepthkitCoreSampleTriangleBuffer_float(in float2 triangleUV, out float2 perspectiveUV, out float3 position, out float3 normal, out uint perspective) +{ + Vertex vert = dkSampleTriangleBuffer((uint)triangleUV.x, (uint)triangleUV.y); + perspective = vert.perspectiveIndex; + position = vert.position; + normal = vert.normal; + perspectiveUV = vert.uv.xy; +} + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl.meta new file mode 100644 index 0000000..d72cf43 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreSampleTriangleBuffer.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9425010fadc863c47b5f8775a2f32428 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl new file mode 100644 index 0000000..4f0b2c9 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl @@ -0,0 +1,53 @@ + +#ifndef DEPTHKIT_FRAGMENT_HLSL_INCLUDED +#define DEPTHKIT_FRAGMENT_HLSL_INCLUDED + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc" + +DK_EDGEMASK_UNIFORMS + +void DepthkitCoreFragment_float(in float3 screenSpacePosition, in float3 objectPosition, out float3 color, out float alpha, out float2 uv, out float alphaclip) +{ + float2 colorUV; + float2 depthUV; + float3 viewspace; + dkWorldToPerspectiveUV(0, objectPosition, uv, depthUV, colorUV, viewspace); + float depth = dkSampleDepth(depthUV, 0, uv); + bool valid = dkValidateNormalizedDepth(0, depth); + +#ifdef DK_USE_DEBUG_COLOR + color = dkGetDebugCameraColor(0); +#else + color = dkSampleColor(colorUV); +#endif + + alpha = lerp(-1.f, DK_SAMPLE_EDGEMASK(uv, 0, screenSpacePosition), valid); + alphaclip = DK_CLIP_THRESHOLD(0); + +#ifdef DK_DEBUG_EDGEMASK + color = float3(alpha * dkGetDebugCameraColor(0)); +#ifdef DK_USE_EDGEMASK + float2 minMaxMask = DK_SAMPLE_DOWNSAMPLED_EDGEMASK(uv, 0); + if (alpha < 0.0) + { + color = float3(0.3, 0.3, 0.3); + } + if (alpha == 0.0) //completely invalid + { + color = float3(0.05, 0.05, 0.05); + } + // dim if is edge + if ((1.0f - minMaxMask.y) < DK_CLIP_THRESHOLD(0)) + { + color *= .5; + } +#else + if (alpha < DK_ALPHA_CLIP_THRESHOLD) { color = float3(0.3f, 0.3f, 0.3f); } +#endif + alpha = 1.0f; +#endif + +} + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl.meta new file mode 100644 index 0000000..d51c2b6 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/Resources/Shaders/Includes/DepthkitCoreShaderGraph.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 54392f0b351a5bc418d0e506882a5db2 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs b/LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs new file mode 100644 index 0000000..fac0bfa --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs @@ -0,0 +1,74 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using System.Collections; +using UnityEngine; + +namespace Depthkit +{ + [RequireComponent(typeof(MeshFilter))] + [RequireComponent(typeof(MeshRenderer))] + public abstract class ShaderGraphLook : Look + { + protected MeshRenderer m_meshRenderer = null; + protected MeshFilter m_meshFilter = null; + + protected abstract Material GetDefaultShaderGraph(); + + protected override void SetDefaults() + { + m_meshFilter = GetComponent(); + m_meshFilter.hideFlags = HideFlags.NotEditable; + m_meshRenderer = GetComponent(); + + if (m_meshRenderer.sharedMaterial == null) + { + m_meshRenderer.material = GetDefaultShaderGraph(); + } + + m_meshRenderer.SetPropertyBlock(materialPropertyBlock); + + base.SetDefaults(); + } + + protected override bool UsesMaterial() { return true; } + protected override Material GetMaterial() + { + return m_meshRenderer.sharedMaterial; + } + + protected override void OnUpdate() + { + if (!meshSource.useTriangleMesh) meshSource.useTriangleMesh = true; + if(meshSource.triangleMesh != null && meshSource.triangleMesh.mesh != m_meshFilter.sharedMesh) + m_meshFilter.sharedMesh = meshSource.triangleMesh.mesh; + m_meshRenderer.SetPropertyBlock(GetMaterialPropertyBlock()); + base.OnUpdate(); + } + + private void OnDestroy() + { + if (m_meshFilter != null) + { + m_meshFilter.hideFlags = HideFlags.None; + } + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs.meta b/LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs.meta new file mode 100644 index 0000000..b665138 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/Runtime/ShaderGraphLook.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c3101e111365f0e45a87bfedbd25d76d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core.shadergraph/package.json b/LocalPackages/depthkit.core.shadergraph/package.json new file mode 100644 index 0000000..d971b14 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/package.json @@ -0,0 +1,28 @@ +{ + "name": "nyc.scatter.depthkit.core.shadergraph", + "version": "0.6.1", + "displayName": "Depthkit Core Shader Graph", + "description": "Use the Depthkit Core Shader Graph Package to render Depthkit captures from Depthkit Core and Depthkit Cinema in Unity’s Scriptable Render Pipeline including High Definition RP and Universal RP. This includes the components to visualize and customize Depthkit captures using Unity’s Shader Graph system.\n\nNote you can only render single-perspective captures with the Depthkit Core packages. For multi-perspective captures, use Depthkit Studio package suite.", + "unity": "2022.3", + "dependencies": { + "nyc.scatter.depthkit.core": "0.14.2", + "com.unity.shadergraph": "14.0.9" + }, + "samples": [ + { + "displayName": "Prefabs - Depthkit Core Shader Graph", + "description": "Prefabs for the Scriptable Render Pipelines", + "path": "Samples~/Depthkit Core Shader Graph Prefabs" + } + ], + "keywords": [ + "Depthkit", + "Volumetric", + "Scatter" + ], + "author": { + "name": "Scatter", + "email": "support@depthkit.tv", + "url": "https://www.depthkit.tv" + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core.shadergraph/package.json.meta b/LocalPackages/depthkit.core.shadergraph/package.json.meta new file mode 100644 index 0000000..269f402 --- /dev/null +++ b/LocalPackages/depthkit.core.shadergraph/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 46adddac66588c1428ec4cef359c7a03 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/CHANGELOG.md b/LocalPackages/depthkit.core/CHANGELOG.md new file mode 100644 index 0000000..ce2d430 --- /dev/null +++ b/LocalPackages/depthkit.core/CHANGELOG.md @@ -0,0 +1,77 @@ +## Changelog + +### 0.14.3 +* Fix bug where certain fields were not serializing after GUI changes + +### 0.14.2 +* Update SDK license agreement + +### 0.14.1 +* Fixed an issue where Built-in RP Looks were not rendering in Unity 2022.3.19 + +### 0.14.0 +* Updated to Unity 2022.3 +* Better handling of clip reconstruction settings when setting a new metadata asset + +### 0.13.4 +* Updated assembly definitions. + +### 0.13.3 +* Fixes a runtime error when disabling and re-enabling a component that uses a Mask Generator +* Fixes an issue on Quest 2 where certain compute shaders would fail to link + +### 0.13.2 +* Bug fixes + +### 0.13.1 +* Bug fixes + +### 0.13.0 +* Support new 0.5.0 metadata version with preconfigured texture blending and depth bias compensation settings + +### 0.12.2 +* Bug fixes + +### 0.12.1 +* Minor UI updates + +### 0.12.0 +* Updated to Unity 2020.3 +* Improved edge masking usability and performance. +* Added edge dithering to soften clipped edges. + +### 0.11.1 +* Updated BiRP Photo Look shader to use light probes by default. +* Exposed Disable Main Directional Shadows toggle in BiRP Photo Look shader. + +### 0.11.0 +* Apply depth bias to depth everywhere depth is sampled. + +### 0.10.2 +* Allow BiRP looks to use shadows from all light types. + +### 0.10.1 +* If OpenVR is detected, force single pass instanced stereo rendering mode. A hack to work around OpenVR not reporting to XRSettings. + +### 0.10.0 +* Allow BiRP light probes +* Pause video or data generation on invisible +* AVPro 2 +* Sync collider and triangle mesh to clip bounds + +### 0.9.0 +* Lifecycle fixes +* Allow changing video player from API + +### 0.8.0 +* Improved GPU resource management and execution order +* Added support for material property blocks +* Bug fixes + +### 0.6.0 +* Removed depthkit info from depthkit clip and added depthkit icon to all depthkit components +* Added Edge Smoothing Scale to **Core Mesh Source** Component +* Reorganized utils files into Utils folder + +### 0.5.1 +* removed Unity Video Player's component menu \ No newline at end of file diff --git a/LocalPackages/depthkit.core/CHANGELOG.md.meta b/LocalPackages/depthkit.core/CHANGELOG.md.meta new file mode 100644 index 0000000..0f815a5 --- /dev/null +++ b/LocalPackages/depthkit.core/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 11fb57a5eed95f2439c5743f2a1e4ceb +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor.meta b/LocalPackages/depthkit.core/Editor.meta new file mode 100644 index 0000000..50d3372 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6ccbc805dc3c70a46a5b7db6bfa86237 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/ClipEditor.cs b/LocalPackages/depthkit.core/Editor/ClipEditor.cs new file mode 100644 index 0000000..ac52995 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/ClipEditor.cs @@ -0,0 +1,184 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Linq; +using System.Collections.Generic; +using System; + +namespace Depthkit +{ + [CustomEditor(typeof(Depthkit.Clip))] + public class ClipEditor : Editor + { + bool m_showAdvanced = false; + bool m_platformValid = true; + List m_invalidReasons = new List(); + + void OnEnable() + { + if(AvailablePlayers.Empty()) + { + AvailablePlayers.UpdatePlayers(); + } + + m_platformValid = Info.IsPlatformValid(ref m_invalidReasons); + } + + public override void OnInspectorGUI() + { + //update the object with the object variables + serializedObject.Update(); + + //set the clip var as the target of this inspector + Depthkit.Clip clip = (Depthkit.Clip)target; + + if (!m_platformValid) + { + EditorGUILayout.BeginVertical(); + GUI.backgroundColor = Color.red; + EditorGUILayout.HelpBox("Depthkit Unity Plugin is incompatible with this platform", MessageType.Error); + foreach (string reason in m_invalidReasons) + { + EditorGUILayout.HelpBox(reason, MessageType.Error); + } + + EditorGUILayout.EndVertical(); + GUI.backgroundColor = Color.white; + } + + EditorGUILayout.BeginVertical("Box"); + { + // PLAYER INFO + SetupPlayerGUI(clip); + SetupMetadataGUI(clip); + SetupPosterGUI(clip); + EditorGUILayout.Space(); + CheckClipSetup(clip); + } + EditorGUILayout.EndVertical(); + m_showAdvanced = EditorGUILayout.Foldout(m_showAdvanced, "Advanced Settings"); + if(m_showAdvanced) + { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField(new GUIContent("Disable Poster", "Disabling the poster will cause the clip not to show anything unless playing. Disable the poster to control the video player via a Timeline Playable."), GUILayout.Width(EditorGUIUtility.labelWidth)); + bool disable = clip.disablePoster; + bool newDisable = EditorGUILayout.Toggle(disable); + if(disable != newDisable) + { + Undo.RecordObject(clip, "Set Disable Poster"); + clip.disablePoster = newDisable; + EditorUtility.SetDirty(clip); + } + EditorGUILayout.EndHorizontal(); + } + EditorGUILayout.Space(); + // APPLY PROPERTY MODIFICATIONS + serializedObject.ApplyModifiedProperties(); + } + + void CheckClipSetup(Depthkit.Clip clip) + { + if (clip.isSetup) + { + GUI.backgroundColor = Color.green; + EditorGUILayout.BeginVertical(); + + EditorGUILayout.HelpBox("Depthkit clip is setup and ready for playback", + MessageType.Info); + } + else + { + GUI.backgroundColor = Color.red; + EditorGUILayout.BeginVertical(); + + EditorGUILayout.HelpBox("Depthkit clip is not setup. \n" + + string.Format("Player Setup: {0} | Metadata Setup: {1}", + clip.playerSetup, clip.hasMetadata), + MessageType.Error); + } + EditorGUILayout.EndVertical(); + GUI.backgroundColor = Color.white; + } + + void SetupPlayerGUI(Depthkit.Clip clip) + { + EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel); + int choiceIndex = -1; + ClipPlayer player = clip.player; + + if(player != null) + { + for (int i = 0; i < AvailablePlayers.Types.Count; ++i) + { + if (AvailablePlayers.Types[i] == player.GetPlayerTypeName()) + { + choiceIndex = i; + break; + } + } + } + else + { + choiceIndex = AvailablePlayers.DefaultPlayerIndex; + } + + int finalChoiceIndex = EditorGUILayout.Popup("Player", choiceIndex, AvailablePlayers.PrettyNames.ToArray()); + + if (finalChoiceIndex < 0 || finalChoiceIndex >= AvailablePlayers.PrettyNames.Count) + finalChoiceIndex = AvailablePlayers.DefaultPlayerIndex; + + if (finalChoiceIndex != choiceIndex) + { + clip.SetPlayer(Type.GetType(AvailablePlayers.AssemblyNames[finalChoiceIndex])); + EditorUtility.SetDirty(clip); + } + } + + void SetupMetadataGUI(Depthkit.Clip clip) + { + //TODO other metadata asset types + EditorGUI.BeginChangeCheck(); + TextAsset metadataFile = EditorGUILayout.ObjectField("Metadata", clip.metadataFile, typeof(TextAsset), false) as TextAsset; + if(EditorGUI.EndChangeCheck()) + { + Undo.RecordObject(clip, "Set Metadata File"); + clip.metadataFile = metadataFile; + EditorUtility.SetDirty(clip); + } + } + + void SetupPosterGUI(Depthkit.Clip clip) + { + Texture2D poster = clip.poster; + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PrefixLabel("Poster"); + Texture2D newPoster = EditorGUILayout.ObjectField(poster, typeof(Texture2D), false) as Texture2D; + if (poster != newPoster) + { + Undo.RecordObject(clip, "Set Poster"); + clip.poster = newPoster; + EditorUtility.SetDirty(clip); + } + EditorGUILayout.EndHorizontal(); + } + } +} diff --git a/LocalPackages/depthkit.core/Editor/ClipEditor.cs.meta b/LocalPackages/depthkit.core/Editor/ClipEditor.cs.meta new file mode 100644 index 0000000..b226012 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/ClipEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 09f4cd57574ad9a4b9292f36adba66bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef b/LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef new file mode 100644 index 0000000..4ef4bac --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef @@ -0,0 +1,17 @@ +{ + "name": "Depthkit.Core.Editor", + "references": [ + "GUID:d757665d4a59fe94bab8bd5391e60e3d" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef.meta b/LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef.meta new file mode 100644 index 0000000..37283b8 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Depthkit.Core.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7ec71480072be074c8f90dd646706fad +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/EditorUtil.cs b/LocalPackages/depthkit.core/Editor/EditorUtil.cs new file mode 100644 index 0000000..f22d0b6 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/EditorUtil.cs @@ -0,0 +1,44 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.IO; + +namespace Depthkit { + public static class EditorUtil + { + public static void ShowEditorComponentLink(T target) where T : MonoBehaviour + { + GUI.enabled = false; + EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour(target), typeof(T), false); + GUI.enabled = true; + } + public static void DrawUILine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += padding / 2; + r.x -= 2; + r.width += 6; + EditorGUI.DrawRect(r, color); + } + } +} diff --git a/LocalPackages/depthkit.core/Editor/EditorUtil.cs.meta b/LocalPackages/depthkit.core/Editor/EditorUtil.cs.meta new file mode 100644 index 0000000..a56672e --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/EditorUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a1d2cd4e73ea57e4ca92a5d8e18c6a2c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/Looks.meta b/LocalPackages/depthkit.core/Editor/Looks.meta new file mode 100644 index 0000000..4d9724e --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Looks.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6b28c48544776e74f9c13a6d2eda471e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs b/LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs new file mode 100644 index 0000000..0969237 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs @@ -0,0 +1,40 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Linq; +using System.Collections.Generic; +using System; + +namespace Depthkit +{ + public class CoreLookGizmosDrawer + { + [DrawGizmo(GizmoType.Selected | GizmoType.Active)] + static void DrawGizmosFor(CoreLook look, GizmoType gizmoType) + { + if (look.showCameraFrustums) + { + Depthkit.Util.RenderMetadataGizmos(look.depthkitClip.metadata, look.transform); + } + } + } +} diff --git a/LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs.meta b/LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs.meta new file mode 100644 index 0000000..f6b8cec --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Looks/CoreLookGizmosDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 82bf8826e90df0641aef0db261581664 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/PlayerProcessor.cs b/LocalPackages/depthkit.core/Editor/PlayerProcessor.cs new file mode 100644 index 0000000..1226f68 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/PlayerProcessor.cs @@ -0,0 +1,87 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Collections.Generic; +using System.Reflection; +using System; + +namespace Depthkit +{ +#if UNITY_EDITOR + public static class AvailablePlayers + { + static AvailablePlayers() + { + Types = new List(); + AssemblyNames = new List(); + PrettyNames = new List(); + } + public static List Types; + public static List PrettyNames; + public static List AssemblyNames; + public static int DefaultPlayerIndex; + + public static bool Empty(){ return AvailablePlayers.Types.Count == 0; } + + public static void UpdatePlayers() + { + AvailablePlayers.Types.Clear(); + AvailablePlayers.PrettyNames.Clear(); + AvailablePlayers.AssemblyNames.Clear(); + var players = Reflector.GetDerivedTypeSet(); + int index = 0; + foreach(KeyValuePair player in players) + { + if(player.Key == typeof(Depthkit.UnityVideoPlayer).Name) + { + AvailablePlayers.DefaultPlayerIndex = index; + } + Type t = Type.GetType(player.Value); + AvailablePlayers.PrettyNames.Add(t.GetMethod("GetPlayerPrettyName").Invoke(null, null) as string); + AvailablePlayers.Types.Add(player.Key); + AvailablePlayers.AssemblyNames.Add(player.Value); + ++index; + } + } + } + + public class Depthkit_PlayerProcessor : UnityEditor.AssetModificationProcessor + { + public static string[] OnWillSaveAssets(string[] paths) + { + AvailablePlayers.UpdatePlayers(); + return paths; + } + + static void OnWillCreateAsset(string name) + { + AvailablePlayers.UpdatePlayers(); + } + + static AssetDeleteResult OnWillDeleteAsset(string name, RemoveAssetOptions options) + { + AvailablePlayers.UpdatePlayers(); + return AssetDeleteResult.DidNotDelete; + } + } +#endif +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Editor/PlayerProcessor.cs.meta b/LocalPackages/depthkit.core/Editor/PlayerProcessor.cs.meta new file mode 100644 index 0000000..2a1f791 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/PlayerProcessor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 689c86c2b7116384fb4aa20757e5e5e5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/Sources.meta b/LocalPackages/depthkit.core/Editor/Sources.meta new file mode 100644 index 0000000..8cf4b14 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Sources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: aba3d1fb25ad3d74fa223dc39e209f56 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs b/LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs new file mode 100644 index 0000000..1e5cd87 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs @@ -0,0 +1,233 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; + +namespace Depthkit +{ + [CustomEditor(typeof(Depthkit.CoreMeshSource))] + public class CoreMeshSourceEditor : Editor + { + private bool m_showAdvanced = false; + private bool m_showRelighting = false; + private static MeshDensity s_maskScale; + + SerializedProperty adjustableNormalSlope; + SerializedProperty normalGenerationTechnique; + SerializedProperty pauseDataGenerationWhenInvisible; + SerializedProperty pausePlayerWhenInvisible; + SerializedProperty radialBias; + + public static readonly GUIContent s_meshDensityLabel = new GUIContent("Mesh Density", "Adjust the density of the Depthkit mesh. Higher values capture more detail and have cleaner edges at the cost of performance."); + public static readonly GUIContent s_maxSurfaceTrianglesLabel = new GUIContent("Surface Buffer Capacity", "This value determines the maximum number of triangles that can be displayed for each frame of this Clip. Each frame will have a variable size mesh based on the shape of its contents. A higher number ensures that no part of the surface is every excluded and allocates a larger memory footprint."); + public static readonly GUIContent s_normalGenTechniqueLabel = new GUIContent("Normal Generation Technique", "This is the algorithm used to generate normals. Flat is the fastest."); + public static readonly GUIContent s_normalSlopeLabel = new GUIContent("Normal Slope", "Adjust the slope of the normal to artificially flatten or sharpen surface normals."); + public static readonly GUIContent s_setSurfaceBufferCapLabel = new GUIContent("Set Surface Buffer Capacity", "Use this button to sample the current frame to set a reasonable Surface Buffer Capacity tailored to your content."); + public static readonly GUIContent s_setSurfaceBufferCapSliderLabel = new GUIContent("Surface Buffer Capacity (% of max)", "Use this slider to adjust Surface Buffer Capacity as a percentage of the maximum triangles needed for your content."); + public static readonly GUIContent s_radialBiasLabel = new GUIContent("Depth Bias Compensation", "Time of Flight cameras measure surfaces farther away than they are in reality. The amount of bias depends greatly on the material of the surface being measured. Skin in particular has a large bias. The Depth Bias Compensation is a correction for this error by pulling the surface back towards their true depth. It most useful for recovering high quality faces and hands on otherwise well-calibrated captures. The larger the value, the larger the compensation. 0 means no depth bias compensation is applied."); + + public static readonly GUIContent s_ditherEdgeLabel = new GUIContent("Dither Edge", ""); + + MaskGeneratorGUI m_maskGeneratorGui; + + void OnEnable() + { + pauseDataGenerationWhenInvisible = serializedObject.FindProperty("pauseDataGenerationWhenInvisible"); + pausePlayerWhenInvisible = serializedObject.FindProperty("pausePlayerWhenInvisible"); + radialBias = serializedObject.FindProperty("radialBias"); + normalGenerationTechnique = serializedObject.FindProperty("normalGenerationTechnique"); + adjustableNormalSlope = serializedObject.FindProperty("adjustableNormalSlope"); + + if(m_maskGeneratorGui == null) + { + m_maskGeneratorGui = new MaskGeneratorGUI(); + } + } + + private void OnDisable() + { + m_maskGeneratorGui?.Release(); + } + + public static bool Check(CoreMeshSource source) + { + if (GUI.changed) + { + EditorUtility.SetDirty(source); + GUI.changed = false; + return true; + } + return false; + } + + public static bool Check(CoreMeshSource source, ref bool resize) + { + if (Check(source)) + { + resize = true; + return true; + } + return false; + } + + public static bool Check(CoreMeshSource source, ref bool resize, ref bool generate) + { + if (Check(source, ref resize)) + { + generate = true; + return true; + } + return false; + } + + public static bool ValidateMeshDensity(System.Enum md) + { + return s_maskScale <= (MeshDensity)md; + } + + public static void MeshSettingsGUI(ref CoreMeshSource meshSource, ref bool doResize, ref bool doGenerate) + { + // save mask scale to static so it can be used in the validator function wrt downscale + s_maskScale = (MeshDensity)meshSource.maskGenerator.scale; + meshSource.meshDensity = (MeshDensity)EditorGUILayout.EnumPopup(s_meshDensityLabel, meshSource.meshDensity, ValidateMeshDensity, false); + Check(meshSource, ref doResize, ref doGenerate); + } + + public static void ResizeTriangleMeshGUI(ref CoreMeshSource meshSource, uint submeshIndex, ref bool doResize, ref bool doGenerate) + { + if (meshSource.useTriangleMesh) + { + if (GUILayout.Button(s_setSurfaceBufferCapLabel)) + { + meshSource.recalculateCurrentSurfaceTriangleCount = true; + } + + GUI.enabled = !meshSource.recalculateCurrentSurfaceTriangleCount; + uint originalIndex = meshSource.currentSubmeshIndex; + meshSource.currentSubmeshIndex = submeshIndex; + float percent = (float)EditorGUILayout.Slider(s_setSurfaceBufferCapSliderLabel, meshSource.surfaceTriangleCountPercent*100, 0.0f, 100.0f)/100.0f; + if( percent != meshSource.surfaceTriangleCountPercent) + { + meshSource.maxSurfaceTriangles = (uint)( percent * (float)meshSource.latticeMaxTriangles); + meshSource.surfaceTriangleCountPercent = percent; + } + GUI.enabled = false; + EditorGUILayout.IntField(s_maxSurfaceTrianglesLabel, (int)meshSource.maxSurfaceTriangles); + GUI.enabled = true; + Check(meshSource, ref doResize, ref doGenerate); + meshSource.currentSubmeshIndex = originalIndex; + } + } + + public static void RelightingGUI(ref bool show, ref SerializedProperty technique, ref SerializedProperty slope, ref bool doResize, ref bool doGenerate) + { + show = EditorGUILayout.Foldout(show, "Normal Generation Settings"); + if (show) + { + EditorGUILayout.PropertyField(technique, s_normalGenTechniqueLabel); + if (GUI.changed) + { + doResize = true; + doGenerate = true; + GUI.changed = false; + } + + NormalGenerationTechnique normalTechnique = (NormalGenerationTechnique)technique.enumValueIndex; + + if (normalTechnique == NormalGenerationTechnique.Adjustable || + normalTechnique == NormalGenerationTechnique.AdjustableSmoother) + { + EditorGUILayout.PropertyField(slope, s_normalSlopeLabel); + if (GUI.changed) + { + doGenerate = true; + GUI.changed = false; + } + } + } + } + + public override void OnInspectorGUI() + { + Depthkit.CoreMeshSource meshSource = target as Depthkit.CoreMeshSource; + bool doGenerate = false; + bool doResize = false; + + serializedObject.Update(); + MeshSettingsGUI(ref meshSource, ref doResize, ref doGenerate); + ResizeTriangleMeshGUI(ref meshSource, 0, ref doResize, ref doGenerate); + RelightingGUI(ref m_showRelighting, ref normalGenerationTechnique, ref adjustableNormalSlope, ref doResize, ref doGenerate); + + EditorGUI.BeginChangeCheck(); + + meshSource.clipThreshold = EditorGUILayout.Slider("Clipping Threshold", meshSource.clipThreshold, 0.0f, 1.0f); + + bool ditherEdge = meshSource.ditherEdge; + ditherEdge = EditorGUILayout.Toggle(s_ditherEdgeLabel, ditherEdge); + + if (ditherEdge != meshSource.ditherEdge) + { + meshSource.ditherEdge = ditherEdge; + } + if (meshSource.ditherEdge) + { + meshSource.ditherWidth = EditorGUILayout.Slider("Dithering Width", meshSource.ditherWidth, 0.0f, 0.2f); + } + if (EditorGUI.EndChangeCheck()) + { + doGenerate = true; + EditorUtility.SetDirty(meshSource); + } + + m_maskGeneratorGui.MaskGui(ref meshSource.maskGenerator, meshSource.meshDensity, ref doGenerate); + Check(meshSource); + + m_showAdvanced = EditorGUILayout.Foldout(m_showAdvanced, "Advanced Settings"); + if (m_showAdvanced) + { + EditorGUI.BeginChangeCheck(); + + EditorGUILayout.PropertyField(radialBias, s_radialBiasLabel); + meshSource.edgeCompressionNoiseThreshold = EditorGUILayout.Slider("Edge Compression Noise Threshold", meshSource.edgeCompressionNoiseThreshold, 0.0f, 1.0f); + EditorGUILayout.PropertyField(pausePlayerWhenInvisible); + EditorGUILayout.PropertyField(pauseDataGenerationWhenInvisible); + + if (EditorGUI.EndChangeCheck()) + { + doGenerate = true; + EditorUtility.SetDirty(meshSource); + } + } + + serializedObject.ApplyModifiedProperties(); + + if (doResize) + { + meshSource.Resize(); + } + if (doGenerate) + { + m_maskGeneratorGui.MarkDirty(); + meshSource.Generate(); + } + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs.meta b/LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs.meta new file mode 100644 index 0000000..8883b3c --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Sources/CoreMeshSourceEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c22cb842fc788774cb0ce85d7280d961 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs b/LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs new file mode 100644 index 0000000..a790406 --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs @@ -0,0 +1,214 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEditor; +using UnityEngine; + +namespace Depthkit +{ + public class MaskGeneratorGUI + { + RenderTexture[] m_arrayTextures = null; + RenderTexture[] m_arrayDownscaledTextures = null; + bool m_filled = false; + float m_scale = 0.5f; + private static MeshDensity s_meshDensity; + + private bool m_showTextures = false; + + public static readonly GUIContent s_maskScaleLabel = new GUIContent("Down Scale", "Adjust the scale of the mask. Higher values capture more detail and have cleaner edges at the cost of performance."); + public static readonly GUIContent s_edgeMaskSobelStrengthLabel = new GUIContent("Intensity", "Corrects texture spill between surfaces, such as fragments of hands appearing on clothing."); + public static readonly GUIContent s_edgeMaskBlurRadiusLabel = new GUIContent("Feather", "Softens texture spill correction. Needs to be adjusted visually and varies based on the Texture Spill Correction Intensity applied above."); + public static readonly GUIContent s_previewMaskOnGeoLabel = new GUIContent("Debug Edge Mask", "Debug view of the mask generated per perspective for precise edge masking adjustments."); + + public static bool ValidateMeshDensity(System.Enum md) + { + return s_meshDensity >= (MeshDensity)md; + } + + public void MaskGui(ref MaskGenerator maskGenerator, MeshDensity meshDensity, ref bool doGenerate, bool drawBox=false) + { + if (drawBox) + { + EditorGUILayout.BeginVertical("Box"); + } + else + { + EditorGUILayout.Space(); + EditorUtil.DrawUILine(Color.gray, 1); + } + + EditorGUI.BeginChangeCheck(); + + bool previewMaskOnGeo = maskGenerator.enableMaskDebug; + previewMaskOnGeo = EditorGUILayout.Toggle(s_previewMaskOnGeoLabel, previewMaskOnGeo); + if (previewMaskOnGeo != maskGenerator.enableMaskDebug) + { + maskGenerator.enableMaskDebug = previewMaskOnGeo; + } + + s_meshDensity = meshDensity; + MeshDensity d = (MeshDensity)EditorGUILayout.EnumPopup(s_maskScaleLabel, (MeshDensity)maskGenerator.scale, ValidateMeshDensity, false); + if (maskGenerator.scale != (int)d) + { + maskGenerator.scale = (int)d; + } + + EditorGUILayout.LabelField("Texture Spill Correction", EditorStyles.boldLabel); + EditorGUILayout.BeginVertical("Box"); + maskGenerator.sobelMultiplier = EditorGUILayout.Slider(s_edgeMaskSobelStrengthLabel, maskGenerator.sobelMultiplier, 0.0f, 100.0f); + maskGenerator.blurRadius = EditorGUILayout.Slider(s_edgeMaskBlurRadiusLabel, maskGenerator.blurRadius, 0.0f, 0.1f); + EditorGUILayout.EndVertical(); + + if (EditorGUI.EndChangeCheck()) + { + doGenerate = true; + } + + PreviewGUI(ref m_showTextures, ref maskGenerator, false); + + if (drawBox) + { + EditorGUILayout.EndVertical(); + } + else + { + EditorUtil.DrawUILine(Color.gray, 1); + EditorGUILayout.Space(); + } + } + + public void MarkDirty() + { + m_filled = false; + } + + void ReleaseTexture(ref RenderTexture[] textures) + { + if (textures != null) + { + foreach (var tex in textures) + { + if (tex == null) continue; + tex.Release(); + Object.DestroyImmediate(tex); + } + } + textures = null; + } + + public void Release() + { + ReleaseTexture(ref m_arrayTextures); + ReleaseTexture(ref m_arrayDownscaledTextures); + } + + public void PreviewGUI(ref bool show, ref MaskGenerator maskGenerator, bool showDownscaled) + { + show = EditorGUILayout.Foldout(show, "Edge Mask Preview"); + if (show) + { + if (maskGenerator.maskTexture != null) + { + m_scale = EditorGUILayout.Slider("Preview Scale", m_scale, 0.0001f, 1.0f); + GUI.enabled = false; + EditorGUILayout.Vector2Field("Mask Dimensions", new Vector2(maskGenerator.maskTexture.width, maskGenerator.maskTexture.height)); + GUI.enabled = true; + switch (maskGenerator.maskTexture.dimension) + { + case UnityEngine.Rendering.TextureDimension.Tex2D: + GUILayout.Label(maskGenerator.maskTexture, GUILayout.Height(maskGenerator.maskTexture.height * m_scale)); + break; + case UnityEngine.Rendering.TextureDimension.Tex2DArray: + { + if (!m_filled) + { + // Mask + if (m_arrayTextures == null || m_arrayTextures.Length != maskGenerator.maskTexture.volumeDepth) + { + if (m_arrayTextures != null) + { + foreach (var tex in m_arrayTextures) + { + tex.Release(); + Object.DestroyImmediate(tex); + } + } + m_arrayTextures = new RenderTexture[maskGenerator.maskTexture.volumeDepth]; + } + for (int i = 0; i < maskGenerator.maskTexture.volumeDepth; ++i) + { + RenderTexture tempTexture = new RenderTexture(maskGenerator.maskTexture.width, maskGenerator.maskTexture.height, 0, maskGenerator.maskTexture.format, 0); + tempTexture.Create(); + Graphics.CopyTexture(maskGenerator.maskTexture, i, tempTexture, 0); + if (m_arrayTextures[i] != null) + { + m_arrayTextures[i].Release(); + } + m_arrayTextures[i] = tempTexture; + } + if (showDownscaled) + { + // Downscaled Mask + if (m_arrayDownscaledTextures == null || m_arrayDownscaledTextures.Length != maskGenerator.downScaledMaskTexture.volumeDepth) + { + if (m_arrayDownscaledTextures != null) + { + foreach (var tex in m_arrayDownscaledTextures) + { + tex.Release(); + Object.DestroyImmediate(tex); + } + } + m_arrayDownscaledTextures = new RenderTexture[maskGenerator.downScaledMaskTexture.volumeDepth]; + } + for (int i = 0; i < maskGenerator.downScaledMaskTexture.volumeDepth; ++i) + { + RenderTexture tempTexture = new RenderTexture(maskGenerator.downScaledMaskTexture.width, maskGenerator.downScaledMaskTexture.height, 0, maskGenerator.downScaledMaskTexture.format, 0); + tempTexture.Create(); + Graphics.CopyTexture(maskGenerator.downScaledMaskTexture, i, tempTexture, 0); + if (m_arrayDownscaledTextures[i] != null) + { + m_arrayDownscaledTextures[i].Release(); + } + m_arrayDownscaledTextures[i] = tempTexture; + } + } + + m_filled = true; + } + for (int i = 0; i < m_arrayTextures.Length; ++i) + { + GUILayout.Label(m_arrayTextures[i], GUILayout.Height(maskGenerator.maskTexture.height * m_scale)); + if (showDownscaled) GUILayout.Label(m_arrayDownscaledTextures[i], GUILayout.Height(maskGenerator.downScaledMaskTexture.height * m_scale)); + } + } + break; + default: break; + } + } + } + else + { + m_filled = false; + } + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs.meta b/LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs.meta new file mode 100644 index 0000000..2e5491c --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/Sources/MaskGeneratorGUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 211f4bdd9821d554cb67ae02e926e266 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Editor/depthkit-symbol-64.png b/LocalPackages/depthkit.core/Editor/depthkit-symbol-64.png new file mode 100644 index 0000000000000000000000000000000000000000..b1ca36072b247c42a0e892cbc1c70f4693f8d799 GIT binary patch literal 5387 zcmV+m74+(fP)?Z1&#p$K0qZ5Fd7wnyT-r>qA%-$%sM4CwMn&Jz}I4?@YRd2M4K?xqX4dy z)Z%0y{RfCslM9MU7#J8+fNbURk^&IB1IQLB0y+xFo&#d1L)aTY>?8>L2v|)>kTZ~d z1ISiL&PW8B!T1Bn)=5GVPe)=y?F9jDm(1dVoWx3n0Am8KB?FYCR+NBf=lp`oqRjM+ z5(P(KD5WZR<|XUtC>R+Snlmtf!W^Rdb09b@8O6>Z#G3CjFxc+@|NsAPgqYWU28NA5 zom@K+Vj30<41(MY3@3ILBo-xtg_wbuDJ_kG;nQ*k2Hr>p2H^`pJ<-K!#ztUyMjj^y z2G)E3|9@6vU|^rj!0>m%|Np-i{r~@WF;Mdz28IK902Lu+?ls5J`v3p{IAvH#W=%~1 zDgXcg2mk?xX#fNO00031000^Q000000-yo_1ONa40RR91K%fHv1ONa40RR91KmY&$ z0A-nAiU0r;AxT6*RCoc+TYHRLRT=-zotd4T>F)NqeJl?PXeli=l@J~R0p-;|fC{u2 zLm{*T42p?DRN_DV$4CXD5fm^fB8>v;K(GlC3nw@%bfM27NGHQ?V*UtR@miA%)c&r;})2A=0qncC%K-U5+DCptOuc#%p@WDt!+ zJAj#no~)t_1lvmJAQ@~R48gzkz6=P+-iy2KJm4z*UFs-{@q zR1$PFrdXcT8Oef^K*qT_Da;UoHs}TdvN8xs2gNVZQ2O&jdkm<(mM)y3tVeBtc8 z%)K}-wRSUy0bD5%GNc26FmbQKa&CCf&3dkR>`z+W2g3d@Gjru`jPARSaDq4wsA_Hq z@-L`#spcksj?ov_9!Q?`v5-c8_v=;5CK9;$K+)8 zcRD5MQ%41c@K`5_!t$VUT(B==3VpO{rdoaLPh|jnj`=SRVMgM#y~&< z6gqCVftrZKy+=5krYn3!ovWBjCtYDN)$GCkAbOFYJ+B z8+Q3~Fm}`V;W~&SI&w0w{*3hH?p8=>nE*;M03MkeXilP8I}|W{K}0Q}v`L6+1VBNu zY6f27)Pg7hXle+x0eK`t$VmjXf~3Uq@%mlT|56{W!}D=nx-(!A2sS)Xvx}mDLA^kC0=m4xydE^9t6hKgz)* zC<&Go5GSDy&`*e@=%l=3<3u581xGDFyGj>j^$P@#{?rhwhZayH66QQFmUIA4@%K9v zsHr~t(hvACk*iRodh=J(XO0aRM$7Y~RgP9i0=RH7anIE#EJ2}6DKHS`5*T3;T-p-U zIqaKr9w91#eWL^-d8^F(8wSR#7m&g_Eu#-}E}zZg^={fNd(Ui_t_AJriy7Fz^=SkQ zh|1huxWKvCMolei0MvOXsJu$MNdriZIYqA}RDIN$vqKL1=dnqZnqa1)s{qTH&6^#o zGo%(!m+BIKVs}}uqt`xhyGJAG;&uGse*hL5W)q1z=Tf|c0Ipy#4;E{Zd)2P=9uQBa{j*94k-Z~ zeBJ%0Za_S7|x0NDzdW#9L)G{_eOi|ssSL(a)Kpm@u zMT7pP$*%?)py`TGAF&)Baso)g0}q^eFC>0n2&5<_T}C-!Yz%HnE+_NlIF&e;v@A#> zNc6Gjkea}9RR;dqujlc6B~!1%rPKl>yGHy~j^CUngaA&UST5cIQ|KpHNmDVjz!Bu#+SjQ-d6Ah)vKM-VvbNr-6>V~^Ux>(YDi5WbNnjDUOYIc-~8 zRKG)mDtP&jGk8+};Pa#1(b5KAr?#&FkOfg{|1=G5s2}>zUX?ui>8&v}KuyPvStc2E zso~X3BTX0qoI){||BX67Y5=x^-!!B~nRyxe?sTd-JW3ljpM&Ge>D?rbwTw3s+du$_ zP@o`zz91Y2lBf{{iHF@AOeg_&tUdePwkZ9Z0>-MKwhPcCgJtI2X3ISyxz_T8AiSrurA4e$MeA2-z1I#lBj~C-^2bX0OV}T1pW*@*v zw@g>i+1k&3KHzE2>%BwLj)$j~EJhgC4OO`2FdxwJy+F9^!Oq)U`abU(50v=2jWGfv zLIytJ1&I;lsY1J}Firp@^wFfzP@o_iA)|;j6HWl07HxH75J13XymG7HUV(QzX#%j3 z&nf7@9|=hD5QxA@6#g_E&amT_&AHDO0d25#-Wg`9%*h6!c|r16{R3>6N~|)6$?y?6 z+Y~Qa3h?r@{SaEKCa^IiPf9psKH(bR(t1xG6C+mQVG3n`sC8KB5e(rW3Vj7JX(M(4 zJu2GT8D8@xng^}@{8iA8qu|{EK09cn2`3<*CWqV9Ol2EWYm|m?gOua_fCr?upOJum zzP_y(GyrwYetQmkd=G^J$TK_RO1cwvB1-NZ-|moS`OjfT|LF z&zMS~BQK>cg5+9{6iCprKhO&}erS=U2_+ymRJn!^1~RASQ5zYi5mos9J?VSu+;r9? zCXnOHcvL4HbJ{cr8YcB-+&GPGPI7N#=uwz30v=fLz|6s9@Fq?M^HNOAnbZVO%ltig z1&$9NUckFsuw+0~o!M8<5a~P&5dcDA9tQ&16bK1<&Lyw;Q#6|}0_w8&C-DBTTBH#S zSY3a*Tei#FkP;q^;nh0(DY&LMz|MCvZGM}Ex+5=VE>>32+(6l?`8u0LnUtAO?@tw5W;N>-91856v@vRXezPHlnvFi8YRydIuj*Wq^CSrjG zs5-C$<@TO7DdB;aK3XS}=*^S?CkwbbeCAWy(6l?G1U&qWpWQ4;yrzJ7qzQsfH%xl~ z56It=O?W8Ui(6Mb%-}{1U=*l^On6O8Cd#u;@9+VTfzJE`3R%n`vU9q~lTFyQct{9X zf7Q&X%a6PhL)&(;-iX>BoR;uhQc(X z?k|_npD#}u?V+FMYG3Z5lSKKzKn#g&W(iKU4Xjz_8_kfuNo9~z1 zvJ0^L;O;7E1ro=-JJ)gmuH#t%Z}$)slmx5I(d6&;o$64?Wy`C!1v{AGy>;N?*>t(M)X|NY0Ff~+$KoA`-|}m-`@1-GdW$; zWB;2S4faMVWd$UI5cfbY3cKrI|bO#RTd9*h(Y!trH-1 z1wZlZh{vWDn-055BAL0<}oFUjenH5gN;+=S;ziCI(ZXQ9tY3t9 ziRR#-9DwufF5mbXSmprABLWVfwG8su59ruV5&{_!>h${nj_1ehI=L*97g74W{Y6r+ zIMntqF?dtSf7?2YzHgZTN;Vsv=yfFJJmZ2SaU(Fku!sqa>WyvSqi-|CrrY4js-E4Dz$iz#8J`pqgxSsy{!4;Wt7w1FAm%)S02K&cFrj)Pxw|g3VLH zG%@CC|0G3Cz%)R=CP7`tDJ7Y4SsB;nb3ZS96+Cu6$N)+Gc!qq*Iquo*VRi?~Th{rigVn{uiC`M-nUKwCfd*dj2J|~F?^Y?wkS!059)0y z4-i^Uun36&ilF&N(3-3K+0V2@+X0+8UuAUP)G1Mc*KJAxxF;ef?gwYN*Z$PhW6a_> z2(Vy7uSnXN_Q}J$JuY#)c~M`0a&U5d15BwiJfgo~JV1acv_>V3GTT{aePL4b^D_B+ zlf-p#eEN{auwi^?Kn3skR-NwNd63f@PZ|dS%}&rJ5u`!$W108u^Z~R{Mh&XslrYJl zIy2xQK$r&2f_{R%nl-}CA`y7bcV<~SuR}zc8&Z<8+h-tdlw~VMUV55)XVZ9qhrX>7 z03ezEso~)gK?D5N2%hivbsa~}rHfiXP?T^4qvc=heS&&@5TXu`w(k80&naIyO^O$` zqiz7_!kJ^UVH@Bh7vU!}Zs`f`9gy(JQtJc^pJ0fJ^6fIm9CP_~;ItyRe@E$GW% z8FINJ2`bg;IcfjqY{@U8k>D4DxCV*kEtE-s%OSaNYjM|c<56zQ|MjD(aS*_@+$c~x z!>FRi%?{58~EMDi_#wL$E#-zq*Zk+)20YT=YUzHl5 zA4}5&pwfwVdIs0DKsH-5+X-7zO0f5h<*T9!vkUF)2l2->RRp@*CEWQi6d!Bsv z5$9IJ4mXZI_$RDwod8TJOEd+wgRDjissR8OKmaGt6>qn4>l}0j#Cd4Sv(ou zeGskuRp0SbMJ4lQC3@akoV&u;9+>FD{OqA_tBUg8zUu` zPjV#$y5&hOEkTyE0kQ}0t9m*lnU60y=kOMCw;F) pGWa5X7W>3Z_d@?c#<}0i{ST^%Lv01BFtPvu002ovPDHLkV1kot>Mj5P literal 0 HcmV?d00001 diff --git a/LocalPackages/depthkit.core/Editor/depthkit-symbol-64.png.meta b/LocalPackages/depthkit.core/Editor/depthkit-symbol-64.png.meta new file mode 100644 index 0000000..167db7d --- /dev/null +++ b/LocalPackages/depthkit.core/Editor/depthkit-symbol-64.png.meta @@ -0,0 +1,92 @@ +fileFormatVersion: 2 +guid: 42c51ff9981f3e24b83cd7ad3c56e235 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/LICENSE.md b/LocalPackages/depthkit.core/LICENSE.md new file mode 100644 index 0000000..4dac3aa --- /dev/null +++ b/LocalPackages/depthkit.core/LICENSE.md @@ -0,0 +1,138 @@ +SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT + +The text of this license (this “License”) may be found at: www.depthkit.tv/license-agreement-v1 + +Thank you for your interest in using the Simile Inc dba Scatter ("Scatter") Software Development Kit (the "SDK"). +In order to obtain and use the SDK, you must first agree to the terms of this License. If you do not agree to the +terms of this License, then you may not use the SDK. + +SDK LICENSE +1. Subject to the terms and conditions of this License, Scatter hereby +grants to you a worldwide, non-exclusive, royalty-free, sublicenseable license to use, reproduce, modify, +embed and redistribute (subject to restrictions below) the software contained in the SDK, including, but +not limited to, the samples, headers, documentation and source code. This License is subject to the +following terms and conditions: +1.1 This license grants you the non-exclusive license and right to use the SDK to develop +methods to play back content produced in the software suite known as Depth Kit (such content referred +to as your “Content”) in the Unity game engine, as well as other features that may be added from time to +time by Scatter. You may not use the SDK to connect Depth Kit to any software platform or game engine +other than Unity. +1.2 For avoidance of doubt, when you use the SDK in or with your Content, you retain all +rights to your Content, and you have no obligations to share or license your Content (including your +source and object code) to Scatter or any third parties; provided, however, Scatter retains all rights to the +SDK and the headers, libraries and APIs of Depth Kit and other tools made available by Scatter, including +those that may be incorporated into your Content by virtue of your producing it through Depth Kit. +1.3 You agree not to commit any act intended to (a) interfere with the normal operation of +Depth Kit or the SDK, (b) provide software to Depth Kit users or developers that would induce breach of +any Scatter agreements, or (c) provide software to Scatter or Depth Kit users that contains malware, +viruses, hacks, bots, Trojan horses, or other malicious code. +1.4 You may not use the SDK for any purpose not expressly permitted by this License. You +may not: + +a. decompile; +b. reverse engineer; +c. disassemble; or +d. attempt to derive the source code of any part of the SDK where source code is +not directly provided to you, or any other software or firmware provided to you by Scatter in binary +form (except as and only to the extent any foregoing restriction is prohibited by applicable law). + +REDISTRIBUTION +2. Subject to the terms and conditions of this License, your license to redistribute and sublicense the SDK +is also expressly made subject to the following conditions: +2.1 You may sublicense and redistribute the binary or object code form of the SDK in whole +for no charge or as part of a for-charge piece of Content; provided, however, you may only license, +sublicense or redistribute the binary or object code of the SDK (and not the SDK’s source code) in its +entirety. The SDK, including its associated libraries, and your Content that includes any portion of the +SDK, may only be used with Depth Kit and may not be used, licensed, or sublicensed to interface with +software that is not authorized and approved by Scatter; +2.2 You must include with all such redistributed or sublicensed SDK code the following copyright +notice: “Copyright 2016-2024 Simile Inc dba Scatter. All rights reserved.”; +2.3 You must give any other recipients of the SDK a copy of this License as such recipients, +licensees or sublicensees may only use the SDK subject to the terms of this License and such recipient's, +licensee's or sublicensee's agreement to and acceptance of this License with Scatter; and +2.4 The SDK includes a “LICENSE” text file (the “License Notice”), and any SDK distribution that +you distribute must include a copy of this License with the License Notice. + +GENERAL PROVISIONS +3. Additional Materials +3.1 Scatter may include in this SDK additional content (e.g., samples) for demonstration, +references or other specific purposes. Such content will be clearly marked in the SDK and is subject to +any included terms and conditions. +3.2 Your use of third-party materials included in the SDK, or which the SDK may be dependent +upon (including without limitation Unity), may be subject to other terms and conditions typically found in +separate third-party license agreements or "READ ME" files included with such third-party materials. To +the extent such other terms and conditions conflict with the terms and conditions of this License, the +former will control with respect to the applicable third-party materials. The terms of licensing the Unity +game engine can be found here: https://unity3d.com/legal/terms-of-service/software. +4. THE SDK AND ANY COMPONENT THEREOF ARE PROVIDED “AS IS” AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL Scatter AS THE COPYRIGHT OWNER OR ITS CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SDK, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOME JURISDICTIONS DO NOT PERMIT THE +EXCLUSION OR LIMITATION OF IMPLIED WARRANTIES, SO YOU MAY HAVE ADDITIONAL +RIGHTS. +5. This License does not grant permission to use the trade names, trademarks, service marks, or product +names of Scatter, including without limitation “Depth Kit,” except as required for reasonable and customary +use in describing the origin of the SDK, and reproducing the content of the License Notice file. Scatter +reserves all rights not expressly granted to you under this License. Neither Scatter’s name nor the names +of Scatter’s contributors, licensors, employees, or contractors, may be used to endorse or promote +products developed using the SDK without specific prior written permission of Scatter. +6. You are responsible for ensuring that your use of the SDK and your Content complies with all +applicable laws (including privacy laws) wherever your Content is made available. You acknowledge and +agree that you are solely responsible for any health and safety issues arising from your Content. +7. Your acceptance of the terms and conditions of this License in and of itself and for all of your Content +may be evidenced by your usage of the SDK or acceptance of this License. As this License is updated for +future releases of the SDK, you agree to abide by and meet all requirements of future updates of this +License for those future SDK releases, with acceptance evidenced by usage of the SDK or any element +thereof and the future updates of this License will apply for your Content that may be developed for or +with that future SDK or any element thereof (i.e., you cannot sidestep out of the requirements of future +updates of the License by developing against an older release of the SDK or License). You acknowledge +that future versions of the SDK may be provided for a fee or otherwise under substantially different terms +from those provided hereunder. +8. Scatter reserves the right to terminate this License and all your rights hereunder immediately in the +event you materially breach this License. +9. Furthermore, Scatter also reserves the right to cancel or terminate this License for any of the following +reasons: +a. Intellectual property infringement by you for your Content that is used with or by +the SDK; +b. Content that violates applicable law; +c. Health and safety issues associated with your Content; +d. Use of the SDK with a commercial product other than Depth Kit and Unity; and +e. Failure to provide required notices as set forth above. +10. You agree to fully indemnify Scatter from any and all losses, costs, damages and expenses (including +reasonable attorney's fees) arising out of your Content or any breach of this License. +11. Scatter may discontinue or change functionality of Depth Kit or the SDK at any time, and your +continued use of Depth Kit or the SDK or use of any modified or additional services in connection +therewith is conditioned upon your adherence to the terms of this License, as modified by Scatter from +time to time, as well as any additional license agreements necessitated by additional features. +12. In the event any provision of this License is determined to be invalid, prohibited or unenforceable by a +court or other body of competent jurisdiction, this License shall be construed as if such invalid, prohibited +or unenforceable provision has been more narrowly drawn so as not to be invalid, prohibited or +unenforceable. +13. You may not assign any rights or obligations under this License without the advance written consent +of Scatter, which may be withheld in its sole discretion. Scatter may assign its rights or obligations under +this License in its sole discretion. +14. Failure of either party at any time to enforce any of the provisions of this License will not be construed +as a waiver of such provisions or in any way affect the validity of this License or parts thereof. +15. Your remedies under this License shall be limited to the right to collect money damages, if any, and +you hereby waive your right to injunctive or other equitable relief. +16. You will comply with all applicable export control laws of the United States and any other applicable +governmental authority, including without limitation, the U.S. Export Administration Regulations. You +agree that this License and the SDK and accompanying documentation are Scatter's confidential +information (and is not publicly available), and you will not use it, disclose it or make it available to others +except in accordance with the terms of this License. +17. This License shall be governed by the laws of the State of New York, without giving effect to choice of +law principles. All disputes relating to this License shall be resolved by binding non-appearance-based +arbitration before a single arbitrator in New York County, New York. The arbitration shall be conducted in +accordance with the rules and procedures of JAMS then in effect, and the judgment of the arbitrator shall +be final and capable of entry in any court of competent jurisdiction. You and Scatter agree to submit to the +personal jurisdiction of the courts located within New York County, New York in connection with any +entrance of an arbitrator’s judgment or decision or any dispute with respect to the arbitration process or +procedure or Scatter’s exercise of its equitable rights or remedies. + +Effective as of October 7, 2016 diff --git a/LocalPackages/depthkit.core/LICENSE.md.meta b/LocalPackages/depthkit.core/LICENSE.md.meta new file mode 100644 index 0000000..7c1ef50 --- /dev/null +++ b/LocalPackages/depthkit.core/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 72a16cade0b6ec746abaaf5084eca140 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/README.md b/LocalPackages/depthkit.core/README.md new file mode 100644 index 0000000..857441a --- /dev/null +++ b/LocalPackages/depthkit.core/README.md @@ -0,0 +1,2 @@ +# Depthkit Core +Copyright 2021 Scatter All Rights reserved. diff --git a/LocalPackages/depthkit.core/README.md.meta b/LocalPackages/depthkit.core/README.md.meta new file mode 100644 index 0000000..f41a726 --- /dev/null +++ b/LocalPackages/depthkit.core/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9454e32cc81dce24abdd4429805c2e9b +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime.meta b/LocalPackages/depthkit.core/Runtime.meta new file mode 100644 index 0000000..ebc5be3 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9df3aea1edf1acc44bf8fdb17a8ee6b4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Clip.cs b/LocalPackages/depthkit.core/Runtime/Clip.cs new file mode 100644 index 0000000..0b3f15c --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Clip.cs @@ -0,0 +1,761 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System; +using System.Runtime.InteropServices; + +namespace Depthkit +{ + public delegate void ClipEventHandler(); + + [ExecuteInEditMode] + [DefaultExecutionOrder(-20)] + [AddComponentMenu("Depthkit/Depthkit Clip")] + public class Clip : MonoBehaviour, IPropertyTransfer + { + [Serializable] + internal class PerspectiveDataBuffer : SyncedStructuredBuffer + { + public PerspectiveDataBuffer(Metadata metadata) : + base("Depthkit Perspective Data Buffer", 0, Depthkit.Metadata.FillPersistentMetadataFromPerspectives(metadata.perspectives)) + { } + } + + #region Events + + //clip specific events + public event ClipPlayerEventHandler newFrame; + public event ClipPlayerEventHandler newPoster; + + private event DataSourceEventHandler m_newMetadata; + public event DataSourceEventHandler newMetadata + { + add + { + if (m_newMetadata != null) + { + foreach (DataSourceEventHandler existingHandler in m_newMetadata.GetInvocationList()) + { + if (existingHandler == value) + { + return; + } + } + } + m_newMetadata += value; + } + remove + { + if (m_newMetadata != null) + { + foreach (DataSourceEventHandler existingHandler in m_newMetadata.GetInvocationList()) + { + if (existingHandler == value) + { + m_newMetadata -= value; + } + } + } + } + } + + protected virtual void OnNewFrame() + { + if (newFrame != null) { newFrame(); } + } + protected virtual void OnNewMetadata() + { + if (m_newMetadata != null) { m_newMetadata(); } + +#if UNITY_EDITOR + UnityEditor.EditorApplication.QueuePlayerLoopUpdate(); +#endif + } + protected virtual void OnNewPoster() + { + if (newPoster != null) { newPoster(); } + } + + public Depthkit.PlayerEvents playerEvents + { + get + { + if (player != null) + { + return player.events; + } + Debug.LogError("Unable to access events as player is currently null"); + return null; + } + } + + #endregion + + #region Metadata + + public enum MetadataSourceType + { + TextAsset, + FilePath, + StreamingAssetPath, + JSONString + } + + /// + /// The metadata path. Can be relative to StreamingAssets. + [Tooltip("The path to your metadata file. Can be relative to StreamingAssets.")] + [SerializeField] + private string m_metadataFilePath; + public string metadataFilePath + { + get + { + return m_metadataFilePath; + } + set + { + + if (!string.IsNullOrEmpty(value)) + { + string metaDataJson; + string path; + MetadataSourceType type; + + if (File.Exists(value)) + { + metaDataJson = System.IO.File.ReadAllText(value); + type = MetadataSourceType.FilePath; + path = value; + } + else if (File.Exists(Path.Combine(Application.streamingAssetsPath, value))) + { + string relPath = Path.Combine(Application.streamingAssetsPath, value); + metaDataJson = System.IO.File.ReadAllText(relPath); + type = MetadataSourceType.StreamingAssetPath; + path = relPath; + } + else + { + Debug.LogError("Metadata filepath does not exist: " + value); + return; + } + + if (LoadMetadata(metaDataJson)) + { + m_metadataSourceType = type; + m_metadataFilePath = path; + OnNewMetadata(); + } + } + } + } + + /// + /// The metadata file text asset that corresponds to a given clip. Setting this asset null will clear the current metadata + [Tooltip("Your metadata TextAsset file, generated when you bring your metadata file anywhere into Unity's Assets/ folder")] + [SerializeField] + private TextAsset m_metadataFile; + public TextAsset metadataFile + { + get + { + return m_metadataFile; + } + set + { + if (value != null) + { + string metaDataJson = value.text; + if (LoadMetadata(metaDataJson)) + { + m_metadataFile = value; + m_metadataSourceType = MetadataSourceType.TextAsset; + OnNewMetadata(); + } + } + else + { + //setting this asset null, will clear the current metadata + m_metadataFile = null; + m_metadata = new Metadata(); + m_perspectiveDataBuffer.Release(); + } + } + } + + /// + /// The Type of Metadata file you're provided to the Depthkit renderer + [Tooltip("The type of Metadata file you're providing for this clip.")] + [SerializeField] + private MetadataSourceType m_metadataSourceType = MetadataSourceType.TextAsset; + public MetadataSourceType metadataSourceType + { + get + { + return metadataSourceType; + } + } + + [SerializeField] + private Depthkit.Metadata m_metadata = null; + public Depthkit.Metadata metadata + { + get + { + return m_metadata; + } + } + + public bool hasMetadata + { + get + { + return m_metadata.Valid(); + } + } + public bool LoadMetadata(string metaDataJson) + { + if (metaDataJson == "") + { + return false; + } + + try + { + m_metadata = Depthkit.Metadata.CreateFromJSON(metaDataJson); + } + catch (System.Exception e) + { + Debug.LogError("Invalid Depthkit Metadata Format. Make sure you are using the proper metadata export from Depthkit."); + Debug.LogError(e.Message); + m_metadata = new Metadata(); + return false; + } + + //TODO have the player's subscribe to the clip's event. + if (m_player != null) + { + m_player.OnMetadataUpdated(m_metadata); + } + + m_doResizeData = true; + m_doGenerateData = true; + + EnsurePerspectiveDataBuffer(); + + return true; + } + + [SerializeField, HideInInspector] + private PerspectiveDataBuffer m_perspectiveDataBuffer; + + private void EnsurePerspectiveDataBuffer() + { + if (hasMetadata) m_perspectiveDataBuffer = new PerspectiveDataBuffer(m_metadata); + } + + public ComputeBuffer perspectiveDataBuffer + { + get + { + return m_perspectiveDataBuffer?.buffer; + } + } + + #endregion + + #region Player + + [SerializeField] + private Depthkit.ClipPlayer m_player; + public Depthkit.ClipPlayer player + { + get + { + return m_player; + } + } + private void CreatePlayer(Type type) + { + //destroy the components that player references + //use a for loop to get around the component potentially shifting in the event of an undo + Depthkit.ClipPlayer[] attachedPlayers = GetComponents(); + for (int i = 0; i < attachedPlayers.Length; i++) + { + attachedPlayers[i].RemoveComponents(); + } + + m_player = null; + + m_player = gameObject.AddComponent(type) as Depthkit.ClipPlayer; + + player.CreatePlayer(); + } + + public void SetPlayer() where T : ClipPlayer + { + m_lastFrame = -1; + + m_player = gameObject.GetComponent(); + + if (player != null) + { + return; + } + + CreatePlayer(typeof(T)); + } + + public void SetPlayer(Type type) + { + m_lastFrame = -1; + + m_player = gameObject.GetComponent(type) as ClipPlayer; + + if (player != null) + { + return; + } + + CreatePlayer(type); + } + + public bool playerSetup + { + get + { + return m_player != null && m_player.IsPlayerSetup(); + } + } + + private int m_lastFrame = -1; + public bool playerIsActive + { + get + { + return (Application.isPlaying || player.IsPlaying()) && isSetup; + } + } + + public uint width + { + get + { + return playerSetup ? player.GetVideoWidth() : 0; + } + } + + public uint height + { + get + { + return playerSetup ? player.GetVideoHeight() : 0; + } + } + + public GammaCorrection gammaCorrectDepth + { + get + { + if (playerIsActive || disablePoster) + { + return player.GammaCorrectDepth(); + } + + return QualitySettings.activeColorSpace == ColorSpace.Linear ? GammaCorrection.LinearToGammaSpace : GammaCorrection.None; + } + } + + public GammaCorrection gammaCorrectColor + { + get + { + return (playerIsActive || disablePoster) ? player.GammaCorrectColor() : GammaCorrection.None; + } + } + + private Texture m_currentCPPTexture; + public Texture cppTexture + { + get + { + if (!playerIsActive && !disablePoster && player.SupportsPosterFrame()) + { + return poster; + } + return m_currentCPPTexture; + } + } + + public bool textureIsFlipped + { + get + { + return (playerIsActive || disablePoster) ? player.IsTextureFlipped() : false; + } + } + + #endregion + + #region Poster + + [SerializeField] + private Texture2D m_poster; + + public Texture2D poster + { + get + { + return m_poster; + } + set + { + m_poster = value; + if (m_poster != null) + { + m_doGenerateData = true; + OnNewPoster(); + } + } + } + + [SerializeField] + private bool m_disablePoster = false; + public bool disablePoster + { + get + { + return m_disablePoster; + } + set + { + if (value != m_disablePoster) + { + m_disablePoster = value; + m_doGenerateData = true; + } + } + } + + #endregion + + #region DataSource + + private List m_dataSourceRoots; + + private bool m_doResizeData = false; + private bool m_doGenerateData = false; + + //if the clip doesn't have the generator it will add it + public T GetDataSource(bool create = true) where T : Depthkit.DataSource + { + if (m_dataSourceRoots == null) + { + ResetDataSources(); + } + else + { + m_dataSourceRoots.RemoveAll(x => x.Target == null); + } + + //check if we already had it cached + foreach (var dataSource in m_dataSourceRoots) + { + var g = dataSource.Target as Depthkit.DataSource; + if (g != null) + { + if (dataSource.Target.GetType().Equals(typeof(T))) + { + return dataSource.Target as T; + } + } + } + if (!create) return null; + //check if its just not cached yet + T gen = gameObject.GetComponent(); + if (gen == null) + { + //add it + gen = gameObject.AddComponent(); + gen.ScheduleGenerate(); + } + //cache it + m_dataSourceRoots.Add(new WeakReference(gen)); + return gen; + } + + internal bool DoResize() + { + if (!hasMetadata || cppTexture == null) + { + return false; + } + foreach (var root in m_dataSourceRoots) + { + var gen = root.Target as Depthkit.DataSource; + if (gen != null) gen.Resize(); + } + return true; + } + + internal bool DoGenerate() + { + if (!hasMetadata || cppTexture == null) + { + return false; + } + + foreach (var root in m_dataSourceRoots) + { + var gen = root.Target as Depthkit.DataSource; + if (gen != null) + { + gen.Generate(); + } + } + m_dataSourceRoots.RemoveAll(x => x.Target == null); + return true; + } + + internal void ResetDataSources() + { + m_dataSourceRoots = new List(); + var datasources = GetComponents(); + foreach (var gen in datasources) + { + if (gen.dataSourceParent == "root") + { + m_dataSourceRoots.Add(new WeakReference(gen)); + } + } + } + + #endregion + + #region ShaderProps + + private static readonly float s_edgeChoke = 0.25f; + + internal static class ShaderIds + { + internal static readonly int + _CPPTexture = Shader.PropertyToID("_CPPTexture"), + _CPPTexture_TexelSize = Shader.PropertyToID("_CPPTexture_TexelSize"), + _EdgeChoke = Shader.PropertyToID("_EdgeChoke"), + _TextureFlipped = Shader.PropertyToID("_TextureFlipped"), + _ColorSpaceCorrectionDepth = Shader.PropertyToID("_ColorSpaceCorrectionDepth"), + _ColorSpaceCorrectionColor = Shader.PropertyToID("_ColorSpaceCorrectionColor"), + _PerspectivesCount = Shader.PropertyToID("_PerspectivesCount"), + _PerspectivesInX = Shader.PropertyToID("_PerspectivesInX"), + _PerspectivesInY = Shader.PropertyToID("_PerspectivesInY"), + _PerspectiveDataStructuredBuffer = Shader.PropertyToID("_PerspectiveDataStructuredBuffer"); + } + + public void SetProperties(ref ComputeShader compute, int kernel) + { + if (cppTexture == null) return; + compute.SetTexture(kernel, ShaderIds._CPPTexture, cppTexture); + compute.SetInt(ShaderIds._TextureFlipped, textureIsFlipped ? 1 : 0); + compute.SetInt(ShaderIds._ColorSpaceCorrectionDepth, (int)gammaCorrectDepth); + compute.SetInt(ShaderIds._ColorSpaceCorrectionColor, (int)gammaCorrectColor); + compute.SetInt(ShaderIds._PerspectivesCount, metadata.perspectivesCount); + compute.SetInt(ShaderIds._PerspectivesInX, metadata.numColumns); + compute.SetInt(ShaderIds._PerspectivesInY, metadata.numRows); + compute.SetFloat(ShaderIds._EdgeChoke, s_edgeChoke); + if (perspectiveDataBuffer != null) + compute.SetBuffer(kernel, ShaderIds._PerspectiveDataStructuredBuffer, perspectiveDataBuffer); + } + + public void SetProperties(ref Material material) + { + if (cppTexture == null) return; + material.SetTexture(ShaderIds._CPPTexture, cppTexture); + material.SetInt(ShaderIds._TextureFlipped, textureIsFlipped ? 1 : 0); + material.SetInt(ShaderIds._ColorSpaceCorrectionDepth, (int)gammaCorrectDepth); + material.SetInt(ShaderIds._ColorSpaceCorrectionColor, (int)gammaCorrectColor); + material.SetInt(ShaderIds._PerspectivesCount, metadata.perspectivesCount); + material.SetInt(ShaderIds._PerspectivesInX, metadata.numColumns); + material.SetInt(ShaderIds._PerspectivesInY, metadata.numRows); + material.SetFloat(ShaderIds._EdgeChoke, s_edgeChoke); + if (perspectiveDataBuffer != null) + material.SetBuffer(ShaderIds._PerspectiveDataStructuredBuffer, perspectiveDataBuffer); + } + + public void SetProperties(ref Material material, ref MaterialPropertyBlock block) + { + if (cppTexture == null) return; + block.SetTexture(ShaderIds._CPPTexture, cppTexture); + block.SetInt(ShaderIds._TextureFlipped, textureIsFlipped ? 1 : 0); + block.SetInt(ShaderIds._ColorSpaceCorrectionDepth, (int)gammaCorrectDepth); + block.SetInt(ShaderIds._ColorSpaceCorrectionColor, (int)gammaCorrectColor); + block.SetInt(ShaderIds._PerspectivesCount, metadata.perspectivesCount); + block.SetInt(ShaderIds._PerspectivesInX, metadata.numColumns); + block.SetInt(ShaderIds._PerspectivesInY, metadata.numRows); + block.SetFloat(ShaderIds._EdgeChoke, s_edgeChoke); + if (perspectiveDataBuffer != null) + block.SetBuffer(ShaderIds._PerspectiveDataStructuredBuffer, perspectiveDataBuffer); + } + + #endregion + + public bool isSetup + { + get + { + return playerSetup && hasMetadata; + } + } + +#if UNITY_EDITOR + void OnAssemblyReload() + { + EnsurePerspectiveDataBuffer(); + } +#endif + + void OnEnable() + { +#if UNITY_EDITOR + AssemblyReloadEvents.afterAssemblyReload += OnAssemblyReload; + EditorApplication.update += Update; +#endif + if (m_dataSourceRoots == null) + { + ResetDataSources(); + } + else + { + m_dataSourceRoots.RemoveAll(x => x.Target == null); + } + foreach (var root in m_dataSourceRoots) + { + var gen = root.Target as Depthkit.DataSource; + if (gen != null) + { + gen.hideFlags = HideFlags.None; + } + } + m_doGenerateData = true; + } + + void OnDisable() + { +#if UNITY_EDITOR + AssemblyReloadEvents.afterAssemblyReload -= OnAssemblyReload; + EditorApplication.update -= Update; +#endif + m_perspectiveDataBuffer?.Release(); + if (m_dataSourceRoots == null) return; + foreach (var root in m_dataSourceRoots) + { + var gen = root.Target as Depthkit.DataSource; + if (gen != null) + { + gen.hideFlags = HideFlags.NotEditable; + } + } + } + + void Start() + { + if (m_player == null) + { + SetPlayer(); + } + ResetDataSources(); + m_doResizeData = true; + m_doGenerateData = true; + EnsurePerspectiveDataBuffer(); + } + + void Update() + { + bool hasNewFrame = false; + + if (isSetup) + { + int frame = player.GetCurrentFrame(); + if (frame != -1 && m_lastFrame != frame) + { + m_currentCPPTexture = player.GetTexture(); + m_lastFrame = frame; + m_doGenerateData = true; + hasNewFrame = true; + } + } + + if (hasNewFrame) + { + OnNewFrame(); + } +#if UNITY_EDITOR + if (isSetup && !Application.isPlaying && player.IsPlaying()) + { + // Ensure continuous Update calls. + UnityEditor.EditorApplication.QueuePlayerLoopUpdate(); + } +#endif + } + + void LateUpdate() + { + if (isSetup) + { + m_perspectiveDataBuffer.Sync(); + + if (m_doResizeData) + { + m_doResizeData = !DoResize(); + } + + if (m_doGenerateData) + { + m_doGenerateData = !DoGenerate(); + } + } + } + + void OnDestroy() + { + if (m_dataSourceRoots == null) return; + foreach (var root in m_dataSourceRoots) + { + var gen = root.Target as Depthkit.DataSource; + if (gen != null) + { + gen.Cleanup(); + } + } + } + + void OnApplicationQuit() + { + if (player != null) + { + player.Stop(); + } + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Clip.cs.meta b/LocalPackages/depthkit.core/Runtime/Clip.cs.meta new file mode 100644 index 0000000..326d411 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Clip.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b4fa781ea55830e408ba83c0f9d07c4b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 42c51ff9981f3e24b83cd7ad3c56e235, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/DataSource.meta b/LocalPackages/depthkit.core/Runtime/DataSource.meta new file mode 100644 index 0000000..b95f7f8 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8d0be35cbb3985b49ba00a3f74d3b68a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs b/LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs new file mode 100644 index 0000000..462f72b --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs @@ -0,0 +1,495 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using System.Runtime.InteropServices; +using System; + +namespace Depthkit +{ + public enum MeshDensity + { + Low = 8, + Medium = 4, + High = 2, + Full = 1 + } + + public enum NormalGenerationTechnique + { + Smooth, + Adjustable, + AdjustableSmoother, + None, + DepthCamera + } + + namespace Core + { + public struct Vertex + { + public Vector4 uv; + public Vector3 position; + public Vector3 normal; + public uint perspectiveIndex; + public uint valid; + + public string Print() + { + return "uv: " + uv.ToString("F4") + " position: " + position.ToString("F4") + " normal: " + normal.ToString("F4"); + } + } + + public struct PackedTriangle + { + public Vertex vertex0; + public Vertex vertex1; + public Vertex vertex2; + } + + public struct IndexedTriangle + { + public uint perspective; + public uint vertex0; + public uint vertex1; + public uint vertex2; + } + } + + [System.Serializable] + public class PackedCoreTriangleSubMesh : SubMesh{} + + [System.Serializable] + public class IndexedCoreTriangleSubMesh : SubMesh{} + + [ExecuteInEditMode] + [AddComponentMenu("Depthkit/Core/Sources/Depthkit Core Mesh Source")] + public class CoreMeshSource : MeshSource + { + public float surfaceTriangleCountPercent = 0.70f; + + [SerializeField, HideInInspector] + private MeshDensity m_meshDensity = 0; + + public MeshDensity meshDensity + { + get + { + return (m_meshDensity == 0) ? MeshDensity.Medium : m_meshDensity; + } + set + { + if (m_meshDensity != value && clip.isSetup) + { + m_meshDensity = value; + maxSurfaceTriangles = 0; + ScheduleResize(); + ScheduleGenerate(); + } + } + } + + [SerializeField, HideInInspector] + protected Vector2Int m_latticeResolution = Vector2Int.one; + + [SerializeField, HideInInspector] + protected uint m_latticeMaxTriangles = 0; + public uint latticeMaxTriangles + { + get + { + return m_latticeMaxTriangles; + } + } + public Vector2Int latticeResolution + { + get { return m_latticeResolution; } + } + + public Vector2Int scaledPerspectiveResolution + { + get { return new Vector2Int(clip.metadata.perspectiveResolution.x / (int)meshDensity, clip.metadata.perspectiveResolution.y / (int)meshDensity); } + } + + protected void ResizeLattice() + { + // Note: we add 1 to the dimensions here to ensure we have enough verts for one quad per pixel of the CPP + m_latticeResolution = new Vector2Int(Math.Max(1 + clip.metadata.paddedTextureDimensions.x / (int)meshDensity, 1), Math.Max(1 + clip.metadata.paddedTextureDimensions.y / (int)meshDensity, 1)); + m_latticeMaxTriangles = (uint)(m_latticeResolution.x - 1) * (uint)(m_latticeResolution.y - 1) * 2; + vertexCount = (uint)m_latticeResolution.x * (uint)m_latticeResolution.y; + } + + public NormalGenerationTechnique normalGenerationTechnique = NormalGenerationTechnique.None; + + [Range(1.0f, 1500.0f)] + public float adjustableNormalSlope = 255.0f; + + [Range(0.0f, 1.0f)] + public float edgeCompressionNoiseThreshold = 0.25f; + + [Range(0.0f, 1.0f)] + public float clipThreshold = 0.5f; + + public bool ditherEdge = false; + + [Range(0.0f, 0.2f)] + public float ditherWidth = 0.1f; + + #region VertexBuffer + public uint vertexCount = 0; + protected ComputeBuffer m_vertexBuffer; + public ComputeBuffer vertexBuffer { get { return m_vertexBuffer; } } + + #endregion + + #region TriangleGeneration + protected enum Phase + { + Vertices_Horizontal = 0, + Vertices_Vertical = 1, + Normals = 2, + Triangles = 3 + } + + [SerializeField, HideInInspector] + protected int m_vertexBufferSlices = 1; + + protected static class CoreShaderIds + { + public static readonly int + _EdgeChoke = Shader.PropertyToID("_EdgeChoke"), //override clip default + _VertexBuffer = Shader.PropertyToID("_VertexBuffer"), + _NormalHeight = Shader.PropertyToID("_NormalHeight"), + _LatticeSize = Shader.PropertyToID("_LatticeSize"), // padded to be multiple of 8 + _PerspectiveTextureSize = Shader.PropertyToID("_PerspectiveTextureSize"); + public static readonly string _DitherEdgeKW = "DK_SCREEN_DOOR_TRANSPARENCY"; + public static readonly string _UseGroupSharedMemory = "DK_USE_GROUPSHARED_MEMORY"; + } + + protected virtual string GetComputeShaderName() + { + return "Shaders/DataSource/DepthkitCoreMeshSource"; + } + + protected ComputeShader m_generateDataCompute; + + protected virtual string GetKernelNamePostfix(string prefix, bool edgeBuffer, bool edgeMask, int submesh = -1) + { + return prefix + (edgeBuffer ? "WEdgeBuffer" : "") + (edgeMask ? "WEdgeMask" : ""); + } + + protected int FindKernelId(Phase phase, bool edgeBuffer, bool edgeMask = false, int submesh = -1) + { + switch (phase) + { + case Phase.Vertices_Horizontal: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateVertices_Horizontal", edgeBuffer, edgeMask, submesh)); + case Phase.Vertices_Vertical: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateVertices_Vertical", edgeBuffer, edgeMask, submesh)); + case Phase.Normals: + switch (normalGenerationTechnique) + { + case NormalGenerationTechnique.Smooth: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateNormals", edgeBuffer, edgeMask, submesh)); + case NormalGenerationTechnique.Adjustable: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateNormalsAdjustable", edgeBuffer, edgeMask, submesh)); + case NormalGenerationTechnique.AdjustableSmoother: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateNormalsAdjustableSmoother", edgeBuffer, edgeMask, submesh)); + case NormalGenerationTechnique.DepthCamera: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateNormalsDepthCamera", edgeBuffer, edgeMask, submesh)); + case NormalGenerationTechnique.None: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateNormalsNone", edgeBuffer, edgeMask, submesh)); + default: return -1; + } + case Phase.Triangles: + return m_generateDataCompute.FindKernel(GetKernelNamePostfix("KGenerateTriangles", edgeBuffer, edgeMask, submesh)); + default: return -1; + } + } + + protected void GenerateVertexBuffer() + { + // generate all vertices + // Vertex generation samples the edge mask to create the vertex data + int kernel = FindKernelId(Phase.Vertices_Horizontal, false, true); + GenerateVertices(kernel, m_vertexBufferSlices); + + kernel = FindKernelId(Phase.Vertices_Vertical, false); + GenerateVertices(kernel, m_vertexBufferSlices); + + kernel = FindKernelId(Phase.Normals, false); + GenerateNormals(kernel, m_vertexBufferSlices); + } + + protected virtual void GenerateTriangles() + { + int kernel = FindKernelId(Phase.Triangles, false); + GenerateTriangles(kernel, 1); + } + + void GenerateVertices(int kernel, int slices = 1) + { + clip.SetProperties(ref m_generateDataCompute, kernel); + + // mask props + maskGenerator.SetProperties(ref m_generateDataCompute, kernel); + + // downscaled mask props + if (maskGenerator.downScaledMaskTexture != null) + m_generateDataCompute.SetTexture(kernel, MaskGenerator.MaskGeneratorShaderIds._MaskTexture, maskGenerator.downScaledMaskTexture); + + m_generateDataCompute.SetFloat(CoreShaderIds._EdgeChoke, edgeCompressionNoiseThreshold); + m_generateDataCompute.SetBuffer(kernel, CoreShaderIds._VertexBuffer, vertexBuffer); + m_generateDataCompute.SetVector(CoreShaderIds._LatticeSize, new Vector2(m_latticeResolution.x, m_latticeResolution.y)); + m_generateDataCompute.SetVector(CoreShaderIds._PerspectiveTextureSize, new Vector2(scaledPerspectiveResolution.x, scaledPerspectiveResolution.y)); + m_generateDataCompute.SetVectorArray(MeshSourceShaderIds._RadialBiasPerspInMeters, radialBiasPerspInMeters); + + if (Application.platform == RuntimePlatform.Android) // Quest 2 has issues with using too much group shared memory + { + m_generateDataCompute.DisableKeyword(CoreShaderIds._UseGroupSharedMemory); + } + else + { + m_generateDataCompute.EnableKeyword(CoreShaderIds._UseGroupSharedMemory); + } + + Util.DispatchGroups(m_generateDataCompute, kernel, m_latticeResolution.x, m_latticeResolution.y, slices); + } + + void GenerateNormals(int kernel, int perspectives = 1) + { + clip.SetProperties(ref m_generateDataCompute, kernel); + m_generateDataCompute.SetFloat(CoreShaderIds._EdgeChoke, edgeCompressionNoiseThreshold); + m_generateDataCompute.SetBuffer(kernel, CoreShaderIds._VertexBuffer, vertexBuffer); + m_generateDataCompute.SetVector(CoreShaderIds._LatticeSize, new Vector2(m_latticeResolution.x, m_latticeResolution.y)); + m_generateDataCompute.SetVector(CoreShaderIds._PerspectiveTextureSize, new Vector2(scaledPerspectiveResolution.x, scaledPerspectiveResolution.y)); + if (normalGenerationTechnique == NormalGenerationTechnique.Adjustable || normalGenerationTechnique == NormalGenerationTechnique.AdjustableSmoother) + m_generateDataCompute.SetFloat(CoreShaderIds._NormalHeight, adjustableNormalSlope); + Util.DispatchGroups(m_generateDataCompute, kernel, m_latticeResolution.x, m_latticeResolution.y, perspectives); + } + + void GenerateTriangles(int kernel, int perspectives = 1) + { + triangleBuffer.SetCounterValue(0); + + clip.SetProperties(ref m_generateDataCompute, kernel); + m_generateDataCompute.SetFloat(CoreShaderIds._EdgeChoke, edgeCompressionNoiseThreshold); + m_generateDataCompute.SetBuffer(kernel, CoreShaderIds._VertexBuffer, vertexBuffer); + m_generateDataCompute.SetVector(CoreShaderIds._LatticeSize, new Vector2(m_latticeResolution.x, m_latticeResolution.y)); + m_generateDataCompute.SetVector(CoreShaderIds._PerspectiveTextureSize, new Vector2(scaledPerspectiveResolution.x, scaledPerspectiveResolution.y)); + m_generateDataCompute.SetBuffer(kernel, SubMesh.TriangleDataShaderIds._TriangleBuffer, triangleBuffer); + + Util.DispatchGroups(m_generateDataCompute, kernel, scaledPerspectiveResolution.x, scaledPerspectiveResolution.y, perspectives); + } + #endregion + + #region DataSource + public override string DataSourceName() + { + return "Depthkit Core Mesh Source"; + } + + protected void EnsureVertexBuffer() + { + if (vertexCount > 0) + { + if (Util.EnsureComputeBuffer(ComputeBufferType.Structured, ref m_vertexBuffer, (int)vertexCount, Marshal.SizeOf(typeof(Core.Vertex)))) + { + m_vertexBuffer.name = "Depthkit Core Mesh Source Vertex Buffer"; + } + } + } + + protected void OnNewMetadata() + { + // if the metatada is completely different (differing number of perspectives) or it contains defaultReconstructionSettings, reset the reconstruction settings, else leave them be + if (maskGenerator.sliceCount != clip.metadata.perspectivesCount || clip.metadata._versionMajor > 0 || (clip.metadata._versionMajor == 0 && m_clip.metadata._versionMinor > 4)) + { + if (clip.metadata.perspectivesCount > 1) + radialBias = Util.metersToCm(clip.metadata.defaultReconstructionSettings.depthBiasAdjustment); + else + radialBias = 0.0f; + + maskGenerator.blurRadius = clip.metadata.defaultReconstructionSettings.edgeMaskBlurAmount; + maskGenerator.sobelMultiplier = clip.metadata.defaultReconstructionSettings.edgeMaskSobelMultiplier; + } + + EnsureMaskGenerator(); + } + + protected override void AcquireResources() + { + base.AcquireResources(); + if (m_latticeResolution.x > 0 && m_latticeResolution.y > 0) + { + if (clip != null && maskGenerator != null && maskGenerator.clip == null) maskGenerator.clip = clip; + } + + EnsureVertexBuffer(); + + if (m_clip) + { + m_clip.newMetadata += OnNewMetadata; + } + } + + protected override void FreeResources() + { + if (m_clip) + { + m_clip.newMetadata -= OnNewMetadata; + } + + Util.ReleaseComputeBuffer(ref m_vertexBuffer); + maskGenerator?.Release(); + base.FreeResources(); + } + + public override bool OnSetup() + { + Util.EnsureComputeShader(ref m_generateDataCompute, GetComputeShaderName()); + EnsureMaskGenerator(); + return base.OnSetup(); + } + + //allows us to call mesh source onResize directly from inherited classes + protected bool baseResize() + { + return base.OnResize(); + } + + protected override bool OnResize() + { + if (m_clip.isSetup) + { + m_vertexBufferSlices = 1; + + ReserveSubMeshes(1); + + ResizeLattice(); + + if (maxSurfaceTriangles == 0 || !useTriangleMesh) + { + if (useTriangleMesh) + { + maxSurfaceTriangles = (uint)(surfaceTriangleCountPercent * latticeMaxTriangles); + } + else + { + maxSurfaceTriangles = latticeMaxTriangles; + } + } + + CurrentSubMesh().Init(); + EnsureVertexBuffer(); + + EnsureMaskGenerator(); + + return baseResize(); + } + return false; + } + + protected virtual void GenerateEdgeMask() + { + maskGenerator.EnsureTexture(); + maskGenerator.GenerateMask(); + //set thresholds + maskGenerator.perspectivesToSlice[0].y = clipThreshold; + maskGenerator.perspectivesToSlice[0].z = ditherWidth; + } + + protected override bool OnGenerate() + { + if(clip.cppTexture == null) return false; + + GenerateEdgeMask(); + + GenerateVertexBuffer(); + GenerateTriangles(); + + bool recomputeMaxTriangles = recalculateCurrentSurfaceTriangleCount; + if (base.OnGenerate()) + { + // base.OnGenerate will recalculate the current surface triangle count if needed and reset the variable to false. + if(recomputeMaxTriangles && !recalculateCurrentSurfaceTriangleCount) + { + // update surfaceTriangleCountPercent + surfaceTriangleCountPercent = (float)maxSurfaceTriangles / (float)m_latticeMaxTriangles ; + } + return true; + } + else + return false; + } + + #endregion + + #region IPropertyTransfer + + public override void SetProperties(ref ComputeShader compute, int kernel) + { + compute.SetBuffer(kernel, CoreShaderIds._VertexBuffer, vertexBuffer); + maskGenerator?.SetProperties(ref compute, kernel); + base.SetProperties(ref compute, kernel); + compute.SetFloat(CoreShaderIds._EdgeChoke, edgeCompressionNoiseThreshold); + } + + public override void SetProperties(ref Material material) + { + material.SetBuffer(CoreShaderIds._VertexBuffer, vertexBuffer); + maskGenerator?.SetProperties(ref material); + base.SetProperties(ref material); + material.SetFloat(CoreShaderIds._EdgeChoke, edgeCompressionNoiseThreshold); + Util.EnsureKeyword(ref material, CoreShaderIds._DitherEdgeKW, ditherEdge); + } + + public override void SetProperties(ref Material material, ref MaterialPropertyBlock block) + { + block.SetBuffer(CoreShaderIds._VertexBuffer, vertexBuffer); + maskGenerator?.SetProperties(ref material, ref block); + base.SetProperties(ref material, ref block); + block.SetFloat(CoreShaderIds._EdgeChoke, edgeCompressionNoiseThreshold); + Util.EnsureKeyword(ref material, CoreShaderIds._DitherEdgeKW, ditherEdge); + } + #endregion + + #region MaskGenerator + + [SerializeField] + public MaskGenerator maskGenerator = null; + + public void EnsureMaskGenerator() + { + if (maskGenerator == null) + { + maskGenerator = new MaskGenerator(); + } + + if (clip != null) + { + maskGenerator.clip = clip; + } + maskGenerator.Setup(); + } + + #endregion + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs.meta b/LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs.meta new file mode 100644 index 0000000..1848e17 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/CoreMeshSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d141e4f523dd8314d99067356eb5952d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 42c51ff9981f3e24b83cd7ad3c56e235, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs b/LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs new file mode 100644 index 0000000..7d6b0e4 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs @@ -0,0 +1,323 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System; +using System.Collections.Generic; + +namespace Depthkit +{ + [ExecuteInEditMode] + [DefaultExecutionOrder(-15)] + public abstract class DataSource : MonoBehaviour + { + public DataSourceEvents events; + [SerializeField] + private bool m_bIsSetup = false; + protected Depthkit.Clip m_clip; + public Depthkit.Clip clip + { + get { return m_clip; } + } + + [SerializeField] + private string m_parent = "root"; + public string dataSourceParent + { + get { return m_parent; } + } + + private bool m_doUpdate = false; + private bool m_doResize = false; + public abstract string DataSourceName(); + + private List m_children; + public T GetChild(bool create = true) where T : DataSource + { + if (m_children == null) + { + ResetChildren(); + } + else + { + m_children.RemoveAll(x => x.Target == null); + } + //check if we already had it cached + foreach (var generator in m_children) + { + if (generator.Target.GetType().Equals(typeof(T))) + { + return generator.Target as T; + } + } + if (!create) return null; + //create it if its missing + T gen = gameObject.GetComponent(); + if (gen == null) + { + //add it + gen = gameObject.AddComponent(); + m_doUpdate = true; + } + gen.m_parent = DataSourceName(); + m_children.Add(new WeakReference(gen)); + return gen; + } + + internal void ResetChildren() + { + if (m_children == null) + { + m_children = new List(); + } + else + { + m_children.Clear(); + } + var dataSources = GetComponents(); + foreach (var source in dataSources) + { + if (source.dataSourceParent == DataSourceName()) + { + m_children.Add(new WeakReference(source)); + } + } + } + + protected virtual void AcquireResources() { } + protected virtual void FreeResources() { } + protected virtual void OnAwake() { } + public virtual void OnCleanup() { } + + public abstract bool OnSetup(); + protected abstract bool OnResize(); + protected abstract bool OnGenerate(); + + protected virtual void OnUpdate() { } + + protected virtual bool CanGenerate() { return true; } + + void Awake() + { + m_children = new List(); + events = new DataSourceEvents(); + m_clip = GetComponent(); + OnAwake(); + } + + void Start() + { + ResetChildren(); + m_bIsSetup = false; + } + + public void ScheduleGenerate() + { + m_doUpdate = true; + } + + public void ScheduleResize() + { + m_doResize = true; + } + public void UnscheduleGenerate() + { + m_doUpdate = false; + } + + public void UnscheduleResize() + { + m_doResize = false; + } + +#if UNITY_EDITOR + protected virtual void OnAssemblyReload() + { + Setup(); + ScheduleResize(); + ScheduleGenerate(); + } +#endif + + void OnEnable() + { +#if UNITY_EDITOR + AssemblyReloadEvents.afterAssemblyReload += OnAssemblyReload; +#endif + ResetChildren(); + foreach (var child in m_children) + { + var gen = child.Target as DataSource; + if (gen != null) + gen.hideFlags = HideFlags.None; + } + AcquireResources(); + } + + void OnDisable() + { +#if UNITY_EDITOR + AssemblyReloadEvents.afterAssemblyReload -= OnAssemblyReload; +#endif + FreeResources(); + + if (m_children == null) return; + + foreach (var child in m_children) + { + var gen = child.Target as DataSource; + if (gen != null) + gen.hideFlags = HideFlags.NotEditable; + } + } + + void Reset() + { + m_bIsSetup = false; + } + + public void Setup() + { + ResetChildren(); + AcquireResources(); + //Debug.Log(DataSourceName() + " - generator setup started..."); + m_bIsSetup = OnSetup(); + if (m_bIsSetup) + { + foreach (var child in m_children) + { + var gen = child.Target as DataSource; + if (gen != null) + gen.Setup(); + } + //Debug.Log(DataSourceName() + " - setup SUCCESS"); + } + } + + public void Cleanup() + { + OnCleanup(); + foreach (var child in m_children) + { + var gen = child.Target as DataSource; + if (gen != null) + gen.Cleanup(); + } + m_children.RemoveAll(x => x.Target == null); + } + + public void Resize() + { + //Debug.Log(DataSourceName() + " - generator resize started..."); + if (!gameObject.activeInHierarchy || !gameObject.activeSelf) + { + return; + } + if (!m_bIsSetup) + { + //Debug.Log(DataSourceName() + " - setting up insize resize..."); + Setup(); + } + if (m_bIsSetup) + { + if (OnResize()) + { + //Debug.Log(DataSourceName() + " - resize SUCCESS"); + events.OnDataResized(); + } + //refresh children regardless + foreach (var child in m_children) + { + var gen = child.Target as DataSource; + if (gen != null) + gen.Resize(); + } + } + } + + public bool IsSetup() + { + return m_bIsSetup; + } + + public void Generate() + { + //Debug.Log(DataSourceName() + " - generator generate started..."); + if (!gameObject.activeInHierarchy || !gameObject.activeSelf) + { + return; + } + + if (!m_bIsSetup) + { + Setup(); + if (!m_bIsSetup) + { + return; //early out if setup fails + } + Resize(); + } + + if (!CanGenerate()) return; + + if (OnGenerate()) + { + //Debug.Log(DataSourceName() + " - calling on generated event."); + events.OnDataGenerated(); + //only generate child data if we processed + foreach (var child in m_children) + { + var gen = child.Target as DataSource; + if (gen != null) + gen.Generate(); + } + } +#if UNITY_EDITOR + if (!Application.isPlaying) + { + //prompt the editor to update everything so the looks can update themselves with the new data + EditorApplication.delayCall += EditorApplication.QueuePlayerLoopUpdate; + } +#endif + //Debug.Log(DataSourceName() + " - generator generate complete"); + } + + void Update() + { + if (m_doResize) + { + Resize(); + m_doResize = false; + } + + } + + void LateUpdate() + { + if (m_doUpdate) + { + Generate(); + m_doUpdate = false; + } + OnUpdate(); + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs.meta b/LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs.meta new file mode 100644 index 0000000..d4341c6 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/DataSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: acdb98fea3f6ee54586aae0b04aef7bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs b/LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs new file mode 100644 index 0000000..eb212a6 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs @@ -0,0 +1,103 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +namespace Depthkit +{ + public delegate void DataSourceEventHandler(); + + /// + /// Class that contains events a given player could potentially emit for listening. + [System.Serializable] + public class DataSourceEvents + { + private event DataSourceEventHandler m_dataGenerated; + public event DataSourceEventHandler dataGenerated + { + add + { + if (m_dataGenerated != null) + { + foreach(DataSourceEventHandler existingHandler in m_dataGenerated.GetInvocationList()) + { + if (existingHandler == value) + { + return; + } + } + } + m_dataGenerated += value; + } + remove + { + if (m_dataGenerated != null) + { + foreach(DataSourceEventHandler existingHandler in m_dataGenerated.GetInvocationList()) + { + if (existingHandler == value) + { + m_dataGenerated -= value; + } + } + } + } + } + private event DataSourceEventHandler m_dataResized; + public event DataSourceEventHandler dataResized + { + add + { + if (m_dataResized != null) + { + foreach(DataSourceEventHandler existingHandler in m_dataResized.GetInvocationList()) + { + if (existingHandler == value) + { + return; + } + } + } + m_dataResized += value; + } + remove + { + if (m_dataResized != null) + { + foreach(DataSourceEventHandler existingHandler in m_dataResized.GetInvocationList()) + { + if (existingHandler == value) + { + m_dataResized -= value; + } + } + } + } + } + + public virtual void OnDataGenerated() + { + if(m_dataGenerated != null) { m_dataGenerated(); } + } + public virtual void OnDataResized() + { + if(m_dataResized != null) { m_dataResized(); } + } + } + +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs.meta b/LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs.meta new file mode 100644 index 0000000..4733ce4 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/DataSourceEvents.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d19808a84026d5a4491d90429bd0dd13 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs b/LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs new file mode 100644 index 0000000..8232ef6 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs @@ -0,0 +1,409 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using System.Collections; +using UnityEngine; +using System; + +namespace Depthkit +{ + [System.Serializable] + public class MaskGenerator : IPropertyTransfer + { + public Clip clip; + + public Texture externalSourceTexture = null; + + [Range(1, 8)] + public int scale = 1; + + protected ComputeShader m_maskGeneratorCompute; + [SerializeField, HideInInspector] + protected RenderTextureFormat m_maskTextureFormat = RenderTextureFormat.RFloat; + protected RenderTexture m_maskTexture; + protected Vector4 m_maskTextureTS; // TODO check if needed + protected ComputeBuffer m_sobelMultiplierBuffer = null; + + // Core & Studio Lite use a lower strength than the Studio renderer. + public bool useStudioCoefficients = false; + + public static class MaskGeneratorShaderIds + { + public static readonly int + _LatticeSize = Shader.PropertyToID("_LatticeSize"), + _MaskTexture = Shader.PropertyToID("_MaskTexture"), + _SobelMultiplier = Shader.PropertyToID("_SobelMultiplier"), + _StaticSobelMultiplier = Shader.PropertyToID("_StaticSobelMultiplier"), + _StaticSobelPower = Shader.PropertyToID("_StaticSobelPower"), + _SobelInvalidateStrength = Shader.PropertyToID("_SobelInvalidateStrength"), + _MaskTextureTS = Shader.PropertyToID("_MaskTextureTS"), + _PerspectiveToSlice = Shader.PropertyToID("_PerspectiveToSlice"), + _SliceCount = Shader.PropertyToID("_SliceCount"), + _SliceToPerspective = Shader.PropertyToID("_SliceToPerspective"), + _Downscaled = Shader.PropertyToID("_Downscaled"), + _FullRes = Shader.PropertyToID("_FullRes"), + _PaddedUVScaleFactor = Shader.PropertyToID("_PaddedUVScaleFactor"), + _DownsampledMaskTexture = Shader.PropertyToID("_DownsampledMaskTexture"), + _SobelInvalidateEdgeWidth = Shader.PropertyToID("_SobelInvalidateEdgeWidth"), + _CPPTexture = Shader.PropertyToID("_CPPTexture"); + public static readonly string _UseEdgeMask = "DK_USE_EDGEMASK"; + public static readonly string _DebugEdgeMask = "DK_DEBUG_EDGEMASK"; + public static readonly string _DitherEdgeKW = "DK_SCREEN_DOOR_TRANSPARENCY"; + } + + //passing arrays to shaders requires padding, so just use Vector4 + //https://cmwdexint.com/2017/12/04/computeshader-setfloats/ + protected Vector4[] m_perspectivesToSlice; + public Vector4[] perspectivesToSlice + { + get { return m_perspectivesToSlice; } + set { m_perspectivesToSlice = value; } + } + + //passing arrays to shaders requires padding, so just use Vector4 + //https://cmwdexint.com/2017/12/04/computeshader-setfloats/ + protected Vector4[] m_sliceToPerspective; + public Vector4[] sliceToPerspective + { + get { return m_sliceToPerspective; } + set { m_sliceToPerspective = value; } + } + + public int sliceCount + { + get { return m_blurFilter != null ? m_blurFilter.slices : 1; } + set { if (m_blurFilter != null) m_blurFilter.slices = value; } + } + + public float blurRadius + { + get { return m_blurFilter != null ? m_blurFilter.radius : Metadata.DefaultReconstructionSettingsDefaults.edgeMaskBlurAmount; } + set { if (m_blurFilter != null) m_blurFilter.radius = value; } + } + + public Vector2 paddedUVScaleFactor + { + get + { + return clip == null ? Vector2.zero : new Vector2(clip.metadata.perspectiveResolution.x, clip.metadata.perspectiveResolution.y) / new Vector2(clip.metadata.paddedTextureDimensions.x, clip.metadata.paddedTextureDimensions.y); + } + } + + public bool enableMaskDebug = false; + + [SerializeField] + protected GaussianBlurFilter m_blurFilter; + + [Range(0.1f, 100.0f)] + public float sobelMultiplier = Metadata.DefaultReconstructionSettingsDefaults.edgeMaskSobelMultiplier; //cm + + protected ComputeShader m_sobelFilterCompute; + protected int m_sobelFilterKId = -1; + + public RenderTexture maskTexture + { + get + { + return m_maskTexture; + } + } + + [SerializeField] + protected int m_downScale = 0; + protected ComputeShader m_downScaleCompute; + protected int m_downScaleKId = -1; + + public int downScale { + get { return m_downScale; } + set + { + m_downScale = Math.Max(value, scale); + DownScaleMaskTexture(); + } + } + + protected RenderTexture m_downScaledMaskTexture = null; + + public RenderTexture downScaledMaskTexture + { + get + { + return downScale != scale ? m_downScaledMaskTexture : m_maskTexture; + } + } + + protected void DownScalePass(RenderTexture src, RenderTexture dst) + { + m_downScaleCompute.SetTexture(m_downScaleKId, MaskGeneratorShaderIds._FullRes, src); + m_downScaleCompute.SetTexture(m_downScaleKId, MaskGeneratorShaderIds._Downscaled, dst); + Util.DispatchGroups(m_downScaleCompute, m_downScaleKId, dst.width, dst.height, dst.volumeDepth); + } + + protected void DownScaleMaskTexture() + { + int downlevels = (int)Mathf.Log((float)m_downScale, 2.0f); + int mainlevels = (int)Mathf.Log((float)scale, 2.0f); + int levels = downlevels - mainlevels; + + m_downScaleKId = m_downScaleCompute.FindKernel(Util.GetScaled2DKernelName("MinMaxDownscaleByHalf")); + + //only scale if we need to + if (levels > 0 && maskTexture != null) + { + Vector2Int newSize = new Vector2Int(clip.metadata.paddedTextureDimensions.x / m_downScale, clip.metadata.paddedTextureDimensions.y / m_downScale); + if (m_downScaledMaskTexture == null || m_downScaledMaskTexture.width != newSize.x || m_downScaledMaskTexture.height != newSize.y || m_downScaledMaskTexture.volumeDepth != maskTexture.volumeDepth) + { + if(m_downScaledMaskTexture != null && m_downScaledMaskTexture.IsCreated()) + { + m_downScaledMaskTexture.Release(); + } + m_downScaledMaskTexture = new RenderTexture(newSize.x, newSize.y, maskTexture.depth, RenderTextureFormat.ARGBHalf); + m_downScaledMaskTexture.dimension = maskTexture.dimension; + m_downScaledMaskTexture.volumeDepth = maskTexture.volumeDepth; + m_downScaledMaskTexture.filterMode = maskTexture.filterMode; + m_downScaledMaskTexture.name = "Downscaled Mask Texture"; + m_downScaledMaskTexture.enableRandomWrite = true; + m_downScaledMaskTexture.autoGenerateMips = maskTexture.autoGenerateMips; + m_downScaledMaskTexture.Create(); + } + + if(levels > 1) + { + //use temp target hald the res of the mask texture. + var desc = maskTexture.descriptor; + desc.graphicsFormat = m_downScaledMaskTexture.descriptor.graphicsFormat; + desc.colorFormat = m_downScaledMaskTexture.descriptor.colorFormat; + desc.width /= 2; + desc.height /= 2; + + RenderTexture[] tmp = new RenderTexture[2]; + + int current = 0; + + tmp[0] = RenderTexture.GetTemporary(desc); + if(!tmp[0].IsCreated()) tmp[0].Create(); + + DownScalePass(maskTexture, tmp[current]); + + for (int level = 1; level < levels - 1; ++level) + { + int next = (current + 1) % 2; + + desc.width /= 2; + desc.height /= 2; + tmp[next] = RenderTexture.GetTemporary(desc); + if (!tmp[next].IsCreated()) tmp[next].Create(); + + DownScalePass(tmp[current], tmp[next]); + + RenderTexture.ReleaseTemporary(tmp[current]); + current = next; + } + + //commit to final tex + DownScalePass(tmp[current], m_downScaledMaskTexture); + + RenderTexture.ReleaseTemporary(tmp[current]); + } + else + { + //commit to final tex + DownScalePass(maskTexture, m_downScaledMaskTexture); + } + } + } + + public void Setup() + { + if (clip == null || !clip.isSetup) return; + + if (m_blurFilter == null) + { + m_blurFilter = new GaussianBlurFilter(); + m_blurFilter.clip = clip; + } + m_blurFilter.Setup(); + Util.EnsureComputeShader(ref m_sobelFilterCompute, "Shaders/Util/SobelFilter"); + Util.EnsureComputeShader(ref m_downScaleCompute, "Shaders/Util/MinMaxDownscaleByHalf"); + + m_sobelFilterKId = m_sobelFilterCompute.FindKernel(Util.GetScaled2DKernelName("KSobelFilter")); + + if (m_perspectivesToSlice == null || m_perspectivesToSlice.Length != Metadata.MaxPerspectives || + m_sliceToPerspective == null || m_sliceToPerspective.Length != Metadata.MaxPerspectives) + { + m_perspectivesToSlice = new Vector4[Metadata.MaxPerspectives]; + m_sliceToPerspective = new Vector4[Metadata.MaxPerspectives]; + } + for (int ind = 0; ind < clip.metadata.perspectivesCount; ++ind) + { + // map perspective id to slice index and slice to perspective id + // they are the same value as the slices are not priortized and are in the same order as the perspectives + m_perspectivesToSlice[ind] = new Vector4(ind, 0, 0, 0); + m_sliceToPerspective[ind] = new Vector4(ind, 0, 0, 0); + } + } + + public void EnsureTexture() + { + if (clip == null || clip.isSetup == false) return; + Vector2Int originalRes = clip.metadata.perspectiveResolution; + Vector2Int paddedRes = clip.metadata.paddedTextureDimensions; + + if (Util.EnsureRenderTexture( + ref m_maskTexture, + paddedRes.x / scale, paddedRes.y / scale, + RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear, + false, + FilterMode.Bilinear, + true, + RenderTextureFormat.RFloat, + UnityEngine.Rendering.TextureDimension.Tex2DArray, + sliceCount)) + { + m_maskTexture.name = "Depthkit Mask Texture"; + m_maskTextureFormat = m_maskTexture.format; + m_maskTextureTS = new Vector4(1.0f / (originalRes.x / (float)scale), 1.0f / (originalRes.y / (float)scale), originalRes.x / (float)scale, originalRes.y / (float)scale); + } + m_blurFilter.EnsureTextures(m_maskTexture); + } + + public void Release() + { + Util.ReleaseComputeBuffer(ref m_sobelMultiplierBuffer); + if (m_blurFilter != null) m_blurFilter.Release(); + Util.ReleaseRenderTexture(ref m_maskTexture); + Util.ReleaseRenderTexture(ref m_downScaledMaskTexture); + } + + public void SobelFilterMask() + { + clip.SetProperties(ref m_sobelFilterCompute, m_sobelFilterKId); + + if (externalSourceTexture != null) + { + m_sobelFilterCompute.SetTexture(m_sobelFilterKId, MaskGeneratorShaderIds._CPPTexture, externalSourceTexture); + } + + m_sobelFilterCompute.SetInt(MaskGeneratorShaderIds._SliceCount, sliceCount); + m_sobelFilterCompute.SetVectorArray(MaskGeneratorShaderIds._SliceToPerspective, m_sliceToPerspective); + + m_sobelFilterCompute.SetTexture(m_sobelFilterKId, MaskGeneratorShaderIds._MaskTexture, m_maskTexture); + + Util.EnsureComputeBuffer(ComputeBufferType.Structured, ref m_sobelMultiplierBuffer, sliceCount, sizeof(float)); + + // compute new sobel strength based on scale differences to original texture size + float[] sobelMultipliers = new float[sliceCount]; + for (int i = 0; i < sliceCount; i++) + { + ref Metadata.Perspective perspective = ref clip.metadata.perspectives[i]; + float minOriginalDim = Mathf.Min(perspective.depthImageSize.x, perspective.depthImageSize.y); + Vector2 croppedDim = perspective.depthImageSize * new Vector2(perspective.crop.z, perspective.crop.w); + + Vector2 scale = new Vector2(m_maskTexture.width, m_maskTexture.height) / croppedDim; + + sobelMultipliers[i] = sobelMultiplier * Mathf.Min(scale.x, scale.y); + } + + m_sobelMultiplierBuffer.SetData(sobelMultipliers); + m_sobelFilterCompute.SetBuffer(m_sobelFilterKId, MaskGeneratorShaderIds._SobelMultiplier, m_sobelMultiplierBuffer); + m_sobelFilterCompute.SetFloat(MaskGeneratorShaderIds._SobelInvalidateStrength, useStudioCoefficients ? 0.25f : 1.0f); + m_sobelFilterCompute.SetFloat(MaskGeneratorShaderIds._StaticSobelMultiplier, useStudioCoefficients ? 24.0f : 1.0f); + m_sobelFilterCompute.SetFloat(MaskGeneratorShaderIds._StaticSobelPower, useStudioCoefficients ? 1.5f : 1.0f); + m_sobelFilterCompute.SetVector(MaskGeneratorShaderIds._MaskTextureTS, m_maskTextureTS); + m_sobelFilterCompute.SetFloat(MaskGeneratorShaderIds._SobelInvalidateEdgeWidth, m_blurFilter.radius); + Util.DispatchGroups(m_sobelFilterCompute, m_sobelFilterKId, m_maskTexture.width, m_maskTexture.height, sliceCount); + } + + public virtual void BlurMask() + { + m_blurFilter.clip = clip; + m_blurFilter.DoBlur(m_maskTexture); + } + + public void GenerateMask() + { + EnsureTexture(); + + SobelFilterMask(); + + if (blurRadius > float.Epsilon) + { + BlurMask(); + } + + if(downScale > 0) + { + DownScaleMaskTexture(); + } + } + + public void SetProperties(ref ComputeShader compute, int kernel) + { + if (perspectivesToSlice != null && perspectivesToSlice.Length != 0) + compute.SetVectorArray(MaskGeneratorShaderIds._PerspectiveToSlice, perspectivesToSlice); + compute.SetInt(MaskGeneratorShaderIds._SliceCount, sliceCount); + compute.SetVector(MaskGeneratorShaderIds._PaddedUVScaleFactor, paddedUVScaleFactor); + if (maskTexture != null) + { + compute.SetTexture(kernel, MaskGeneratorShaderIds._MaskTexture, maskTexture); + compute.SetVector(MaskGeneratorShaderIds._MaskTextureTS, m_maskTextureTS); + } + } + + public void SetProperties(ref Material material) + { + if (perspectivesToSlice != null && perspectivesToSlice.Length != 0) + material.SetVectorArray(MaskGeneratorShaderIds._PerspectiveToSlice, perspectivesToSlice); + material.SetInt(MaskGeneratorShaderIds._SliceCount, sliceCount); + material.SetVector(MaskGeneratorShaderIds._PaddedUVScaleFactor, paddedUVScaleFactor); + Util.EnsureKeyword(ref material, MaskGeneratorShaderIds._UseEdgeMask, true); + Util.EnsureKeyword(ref material, MaskGeneratorShaderIds._DebugEdgeMask, enableMaskDebug); + if (maskTexture != null) + { + material.SetTexture(MaskGeneratorShaderIds._MaskTexture, maskTexture); + material.SetVector(MaskGeneratorShaderIds._MaskTextureTS, m_maskTextureTS); + } + if (enableMaskDebug && downScaledMaskTexture != null) + { + material.SetTexture(MaskGeneratorShaderIds._DownsampledMaskTexture, downScaledMaskTexture); + } + } + + public void SetProperties(ref Material material, ref MaterialPropertyBlock block) + { + if(perspectivesToSlice != null && perspectivesToSlice.Length != 0) + block.SetVectorArray(MaskGeneratorShaderIds._PerspectiveToSlice, perspectivesToSlice); + block.SetInt(MaskGeneratorShaderIds._SliceCount, sliceCount); + block.SetVector(MaskGeneratorShaderIds._PaddedUVScaleFactor, paddedUVScaleFactor); + Util.EnsureKeyword(ref material, MaskGeneratorShaderIds._UseEdgeMask, true); + Util.EnsureKeyword(ref material, MaskGeneratorShaderIds._DebugEdgeMask, enableMaskDebug); + if (maskTexture != null) + { + block.SetTexture(MaskGeneratorShaderIds._MaskTexture, maskTexture); + block.SetVector(MaskGeneratorShaderIds._MaskTextureTS, m_maskTextureTS); + } + if (enableMaskDebug && downScaledMaskTexture != null) + { + block.SetTexture(MaskGeneratorShaderIds._DownsampledMaskTexture, downScaledMaskTexture); + } + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs.meta b/LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs.meta new file mode 100644 index 0000000..78a7c2d --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/MaskGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9da6cdd240e7d0f429b6ea45e868be43 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs b/LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs new file mode 100644 index 0000000..046b64f --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs @@ -0,0 +1,497 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEngine.XR; +using System.Linq; +using System; +using System.Runtime.InteropServices; + +namespace Depthkit +{ + public abstract class MeshSource : DataSource, IPropertyTransfer + { + #region SubMeshes + + public bool recalculateCurrentSurfaceTriangleCount = false; + + private SubMesh[] m_subMeshes; + + // Note: this is to serialize the max triangles, as the m_subMeshes array cannot be serialized. + [SerializeField] + private uint[] m_subMeshMaxTriangles; + + public SubMesh GetSubMesh(int index) + { + if (m_subMeshes == null || index >= m_subMeshes.Length) return null; + return m_subMeshes[index]; + } + + public T GetSubMesh(int index) where T : SubMesh + { + return GetSubMesh(index) as T; + } + + public SubMesh CurrentSubMesh() + { + if (m_subMeshes == null || currentSubmeshIndex >= m_subMeshes.Length) return null; + return m_subMeshes[currentSubmeshIndex]; + } + + public T CurrentSubMesh() where T : SubMesh + { + return CurrentSubMesh() as T; + } + + public void ReserveSubMeshes(int count) where T : SubMesh, new() + { + if (m_subMeshMaxTriangles == null || m_subMeshMaxTriangles.Length != count) + { + m_subMeshMaxTriangles = new uint[count]; + for (int idx = 0; idx < count; idx++) + { + m_subMeshMaxTriangles[idx] = 0; + } + } + + if (m_subMeshes == null || m_subMeshes.Length != count) + { + if (m_subMeshes != null) + { + foreach (var sm in m_subMeshes) + { + sm.Release(); + } + } + m_subMeshes = Enumerable.Range(0, count).Select(i => + { + return new T(); + }).ToArray(); + } + + for (int idx = 0; idx < count; idx++) + { + m_subMeshes[idx].source = this; + m_subMeshes[idx].maxTriangles = m_subMeshMaxTriangles[idx]; + m_subMeshes[idx].useTriangleMesh = m_useTriangleMesh; + } + } + + #endregion + + #region Properties + public static class MeshSourceShaderIds + { + public static readonly int + _RadialBiasPerspInMeters = Shader.PropertyToID("_RadialBiasPerspInMeters"); + } + + protected bool m_forceStereo = false; + + protected uint m_currentSubmeshIndex; + public uint currentSubmeshIndex + { + get + { + return m_currentSubmeshIndex; + } + set + { + m_currentSubmeshIndex = value; + } + } + + public ComputeBuffer triangleBuffer + { + get + { + return m_subMeshes == null ? null : m_subMeshes.Length <= m_currentSubmeshIndex ? null : m_subMeshes[m_currentSubmeshIndex].triangleBuffer; + } + } + + public ComputeBuffer triangleBufferDispatchIndirectArgs + { + get + { + return m_subMeshes == null ? null : m_subMeshes.Length <= m_currentSubmeshIndex ? null : m_subMeshes[m_currentSubmeshIndex].dispatchIndirectArgs; + } + } + + public ComputeBuffer triangleBufferDrawIndirectArgs + { + get + { + return m_subMeshes == null ? null : m_subMeshes.Length <= m_currentSubmeshIndex ? null : m_subMeshes[m_currentSubmeshIndex].drawIndirectArgs; + } + } + + public uint maxSurfaceTriangles + { + get + { + return m_subMeshes == null ? 0 : m_subMeshes.Length <= m_currentSubmeshIndex ? 0 : m_subMeshes[m_currentSubmeshIndex].maxTriangles; + } + set + { + if (m_subMeshes != null) + { + m_subMeshes[m_currentSubmeshIndex].maxTriangles = value; + m_subMeshMaxTriangles[m_currentSubmeshIndex] = value; + ScheduleResize(); + ScheduleGenerate(); + } + } + } + + [SerializeField, HideInInspector] + bool m_useTriangleMesh = false; + public bool useTriangleMesh + { + get + { + return m_useTriangleMesh; + } + set + { + if (m_subMeshes != null) + { + foreach (var persp in m_subMeshes) + { + persp.useTriangleMesh = value; + } + m_useTriangleMesh = value; + } + } + } + + public TriangleMesh triangleMesh + { + get + { + return m_subMeshes == null ? null : m_subMeshes[m_currentSubmeshIndex].triangleMesh; + } + } + + #endregion + + #region RadialBias + public const float radialBiasMin = 0.0f; + public const float radialBiasMax = 2.50f; + [Range(radialBiasMin, radialBiasMax)] + public float radialBias = Metadata.DefaultReconstructionSettingsDefaults.depthBiasAdjustment; + + [SerializeField, HideInInspector] + public float[] radialBiasPersp = null; + // The datatype for the per perspective bias is a float4 because float arrays get pushed to the shader as 4 component float vectors. + [SerializeField, HideInInspector] + protected Vector4[] radialBiasPerspInMeters = null; + void EnsureRadialBias() + { + // This way of sizing the radialBiasPersp array will cause multiperspective core clips to be sized to 12 + if (radialBiasPersp == null || radialBiasPersp.Length != clip.metadata.perspectivesCount) + { + radialBiasPersp = new float[clip.metadata.perspectivesCount]; + for (int i = 0; i < clip.metadata.perspectivesCount; ++i) + { + radialBiasPersp[i] = radialBias; + } + radialBiasPerspInMeters = null; + } + + // This way of sizing the radialBiasPersp array will cause multiperspective core clips to be sized to 12 + int size = (clip.metadata.perspectivesCount > 1) ? 12 : 1; + if (radialBiasPerspInMeters == null || radialBiasPerspInMeters.Length != size) + { + Vector4 defaultVal = new Vector4(Util.cmToMeters(radialBias), 0, 0, 0); + radialBiasPerspInMeters = new Vector4[size]; + for (int i = 0; i < size; ++i) + { + radialBiasPerspInMeters[i] = defaultVal; + } + } + } + #endregion + + #region DataSource + protected override void AcquireResources() + { + if (m_subMeshes != null) + { + int index = 0; + foreach (var persp in m_subMeshes) + { + persp.EnsureBuffers(index++); + } + } + + if (!m_clip.isSetup) return; + EnsureRadialBias(); + base.AcquireResources(); + } + + protected override void FreeResources() + { + if (m_subMeshes != null) + { + foreach (var submesh in m_subMeshes) + { + submesh.Release(); + } + } + base.FreeResources(); + } + + protected override bool CanGenerate() + { + if (m_subMeshes == null) return false; + + bool usesTriangleMesh = false; + foreach (var persp in m_subMeshes) + { + if (persp.useTriangleMesh) usesTriangleMesh = true; + } + + if (!usesTriangleMesh && (pauseDataGenerationWhenInvisible || pausePlayerWhenInvisible)) + { + CheckVisibility(); + } + return m_doGeneration; + } + + public override bool OnSetup() + { + Util.ArgsBufferPrep.Setup(); + + //TODO this is a hack b/c the openVR plugin doesn't properly report XRSettings.stereoRenderingMode + if (XRSettings.supportedDevices.Length > 0) + { + foreach (var dev in XRSettings.supportedDevices) + { + if (dev.Contains("OpenVR")) + { + m_forceStereo = true; + break; + } + } + } + + return true; + } + + protected override bool OnResize() + { + if (!m_clip.isSetup || m_clip.metadata.textureWidth == 0 || m_clip.metadata.textureHeight == 0) return true; + + // This way of sizing the radialBiasPersp array will cause multiperspective core clips to be sized to 12 + if (radialBiasPersp == null || radialBiasPersp.Length != clip.metadata.perspectivesCount) + { + radialBiasPersp = new float[clip.metadata.perspectivesCount]; + for (int i = 0; i < clip.metadata.perspectivesCount; ++i) + { + radialBiasPersp[i] = radialBias; + } + radialBiasPerspInMeters = null; + } + + // This way of sizing the radialBiasPersp array will cause multiperspective core clips to be sized to 12 + int size = (clip.metadata.perspectivesCount > 1) ? 12 : 1; + if (radialBiasPerspInMeters == null || radialBiasPerspInMeters.Length != size) + { + Vector4 defaultVal = new Vector4(Util.cmToMeters(radialBias), 0, 0, 0); + radialBiasPerspInMeters = new Vector4[size]; + for (int i = 0; i < size; ++i) + { + radialBiasPerspInMeters[i] = defaultVal; + } + } + + return true; + } + + protected override void OnUpdate() + { + if (m_wasPlaying && !m_pausedFromRenderer) + { + CheckVisibility(); + } + else if (pauseDataGenerationWhenInvisible && !m_seenOnce) + { + CheckVisibility(); + m_seenOnce = true; + } + + if (clip != null && clip.isSetup && radialBiasPersp != null && radialBiasPerspInMeters != null) + { + // propagate radialBias value to per perspective + for (int i = 0; i < radialBiasPersp.Length; ++i) + { + if (radialBiasPerspInMeters != null && radialBiasPerspInMeters.Length > 0) + { + radialBiasPerspInMeters[i].x = Util.cmToMeters(radialBias); + } + } + } + base.OnUpdate(); + } + + protected override bool OnGenerate() + { + if (m_subMeshes == null) return false; + + foreach (var submesh in m_subMeshes) + { + submesh.CopyTriangleCount(); + Util.ArgsBufferPrep.PrepareDrawArgs(submesh.trianglesCount, submesh.drawIndirectArgs, m_forceStereo); + } + + if (recalculateCurrentSurfaceTriangleCount) + { + uint tempSubMeshIndex = currentSubmeshIndex; + for (uint i = 0; i < m_subMeshes.Length; i++) + { + currentSubmeshIndex = i; + maxSurfaceTriangles = m_subMeshes[i].calculateMaxTrianglesNeeded(); + } + currentSubmeshIndex = tempSubMeshIndex; + + recalculateCurrentSurfaceTriangleCount = false; + ScheduleResize(); + ScheduleGenerate(); + } + + return true; + } + #endregion + + #region Visibility + + public bool pauseDataGenerationWhenInvisible = false; + public bool pausePlayerWhenInvisible = false; + + protected bool m_wasPlaying = false; + protected bool m_doGeneration = true; + protected bool m_pausedFromRenderer = false; + protected bool m_seenOnce = false; + + public virtual Bounds GetLocalBounds() + { + return clip != null ? + new Bounds(clip.metadata.boundsCenter, clip.metadata.boundsSize) : + new Bounds(Vector3.zero, Vector3.one); + } + + public virtual Bounds GetWorldBounds() + { + Bounds bounds = GetLocalBounds(); + Vector3 alt1 = bounds.center - new Vector3(-bounds.extents.x, -bounds.extents.y, bounds.extents.z); + Vector3 alt2 = bounds.center + new Vector3(-bounds.extents.x, -bounds.extents.y, bounds.extents.z); + return GeometryUtility.CalculateBounds(new Vector3[] { bounds.min, bounds.max, alt1, alt2 }, transform.localToWorldMatrix); + } + + internal void Pause() + { + if (pausePlayerWhenInvisible) + { + if (clip.player.IsPlaying()) + { + m_wasPlaying = true; + clip.player.Pause(); + } + } + if (pauseDataGenerationWhenInvisible || pausePlayerWhenInvisible) + { + m_doGeneration = false; + } + } + + internal void Continue() + { + if (pausePlayerWhenInvisible) + { + if (!clip.player.IsPlaying() && m_wasPlaying) + { + clip.player.Play(); + m_wasPlaying = false; + } + } + if (pauseDataGenerationWhenInvisible || pausePlayerWhenInvisible) + { + m_doGeneration = true; + } + } + + private void OnBecameVisible() + { + Continue(); + m_pausedFromRenderer = false; + m_seenOnce = true; + } + + private void OnBecameInvisible() + { + Pause(); + m_pausedFromRenderer = true; + } + + internal void CheckVisibility() + { + bool visible = Util.IsVisible(GetWorldBounds()); + if (visible != m_doGeneration) //these should always be the same + { + if (visible) + { + Continue(); + } + else + { + Pause(); + } + } + } + #endregion + + #region IPropertyTransfer + + public virtual void SetProperties(ref ComputeShader compute, int kernel) + { + if (radialBiasPerspInMeters != null) + compute.SetVectorArray(MeshSourceShaderIds._RadialBiasPerspInMeters, radialBiasPerspInMeters); + if (m_subMeshes != null && m_subMeshes.Length > currentSubmeshIndex) + m_subMeshes[currentSubmeshIndex].SetProperties(ref compute, kernel); + } + + public virtual void SetProperties(ref Material material) + { + if (radialBiasPerspInMeters != null) + material.SetVectorArray(MeshSourceShaderIds._RadialBiasPerspInMeters, radialBiasPerspInMeters); + if (m_subMeshes != null && m_subMeshes.Length > currentSubmeshIndex) + m_subMeshes[currentSubmeshIndex].SetProperties(ref material); + } + + public virtual void SetProperties(ref Material material, ref MaterialPropertyBlock block) + { + if (radialBiasPerspInMeters != null) + block.SetVectorArray(MeshSourceShaderIds._RadialBiasPerspInMeters, radialBiasPerspInMeters); + if (m_subMeshes != null && m_subMeshes.Length > currentSubmeshIndex) + m_subMeshes[currentSubmeshIndex].SetProperties(ref material, ref block); + } + #endregion + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs.meta b/LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs.meta new file mode 100644 index 0000000..ec57596 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/MeshSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6e298b291aebe7a4797e9ea0020f2d44 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs b/LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs new file mode 100644 index 0000000..64848aa --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs @@ -0,0 +1,200 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using System.Collections; +using UnityEngine; +using UnityEngine.XR; +using System.Runtime.InteropServices; + +namespace Depthkit +{ + [System.Serializable] + public abstract class SubMesh : IPropertyTransfer + { + public uint maxTriangles; + + #region TriangleData + + public static class TriangleDataShaderIds + { + public static readonly int + _TriangleBuffer = Shader.PropertyToID("_TriangleBuffer"), + _TrianglesDispatchIndirectArgs = Shader.PropertyToID("_TrianglesDispatchIndirectArgs"), + _TrianglesCount = Shader.PropertyToID("_TrianglesCount"), + _TrianglesDrawIndirectArgs = Shader.PropertyToID("_TrianglesDrawIndirectArgs"); + } + + public abstract int GetDataTypeSizeInBytes(); + + protected ComputeBuffer m_triangleBuffer; + protected ComputeBuffer m_trianglesCount = null; + protected ComputeBuffer m_dispatchIndirectArgs = null; + protected ComputeBuffer m_drawIndirectArgs = null; + + //returns appendable buffer that contains packed valid triangle data + public ComputeBuffer triangleBuffer { get { return m_triangleBuffer; } } + + //returns a buffer that contains only the count of appended triangles + public ComputeBuffer trianglesCount { get { return m_trianglesCount; } } + + //returns buffer with triangle count in the x dispatch for DispatchIndirect + public ComputeBuffer dispatchIndirectArgs { get { return m_dispatchIndirectArgs; } } + + //returns buffer with drawable vertex count and instanced stereo count for DrawIndirect + public ComputeBuffer drawIndirectArgs { get { return m_drawIndirectArgs; } } + + #endregion + + #region BufferManagement + public virtual void Init(int subMeshIndex = -1) + { + if (maxTriangles == 0) + { + maxTriangles = 200000; + } + + EnsureBuffers(subMeshIndex); + triangleBuffer.SetCounterValue(0); + + if (useTriangleMesh) + { + triangleMesh.EnsureTriangleMesh((int)maxTriangles); + } + } + + public void CopyTriangleCount() + { + ComputeBuffer.CopyCount(triangleBuffer, trianglesCount, 0); + } + + public uint calculateMaxTrianglesNeeded() { + int[] bufferDataTris = new int[1]; + trianglesCount.GetData(bufferDataTris); + return (uint)bufferDataTris[0] + (uint)((float)bufferDataTris[0] * 0.2f); // set 20% higher to account for frame variations in triangle count + } + + public void PrepareDrawArgs(bool forceStereo) + { + Util.ArgsBufferPrep.PrepareDrawArgs(trianglesCount, drawIndirectArgs, forceStereo); + } + + public void PrepareDispatchArgs(int groupSize, int dispatchY = 1, int dispatchZ = 1) + { + Util.ArgsBufferPrep.PrepareDispatchArgs(trianglesCount, dispatchIndirectArgs, groupSize, dispatchY, dispatchZ); + } + + #endregion + + #region LifeCycle + public virtual void EnsureBuffers(int submeshIndex = -1) + { + if (maxTriangles > 0) + { + if (Util.EnsureComputeBuffer(ComputeBufferType.Append, ref m_triangleBuffer, (int)maxTriangles, GetDataTypeSizeInBytes())) + { + triangleBuffer.name = "Depthkit Mesh Source Triangles Buffer " + (submeshIndex == -1 ? "" : submeshIndex.ToString()); + } + if (Util.EnsureComputeBuffer(ComputeBufferType.IndirectArguments, ref m_trianglesCount, 1, sizeof(int))) + { + trianglesCount.name = "Depthkit Mesh Source Triangles Count Buffer " + (submeshIndex == -1 ? "" : submeshIndex.ToString()); + trianglesCount.SetData(new int[] { 0 }); + } + if (Util.EnsureComputeBuffer(ComputeBufferType.IndirectArguments, ref m_dispatchIndirectArgs, 3, sizeof(int))) + { + dispatchIndirectArgs.name = "Depthkit Mesh Source Triangles Dispatch Args Buffer " + (submeshIndex == -1 ? "" : submeshIndex.ToString()); + dispatchIndirectArgs.SetData(new int[] { 0, 1, 1 }); + } + if (Util.EnsureComputeBuffer(ComputeBufferType.IndirectArguments, ref m_drawIndirectArgs, 5, sizeof(int))) + { + drawIndirectArgs.name = "Depthkit Mesh Source Triangles Indirect Draw Args Buffer " + (submeshIndex == -1 ? "" : submeshIndex.ToString()); + drawIndirectArgs.SetData(new int[] { 0, (XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.SinglePassInstanced || XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.SinglePassMultiview) ? 2 : 1, 0, 0 }); + } + } + + if (useTriangleMesh) triangleMesh.EnsureTriangleMesh((int)maxTriangles); + } + + public virtual void Release() + { + Util.ReleaseComputeBuffer(ref m_triangleBuffer); + Util.ReleaseComputeBuffer(ref m_trianglesCount); + Util.ReleaseComputeBuffer(ref m_dispatchIndirectArgs); + Util.ReleaseComputeBuffer(ref m_drawIndirectArgs); + if (useTriangleMesh && m_triangleMesh != null) m_triangleMesh.ReleaseMesh(); + } + #endregion + + #region TriangleMesh + + [SerializeField] + private MeshSource m_source = null; + + public MeshSource source + { + set { m_source = value; } + } + + public bool useTriangleMesh = false; + + private Depthkit.TriangleMesh m_triangleMesh; + public Depthkit.TriangleMesh triangleMesh + { + get + { + if (m_triangleMesh == null) + { + if (useTriangleMesh) + { + m_triangleMesh = new Depthkit.TriangleMesh(); + m_triangleMesh.source = m_source; + } + } + return m_triangleMesh; + } + } + #endregion + + #region IPropertyTransfer + public virtual void SetProperties(ref ComputeShader compute, int kernel) + { + compute.SetBuffer(kernel, TriangleDataShaderIds._TriangleBuffer, triangleBuffer); + compute.SetBuffer(kernel, TriangleDataShaderIds._TrianglesCount, trianglesCount); + } + + public virtual void SetProperties(ref Material material) + { + material.SetBuffer(TriangleDataShaderIds._TriangleBuffer, triangleBuffer); + material.SetBuffer(TriangleDataShaderIds._TrianglesCount, trianglesCount); + } + + public virtual void SetProperties(ref Material material, ref MaterialPropertyBlock block) + { + block.SetBuffer(TriangleDataShaderIds._TriangleBuffer, triangleBuffer); + block.SetBuffer(TriangleDataShaderIds._TrianglesCount, trianglesCount); + } + #endregion + } + + [System.Serializable] + public class SubMesh : SubMesh where TriangleType : struct + { + public override int GetDataTypeSizeInBytes() { return Marshal.SizeOf(typeof(TriangleType)); } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs.meta b/LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs.meta new file mode 100644 index 0000000..77e3d13 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/DataSource/SubMesh.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d274ecb28ac19da4d8d3462bd93bab50 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef b/LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef new file mode 100644 index 0000000..de97473 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef @@ -0,0 +1,14 @@ +{ + "name": "Depthkit.Core", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef.meta b/LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef.meta new file mode 100644 index 0000000..1c86280 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Depthkit.Core.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d757665d4a59fe94bab8bd5391e60e3d +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Interfaces.meta b/LocalPackages/depthkit.core/Runtime/Interfaces.meta new file mode 100644 index 0000000..2b7de2a --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Interfaces.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fe8d6b0623f8c6b4587602c74181d4da +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs b/LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs new file mode 100644 index 0000000..835fc5d --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs @@ -0,0 +1,33 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using System.Collections; +using UnityEngine; + +namespace Depthkit +{ + //Transfer properties from a source to a target compute, material or material prop block + public interface IPropertyTransfer + { + void SetProperties(ref ComputeShader compute, int kernel); + void SetProperties(ref Material material); + void SetProperties(ref Material material, ref MaterialPropertyBlock block); + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs.meta b/LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs.meta new file mode 100644 index 0000000..432da3e --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Interfaces/IPropertyTransfer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59a956bcb59b6084d82c60bd04b23e96 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Looks.meta b/LocalPackages/depthkit.core/Runtime/Looks.meta new file mode 100644 index 0000000..142630a --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Looks.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0d618fb68f1d05549a1b8e6672caadcd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs b/LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs new file mode 100644 index 0000000..7a35c51 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs @@ -0,0 +1,70 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Collections; +using System.IO; +using System; + +namespace Depthkit +{ + [ExecuteInEditMode] + [AddComponentMenu("Depthkit/Core/Built-in RP/Depthkit Core Built-in Look")] + public class CoreLook : ProceduralLook + { + protected static Shader s_defaultUnlitPhotoLookShader = null; + protected static Material s_defaultUnlitPhotoLookMaterial = null; + + protected static Material GetDefaultMaterial() + { + if(s_defaultUnlitPhotoLookShader == null) + { + s_defaultUnlitPhotoLookShader = Shader.Find("Depthkit/Core/Depthkit Core Photo Look Built-in RP"); + } + + if(s_defaultUnlitPhotoLookMaterial == null) + { + s_defaultUnlitPhotoLookMaterial = new Material(s_defaultUnlitPhotoLookShader); + } + return s_defaultUnlitPhotoLookMaterial; + } + + public override string GetLookName(){ return "Depthkit Core Look"; } + + protected override void SetDefaults() + { + if(lookMaterial == null) + { + lookMaterial = GetDefaultMaterial(); + } + base.SetDefaults(); + } + + protected override void SetDataSources() + { + if (meshSource == null) + { + meshSource = depthkitClip.GetDataSource(); + } + } + + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs.meta b/LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs.meta new file mode 100644 index 0000000..f1d9671 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Looks/CoreLook.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 03bb0f90eda0bf24e9fe79bcd169940b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 42c51ff9981f3e24b83cd7ad3c56e235, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Looks/Look.cs b/LocalPackages/depthkit.core/Runtime/Looks/Look.cs new file mode 100644 index 0000000..c1b282f --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Looks/Look.cs @@ -0,0 +1,238 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Collections; +using System.IO; +using System; + +namespace Depthkit +{ + public delegate void DepthkitLookEventHandler(); + + [DefaultExecutionOrder(-10)] + [RequireComponent(typeof(BoxCollider))] + [ExecuteInEditMode] + public abstract class Look : MonoBehaviour + { + protected static class LookCommonShaderIds + { + internal static readonly int _LocalTransformInverse = Shader.PropertyToID("_LocalTransformInverse"); + internal static readonly int _LocalTransform = Shader.PropertyToID("_LocalTransform"); + internal static readonly string _DebugKeyword = "DK_USE_DEBUG_COLOR"; + } + + public Clip depthkitClip = null; + public bool showPerViewColorDebug = false; + public bool showCameraFrustums = false; + public DepthkitLookEventHandler onUpdated; + + private MaterialPropertyBlock m_materialPropertyBlock = null; + + protected void EnsureMaterialPropertyBlock() + { + if (UsesMaterialPropertyBlock()) + { + if (m_materialPropertyBlock == null) + { + m_materialPropertyBlock = new MaterialPropertyBlock(); + } + } + } + + protected MaterialPropertyBlock materialPropertyBlock + { + get + { + EnsureMaterialPropertyBlock(); + return m_materialPropertyBlock; + } + } + + [HideInInspector] + public MeshSource meshSource = null; + + /// The bounding box collider + [HideInInspector, SerializeField] + protected BoxCollider m_collider = null; + + private bool m_bIsInit = false; + + + public abstract string GetLookName(); + protected abstract bool UsesMaterial(); + protected abstract Material GetMaterial(); + protected virtual bool UsesMaterialPropertyBlock() { return true; } + protected virtual MaterialPropertyBlock GetMaterialPropertyBlock() { return materialPropertyBlock; } + protected abstract void SetDataSources(); + protected virtual bool ValidateDataSources() + { + return meshSource != null; + } + protected virtual void SetMaterialProperties(ref Material material) { } + protected virtual void SetMaterialProperties(ref Material material, ref MaterialPropertyBlock block) { } + + protected virtual void OnUpdate() + { + SetLookProperties(); + } + + protected virtual void SetDefaults() + { + EnsureMaterialPropertyBlock(); + m_collider = GetComponent(); + } + protected virtual void SetLookProperties() + { + SyncColliderToBounds(); + + var material = GetMaterial(); + if (material == null) + { + return; + } + + if (UsesMaterialPropertyBlock()) + { + MaterialPropertyBlock block = GetMaterialPropertyBlock(); + block.Clear(); + depthkitClip.SetProperties(ref material, ref block); + meshSource.SetProperties(ref material, ref block); + Util.EnsureKeyword(ref material, LookCommonShaderIds._DebugKeyword, showPerViewColorDebug); + block.SetMatrix(LookCommonShaderIds._LocalTransform, transform.localToWorldMatrix); + block.SetMatrix(LookCommonShaderIds._LocalTransformInverse, transform.localToWorldMatrix.inverse); + SetMaterialProperties(ref material, ref block); + } + else + { + depthkitClip.SetProperties(ref material); + meshSource.SetProperties(ref material); + Util.EnsureKeyword(ref material, LookCommonShaderIds._DebugKeyword, showPerViewColorDebug); + material.SetMatrix(LookCommonShaderIds._LocalTransform, transform.localToWorldMatrix); + material.SetMatrix(LookCommonShaderIds._LocalTransformInverse, transform.localToWorldMatrix.inverse); + SetMaterialProperties(ref material); + } + } + + void Awake() + { + if (m_materialPropertyBlock == null) + { + m_materialPropertyBlock = new MaterialPropertyBlock(); + } + if (depthkitClip == null) + { + depthkitClip = GetComponentInParent(); + } + SetDefaults(); + } + + protected virtual bool Init() + { + if (depthkitClip == null) + { + depthkitClip = GetComponent(); + } + if (!ValidateDataSources()) + { + if (depthkitClip != null) + { + depthkitClip.newMetadata += OnMetaDataUpdated; + OnMetaDataUpdated(); + SetDataSources(); + } + } + return depthkitClip != null && ValidateDataSources(); + } + + void Start() + { + m_bIsInit = Init(); + } + +#if UNITY_EDITOR + protected virtual void OnAssemblyReload() + { + Awake(); + } +#endif + + void OnEnable() + { +#if UNITY_EDITOR + AssemblyReloadEvents.afterAssemblyReload += OnAssemblyReload; +#endif + if (depthkitClip != null) + { + depthkitClip.newMetadata += OnMetaDataUpdated; + } + } + + void OnDisable() + { +#if UNITY_EDITOR + AssemblyReloadEvents.afterAssemblyReload -= OnAssemblyReload; +#endif + if (depthkitClip != null) + { + depthkitClip.newMetadata -= OnMetaDataUpdated; + } + } + + protected void SyncColliderToBounds() + { + if (meshSource != null) + { + Bounds localBounds = meshSource.GetLocalBounds(); + m_collider.center = localBounds.center; + m_collider.size = localBounds.size; + } + else if (depthkitClip != null) + { + m_collider.center = depthkitClip.metadata.boundsCenter; + m_collider.size = depthkitClip.metadata.boundsSize; + } + } + + protected virtual void OnMetaDataUpdated() + { + SyncColliderToBounds(); + } + + void LateUpdate() + { + if (depthkitClip == null) m_bIsInit = false; + if (!m_bIsInit) + { + m_bIsInit = Init(); + } + else + { + if (!depthkitClip.isSetup) return; + OnUpdate(); + if (onUpdated != null) + { + onUpdated(); + } + } + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Looks/Look.cs.meta b/LocalPackages/depthkit.core/Runtime/Looks/Look.cs.meta new file mode 100644 index 0000000..49772b0 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Looks/Look.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 56bfcdaaeb8c5c840b47b3d8effb9b7b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs b/LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs new file mode 100644 index 0000000..9172596 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs @@ -0,0 +1,77 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEngine.Rendering; + +namespace Depthkit +{ + public abstract class ProceduralLook : Look + { + public ShadowCastingMode shadowCastingMode = ShadowCastingMode.On; + public bool receiveShadows = true; + public bool interpolateLightProbes = true; + public Transform anchorOverride = null; + public Material lookMaterial = null; + + protected override bool UsesMaterial() { return true; } + protected override Material GetMaterial() { return lookMaterial; } + + protected override bool UsesMaterialPropertyBlock() { return true; } + + protected override void SetMaterialProperties(ref Material material, ref MaterialPropertyBlock block) + { + if (interpolateLightProbes) + { + Vector3[] positions = new Vector3[1] { anchorOverride != null ? anchorOverride.position : transform.position }; + SphericalHarmonicsL2[] harmonics = new SphericalHarmonicsL2[1]; + Vector4[] occlusions = new Vector4[1]; + + LightProbes.CalculateInterpolatedLightAndOcclusionProbes(positions, harmonics, occlusions); + + block.CopyProbeOcclusionArrayFrom(occlusions, 0, 0, 1); + block.CopySHCoefficientArraysFrom(harmonics, 0, 0, 1); + } + } + + protected override void OnUpdate() + { + base.OnUpdate(); + if (meshSource.triangleBufferDrawIndirectArgs == null || + !meshSource.triangleBufferDrawIndirectArgs.IsValid() || + meshSource.triangleBuffer == null || + !meshSource.triangleBuffer.IsValid()) + { + return; + } + + Graphics.DrawProceduralIndirect( + GetMaterial(), + meshSource.GetWorldBounds(), + MeshTopology.Triangles, + meshSource.triangleBufferDrawIndirectArgs, 0, + null, + GetMaterialPropertyBlock(), + shadowCastingMode, //cast shadows + receiveShadows, //receive shadows + gameObject.layer); + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs.meta b/LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs.meta new file mode 100644 index 0000000..b7dc70c --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Looks/ProceduralLook.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12aed2a2b7dd1434ebc10bc2aa9a0ced +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Players.meta b/LocalPackages/depthkit.core/Runtime/Players.meta new file mode 100644 index 0000000..8710856 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Players.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4d8fa63134a15f342a95986e48f49159 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs b/LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs new file mode 100644 index 0000000..f389e84 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs @@ -0,0 +1,148 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using System.Collections; + +namespace Depthkit +{ + + /// + /// The base class that any Depthkit player implementation will derrive from + /// + /// This class provides methods that are implemented in child classes to allow + /// a way for clip to generically interact with a given player backend. + + [RequireComponent(typeof(Depthkit.Clip))] + [ExecuteInEditMode] + public abstract class ClipPlayer : MonoBehaviour + { + public bool videoLoaded { get; protected set; } + + [HideInInspector] + public Depthkit.PlayerEvents events = new Depthkit.PlayerEvents(); + + /// + /// creates the appropriate player + /// + public abstract void CreatePlayer(); + + /// + /// returns player created status + /// + public abstract bool IsPlayerCreated(); + + /// + /// returns true if the video player has a video configured and is ready to play + /// + public abstract bool IsPlayerSetup(); + + /// + /// Load the implemented player video. + /// + public abstract IEnumerator Load(); + + /// + /// Method to dispatch the video loader to start + public abstract void StartVideoLoad(); + + /// + /// Load a video and then play through the implemented player. + public abstract IEnumerator LoadAndPlay(); + + /// + /// Sets the video from a path. Assumed absolute file path. + public abstract void SetVideoPath(string path); + + /// + /// Get the absolute path to the video. + public abstract string GetVideoPath(); + + /// + /// Callback for metadata updated on the clip. + public abstract void OnMetadataUpdated(Depthkit.Metadata metadata); + + /// + /// Play through the implemented player. Worth using in combination with VideoLoaded to ensure playback will start when called. + public abstract void Play(); + + /// + /// Pause through the implemented player. + public abstract void Pause(); + + /// + /// Stop playback through the player. + public abstract void Stop(); + + /// + /// Remove the player components from this GameObject. + public abstract void RemoveComponents(); + + /// + /// Return the texture for Depthkit to use by Renderers + public abstract Texture GetTexture(); + + /// + /// Returns if texture generated is flipped + public abstract bool IsTextureFlipped(); + + /// + /// Returns if shader needs to gamma correct depth value on this texture + public abstract GammaCorrection GammaCorrectDepth(); + + /// Returns if shader needs to gamma correct color value on this shader + public abstract GammaCorrection GammaCorrectColor(); + + /// + /// Return the type name of player being used + public abstract string GetPlayerTypeName(); + + /// + /// Return the pretty name of player being used + public static string GetPlayerPrettyName(){ return "Must Provide this function"; } + + /// + /// Check if video is playing right now or not + public abstract bool IsPlaying(); + + /// + /// Get the current playback time of the video in seconds. + public abstract double GetCurrentTime(); + + /// + /// Get the current playback frame of the video. + public abstract int GetCurrentFrame(); + + /// + /// Get duration of video in seconds + public abstract double GetDuration(); + + /// + /// Seek to a time point in the video in seconds + public abstract void Seek(float toTimeSeconds); + + public abstract uint GetVideoWidth(); + + public abstract uint GetVideoHeight(); + + public abstract bool SupportsPosterFrame(); + + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs.meta b/LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs.meta new file mode 100644 index 0000000..caa8cbc --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Players/ClipPlayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d8da4e768aedd64dba1ce3c10d7d5cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs b/LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs new file mode 100644 index 0000000..8a6bd4b --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs @@ -0,0 +1,61 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +namespace Depthkit +{ + public delegate void ClipPlayerEventHandler(); + + /// + /// Class that contains events a given player could potentially emit for listening. + [System.Serializable] + public class PlayerEvents + { + public event ClipPlayerEventHandler playbackStarted; + public event ClipPlayerEventHandler playbackPaused; + public event ClipPlayerEventHandler playbackStopped; + public event ClipPlayerEventHandler loadingStarted; + public event ClipPlayerEventHandler loadingFinished; + + public virtual void OnClipPlaybackStarted() + { + if(playbackStarted != null) { playbackStarted(); } + } + + public virtual void OnClipPlaybackPaused() + { + if(playbackPaused != null) { playbackPaused(); } + } + + public virtual void OnClipPlaybackStopped() + { + if(playbackStopped != null) { playbackStopped(); } + } + + public virtual void OnClipLoadingStarted() + { + if(loadingStarted != null) { loadingStarted(); } + } + + public virtual void OnClipLoadingFinished() + { + if(loadingFinished != null) { loadingFinished(); } + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs.meta b/LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs.meta new file mode 100644 index 0000000..ed56ae9 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Players/PlayerEvents.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a90e680aea53a2642b46483fa081088a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs b/LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs new file mode 100644 index 0000000..4411eb2 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs @@ -0,0 +1,286 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using System; +using System.Collections; + +namespace Depthkit +{ + /// + /// Implementation of the Depthkit player with the Unity VideoPlayer-based backend. + /// + [AddComponentMenu("Depthkit/Players/Depthkit Video Player (Unity)")] + public class UnityVideoPlayer : Depthkit.ClipPlayer + { + //reference to the MovieTexture passed in through Clip + [SerializeField, HideInInspector] + protected UnityEngine.Video.VideoPlayer m_mediaPlayer; + [SerializeField, HideInInspector] + protected AudioSource m_audioSource; + + public override void CreatePlayer() + { + m_mediaPlayer = gameObject.GetComponent(); + + if (m_mediaPlayer == null) + { + m_mediaPlayer = gameObject.AddComponent(); + } + + m_audioSource = gameObject.GetComponent(); + + if (m_audioSource == null) + { + m_audioSource = gameObject.AddComponent(); + } + + m_mediaPlayer.audioOutputMode = UnityEngine.Video.VideoAudioOutputMode.AudioSource; + m_mediaPlayer.SetTargetAudioSource(0, m_audioSource); + m_mediaPlayer.renderMode = UnityEngine.Video.VideoRenderMode.APIOnly; + m_mediaPlayer.prepareCompleted += OnVideoLoadingComplete; + m_mediaPlayer.EnableAudioTrack(0, true); + } + + public override bool IsPlayerCreated() + { + return m_mediaPlayer != null; + } + + public override bool IsPlayerSetup() + { + if(!IsPlayerCreated()) + { + return false; + } + + if(m_mediaPlayer.source == UnityEngine.Video.VideoSource.VideoClip) + { + return m_mediaPlayer.clip != null; + } + else + { + return m_mediaPlayer.url != null && m_mediaPlayer.url != ""; + } + } + + /// + /// Sets the video from a path. Assumed relative to data folder file path. + public override void SetVideoPath(string path) + { + if (!IsPlayerCreated()) + { + return; + } + // path = path.Replace("\\", "/"); + // if (path.StartsWith(Application.dataPath)) + // { + // path = "Assets" + path.Substring(Application.dataPath.Length); + // } + // m_mediaPlayer.source = UnityEngine.Video.VideoSource.Url; + m_mediaPlayer.url = path; + } + + /// + /// Get the absolute path to the video. + public override string GetVideoPath() + { + if (!IsPlayerSetup()) + { + return ""; + } + + if (m_mediaPlayer.source == UnityEngine.Video.VideoSource.VideoClip) + { + return m_mediaPlayer.clip.originalPath; + } + else + { + return m_mediaPlayer.url; + } + } + + public override void StartVideoLoad() + { + + StartCoroutine(Load()); + } + + public override IEnumerator Load() + { + events.OnClipLoadingStarted(); + m_mediaPlayer.Prepare(); + yield return null; + } + + public void OnVideoLoadingComplete(UnityEngine.Video.VideoPlayer player) + { + videoLoaded = true; + events.OnClipLoadingFinished(); + } + + public override void OnMetadataUpdated(Depthkit.Metadata metadata){ /* do nothing */ } + + public override IEnumerator LoadAndPlay() + { + StartVideoLoad(); + while (!videoLoaded) + { + yield return null; + } + Play(); + yield return null; + } + + public override void Play() + { + m_mediaPlayer.Play(); + events.OnClipPlaybackStarted(); + } + public override void Pause() + { + m_mediaPlayer.Pause(); + events.OnClipPlaybackPaused(); + } + public override void Stop() + { + m_mediaPlayer.Stop(); + events.OnClipPlaybackStopped(); + } + + public override int GetCurrentFrame() + { + return (int)m_mediaPlayer.frame; + } + public override double GetCurrentTime() + { + return m_mediaPlayer.time; + } + + public override double GetDuration() + { + return m_mediaPlayer.clip.length; + } + + public override Texture GetTexture() + { + return m_mediaPlayer.texture; + } + public override bool IsTextureFlipped () + { + return false; + } + public override GammaCorrection GammaCorrectDepth() + { + if (QualitySettings.activeColorSpace == ColorSpace.Linear) + { +#if UNITY_2018_2_OR_NEWER + return GammaCorrection.LinearToGammaSpace; +#elif UNITY_2017_1_OR_NEWER + //https://issuetracker.unity3d.com/issues/regression-videos-are-dark-when-using-linear-color-space?page=1 + Debug.LogWarning("Video Player (Unity) does not display correct color on Windows between version 2017.1 and 2018.2. Use AVPro, switch to Gamma Color Space, or upgrade Unity to use Depthkit with this project."); + return GammaCorrection.LinearToGammaSpace2x; +#else + return GammaCorrection.LinearToGammaSpace; +#endif + } + else + { + return GammaCorrection.None; + } + } + public override GammaCorrection GammaCorrectColor() + { + if (QualitySettings.activeColorSpace == ColorSpace.Linear) + { +#if UNITY_2018_2_OR_NEWER + return GammaCorrection.None; +#elif UNITY_2017_1_OR_NEWER + return GammaCorrection.LinearToGammaSpace; +#else + return GammaCorrection.None; +#endif + } + else + { + return GammaCorrection.None; + } + } + public override bool IsPlaying() + { + return m_mediaPlayer.isPlaying; + } + + public override void RemoveComponents() + { + if(!Application.isPlaying) + { + DestroyImmediate(m_mediaPlayer, true); + DestroyImmediate(m_audioSource, true); + DestroyImmediate(this, true); + } + else + { + Destroy(m_mediaPlayer); + Destroy(m_audioSource); + Destroy(this); + } + } + + public override string GetPlayerTypeName() + { + return typeof(Depthkit.UnityVideoPlayer).Name; + } + + public new static string GetPlayerPrettyName() + { + return "Video Player (Unity)"; + } + + public UnityEngine.Video.VideoPlayer GetPlayerBackend() + { + return m_mediaPlayer; + } + + public override void Seek(float toTime) + { + if (m_mediaPlayer == null) + { + return; + } + + m_mediaPlayer.time = toTime; + } + + public override uint GetVideoWidth() + { + return m_mediaPlayer != null ? m_mediaPlayer.width : 0; + } + public override uint GetVideoHeight() + { + return m_mediaPlayer != null ? m_mediaPlayer.height : 0; + } + + public override bool SupportsPosterFrame() + { + return true; + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs.meta b/LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs.meta new file mode 100644 index 0000000..48be3ce --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Players/UnityVideoPlayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 78d45f7d508d0a14884bec1201260eff +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 42c51ff9981f3e24b83cd7ad3c56e235, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources.meta b/LocalPackages/depthkit.core/Runtime/Resources.meta new file mode 100644 index 0000000..9c9383f --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 32fcbcdb90b345c459b070716a724e41 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders.meta new file mode 100644 index 0000000..41754bf --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4216d3a85251c074ab509288dbd7e17b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource.meta new file mode 100644 index 0000000..15cedec --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 988c575dd5c87004aa7e679acd4c89bb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute new file mode 100644 index 0000000..f02d255 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute @@ -0,0 +1,57 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +//vertices +#pragma kernel KGenerateVertices_Horizontal TILE_BORDER=3 +#pragma kernel KGenerateVertices_HorizontalWEdgeMask DK_CORE_USE_EDGEMASK TILE_BORDER=3 +#pragma kernel KGenerateVertices_Vertical TILE_BORDER=3 +#pragma kernel KGenerateVertices_VerticalWEdgeMask DK_CORE_USE_EDGEMASK TILE_BORDER=3 + +//normals +#pragma kernel KGenerateNormals DK_CORE_SMOOTH_NORMALS TILE_BORDER=1 +#pragma kernel KGenerateNormalsAdjustable DK_CORE_ADJUSTABLE_NORMALS TILE_BORDER=1 +#pragma kernel KGenerateNormalsAdjustableSmoother DK_CORE_ADJUSTABLE_NORMALS DK_CORE_ADJUSTABLE_NORMALS_SMOOTHER TILE_BORDER=1 +#pragma kernel KGenerateNormalsNone DK_CORE_NO_NORMALS TILE_BORDER=0 +#pragma kernel KGenerateNormalsDepthCamera DK_CORE_DEPTHCAMERA_NORMALS TILE_BORDER=0 + +//triangles +#pragma kernel KGenerateTriangles DK_VERTEX_BUFFER_READONLY TILE_BORDER=1 +#pragma kernel KGenerateTrianglesWEdgeMask DK_CORE_USE_EDGEMASK DK_VERTEX_BUFFER_READONLY TILE_BORDER=1 + +#pragma multi_compile_local __ DK_USE_GROUPSHARED_MEMORY + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc" + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KGenerateTriangles(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateTriangles(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KGenerateTrianglesWEdgeMask(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateTriangles(id, GroupId, GroupThreadId, GroupIndex); +} diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute.meta new file mode 100644 index 0000000..50ec6b7 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSource.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 68d530c9dc30f2f4895eebf7283e59c5 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 4 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc new file mode 100644 index 0000000..2f7a822 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc @@ -0,0 +1,96 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef DK_COREMESHSOURCECOMMON_INC +#define DK_COREMESHSOURCECOMMON_INC + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc" + +float2 _LatticeSize; +float2 _PerspectiveTextureSize; + +AppendStructuredBuffer _TriangleBuffer; + +#ifdef DK_VERTEX_BUFFER_READONLY +StructuredBuffer _VertexBuffer; +#else +RWStructuredBuffer _VertexBuffer; +#endif + +#ifdef DK_USE_EDGE_TRIANGLES_BUFFER +AppendStructuredBuffer _EdgeTriangleBuffer; +#endif + +#ifdef DK_CORE_USE_EDGEMASK +Texture2DArray _MaskTexture; +SamplerState _Mask_LinearClamp; +#endif +float _MaskClipThreshold; +float4 _PerspectiveToSlice[DK_MAX_NUM_PERSPECTIVES]; + +float _NormalHeight = 255.0f; + +#define BLOCK_SIZE 8 + +#define INVALID_POSITION float3(0,0,0); + +static const uint2 vert_coords[4] = +{ + uint2(0, 0), //tl + uint2(0, 1), //bl + uint2(1, 0), //tr + uint2(1, 1) //br +}; + +bool vertexOutOfBounds(int3 pixel) +{ + // Note: using > instead of >= here to ensure we have enough verts for one quad per pixel of the CPP. + // Using >= would omit the top right edge verts + return pixel.x < 0 || pixel.y < 0 || pixel.x > (int)(_PerspectiveTextureSize.x) || pixel.y > (int)(_PerspectiveTextureSize.y); +} + +#ifndef DK_CORE_CHECK_DISPATCH_VALID +#define DK_CORE_CHECK_DISPATCH_VALID +#endif + +#ifndef DK_CORE_DATA_SAMPLE_FN +#define DK_CORE_DATA_SAMPLE_FN(dispatchUV, pixel) dispatchUV; +#endif + +#ifndef DK_SLICE_OFFSET +#define DK_SLICE_OFFSET(z) z +#endif + +#ifndef DK_TO_VERTEX_BUFFER_INDEX +#define DK_TO_VERTEX_BUFFER_INDEX(coord) toIndexClamp(coord.xy, _LatticeSize) +#endif + +//validflags +#define DK_VERTEX_INVALID 0 +#define DK_VERTEX_VALID 1 +#define DK_VERTEX_LINEAR_MIN_THRESHOLD_VALID 2 +#define DK_VERTEX_LINEAR_MAX_THRESHOLD_VALID 4 +#define DK_VERTEX_POINT_MIN_THRESHOLD_VALID 8 +#define DK_VERTEX_POINT_MAX_THRESHOLD_VALID 16 +#define DK_VERTEX_OUT_OF_BOUNDS 32 + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc.meta new file mode 100644 index 0000000..6206700 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: dc7b48a786ad61e46acf4782f71cf1ca +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc new file mode 100644 index 0000000..65fe69d --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc @@ -0,0 +1,215 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef DK_COREMESHSOURCEGENERATENORMALS_INC +#define DK_COREMESHSOURCEGENERATENORMALS_INC + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc" + +#ifndef DK_CORE_DISPATCH_CONSTANTS +#define DK_CORE_DISPATCH_CONSTANTS +static const uint BLOCK_THREAD_COUNT = BLOCK_SIZE * BLOCK_SIZE; //64 dispatch threads +static const uint TILE_SIZE = BLOCK_SIZE + TILE_BORDER * 2; //10x10 pixel sampling tile +static const uint TILE_PIXEL_COUNT = TILE_SIZE * TILE_SIZE; //100 pixel samples per group +#endif + +#define NUM_HEX_SAMPLES 7 + +static const int2 hex_coord_offsets[NUM_HEX_SAMPLES] = +{ + int2(0, 0), // 0: center + int2(-1, 1), // 1: upper left + int2(-1, 0), // 2: left + int2(1, -1), // 3: lower right + int2(1, 0), // 4: right + int2(0, -1), // 5: down + int2(0, 1), // 6: up +}; + +#define NUM_HEX_TRIANGLES 6 + +static const uint hex_triangle_idx[NUM_HEX_TRIANGLES * 3] = +{ + 1, 0, 2, + 0, 5, 2, + 0, 3, 5, + 4, 3, 0, + 6, 4, 0, + 6, 0, 1 +}; + +#ifdef DK_CORE_SMOOTH_NORMALS +groupshared float3 g_vertexnormaldata[TILE_PIXEL_COUNT]; +#else +struct NormalData { + float depth; + uint perspectiveIndex; +}; +groupshared NormalData g_vertexnormaldata[TILE_PIXEL_COUNT]; +#endif + +void GenerateNormals(uint3 id, uint3 GroupId, uint3 GroupThreadId, uint GroupIndex) +{ +#if defined(DK_CORE_NO_NORMALS) || defined(DK_CORE_DEPTHCAMERA_NORMALS) +#ifndef DK_VERTEX_BUFFER_READONLY +#ifdef DK_CORE_NO_NORMALS + _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(id)].normal = float3(0, 0, 0); +#endif +#ifdef DK_CORE_DEPTHCAMERA_NORMALS + _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(id)].normal = dkGetDepthCameraDirection(id.z) * -1.0f; +#endif +#endif +#else + + uint ind; + const int2 tileSize = int2(TILE_SIZE, TILE_SIZE); + + ////////////////////////// + //LOAD VERTEX POSITION OR VERTEX DEPTH + ////////////////////////// + + const int2 tile_upperleft = int2(GroupId.xy * (int2)BLOCK_SIZE) - (int2)TILE_BORDER; + float depth; + [unroll] + for (ind = GroupIndex; ind < TILE_PIXEL_COUNT; ind += BLOCK_THREAD_COUNT) + { + const int3 pixel = int3(tile_upperleft + (int2)toCoord(ind, tileSize), id.z); + Vertex v = _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(pixel)]; +#ifdef DK_CORE_SMOOTH_NORMALS + g_vertexnormaldata[ind] = v.position; +#else + NormalData d; + d.depth = dkWorldSpaceToDepthCameraObjectSpace(v.perspectiveIndex, v.position).z; + d.perspectiveIndex = v.perspectiveIndex; + g_vertexnormaldata[ind] = d; +#endif + } + + GroupMemoryBarrierWithGroupSync(); + + DK_CORE_CHECK_DISPATCH_VALID + + int2 tileCoord = GroupThreadId.xy + int2(TILE_BORDER, TILE_BORDER); + +#ifdef DK_CORE_ADJUSTABLE_NORMALS + ////////////////////////// + //HEIGHT MAP NORMALS + ////////////////////////// + + float3 normal = 0; + float3 dir = float3(0, 0, 0); + uint perspectiveIndex = 0; + + { + uint x1_idx = toIndex(tileCoord + int2(1, 0), tileSize); + uint x2_idx = toIndex(tileCoord + int2(-1, 0), tileSize); + uint y1_idx = toIndex(tileCoord + int2(0, 1), tileSize); + uint y2_idx = toIndex(tileCoord + int2(0, -1), tileSize); + + NormalData x1 = g_vertexnormaldata[x1_idx]; + NormalData x2 = g_vertexnormaldata[x2_idx]; + NormalData y1 = g_vertexnormaldata[y1_idx]; + NormalData y2 = g_vertexnormaldata[y2_idx]; + + perspectiveIndex = x1.perspectiveIndex; + + float dzdx = (x1.depth * _NormalHeight - x2.depth * _NormalHeight) / 2.0; + float dzdy = (y1.depth * _NormalHeight - y2.depth * _NormalHeight) / 2.0; + + dir += float3(dzdx, dzdy, -1.0); + } + +#ifdef DK_CORE_ADJUSTABLE_NORMALS_SMOOTHER + { + uint x1_idx = toIndex(tileCoord + int2(1, 1), tileSize); + uint x2_idx = toIndex(tileCoord + int2(-1, -1), tileSize); + uint y1_idx = toIndex(tileCoord + int2(-1, 1), tileSize); + uint y2_idx = toIndex(tileCoord + int2(1, -1), tileSize); + + NormalData x1 = g_vertexnormaldata[x1_idx]; + NormalData x2 = g_vertexnormaldata[x2_idx]; + NormalData y1 = g_vertexnormaldata[y1_idx]; + NormalData y2 = g_vertexnormaldata[y2_idx]; + + float dzdx = (x1.depth * _NormalHeight - x2.depth * _NormalHeight) / 2.0; + float dzdy = (y1.depth * _NormalHeight - y2.depth * _NormalHeight) / 2.0; + + dir += float3(dzdx, dzdy, -1.0); + } +#endif +#ifndef DK_VERTEX_BUFFER_READONLY + _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(id)].normal = dkDepthCameraObjectSpaceDirToWorldSpaceDir(perspectiveIndex, normalize(dir)); +#endif +#endif + + +#ifdef DK_CORE_SMOOTH_NORMALS + + ////////////////////////// + //HEX NORMALS + ////////////////////////// + + float3 normal = 0; + [unroll] + for (uint tri_ind = 0; tri_ind < NUM_HEX_TRIANGLES; ++tri_ind) + { + float3 p1 = g_vertexnormaldata[toIndex(tileCoord + hex_coord_offsets[hex_triangle_idx[tri_ind * 3]], tileSize)]; + float3 p2 = g_vertexnormaldata[toIndex(tileCoord + hex_coord_offsets[hex_triangle_idx[(tri_ind * 3) + 1]], tileSize)]; + float3 p3 = g_vertexnormaldata[toIndex(tileCoord + hex_coord_offsets[hex_triangle_idx[(tri_ind * 3) + 2]], tileSize)]; + normal += normalize(cross(p2 - p1, p3 - p1)); + } +#ifndef DK_VERTEX_BUFFER_READONLY + _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(id)].normal = normalize(normal / 6.0); +#endif +#endif +#endif +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KGenerateNormals(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateNormals(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KGenerateNormalsAdjustable(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateNormals(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KGenerateNormalsAdjustableSmoother(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateNormals(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KGenerateNormalsNone(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateNormals(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KGenerateNormalsDepthCamera(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateNormals(id, GroupId, GroupThreadId, GroupIndex); +} + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc.meta new file mode 100644 index 0000000..9b21de0 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateNormals.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: cf0cc95f0c593ae4c9f18554fa27eb62 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc new file mode 100644 index 0000000..cf935c7 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc @@ -0,0 +1,176 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef DK_COREMESHSOURCEGENERATETRIANGLES_INC +#define DK_COREMESHSOURCEGENERATETRIANGLES_INC + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc" + +#ifndef DK_CORE_CHECK_DISPATCH_VALID +#define DK_CORE_CHECK_DISPATCH_VALID +#endif + +#ifndef DK_CORE_DISPATCH_CONSTANTS +#define DK_CORE_DISPATCH_CONSTANTS + +static const uint BLOCK_THREAD_COUNT = BLOCK_SIZE * BLOCK_SIZE; +static const uint TILE_BORDER = 1; + +static const uint TILE_SIZE = BLOCK_SIZE + TILE_BORDER * 2; +static const uint TILE_PIXEL_COUNT = TILE_SIZE * TILE_SIZE; + +#endif + +bool dkCheckQuadTriangleValid(uint quadMask, uint v1, uint v2, uint v3, out bool isEdge) +{ + isEdge = false; + bool vertexOutOfBounds = ((v1 & DK_VERTEX_OUT_OF_BOUNDS) > 0) || ((v2 & DK_VERTEX_OUT_OF_BOUNDS) > 0) || ((v3 & DK_VERTEX_OUT_OF_BOUNDS) > 0); + if (vertexOutOfBounds) + return false; +#ifdef DK_CORE_USE_EDGEMASK + isEdge = ((quadMask & DK_VERTEX_POINT_MAX_THRESHOLD_VALID) == 0) || ((v1 & DK_VERTEX_LINEAR_MAX_THRESHOLD_VALID) == 0) || ((v2 & DK_VERTEX_LINEAR_MAX_THRESHOLD_VALID) == 0) || ((v3 & DK_VERTEX_LINEAR_MAX_THRESHOLD_VALID) == 0); + return ((quadMask & DK_VERTEX_POINT_MIN_THRESHOLD_VALID) > 0) || ((v1 & DK_VERTEX_LINEAR_MIN_THRESHOLD_VALID) > 0) || ((v2 & DK_VERTEX_LINEAR_MIN_THRESHOLD_VALID) > 0) || ((v3 & DK_VERTEX_LINEAR_MIN_THRESHOLD_VALID) > 0); +#else + uint v1v = v1 & DK_VERTEX_VALID; + uint v2v = v2 & DK_VERTEX_VALID; + uint v3v = v3 & DK_VERTEX_VALID; + + uint t = v1v + v2v + v3v; + + switch (t) + { + case 3: //all valid + return true; + case 0: //all invalid + return false; + default: //an edge + isEdge = true; + return true; + } +#endif +} + +Triangle setupTriangle(int ind1, int ind2, int ind3) +{ + Triangle t; + t.vertex[0] = ind1; + t.vertex[1] = ind2; + t.vertex[2] = ind3; + return t; +} + +void writeTriangle(in Vertex v1, in Vertex v2, in Vertex v3, in int v1_idx, in int v2_idx, in int v3_idx, in bool isEdge) +{ + Triangle o = setupTriangle(v1_idx, v2_idx, v3_idx); + o.perspectiveIndex = v1.perspectiveIndex; +#ifdef DK_USE_EDGE_TRIANGLES_BUFFER + if (isEdge) + { + _EdgeTriangleBuffer.Append(o); + } + else + { + _TriangleBuffer.Append(o); + } +#else + _TriangleBuffer.Append(o); +#endif +} + +void writeTriangles(in Vertex tl, in Vertex bl, in Vertex tr, in Vertex br, in int tl_idx, in int bl_idx, in int tr_idx, in int br_idx) +{ + bool isEdge; + if (dkCheckQuadTriangleValid(tl.validFlag, bl.validFlag, br.validFlag, tl.validFlag, isEdge)) + { + writeTriangle(bl, br, tl, bl_idx, br_idx, tl_idx, isEdge); + } + if (dkCheckQuadTriangleValid(tl.validFlag, br.validFlag, tr.validFlag, tl.validFlag, isEdge)) + { + writeTriangle(br, tr, tl, br_idx, tr_idx, tl_idx, isEdge); + } +} + +#ifdef DK_USE_GROUPSHARED_MEMORY +groupshared Vertex g_trianglevertexdata[TILE_PIXEL_COUNT]; +#endif + +void GenerateTriangles(uint3 id, uint3 GroupId, uint3 GroupThreadId, uint GroupIndex) +{ + const int2 tileSize = int2(TILE_SIZE, TILE_SIZE); +#ifdef DK_USE_GROUPSHARED_MEMORY + + uint ind; + + ////////////////////////// + //LOAD VERTEX DATA + ////////////////////////// + + const int2 tile_upperleft = int2(GroupId.xy * (int2)BLOCK_SIZE) - (int2)TILE_BORDER; + float depth; + [unroll] + for (ind = GroupIndex; ind < TILE_PIXEL_COUNT; ind += BLOCK_THREAD_COUNT) + { + const int3 pixel = int3(tile_upperleft + (int2)toCoord(ind, tileSize), id.z); + g_trianglevertexdata[ind] = _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(pixel)]; + } + + GroupMemoryBarrierWithGroupSync(); +#endif + + DK_CORE_CHECK_DISPATCH_VALID + + ////////////////////// + // OUTPUT TRIANGLES + ////////////////////// + + uint2 offset = GroupThreadId.xy + TILE_BORDER; + uint2 vertex = id.xy; + + //make sure there's a vertex here + if (vertex.x < 0 || vertex.y < 0 || vertex.x >= (uint)_PerspectiveTextureSize.x || vertex.y >= (uint)_PerspectiveTextureSize.y) + return; + + int tl_idx = toIndex(offset + vert_coords[0], tileSize); + int bl_idx = toIndex(offset + vert_coords[1], tileSize); + int tr_idx = toIndex(offset + vert_coords[2], tileSize); + int br_idx = toIndex(offset + vert_coords[3], tileSize); + +#ifdef DK_USE_GROUPSHARED_MEMORY + //get triangle shared vertices and try to output the two triangles for this group thread + Vertex tl = g_trianglevertexdata[tl_idx]; + Vertex bl = g_trianglevertexdata[bl_idx]; + Vertex tr = g_trianglevertexdata[tr_idx]; + Vertex br = g_trianglevertexdata[br_idx]; +#else + Vertex tl = _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[0], id.z))]; + Vertex bl = _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[1], id.z))]; + Vertex tr = _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[2], id.z))]; + Vertex br = _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[3], id.z))]; +#endif + + tl_idx = DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[0], id.z)); + bl_idx = DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[1], id.z)); + tr_idx = DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[2], id.z)); + br_idx = DK_TO_VERTEX_BUFFER_INDEX(int3(vertex + vert_coords[3], id.z)); + + writeTriangles(tl, bl, tr, br, tl_idx, bl_idx, tr_idx, br_idx); +} + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc.meta new file mode 100644 index 0000000..2d190b3 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateTriangles.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ecbede3e91004874f9b73c2528986c3f +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc new file mode 100644 index 0000000..55e6868 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc @@ -0,0 +1,227 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef DK_COREMESHSOURCEGENERATEVERTS_INC +#define DK_COREMESHSOURCEGENERATEVERTS_INC + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/DataSource/DepthkitCoreMeshSourceCommon.cginc" + +static const uint BLOCK_WIDTH = BLOCK_SIZE * BLOCK_SIZE; // 64x1x1 dispatch tile +static const uint TILE_WIDTH = BLOCK_WIDTH + TILE_BORDER * 2; + +struct VertexData { + float4 uv; //[xy = perspective uv, zw = packed uv] + uint perspectiveIndex; + int validFlag; + float depth; +}; + +VertexData getVertexData(int3 pixel) +{ + VertexData v; + // Note: we add 1 to the _PerspectiveTextureSize here to ensure proper UV calculation as we have enough verts for 1 quad per pixel + float2 dispatchUV = saturate(((float2) pixel.xy) / (_PerspectiveTextureSize + 1.0f)); + v.uv.zw = DK_CORE_DATA_SAMPLE_FN(dispatchUV, pixel) + + if (vertexOutOfBounds(pixel)) + { + v.validFlag = DK_VERTEX_OUT_OF_BOUNDS | DK_VERTEX_INVALID; + v.uv = 0; + v.perspectiveIndex = 0; + v.depth = 0; + } + else + { + float2 depthUV; + float depth; + uint perspectiveIndex; + float2 perspUV; + bool valid = dkLoadDepthNormalized(v.uv.zw, depth, depthUV, perspUV, perspectiveIndex); + v.uv.xy = perspUV; + v.perspectiveIndex = perspectiveIndex; + +#ifdef DK_CORE_USE_EDGEMASK + uint4 maskDims; + _MaskTexture.GetDimensions(0, maskDims.x, maskDims.y, maskDims.z, maskDims.w); + + // Note: we add 1 to the maskDims.xy here to ensure proper UV calculation as we have enough verts for 1 quad per pixel + float2 maskLinearSample = _MaskTexture.SampleLevel(_Mask_LinearClamp, float3(((float2)pixel.xy) / ((float2)maskDims.xy + 1.0f), DK_SLICE_OFFSET(pixel.z)), 0).rg; + float2 maskPointSample = _MaskTexture.Load(float4(pixel.xy, DK_SLICE_OFFSET(pixel.z), 0)).rg; + + bool minLinearValid = (1.0f - maskLinearSample.r) >= _PerspectiveToSlice[perspectiveIndex].y; + bool maxLinearValid = (1.0f - max(maskLinearSample.r, maskLinearSample.g)) >= _PerspectiveToSlice[perspectiveIndex].y + _PerspectiveToSlice[perspectiveIndex].z; + bool minPointValid = (1.0f - maskPointSample.r) >= _PerspectiveToSlice[perspectiveIndex].y; + bool maxPointValid = (1.0f - max(maskPointSample.r, maskPointSample.g)) >= _PerspectiveToSlice[perspectiveIndex].y + _PerspectiveToSlice[perspectiveIndex].z; +#else + bool minLinearValid = false; + bool maxLinearValid = false; + bool minPointValid = false; + bool maxPointValid = false; +#endif + v.depth = depth; + + v.validFlag = valid ? DK_VERTEX_VALID : DK_VERTEX_INVALID; + v.validFlag |= minLinearValid ? DK_VERTEX_LINEAR_MIN_THRESHOLD_VALID : DK_VERTEX_INVALID; + v.validFlag |= maxLinearValid ? DK_VERTEX_LINEAR_MAX_THRESHOLD_VALID : DK_VERTEX_INVALID; + v.validFlag |= minPointValid ? DK_VERTEX_POINT_MIN_THRESHOLD_VALID : DK_VERTEX_INVALID; + v.validFlag |= maxPointValid ? DK_VERTEX_POINT_MAX_THRESHOLD_VALID : DK_VERTEX_INVALID; + } + + return v; +} +groupshared VertexData g_vertexdata[TILE_WIDTH]; + +float flattenFlangeFilter(int offset) +{ + float maxDepth = 0.f; + [unroll] + for (int kernel_ind = -TILE_BORDER; kernel_ind <= TILE_BORDER; kernel_ind++) + { + maxDepth = max(g_vertexdata[kernel_ind + offset].depth, maxDepth); + } + float depth = g_vertexdata[offset].depth; + return lerp(maxDepth, depth, depth > 0); +} + +void GenerateVertices_Horizontal(uint3 id, uint3 GroupId, uint3 GroupThreadId, uint GroupIndex) +{ + ////////////////////////// + //SAMPLE DEPTH AND GENERATE VERTEX + ////////////////////////// + + uint ind; + + const int2 tile_upperleft = int2(GroupId.xy) * int2(BLOCK_WIDTH, 1) - int2(TILE_BORDER, 0); + + [unroll] + for (ind = GroupIndex; ind < TILE_WIDTH; ind += BLOCK_WIDTH) + { + const int3 pixel = int3(tile_upperleft + int2(ind, 0), id.z); + VertexData d = getVertexData(pixel); + g_vertexdata[ind] = d; + } + + GroupMemoryBarrierWithGroupSync(); + + DK_CORE_CHECK_DISPATCH_VALID + + int sampleOffset = GroupThreadId.x + TILE_BORDER; + const int3 vertex = int3(tile_upperleft.x + sampleOffset, tile_upperleft.y, id.z); + + //make sure there's a vertex here + if (vertex.x < 0 || vertex.y < 0 || vertex.x >= _LatticeSize.x || vertex.y >= _LatticeSize.y) + return; + + ////////////////////////// + //APPLY FLANGE FLATTEN FILTER TO DEPTH + ////////////////////////// + + VertexData d = g_vertexdata[sampleOffset]; + + Vertex v = newVertex(); + v.perspectiveIndex = d.perspectiveIndex; + v.uv = d.uv; + v.validFlag = d.validFlag; + + // Note: Here we temporarily store the modified depth in the normal. + // We cannot use any other components as they either already + // have valid data or will be overwritten in the Vertical pass + v.normal.x = flattenFlangeFilter(sampleOffset); + +#ifndef DK_VERTEX_BUFFER_READONLY + _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(vertex)] = v; +#endif + +} + +void GenerateVertices_Vertical(uint3 id, uint3 GroupId, uint3 GroupThreadId, uint GroupIndex) +{ + uint ind; + const int2 tile_upperleft = int2(GroupId.xy) * int2(1, BLOCK_WIDTH) - int2(0, TILE_BORDER); + + ////////////////////////// + //LOAD VERTEX DATA + ////////////////////////// + + [unroll] + for (ind = GroupIndex; ind < TILE_WIDTH; ind += BLOCK_WIDTH) + { + const int3 vertex = int3(tile_upperleft + int2(0, ind), id.z); + + Vertex v = _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(vertex)]; + // needed to compute the vertex position + VertexData d; + d.uv = v.uv; + d.perspectiveIndex = v.perspectiveIndex; + d.depth = v.normal.x; + g_vertexdata[ind] = d; + } + + GroupMemoryBarrierWithGroupSync(); + + DK_CORE_CHECK_DISPATCH_VALID + + int sampleOffset = GroupThreadId.y + TILE_BORDER; + const int3 vertex = int3(tile_upperleft.x, tile_upperleft.y + sampleOffset, id.z); + + //make sure there's a vertex here + if (vertex.x < 0 || vertex.y < 0 || vertex.x >= _LatticeSize.x || vertex.y >= _LatticeSize.y) + return; + + + ////////////////////////// + //APPLY FLANGE FLATTEN FILTER TO DEPTH + ////////////////////////// + + VertexData d = g_vertexdata[sampleOffset]; + float updatedDepth = flattenFlangeFilter(sampleOffset); + + float3 position = dkPerspectiveUVToWorld(d.perspectiveIndex, d.uv.xy, updatedDepth).xyz; + +#ifndef DK_VERTEX_BUFFER_READONLY + _VertexBuffer[DK_TO_VERTEX_BUFFER_INDEX(vertex)].position = position; +#endif +} + +[numthreads(BLOCK_SIZE * BLOCK_SIZE, 1, 1)] +void KGenerateVertices_Horizontal(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateVertices_Horizontal(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE * BLOCK_SIZE, 1, 1)] +void KGenerateVertices_HorizontalWEdgeMask(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateVertices_Horizontal(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(1, BLOCK_SIZE * BLOCK_SIZE, 1)] +void KGenerateVertices_Vertical(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateVertices_Vertical(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(1, BLOCK_SIZE * BLOCK_SIZE, 1)] +void KGenerateVertices_VerticalWEdgeMask(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GenerateVertices_Vertical(id, GroupId, GroupThreadId, GroupIndex); +} + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc.meta new file mode 100644 index 0000000..9923838 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/DataSource/GenerateVertices.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c35c7e1d9fa849041bbef12f786dd13c +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes.meta new file mode 100644 index 0000000..32e65ac --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: baa8c98ea7deb6b4aa4a1c20b247944e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc new file mode 100644 index 0000000..fe9e13f --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc @@ -0,0 +1,81 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DEPTHKIT_COLORCORRECTION_CGINC +#define _DEPTHKIT_COLORCORRECTION_CGINC + +float GammaToLinearSpaceExact (float value) +{ + value = abs(value); + + if (value <= 0.04045F) + return value / 12.92F; + else if (value < 1.0F) + return pow((value + 0.055F)/1.055F, 2.4F); + else + return pow(value, 2.2F); +} + +float LinearToGammaSpaceExact (float value) +{ + value = abs(value); + + if (value <= 0.0F) + return 0.0F; + else if (value <= 0.0031308F) + return 12.92F * value; + else if (value < 1.0F) + return 1.055F * pow(value, 0.4166667F) - 0.055F; + else + return pow(value, 0.45454545F); +} + +#ifdef HALF_COLOR_CONVERSION + +half3 LinearToGammaSpace (half3 linRGB) +{ + linRGB = max(linRGB, half3(0.h, 0.h, 0.h)); + // An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 + return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h); +} + +half3 GammaToLinearSpace (half3 sRGB) +{ + // Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 + return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h); +} + +#else + +float3 LinearToGammaSpace (float3 linRGB) +{ + linRGB = max(linRGB, float3(0.f, 0.f, 0.f)); + // An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 + return max(1.055f * pow(linRGB, 0.416666667) - 0.055f, 0.f); +} + +float3 GammaToLinearSpace (float3 sRGB) +{ + // Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 + return sRGB * (sRGB * (sRGB * 0.305306011f + 0.682171111f) + 0.012522878f); +} + +#endif //HALF_COLOR_CONVERSION +#endif //_DEPTHKIT_COLORCORRECTION_CGINC \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc.meta new file mode 100644 index 0000000..b2af746 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8222bb681c01ff7479c7e11f0da420a2 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc new file mode 100644 index 0000000..47841be --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc @@ -0,0 +1,50 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DK_CORE_TRIANGLE_TYPES_CGINC +#define _DK_CORE_TRIANGLE_TYPES_CGINC + +struct Triangle +{ +#ifndef DK_CORE_PACKED_TRIANGLE + uint perspectiveIndex; + uint vertex[3]; +#else + Vertex vertex[3]; +#endif +}; + +Triangle newTriangle() +{ + Triangle t; +#ifndef DK_CORE_PACKED_TRIANGLE + t.perspectiveIndex = 0; + t.vertex[0] = 0; + t.vertex[1] = 0; + t.vertex[2] = 0; +#else + t.vertex[0] = newVertex(); + t.vertex[1] = newVertex(); + t.vertex[2] = newVertex(); +#endif + return t; +} + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc.meta new file mode 100644 index 0000000..454428e --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: d795549b204d5944391cf56bd9908c49 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc new file mode 100644 index 0000000..5630165 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc @@ -0,0 +1,45 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DK_CORE_VERTEX_TYPE_CGINC +#define _DK_CORE_VERTEX_TYPE_CGINC + +//Vertices are in Object Space +struct Vertex +{ + float4 uv; //[xy = perspective, zw = packed] + float3 position; + float3 normal; + uint perspectiveIndex; + uint validFlag; +}; + +Vertex newVertex() +{ + Vertex v; + v.uv = float4(0, 0, 0, 0); + v.perspectiveIndex = 0; + v.position = float3(0, 0, 0); + v.normal = float3(0, 0, 0); + v.validFlag = 0; + return v; +} + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc.meta new file mode 100644 index 0000000..9649146 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: da7c2b0a4441920488e27d2797f978f3 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc new file mode 100644 index 0000000..d9a0220 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc @@ -0,0 +1,39 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DEPTHKIT_DEBUGCAMERACOLORS_CGINC +#define _DEPTHKIT_DEBUGCAMERACOLORS_CGINC + +static const float3 dkDebugCameraColors[12] = { + float3(1, 0, 0), + float3(0, 1, 0), + float3(0, 0, 1), + float3(1, 1, 0), + float3(0, 1, 1), + float3(1, 0, 1), + float3(0.5f, 1, 0), + float3(0, 1, 0.5f), + float3(1, 0.5f, 0), + float3(1, 0, 0.5f), + float3(0.5f, 0, 1), + float3(0.5f, 0.5f, 1) +}; + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc.meta new file mode 100644 index 0000000..9b199a8 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: da12b703446d5d1448eca9f8e6ad06c2 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc new file mode 100644 index 0000000..a885ed9 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc @@ -0,0 +1,33 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DEPTHKIT_DEFINES_CGINC +#define _DEPTHKIT_DEFINES_CGINC + +#define DK_BRIGHTNESS_THRESHOLD_OFFSET 0.01f +#define DK_MAX_NUM_PERSPECTIVES 10 + +#define DK_CORRECT_NONE 0 +#define DK_CORRECT_LINEAR_TO_GAMMA 1 +#define DK_CORRECT_GAMMA_TO_LINEAR 2 +//Unity 2017.1 - 2018.2 has a video player bug where Linear->Gamma needs to be applied twice before texture look up in depth +#define DK_CORRECT_LINEAR_TO_GAMMA_2X 3 + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc.meta new file mode 100644 index 0000000..c1d0590 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8552efddcb1ed634dac125fc2698e383 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc new file mode 100644 index 0000000..dc6585a --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc @@ -0,0 +1,460 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DEPTHKIT_CGINC +#define _DEPTHKIT_CGINC + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc" +#ifndef DK_USE_BUILT_IN_COLOR_CONVERSION +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/ColorCorrection.cginc" +#endif +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/DebugCameraColors.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc" + +float3 dkGetDebugCameraColor(uint perspectiveIndex) +{ + return dkDebugCameraColors[perspectiveIndex]; +} + +uint2 dkGetPerspectiveCoordFromPackedUV(float2 packedUV) +{ + // clamp values to _PerspectivesInX/Y -1 so that a uv of 1 doesn't result in an index of _PerspectivesInX/Y + return uint2(clamp(floor(packedUV.x * _PerspectivesInX), 0 , _PerspectivesInX-1), + clamp(floor(packedUV.y * _PerspectivesInY), 0 , _PerspectivesInY-1)); +} + +uint dkGetPerspectiveIndexFromCoord(uint2 perspectiveCoord) +{ + if (!_TextureFlipped) + { + // flip the y index before converting these coordinates to an index to index the correct perspective data + // (unity image coordinates are at the bottom left so the y index goes at the bottom to the top while depthkit + // expects the y index to increase from the top left going down to the bottom + perspectiveCoord.y = ((_PerspectivesInY - 1) - perspectiveCoord.y); + } + uint perspectiveIndex = toIndex(perspectiveCoord, uint2(_PerspectivesInX, _PerspectivesInY)); + // clamp the perspective index to _PerspectivesCount in the case that the number of perspectives is not equal to + // _PerspectivesInX * _PerspectivesInY eg: 9 perspectives divided into 5x2 + return clamp(perspectiveIndex, 0, _PerspectivesCount - 1); +} + +uint2 dkGetPerspectiveCoordsFromIndex(uint perspectiveIndex) +{ + uint2 perspectiveCoord = toCoord(perspectiveIndex, uint2(_PerspectivesInX, _PerspectivesInY)); + + if (!_TextureFlipped) + { + // flip the y index before converting these coordinates to an index to index the correct perspective data + // (unity image coordinates are at the bottom left so the y index goes at the bottom to the top while depthkit + // expects the y index to increase from the top left to the bottom + perspectiveCoord.y = ((_PerspectivesInY - 1) - perspectiveCoord.y); + } + return perspectiveCoord; +} + +uint dkGetPerspectiveIndexFromPackedUV(float2 packedUV) +{ + return dkGetPerspectiveIndexFromCoord(dkGetPerspectiveCoordFromPackedUV(packedUV)); +} + +float2 dkGetDepthImageSize(uint perspectiveIndex) +{ + return _PerspectiveDataStructuredBuffer[perspectiveIndex].depthImageSize.xy; +} + +float3 dkGetDepthCameraPosition(uint perspectiveIndex) +{ + return _PerspectiveDataStructuredBuffer[perspectiveIndex].cameraPosition; +} + +float3 dkGetDepthCameraDirection(uint perspectiveIndex) +{ + return normalize(_PerspectiveDataStructuredBuffer[perspectiveIndex].cameraNormal); +} + +//(0 - 1) UV to perspective's uv in packed texture space +float2 dkPerspectiveToPackedUV(uint2 perspectiveCoord, float2 perspectiveUV) +{ + float2 frameScale = { 1.0f / float(_PerspectivesInX), 1.0f / float(_PerspectivesInY) }; + float2 offset = float2(perspectiveCoord) * frameScale; + return saturate(remap2(perspectiveUV, float2(0.0f, 0.0f), float2(1.0f, 1.0f), offset, offset + frameScale)); +} + +//(0 - 1) UV to perspective's uv in packed texture space +float2 dkPerspectiveToPackedUV(uint perspectiveIndex, float2 perspectiveUV) +{ + return dkPerspectiveToPackedUV(dkGetPerspectiveCoordsFromIndex(perspectiveIndex), perspectiveUV); +} + +//uv from packed texture, aka cpp image space +float2 dkPackedToPerspectiveUV(float2 packedUV, uint2 perspectiveCoord) +{ + float2 frameScale = { 1.0f / float(_PerspectivesInX), 1.0f / float(_PerspectivesInY) }; + float2 offset = float2(perspectiveCoord)*frameScale; + return saturate(remap2(packedUV, offset, offset + frameScale, float2(0.0f, 0.0f), float2(1.0f, 1.0f))); +} + +//uv from packed texture, aka cpp image space +float2 dkPackedToPerspectiveUV(float2 packedUV) +{ + uint2 perspectiveCoord = dkGetPerspectiveCoordFromPackedUV(packedUV); + return dkPackedToPerspectiveUV(packedUV, perspectiveCoord); +} + +float2 dkPerspectiveToCroppedUV(uint perspectiveIndex, float2 uncroppedUV) +{ + return _PerspectiveDataStructuredBuffer[perspectiveIndex].crop.xy + (uncroppedUV * _PerspectiveDataStructuredBuffer[perspectiveIndex].crop.zw); +} + +float2 dkCroppedToPerspectiveUV(uint perspectiveIndex, float2 croppedUV) +{ + return (croppedUV - _PerspectiveDataStructuredBuffer[perspectiveIndex].crop.xy) / _PerspectiveDataStructuredBuffer[perspectiveIndex].crop.zw; +} + +float dkNormalizedDepthToMeters(uint perspectiveIndex, float normalizedDepth) +{ + return normalizedDepth * (_PerspectiveDataStructuredBuffer[perspectiveIndex].farClip - _PerspectiveDataStructuredBuffer[perspectiveIndex].nearClip) + _PerspectiveDataStructuredBuffer[perspectiveIndex].nearClip; +} + +float dkMetersToNormalizedDepth(uint perspectiveIndex, float depthMeters) +{ + return (depthMeters - _PerspectiveDataStructuredBuffer[perspectiveIndex].nearClip) / (_PerspectiveDataStructuredBuffer[perspectiveIndex].farClip - _PerspectiveDataStructuredBuffer[perspectiveIndex].nearClip); +} + +float3 dkUnproject(uint perspectiveIndex, float2 pixel, float depthMeters) +{ + return float3((pixel - _PerspectiveDataStructuredBuffer[perspectiveIndex].depthPrincipalPoint.xy) * depthMeters / _PerspectiveDataStructuredBuffer[perspectiveIndex].depthFocalLength.xy, depthMeters); +} + +float2 dkProject(uint perspectiveIndex, float3 position) +{ + return (position.xy / position.z) * _PerspectiveDataStructuredBuffer[perspectiveIndex].depthFocalLength.xy + _PerspectiveDataStructuredBuffer[perspectiveIndex].depthPrincipalPoint.xy; +} + +float3 dkDepthCameraObjectSpaceToWorldSpace(uint perspectiveIndex, float3 objectPosition) +{ + return mul(_PerspectiveDataStructuredBuffer[perspectiveIndex].extrinsics, float4(objectPosition, 1)).xyz; +} + +float3 dkWorldSpaceToDepthCameraObjectSpace(uint perspectiveIndex, float3 objectPosition) +{ + return mul(_PerspectiveDataStructuredBuffer[perspectiveIndex].extrinsicsInverse, float4(objectPosition, 1)).xyz; +} + +float3 dkDepthCameraObjectSpaceDirToWorldSpaceDir(uint perspectiveIndex, float3 dir) +{ + return normalize(mul((float3x3)_PerspectiveDataStructuredBuffer[perspectiveIndex].extrinsics, dir).xyz); +} + +float3 dkWorldSpaceDirToDepthCameraObjectSpaceDir(uint perspectiveIndex, float3 dir) +{ + return normalize(mul((float3x3)_PerspectiveDataStructuredBuffer[perspectiveIndex].extrinsicsInverse, dir).xyz); +} + +void dkGetColorAndDepthUV(float2 packedUV, out float2 colorUV, out float2 depthUV) +{ + uint2 perspectiveCoord = dkGetPerspectiveCoordFromPackedUV(packedUV); + + float uv_yStart = float(perspectiveCoord.y) /float(_PerspectivesInY); + float uv_yEnd = float(perspectiveCoord.y +1) / float(_PerspectivesInY); + float uv_yMid = 0.5 / float(_PerspectivesInY); + + colorUV.x = depthUV.x = packedUV.x; + if (_TextureFlipped) + { + // Convert to packedY to perspectiveY range before mapping to color and depth + float perspectiveY = dkPackedToPerspectiveUV(packedUV, perspectiveCoord).y; + + // color y is lesser that depth y + // example range in single row: 0 - 0.5 color, 0.5 - 1 depth + perspectiveY = 1.0 - perspectiveY; + colorUV.y = uv_yStart+ perspectiveY * uv_yMid; + depthUV.y = colorUV.y + uv_yMid; + } + else + { + // unity coordinates are inverted in y therefore the depth y is lesser that the color y + // example range in single row: 0 - 0.5 depth, 0.5 - 1 color + depthUV.y = remap(packedUV.y, uv_yStart, uv_yEnd, uv_yStart, uv_yStart+ uv_yMid); + colorUV.y = depthUV.y + uv_yMid; + } +} + +// perspectiveUV [0-1] is in the perspective's image space, not in packed cpp image space +float4 dkPerspectiveUVToLocalDepthInMeters(uint perspectiveIndex, float2 perspectiveUV, float depthInMeters) +{ + // TODO:: fix with coordinate system clean up + // This y flip works around the unity coordinate system origin at the bottom left of the image + perspectiveUV.y = 1.0f - perspectiveUV.y; + + float2 croppedUv = dkPerspectiveToCroppedUV(perspectiveIndex, perspectiveUV); + + float2 pixel = croppedUv * dkGetDepthImageSize(perspectiveIndex); + + float3 worldPosition = dkUnproject(perspectiveIndex, pixel, depthInMeters); + + // TODO:: fix with coordinate system clean up + // This y flip ensures the geometry is the upright + worldPosition.y *= -1.0f; + + return float4(worldPosition, 1); +} + +// perspectiveUV [0-1] is in the perspective's image space, not in packed cpp image space +float4 dkPerspectiveUVToLocal(uint perspectiveIndex, float2 perspectiveUV, float normalizedDepth) +{ + return dkPerspectiveUVToLocalDepthInMeters( + perspectiveIndex, + perspectiveUV, + dkNormalizedDepthToMeters(perspectiveIndex, normalizedDepth) + ); +} + +// perspectiveUV [0-1] is in the perspective's image space, not in packed cpp image space +float4 dkPerspectiveUVToWorld(uint perspectiveIndex, float2 perspectiveUV, float normalizedDepth) +{ + float3 localPosition = dkPerspectiveUVToLocal(perspectiveIndex, perspectiveUV, normalizedDepth).xyz; + + return float4(dkDepthCameraObjectSpaceToWorldSpace(perspectiveIndex, localPosition), 1); +} + +//uv is in packed cpp image space, convert to that perspective's world space +float4 dkPackedUVToWorld(float2 packedUV, float depth) +{ + // get index by converting the perspective coordinates this ensures the mapping between the uvs and + // the index into the camera array is accurate regardless of image space coordinate origins + uint2 perspectiveCoord = dkGetPerspectiveCoordFromPackedUV(packedUV); + float2 perspectiveUV = dkPackedToPerspectiveUV(packedUV, perspectiveCoord); + return dkPerspectiveUVToWorld(dkGetPerspectiveIndexFromCoord(perspectiveCoord), perspectiveUV, depth); +} + +//uv is in packed cpp image space, convert to that perspective's world space +float4 dkPackedUVToLocal(float2 packedUV, float depth) +{ + // get index by converting the perspective coordinates this ensures the mapping between the uvs and + // the index into the camera array is accurate regardless of image space coordinate origins + uint2 perspectiveCoord = dkGetPerspectiveCoordFromPackedUV(packedUV); + float2 perspectiveUV = dkPackedToPerspectiveUV(packedUV, perspectiveCoord); + return dkPerspectiveUVToLocal(dkGetPerspectiveIndexFromCoord(perspectiveCoord), perspectiveUV, depth); +} + +// single perspective world space to packed color and depth uvs, includes their perspective offset. uv contains the 0-1 uv for that perspective's view +void dkWorldToPerspectiveUV(uint perspectiveIndex, float3 position, out float2 perspectiveUV, out float2 depthUV, out float2 colorUV, out float3 depthViewSpacePos) +{ + depthViewSpacePos = dkWorldSpaceToDepthCameraObjectSpace(perspectiveIndex, position); + + // TODO:: fix with coordinate system clean up + // This y flip ensures the geometry projected to the correct image space + depthViewSpacePos.y *= -1.0f; + + float2 projected = dkProject(perspectiveIndex, depthViewSpacePos); + + float2 croppedUV = projected / dkGetDepthImageSize(perspectiveIndex); + + perspectiveUV = dkCroppedToPerspectiveUV(perspectiveIndex, croppedUV); + + // TODO:: fix with coordinate system clean up + // This y flip works around the unity coordinate system origin at the bottom left of the image + perspectiveUV.y = 1.0 - perspectiveUV.y; + + + float2 packedUV = dkPerspectiveToPackedUV(perspectiveIndex, perspectiveUV); + + //adjust y for cpp format + dkGetColorAndDepthUV(packedUV, colorUV, depthUV); +} + +float3 dkColorCorrect_Depth(float3 samplecolor) +{ + // if Unity is rendering in Linear space and we are using unity video player (which must encode frames in gamma space), we apply inverse gamma (1/2.2) to depth frame to get a linear sample + float3 correctedColor = samplecolor; + if (_ColorSpaceCorrectionDepth == DK_CORRECT_LINEAR_TO_GAMMA) + { + correctedColor = float3(LinearToGammaSpaceExact(samplecolor.r), + LinearToGammaSpaceExact(samplecolor.g), + LinearToGammaSpaceExact(samplecolor.b)); + } + else if (_ColorSpaceCorrectionDepth == DK_CORRECT_GAMMA_TO_LINEAR) + { + correctedColor = float3(GammaToLinearSpaceExact(samplecolor.r), + GammaToLinearSpaceExact(samplecolor.g), + GammaToLinearSpaceExact(samplecolor.b)); + } + else if (_ColorSpaceCorrectionDepth == DK_CORRECT_LINEAR_TO_GAMMA_2X) + { + correctedColor = float3( + LinearToGammaSpaceExact(LinearToGammaSpaceExact(samplecolor.r)), + LinearToGammaSpaceExact(LinearToGammaSpaceExact(samplecolor.g)), + LinearToGammaSpaceExact(LinearToGammaSpaceExact(samplecolor.b))); + } + return correctedColor; +} + +float3 dkColorCorrect_Color(float3 samplecolor) +{ + // if unity is rendering in linear space and we are using external gamma corrected assets, then encode to gamma space pow(2.2) to match the input assets + float3 correctedColor = samplecolor; + if (_ColorSpaceCorrectionColor == DK_CORRECT_LINEAR_TO_GAMMA) + { + correctedColor = LinearToGammaSpace(samplecolor); + } + else if (_ColorSpaceCorrectionColor == DK_CORRECT_GAMMA_TO_LINEAR) + { + correctedColor = GammaToLinearSpace(samplecolor); + } + else if (_ColorSpaceCorrectionDepth == DK_CORRECT_LINEAR_TO_GAMMA_2X) + { + correctedColor = LinearToGammaSpace(LinearToGammaSpace(samplecolor)); + } + return correctedColor; +} + +// Returns bias adjusted normalized depth +// TODO: stop using normalized depth for anything outside of the internals of this function. +float dkConvertDepthHSV(in float4 depthsample, in uint perspectiveIndex, in float2 perspectiveUV) +{ + float3 depthsamplehsv = rgb2hsv(dkColorCorrect_Depth(depthsample.rgb)); + float filtereddepth = pow(depthsamplehsv.b, 6); + float preBiasDepth = filtereddepth > _EdgeChoke + DK_BRIGHTNESS_THRESHOLD_OFFSET ? depthsamplehsv.r : 0.0; + float4 projectionPlanePos = dkPerspectiveUVToLocalDepthInMeters(perspectiveIndex, perspectiveUV, 1.0); + + float depthMeters = dkNormalizedDepthToMeters(perspectiveIndex, preBiasDepth); + float adjustedDepth = depthMeters - (_RadialBiasPerspInMeters[perspectiveIndex].x * rsqrt(lengthSquared(projectionPlanePos.xyz))); + + return dkMetersToNormalizedDepth(perspectiveIndex, adjustedDepth); +} + +//uv is in perspective cpp image space, includes perspective offset +//returns normalized depth loaded to the nearest pixel +float dkLoadDepth(in float2 depthUV, in uint perspectiveIndex, in float2 perspectiveUV) +{ + depthUV = saturate(depthUV); + int textureWidth, textureHeight, levels; + _CPPTexture.GetDimensions(0, textureWidth, textureHeight, levels); + float4 depthsample = _CPPTexture.Load(int3(depthUV * float2(textureWidth, textureHeight), 0)); + return dkConvertDepthHSV(depthsample, perspectiveIndex, perspectiveUV); +} + +//uv is in perspective cpp image space, includes perspective offset +//returns normalized depth with binliear interpolation +float dkSampleDepth(in float2 depthUV, in uint perspectiveIndex, in float2 perspectiveUV) +{ + depthUV = saturate(depthUV); + float4 depthsample = _CPPTexture.SampleLevel(_LinearClamp, depthUV, 0); + return dkConvertDepthHSV(depthsample, perspectiveIndex, perspectiveUV); +} + +//uv is in packed cpp image space, returns crop adjusted uvs for the given perspective +void dkUnpackUVs(in float2 packedUV, out float2 colorUV, out float2 depthUV, out float2 perspectiveUV, out uint perspectiveIndex) +{ + // get index by converting the perspective coordinates this ensures the mapping between the uvs and + // the index into the camera array is accurate regardless of image space coordinate origins + uint2 perspectiveCoord = dkGetPerspectiveCoordFromPackedUV(packedUV); + perspectiveIndex = dkGetPerspectiveIndexFromCoord(perspectiveCoord); + perspectiveUV = dkPackedToPerspectiveUV(packedUV, perspectiveCoord); + dkGetColorAndDepthUV(packedUV, colorUV, depthUV); +} + +//checks that normalized depth is valid for perspective +bool dkValidateNormalizedDepth(in uint perspectiveIndex, in float depth) { + bool result = false; + if ((depth >= _PerspectiveDataStructuredBuffer[perspectiveIndex].clipEpsilon) && (depth <= (1.0f - _PerspectiveDataStructuredBuffer[perspectiveIndex].clipEpsilon))) result = true; + return result; +} + +//uv is in cpp image space, not including any perspective offset. +// returned sample is loaded to the nearest pixel +bool dkLoadDepthNormalized(in float2 packedUV, out float depth, out float2 depthUV, out float2 perspectiveUV, out uint perspectiveIndex) +{ + float2 colorUV; + dkUnpackUVs(packedUV, colorUV, depthUV, perspectiveUV, perspectiveIndex); + depth = dkLoadDepth(depthUV, perspectiveIndex, perspectiveUV); + return dkValidateNormalizedDepth(perspectiveIndex, depth); +} + +//uv is in cpp image space, not including any perspective offset +// returned sample is bilinearly interpolated +bool dkSampleDepthNormalized(in float2 packedUV, out float depth, out float2 depthUV, out float2 perspectiveUV, out uint perspectiveIndex) +{ + float2 colorUV; + dkUnpackUVs(packedUV, colorUV, depthUV, perspectiveUV, perspectiveIndex); + depth = dkSampleDepth(depthUV, perspectiveIndex, perspectiveUV); + return dkValidateNormalizedDepth(perspectiveIndex, depth); +} + +// NOT USED +//uv is in cpp image space, not including any perspective offset +// returned sample is loaded to the nearest pixel +bool dkLoadDepthMeters(in float2 uv, out float depthMeters, out float2 depthUV, out uint perspectiveIndex) +{ + float2 colorUV, perspectiveUV; + dkUnpackUVs(uv, colorUV, depthUV, perspectiveUV, perspectiveIndex); + float depth = dkLoadDepth(depthUV, perspectiveIndex, perspectiveUV); + bool valid = dkValidateNormalizedDepth(perspectiveIndex, depth); + depthMeters = dkNormalizedDepthToMeters(perspectiveIndex, depth); + return valid; +} + +//uv is in cpp image space, not including any perspective offset +// returned sample is bilinearly interpolated +bool dkSampleDepthMeters(in float2 uv, out float depthMeters, out float2 depthUV, out uint perspectiveIndex) +{ + float2 colorUV, perspectiveUV; + dkUnpackUVs(uv, colorUV, depthUV, perspectiveUV, perspectiveIndex); + float depth = dkSampleDepth(depthUV, perspectiveIndex, perspectiveUV); + bool valid = dkValidateNormalizedDepth(perspectiveIndex, depth); + depthMeters = dkNormalizedDepthToMeters(perspectiveIndex, depth); + return valid; +} + +// NOT USED +//uvs are in perspective cpp image space, includes perspective offset +bool dkSampleColorAndLoadDepth(in float2 packedUV, out float3 color, out float depth) +{ + float2 depthUV, colorUV, perspectiveUV; + uint perspectiveIndex; + dkUnpackUVs(packedUV, colorUV, depthUV, perspectiveUV, perspectiveIndex); + depth = dkLoadDepth(depthUV, perspectiveIndex, perspectiveUV); + float4 sampledColor = _CPPTexture.SampleLevel(_LinearClamp, colorUV, 0); + color = dkColorCorrect_Color(sampledColor.rgb); + return dkValidateNormalizedDepth(0, depth); +} + +//uv is in perspective cpp image space, includes perspective offset +float3 dkSampleColor(in float2 colorUV) +{ + float4 sampledColor = _CPPTexture.SampleLevel(_LinearClamp, colorUV, 0); + return dkColorCorrect_Color(sampledColor.rgb); +} + +// Returns the pixel resolution of a single perspective's color or depth portion +// This is identical for all perspectives +int2 dkGetPerspectiveResolution() +{ + int textureWidth, textureHeight, levels; + _CPPTexture.GetDimensions(0, textureWidth, textureHeight, levels); + + // Note: dividing textureHeight by two since each perspective contains both a color and depth portion + return int2((uint)textureWidth / (uint)_PerspectivesInX, (uint)textureHeight / 2u / (uint)_PerspectivesInY); +} + +#endif // _DEPTHKIT_CGINC diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc.meta new file mode 100644 index 0000000..b35f04a --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: dc67109830abd954884cb4acc75272d0 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc new file mode 100644 index 0000000..65a77bf --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc @@ -0,0 +1,41 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DEPTHKIT_CORE_UNIFORMS_CGINC +#define _DEPTHKIT_CORE_UNIFORMS_CGINC + +// CLIP DATA +float _EdgeChoke = 0.5; // per-pixel brightness threshold, used to refine edge geometry from eroneous edge depth samples +StructuredBuffer _PerspectiveDataStructuredBuffer; +int _PerspectivesCount; +int _PerspectivesInX; +int _PerspectivesInY; +int _TextureFlipped; +int _ColorSpaceCorrectionDepth; +int _ColorSpaceCorrectionColor; + +Texture2D _CPPTexture; +SamplerState _LinearClamp; + +// MESH SOURCE DATA +// The datatype for the per perspective bias is a float4 because float arrays get pushed to the shader as 4 component float vectors. +float4 _RadialBiasPerspInMeters[DK_MAX_NUM_PERSPECTIVES]; + +#endif //_DEPTHKIT_CORE_UNIFORMS_CGINC \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc.meta new file mode 100644 index 0000000..621f717 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/DepthkitCoreUniforms.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 2c1a34061e78f09468a53a0e32c0e72e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc new file mode 100644 index 0000000..25ce766 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc @@ -0,0 +1,69 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DEPTHKIT_SAMPLETRIANGLES_CGINC +#define _DEPTHKIT_SAMPLETRIANGLES_CGINC + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/CoreVertex.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/CoreTriangle.cginc" +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc" + +StructuredBuffer _TriangleBuffer; +StructuredBuffer _TrianglesCount; + +#ifdef DK_CORE_PACKED_TRIANGLE + +Vertex dkSampleTriangleBuffer(uint triangleId, uint vertexId) +{ + if (triangleId >= _TrianglesCount[0]) + { + return newVertex(); + } + else + { + Triangle t = _TriangleBuffer[triangleId]; + Vertex v = t.vertex[vertexId]; + v.normal = clamp3(v.normal, float3(-1.0, -1.0, -1.0), float3(1.0, 1.0, 1.0)); + return v; + } +} + +#else + +StructuredBuffer _VertexBuffer; + +Vertex dkSampleTriangleBuffer(uint triangleId, uint vertexId) +{ + if (triangleId >= _TrianglesCount[0]) + { + return newVertex(); + } + else + { + Triangle t = _TriangleBuffer[triangleId]; + Vertex v = _VertexBuffer[t.vertex[vertexId]]; + v.normal = clamp3(v.normal, float3(-1.0, -1.0, -1.0), float3(1.0, 1.0, 1.0)); + return v; + } +} + +#endif + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc.meta new file mode 100644 index 0000000..d4654f4 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 23addcb533764fa4e8c66aa71961de6f +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc new file mode 100644 index 0000000..a2c08f8 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc @@ -0,0 +1,106 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DK_SAMPLE_EDGE_MASK_INC +#define _DK_SAMPLE_EDGE_MASK_INC + +#define DK_ALPHA_CLIP_THRESHOLD 0.5f + +#ifndef DK_EDGEMASK_UNIFORMS_DEF +#define DK_EDGEMASK_UNIFORMS_DEF \ + SamplerState _Mask_LinearClamp; \ + SamplerState _Mask_PointClamp; \ + Texture2DArray _MaskTexture; \ + float4 _PerspectiveToSlice[DK_MAX_NUM_PERSPECTIVES]; \ + float2 _PaddedUVScaleFactor; + float4 _MaskTextureTS; +#endif + +#ifdef DK_DEBUG_EDGEMASK +#ifndef DK_USE_DOWNSAMPLED_EDGEMASK +#define DK_USE_DOWNSAMPLED_EDGEMASK +#endif +#endif + +#ifdef DK_USE_DOWNSAMPLED_EDGEMASK +#ifndef DK_SAMPLE_DOWNSAMPLED_EDGEMASK +Texture2DArray _DownsampledMaskTexture; +#define DK_SAMPLE_DOWNSAMPLED_EDGEMASK(uv, perspectiveIndex) _DownsampledMaskTexture.SampleLevel(_Mask_PointClamp, float3(uv.xy * _PaddedUVScaleFactor, _PerspectiveToSlice[perspectiveIndex].x), 0).rg +#else +#define DK_SAMPLE_DOWNSAMPLED_EDGEMASK(uv, perspectiveIndex) float2(1, 1) +#endif +#endif + +#ifndef DK_CLIP_THRESHOLD +#ifdef DK_USE_EDGEMASK + #ifdef DK_SCREEN_DOOR_TRANSPARENCY + #define DK_CLIP_THRESHOLD(perspectiveIndex) 0 + #else + #define DK_CLIP_THRESHOLD(perspectiveIndex) _PerspectiveToSlice[perspectiveIndex].y + #endif +#else +#define DK_CLIP_THRESHOLD(perspectiveIndex) DK_ALPHA_CLIP_THRESHOLD +#endif +#endif + +#if defined(DK_SCREEN_DOOR_TRANSPARENCY) && defined(DK_USE_EDGEMASK) +static const float4x4 thresholdMatrix = +{ + 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0, + 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0, + 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0, + 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0 +}; + +#ifndef DK_DITHER_ALPHA +#define DK_DITHER_ALPHA(alpha, perspectiveIndex, pos) remap(alpha, _PerspectiveToSlice[perspectiveIndex].y, _PerspectiveToSlice[perspectiveIndex].y + _PerspectiveToSlice[perspectiveIndex].z, 0.0f, 1.0f) - thresholdMatrix[pos.x % 4][pos.y % 4] +#endif +#endif + +#ifndef DK_SAMPLE_EDGEMASK +#ifdef DK_USE_EDGEMASK //uv [xy = perspective, zw = packed] + #define __DK_SAMPLE_EDGEMASK(uv, perspectiveIndex) 1.0f - _MaskTexture.SampleLevel(_Mask_LinearClamp, float3(uv.xy * _PaddedUVScaleFactor, _PerspectiveToSlice[perspectiveIndex].x), 0).r + #ifdef DK_SCREEN_DOOR_TRANSPARENCY + #define DK_SAMPLE_EDGEMASK(uv, perspectiveIndex, clipPos) DK_DITHER_ALPHA(__DK_SAMPLE_EDGEMASK(uv, perspectiveIndex), perspectiveIndex, clipPos) + #else + #define DK_SAMPLE_EDGEMASK(uv, perspectiveIndex, clipPos) __DK_SAMPLE_EDGEMASK(uv, perspectiveIndex) + #endif +#else + #define DK_SAMPLE_EDGEMASK(uv, perspectiveIndex, clipPos) 1.0f +#endif +#endif + +///////////////////////////////// + +#ifdef DK_USE_EDGEMASK +#define DK_EDGEMASK_UNIFORMS DK_EDGEMASK_UNIFORMS_DEF +#else +#define DK_EDGEMASK_UNIFORMS +#endif + +#ifndef DK_FRAGMENT_CLIP +#ifdef DK_SKIP_FRAGMENT_CLIP +#define DK_FRAGMENT_CLIP(alpha, perspectiveIndex) +#else +#define DK_FRAGMENT_CLIP(alpha, perspectiveIndex) clip(alpha - DK_CLIP_THRESHOLD(perspectiveIndex)); +#endif +#endif + +#endif diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc.meta new file mode 100644 index 0000000..e8edac3 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8914eb139fa6a87428e72e271dcd8c7f +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc new file mode 100644 index 0000000..8ea8604 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc @@ -0,0 +1,40 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DEPTHKIT_TYPES_CGINC +#define _DEPTHKIT_TYPES_CGINC + +struct PerspectiveData +{ + float2 depthImageSize; + float2 depthPrincipalPoint; + float2 depthFocalLength; + float farClip; + float nearClip; + float4x4 extrinsics; + float4x4 extrinsicsInverse; + float4 crop; + float clipEpsilon; + float3 cameraPosition; + float3 cameraNormal; + float pad; +}; + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc.meta new file mode 100644 index 0000000..e6283dd --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Types.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 222e33bdff6a1df41a2f19fc1b6b896b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc new file mode 100644 index 0000000..665f791 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc @@ -0,0 +1,279 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _Depthkit_UtilS_CGINC +#define _Depthkit_UtilS_CGINC + +#define FLOAT_EPS 0.00001f + +float3 rgb2hsv(float3 c) +{ + float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g)); + float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + return float3(abs(q.z + (q.w - q.y) / (6.0 * d + FLOAT_EPS)), d / (q.x + FLOAT_EPS), q.x); +} + +float3 hsv2rgb(float3 c) +{ + float4 K = float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); + float3 p = abs(frac(c.xxx + K.xyz) * 6.0f - K.www); + return c.z * lerp(float3(K.xxx), clamp(p - K.xxx, 0.0f, 1.0f), c.y); +} + +float remap(float value, float low1, float high1, float low2, float high2) { + return (low2 + (value - low1) * (high2 - low2) / (high1 - low1)); +} + +float2 remap2(float2 value, float2 low1, float2 high1, float2 low2, float2 high2) { + return (low2 + (value - low1) * (high2 - low2) / (high1 - low1)); +} + +uint2 toCoord(uint idx, uint2 dim) +{ + return uint2(idx % dim.x, idx / dim.x); +} + +uint toIndex(uint2 coord, uint2 dim) +{ + return coord.x + coord.y * dim.x; +} + +uint2 toCoordClamp(int idx, uint2 dim) +{ + idx = clamp(idx, 0, (dim.x * dim.y) - 1); + return uint2(idx % dim.x, idx / dim.x); +} + +uint toIndexClamp(int2 coord, uint2 dim) +{ + coord = clamp(coord, 0, (int2)dim - 1); + return coord.x + coord.y * dim.x; +} + +uint3 toCoord3D(uint idx, uint3 dim) +{ + return uint3(idx % dim.x, (idx / dim.x) % dim.y, idx / (dim.x * dim.y)); +} + +uint toIndex3D(uint3 coord, uint3 dim) +{ + return coord.x + coord.y * dim.x + coord.z * dim.x * dim.y; +} + +uint3 toCoord3DClamp(int idx, uint3 dim) +{ + idx = clamp(idx, 0, (dim.x * dim.y * dim.z) - 1); + return uint3(idx % dim.x, (idx / dim.x) % dim.y, idx / (dim.x * dim.y)); +} + +uint toIndex3DClamp(int3 coord, uint3 dim) +{ + coord = clamp(coord, 0, (int3)dim - 1); + return coord.x + coord.y * dim.x + coord.z * dim.x * dim.y; +} + +float lengthSquared(float3 v) +{ + return dot(v, v); +} + +float lengthSquared(float2 v) +{ + return dot(v, v); +} + +float distanceSquared(float3 a, float3 b) +{ + return lengthSquared(a - b); +} + +float luminance(float3 color) +{ + return dot(color, float3(0.299f, 0.587f, 0.114f)); +} + +float cmToMeters(float cm) +{ + return cm / 100.0f; +} + +float metersTocm(float meters) +{ + return meters * 100.0f; +} + +float3 clamp3(float3 val, float3 minimum, float3 maximum) +{ + return min(maximum, max(minimum, val)); +} + +// returns int2(input, 1) or int2(1, input) depending on Axis +int2 AxisMask(int2 axis, int input) +{ + return axis * input + axis.yx; +} + +// Swizzles based on Axis floattor +int2 AxisSwizzle(int2 axis, int2 input) +{ + return axis.xx * input.xy + axis.yy * input.yx; +} + +//https://forum.unity.com/threads/storing-two-16-bits-halfs-in-one-32-bits-float.987531/ +//when in 0-1 range +float dkScale01FloatTo16BitRange(float a) +{ + return log2(saturate(a) + 1.0) * 65535.0; +} +//when in 0-1 range +float dkUnscale01FloatFrom16BitRange(uint a) +{ + return pow(2.0, (a >> 16) / 65535.0) - 1.0; +} + +float dkPackFloats(float a, float b) +{ + //Packing + uint a16 = f32tof16(a); + uint b16 = f32tof16(b); + uint packed = (a16 << 16) | (b16 & 0xFFFF); + return asfloat(packed); +} + +void dkUnpackFloats(float input, out float a, out float b) +{ + //Unpacking + uint uintInput = asuint(input); + a = f16tof32(uintInput >> 16); + b = f16tof32(uintInput & 0xFFFF); +} + +// inclusive-inclusive +#define INRANGE_II_TEMPLATE_S(TTYPE) bool inRange_ii(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ return v >= minValue && v <= maxValue; } + +#define INRANGE_II_TEMPLATE_V(TTYPE) \ +bool inRange_ii(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ \ + return all(v >= minValue) && all(v <= maxValue); \ +} +INRANGE_II_TEMPLATE_S(float) +INRANGE_II_TEMPLATE_S(int) +INRANGE_II_TEMPLATE_S(uint) +INRANGE_II_TEMPLATE_V(float2) +INRANGE_II_TEMPLATE_V(int2) +INRANGE_II_TEMPLATE_V(uint2) +INRANGE_II_TEMPLATE_V(float3) +INRANGE_II_TEMPLATE_V(int3) +INRANGE_II_TEMPLATE_V(uint3) +INRANGE_II_TEMPLATE_V(float4) +INRANGE_II_TEMPLATE_V(int4) +INRANGE_II_TEMPLATE_V(uint4) + +// inclusive-exclusive +#define INRANGE_IE_TEMPLATE_S(TTYPE) bool inRange_ie(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ return v >= minValue && v < maxValue; } + +#define INRANGE_IE_TEMPLATE_V(TTYPE) \ +bool inRange_ie(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ \ +return all(v >= minValue) && all(v < maxValue); \ +} +INRANGE_IE_TEMPLATE_S(float) +INRANGE_IE_TEMPLATE_S(int) +INRANGE_IE_TEMPLATE_S(uint) +INRANGE_IE_TEMPLATE_V(float2) +INRANGE_IE_TEMPLATE_V(int2) +INRANGE_IE_TEMPLATE_V(uint2) +INRANGE_IE_TEMPLATE_V(float3) +INRANGE_IE_TEMPLATE_V(int3) +INRANGE_IE_TEMPLATE_V(uint3) +INRANGE_IE_TEMPLATE_V(float4) +INRANGE_IE_TEMPLATE_V(int4) +INRANGE_IE_TEMPLATE_V(uint4) + +// exclusive-inclusive +#define INRANGE_EI_TEMPLATE_S(TTYPE) bool inRange_ei(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ return v > minValue && v <= maxValue; } + +#define INRANGE_EI_TEMPLATE_V(TTYPE) \ +bool inRange_ei(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ \ + return all(v > minValue) && all(v <= maxValue); \ +} +INRANGE_EI_TEMPLATE_S(float) +INRANGE_EI_TEMPLATE_S(int) +INRANGE_EI_TEMPLATE_S(uint) +INRANGE_EI_TEMPLATE_V(float2) +INRANGE_EI_TEMPLATE_V(int2) +INRANGE_EI_TEMPLATE_V(uint2) +INRANGE_EI_TEMPLATE_V(float3) +INRANGE_EI_TEMPLATE_V(int3) +INRANGE_EI_TEMPLATE_V(uint3) +INRANGE_EI_TEMPLATE_V(float4) +INRANGE_EI_TEMPLATE_V(int4) +INRANGE_EI_TEMPLATE_V(uint4) + +// exclusive-exclusive +#define INRANGE_EE_TEMPLATE_S(TTYPE) bool inRange_ee(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ return v > minValue && v < maxValue; } + +#define INRANGE_EE_TEMPLATE_V(TTYPE) \ +bool inRange_ee(TTYPE v, TTYPE minValue, TTYPE maxValue) \ +{ \ + return all(v > minValue) && all(v < maxValue); \ +} +INRANGE_EE_TEMPLATE_S(float) +INRANGE_EE_TEMPLATE_S(int) +INRANGE_EE_TEMPLATE_S(uint) +INRANGE_EE_TEMPLATE_V(float2) +INRANGE_EE_TEMPLATE_V(int2) +INRANGE_EE_TEMPLATE_V(uint2) +INRANGE_EE_TEMPLATE_V(float3) +INRANGE_EE_TEMPLATE_V(int3) +INRANGE_EE_TEMPLATE_V(uint3) +INRANGE_EE_TEMPLATE_V(float4) +INRANGE_EE_TEMPLATE_V(int4) +INRANGE_EE_TEMPLATE_V(uint4) + +// inclusive-exclusive with lower bounds of zero +#define INBOUNDS_TEMPLATE(TTYPE, LOWER_BOUND) \ +bool inBounds(TTYPE v, TTYPE exclusiveUpperBounds) \ +{ \ + return inRange_ie(v, LOWER_BOUND, exclusiveUpperBounds); \ +} +INBOUNDS_TEMPLATE(float, 0.f) +INBOUNDS_TEMPLATE(int, 0) +INBOUNDS_TEMPLATE(uint, 0) +INBOUNDS_TEMPLATE(float2, float2(0.f, 0.f)) +INBOUNDS_TEMPLATE(int2, int2(0, 0)) +INBOUNDS_TEMPLATE(uint2, uint2(0, 0)) +INBOUNDS_TEMPLATE(float3, float3(0.f, 0.f, 0.f)) +INBOUNDS_TEMPLATE(int3, int3(0, 0, 0)) +INBOUNDS_TEMPLATE(uint3, uint3(0, 0, 0)) +INBOUNDS_TEMPLATE(float4, float4(0.f, 0.f, 0.f, 0.f)) +INBOUNDS_TEMPLATE(int4, int4(0, 0, 0, 0)) +INBOUNDS_TEMPLATE(uint4, uint4(0, 0, 0, 0)) + + +#endif \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc.meta new file mode 100644 index 0000000..ead8733 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 0945c05922e75e14bbd61b0623370c7c +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks.meta new file mode 100644 index 0000000..70c3d28 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dc263af237ce4ac4fabc2fbbe7b35a1c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc new file mode 100644 index 0000000..232f62c --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc @@ -0,0 +1,142 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +DK_EDGEMASK_UNIFORMS + +float4x4 _LocalTransform; +float _ShadowAmount; + +struct appdata +{ + float4 vertex : POSITION; + float3 normal : NORMAL; + float2 packedUV : TEXCOORD0; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct v2f +{ + float2 packedUV : TEXCOORD0; + float4 pos : SV_POSITION; +#if defined(DK_USE_LIGHTPROBES) && defined(DK_FORWARDBASE_PASS) + float3 indirect : COLOR1; +#endif + UNITY_FOG_COORDS(1) + SHADOW_COORDS(3) + UNITY_VERTEX_OUTPUT_STEREO +}; + +v2f vert(appdata v) +{ + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + Vertex vert = dkSampleTriangleBuffer(floor(v.id / 3), v.id % 3); + + o.packedUV = vert.uv.zw; + v.vertex = mul(_LocalTransform, float4(vert.position.xyz, 1)); + v.normal = mul((float3x3)_LocalTransform, vert.normal); + + o.pos = UnityObjectToClipPos(v.vertex); + +#if defined(DK_USE_LIGHTPROBES) && defined(DK_FORWARDBASE_PASS) + float3 worldNormal = UnityObjectToWorldNormal(v.normal); + o.indirect = max(0, ShadeSH9(half4(worldNormal, 1))); +#endif + + UNITY_TRANSFER_FOG(o, o.pos); + TRANSFER_SHADOW(o); + return o; +} + +fixed4 frag(v2f i) : SV_Target +{ + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + uint perspectiveIndex; + float2 depthUV, colorUV, perspectiveUV; + dkUnpackUVs(i.packedUV, colorUV, depthUV, perspectiveUV, perspectiveIndex); + + float alpha = 1.0f; + +#if defined(DK_USE_EDGEMASK) && (!defined(DK_CORE_SKIP_SAMPLE_EDGEMASK) || defined(DK_DEBUG_EDGEMASK)) + alpha = DK_SAMPLE_EDGEMASK(perspectiveUV, perspectiveIndex, i.pos); +#endif + +#ifndef DK_CORE_SKIP_FRAGMENT_DEPTHSAMPLE + float depth = dkSampleDepth(depthUV, perspectiveIndex, perspectiveUV); + alpha = dkValidateNormalizedDepth(perspectiveIndex, depth) ? alpha : -1.f; +#endif + +#ifdef DK_DEBUG_EDGEMASK + float3 color = float3(alpha * dkGetDebugCameraColor(perspectiveIndex)); + #ifdef DK_USE_EDGEMASK + float2 minMaxMask = DK_SAMPLE_DOWNSAMPLED_EDGEMASK(perspectiveUV, perspectiveIndex); + if (alpha < 0.0) + { + color = float3(0.3, 0.3, 0.3); + } + if (alpha == 0.0) //completely invalid + { + color = float3(0.05, 0.05, 0.05); + } + // dim if is edge + if ((1.0f - minMaxMask.y) < DK_CLIP_THRESHOLD(perspectiveIndex)) + { + color *= .5; + } + #else + if (alpha < DK_ALPHA_CLIP_THRESHOLD) { color = float3(0.3f, 0.3f, 0.3f); } + #endif + fixed4 col = fixed4(color.rgb, 1.0); +#else + + #ifndef DK_CORE_SKIP_FRAGMENT_DEPTHSAMPLE + DK_FRAGMENT_CLIP(alpha, perspectiveIndex) + #endif + + #ifdef DK_USE_DEBUG_COLOR + fixed4 col = fixed4(dkGetDebugCameraColor(perspectiveIndex),alpha); + #else + float3 color = dkSampleColor(colorUV); + + #if defined(DK_NO_MAIN_LIGHT) && defined(DK_FORWARDBASE_PASS) + #if defined(DK_USE_LIGHTPROBES) + color = color * i.indirect; + #endif + #else + float3 shadow = lerp(float3(1.0, 1.0, 1.0), SHADOW_ATTENUATION(i), saturate(_ShadowAmount)); + #if defined(DK_USE_LIGHTPROBES) && defined(DK_FORWARDBASE_PASS) + color = lerp(color * i.indirect, color, shadow); + #else + color *= shadow; + #endif + #endif + fixed4 col = fixed4(color.rgb, alpha); + #endif +#endif + + // apply fog + UNITY_APPLY_FOG(i.fogCoord, col); + return col; +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc.meta new file mode 100644 index 0000000..f8c5e56 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: bd62c6f408c8a9e40902dbc174b5c270 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc new file mode 100644 index 0000000..cdc310f --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc @@ -0,0 +1,75 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +DK_EDGEMASK_UNIFORMS + +float4x4 _LocalTransform; + +struct appdata +{ + float4 vertex : POSITION; + float3 normal : NORMAL; + uint id : SV_VertexID; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct v2f +{ + V2F_SHADOW_CASTER; +#ifndef DK_CORE_SKIP_FRAGMENT_DEPTHSAMPLE + float2 packedUV : TEXCOORD1; +#endif + UNITY_VERTEX_OUTPUT_STEREO +}; + +v2f vert(appdata v) +{ + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + Vertex vert = dkSampleTriangleBuffer(floor(v.id / 3), v.id % 3); + +#ifndef DK_CORE_SKIP_FRAGMENT_DEPTHSAMPLE + o.packedUV = vert.uv.zw; +#endif + + v.vertex = mul(_LocalTransform, float4(vert.position, 1)); + v.normal = mul((float3x3) _LocalTransform, vert.normal); + TRANSFER_SHADOW_CASTER_NORMALOFFSET(o) + + return o; +} + +float4 frag(v2f i) : COLOR +{ + +#ifndef DK_CORE_SKIP_FRAGMENT_DEPTHSAMPLE + uint perspectiveIndex; + float2 depthUV, colorUV, perspectiveUV; + dkUnpackUVs(i.packedUV, colorUV, depthUV, perspectiveUV, perspectiveIndex); + float depth = dkSampleDepth(depthUV, perspectiveIndex, perspectiveUV); + float alpha = dkValidateNormalizedDepth(perspectiveIndex, depth) ? DK_SAMPLE_EDGEMASK(perspectiveUV, perspectiveIndex, i.pos) : -1.f; + DK_FRAGMENT_CLIP(alpha, perspectiveIndex) +#endif + + SHADOW_CASTER_FRAGMENT(i) +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc.meta new file mode 100644 index 0000000..083de9c --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 932011e03048c7649afdd912bc62e240 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader new file mode 100644 index 0000000..fdd2de9 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader @@ -0,0 +1,129 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' + +Shader "Depthkit/Core/Depthkit Core Photo Look Built-in RP" +{ + Properties + { + _ShadowAmount ("Shadow Amount", Range (0.0,1.0)) = 1.0 + [Toggle(DK_USE_LIGHTPROBES)] _SampleProbes("Use Light Probes", Float) = 1 + [Toggle(DK_USE_EDGEMASK)] _UseEdgeMask("Use Edge Mask", Float) = 0 + [Toggle(DK_DEBUG_EDGEMASK)] _RenderMaskOnGeo("Debug Edge Mask", Float) = 0 + [Toggle(DK_NO_MAIN_LIGHT)] _NoMainLight("Disable Main Directional Shadows", Float) = 0 + [Toggle(DK_USE_DEBUG_COLOR)] _DebugColor("Debug Per Perspective Color", Float) = 0 + [Toggle(DK_SCREEN_DOOR_TRANSPARENCY)] _DitherEdge("Dither Edge", Float) = 0 + } + + SubShader + { + Tags { "RenderType"="Opaque" } + Cull off + LOD 100 + + Pass + { + Tags {"LightMode" = "ForwardBase"} + CGPROGRAM + + #pragma shader_feature_local __ DK_USE_LIGHTPROBES + #pragma shader_feature_local __ DK_USE_DEBUG_COLOR + #pragma shader_feature_local __ DK_USE_EDGEMASK + #pragma shader_feature_local __ DK_DEBUG_EDGEMASK + #pragma shader_feature_local __ DK_NO_MAIN_LIGHT + #pragma shader_feature_local __ DK_SCREEN_DOOR_TRANSPARENCY + + #pragma vertex vert + #pragma fragment frag + // make fog work + #pragma multi_compile_fog + #pragma multi_compile_fwdbase + + #include "UnityCG.cginc" + #include "AutoLight.cginc" + #define DK_USE_BUILT_IN_COLOR_CONVERSION + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc" + #define DK_FORWARDBASE_PASS + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc" + + ENDCG + } + + Pass + { + Tags {"LightMode" = "ForwardAdd"} + BlendOp Max + Blend One One + ZWrite Off + + CGPROGRAM + + #pragma shader_feature_local __ DK_USE_LIGHTPROBES + #pragma shader_feature_local __ DK_USE_EDGEMASK + #pragma shader_feature_local __ DK_USE_DEBUG_COLOR + #pragma shader_feature_local __ DK_SCREEN_DOOR_TRANSPARENCY + + #pragma vertex vert + #pragma fragment frag + // make fog work + #pragma multi_compile_fog + #pragma multi_compile_fwdadd_fullshadows + + #include "UnityCG.cginc" + #include "AutoLight.cginc" + #define DK_USE_BUILT_IN_COLOR_CONVERSION + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCorePhotoLook.cginc" + ENDCG + } + + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + Fog {Mode Off} + ZWrite On ZTest LEqual Cull Off + Offset 1, 1 + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #pragma shader_feature_local __ DK_USE_EDGEMASK + #pragma shader_feature_local __ DK_SCREEN_DOOR_TRANSPARENCY + + #pragma multi_compile_shadowcaster + #pragma fragmentoption ARB_precision_hint_fastest + #include "UnityCG.cginc" + #define DK_USE_BUILT_IN_COLOR_CONVERSION + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleCoreTriangles.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/SampleEdgeMask.cginc" + #include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitCoreShadowCaster.cginc" + ENDCG + } + } + Fallback "VertexLit" +} diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader.meta new file mode 100644 index 0000000..8e7d2f5 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Looks/DepthkitPhotoLookBuiltInRP.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 81a995dd51908fd4aa276b3cd023c563 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util.meta new file mode 100644 index 0000000..beea8e0 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a52e903ecde5e624c91fc411bfe100b4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc new file mode 100644 index 0000000..4e049a1 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc @@ -0,0 +1,84 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#ifndef _DK_GAUSSIANBLUR_INC +#define _DK_GAUSSIANBLUR_INC + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc" + +SamplerState _LinearClamp; + +float2 _PongSize; +float2 _Axis; +float _GaussianExponential; +float _GaussianNormalization; + +static const uint BLOCK_WIDTH = BLOCK_SIZE * BLOCK_SIZE; // 64x1x1 dispatch tile +static const int KERNEL_WIDTH = TILE_BORDER; +static const uint TILE_WIDTH = BLOCK_WIDTH + TILE_BORDER * 2; + +groupshared float gsamples[TILE_WIDTH]; + +#ifndef DK_GAUSSIAN_FILTER_SAMPLE_UV +#define DK_GAUSSIAN_FILTER_SAMPLE_UV(uv) uv +#endif + +#ifndef DK_GAUSSIAN_FILTER_OUTPUT_COORD +#define DK_GAUSSIAN_FILTER_OUTPUT_COORD(pixel) pixel.xy +#endif + +void GaussianBlurFilter(uint3 id, uint3 GroupId, uint3 GroupThreadId, uint GroupIndex) +{ + uint ind; + const float2 oneOverPongSize = 1.0f / _PongSize; + + const int2 tile_upperleft = AxisSwizzle(_Axis, int2(GroupId.xy)) * AxisMask(_Axis, BLOCK_WIDTH) - TILE_BORDER * _Axis; + + [unroll] + for (ind = GroupIndex; ind < TILE_WIDTH; ind += BLOCK_WIDTH) + { + const int2 pixel = tile_upperleft + ind * int2(_Axis); + const float2 uv = (pixel.xy + 0.5f) * oneOverPongSize; + gsamples[ind] = _PingData.SampleLevel(_LinearClamp, DK_GAUSSIAN_FILTER_SAMPLE_UV(uv), 0); + } + + GroupMemoryBarrierWithGroupSync(); + + int2 coord = AxisSwizzle(_Axis, GroupThreadId.xy) + TILE_BORDER * _Axis; + + const int2 pixel = tile_upperleft + coord; + + //make sure there's a pixel here + if(pixel.x < 0 || pixel.y < 0 || pixel.x >= _PongSize.x || pixel.y >= _PongSize.y) return; + + float2 r = 0.0; + + int sampleOffset = max(coord.x, coord.y); + [unroll] + for (int kernel_ind = -KERNEL_WIDTH; kernel_ind <= KERNEL_WIDTH; kernel_ind++) + { + int sampleCoord = kernel_ind + sampleOffset; + float gaussian = _GaussianNormalization * exp(_GaussianExponential * float(kernel_ind*kernel_ind)); + r += float2(gsamples[sampleCoord] * gaussian, gaussian); + } + _PongData[DK_GAUSSIAN_FILTER_OUTPUT_COORD(pixel)] = r.x / r.y; +} + +#endif diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc.meta new file mode 100644 index 0000000..8a1ba7a --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b6019c3e9986d014f82fd2d8c1ec831d +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute new file mode 100644 index 0000000..af780ad --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute @@ -0,0 +1,75 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#pragma kernel GaussianBlurFilter1 TILE_BORDER=1 +#pragma kernel GaussianBlurFilter2 TILE_BORDER=2 +#pragma kernel GaussianBlurFilter4 TILE_BORDER=4 +#pragma kernel GaussianBlurFilter8 TILE_BORDER=8 +#pragma kernel GaussianBlurFilter16 TILE_BORDER=16 +#pragma kernel GaussianBlurFilter32 TILE_BORDER=32 + + +static const uint BLOCK_SIZE = 8; + +Texture2DArray _PingData; +RWTexture2DArray _PongData; +int _Slice; + +#define DK_GAUSSIAN_FILTER_SAMPLE_UV(uv) float3(uv.xy, (float)_Slice) + +#define DK_GAUSSIAN_FILTER_OUTPUT_COORD(pixel) int3(pixel.xy, _Slice) + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.cginc" + +[numthreads(BLOCK_WIDTH, 1, 1)] +void GaussianBlurFilter1(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GaussianBlurFilter(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_WIDTH, 1, 1)] +void GaussianBlurFilter2(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GaussianBlurFilter(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_WIDTH, 1, 1)] +void GaussianBlurFilter4(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GaussianBlurFilter(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_WIDTH, 1, 1)] +void GaussianBlurFilter8(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GaussianBlurFilter(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_WIDTH, 1, 1)] +void GaussianBlurFilter16(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GaussianBlurFilter(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_WIDTH, 1, 1)] +void GaussianBlurFilter32(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + GaussianBlurFilter(id, GroupId, GroupThreadId, GroupIndex); +} diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute.meta new file mode 100644 index 0000000..cb22270 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/GaussianBlurFilter.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9cd3ebcd48024b54983d04bc90c978be +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 4 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute new file mode 100644 index 0000000..c27c7bb --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute @@ -0,0 +1,61 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#pragma kernel MinMaxDownscaleByHalf4x4 BLOCK_SIZE=4 +#pragma kernel MinMaxDownscaleByHalf8x8 BLOCK_SIZE=8 +#pragma kernel MinMaxDownscaleByHalf16x16 BLOCK_SIZE=16 + +Texture2DArray _FullRes; +RWTexture2DArray _Downscaled; + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc" + +void MinMaxDownscaleByHalf(uint3 id, uint3 GroupId, uint3 GroupThreadId, uint GroupIndex) +{ + float2 sample0 = _FullRes.Load(int4(id.xy * 2 + int2(0, 0), id.z, 0)); + float2 sample1 = _FullRes.Load(int4(id.xy * 2 + int2(1, 0), id.z, 0)); + float2 sample2 = _FullRes.Load(int4(id.xy * 2 + int2(0, 1), id.z, 0)); + float2 sample3 = _FullRes.Load(int4(id.xy * 2 + int2(1, 1), id.z, 0)); + + float minSampleX = min(min(sample0.x, sample1.x), min(sample2.x, sample3.x)); + float maxSampleX = max(max(sample0.x, sample1.x), max(sample2.x, sample3.x)); + _Downscaled[id.xyz] = float4( + minSampleX, + max(max(max(sample0.y, sample1.y), max(sample2.y, sample3.y)), maxSampleX), 0.0f, 1.0f + ); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void MinMaxDownscaleByHalf4x4(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + MinMaxDownscaleByHalf(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void MinMaxDownscaleByHalf8x8(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + MinMaxDownscaleByHalf(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void MinMaxDownscaleByHalf16x16(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + MinMaxDownscaleByHalf(id, GroupId, GroupThreadId, GroupIndex); +} diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute.meta new file mode 100644 index 0000000..c8e80c8 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MinMaxDownscaleByHalf.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7cb6a1d7eda193143851efcdefa3531a +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 2052 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute new file mode 100644 index 0000000..927fe28 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute @@ -0,0 +1,71 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#pragma kernel CSMain + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Utils.cginc" + +Texture2DArray _InputTexture; +SamplerState _InputTrilinearClampSampler; + +globallycoherent RWTexture2DArray _OutputTexture; +float2 _Axis; +float _MinDim; // The minimum pixel dimensions of the (unpadded) texture size +StructuredBuffer _BlurWidth; // normalized multiple of minimum dimension + +static const uint BLUR_SAMPLE_RADIUS = 6; +static const uint BLUR_SAMPLE_WIDTH = BLUR_SAMPLE_RADIUS * 2 + 1; + +static const uint3 WorkGroupSize = uint3(8, 8, 1); + +[numthreads(WorkGroupSize.x, WorkGroupSize.y, WorkGroupSize.z)] +void CSMain (uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + uint3 inputSize; + _InputTexture.GetDimensions(inputSize.x, inputSize.y, inputSize.z); + uint3 outputSize; + _OutputTexture.GetDimensions(outputSize.x, outputSize.y, outputSize.z); + + if (!inBounds(id, outputSize)) { return; } + + float blurWidth = _BlurWidth[id.z]; + + float lod = (max(0.0, log2(blurWidth * _MinDim / float(BLUR_SAMPLE_RADIUS)))); + float2 oneOverImageDimensions = float2(1.0f, 1.0f) / float2(inputSize.xy); + float2 accumulator = float2(0.0f, 0.0f), uv; + float r = float(BLUR_SAMPLE_WIDTH - 1) / 2.f, kr, weight, interp; + for (uint k = 0; k < BLUR_SAMPLE_WIDTH; k++) + { + kr = float(k) / r - 1.0f; + weight = exp(-2.0f * kr * kr); + + interp = blurWidth * kr; + + uv = (float2(id.xy) + 0.5f) / _MinDim; + uv = (uv + interp * _Axis) * _MinDim * oneOverImageDimensions; + + float s = _InputTexture.SampleLevel(_InputTrilinearClampSampler, float3(uv, id.z), lod); + + accumulator += float2(s * weight, weight); + } + float blurred = accumulator.x / accumulator.y; + + _OutputTexture[int3(id.xyz)] = blurred; +} diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute.meta new file mode 100644 index 0000000..90b0e8e --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/MipMapGaussianBlur.compute.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 00901226e6a45ba4cae17a7185473045 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 4 + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute new file mode 100644 index 0000000..8aa7d4a --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute @@ -0,0 +1,72 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#pragma kernel KPrepareDrawIndirectArgs +#pragma kernel KPrepareDispatchIndirectArgs +#pragma kernel KPrepareAllIndirectArgs + +StructuredBuffer _TrianglesCount; //[count] + +bool _SinglePassStereo = false; +RWStructuredBuffer _TrianglesDrawIndirectArgs; //[vertex count, instance count, vertex offset, instance offset] + +uint _GroupSize; +uint _DispatchY = 1; +uint _DispatchZ = 1; +RWStructuredBuffer _TrianglesDispatchIndirectArgs; //[dispatch groups x, dispatch groups y, dispatch groups z] + +void prepareDrawIndirectArgs(uint count) +{ + _TrianglesDrawIndirectArgs[0] = count * 3; // triangle count * 3 verts + _TrianglesDrawIndirectArgs[1] = lerp(1, 2, _SinglePassStereo); + _TrianglesDrawIndirectArgs[2] = 0; + _TrianglesDrawIndirectArgs[3] = 0; +} + +void prepareDispatchIndirectArgs(uint count) +{ + _TrianglesDispatchIndirectArgs[0] = count / _GroupSize; // triangle count / group size to dispatch indirect + _TrianglesDispatchIndirectArgs[1] = _DispatchY; + _TrianglesDispatchIndirectArgs[2] = _DispatchZ; +} + +/////KERNELS + +[numthreads(1, 1, 1)] +void KPrepareDrawIndirectArgs(uint3 id : SV_DispatchThreadID) +{ + uint count = _TrianglesCount[0]; + prepareDrawIndirectArgs(count); +} + +[numthreads(1, 1, 1)] +void KPrepareDispatchIndirectArgs(uint3 id : SV_DispatchThreadID) +{ + uint count = _TrianglesCount[0]; + prepareDispatchIndirectArgs(count); +} + +[numthreads(1, 1, 1)] +void KPrepareAllIndirectArgs(uint3 id : SV_DispatchThreadID) +{ + uint count = _TrianglesCount[0]; + prepareDrawIndirectArgs(count); + prepareDispatchIndirectArgs(count); +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute.meta new file mode 100644 index 0000000..14ab521 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PrepareArgs.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 44c8d58c5e35fbb48a02d38276821810 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 4 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader new file mode 100644 index 0000000..16abb74 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader @@ -0,0 +1,90 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +Shader "Depthkit/Util/PushPullMips" +{ + Properties + { + _MainTex("Texture", 2D) = "white" {} + _MipLevel("Mip Levels", Float) = 0.0 + } + + SubShader + { + Tags { "RenderType" = "Opaque" } + LOD 100 + ZWrite Off + Blend Off + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float _MipLevels = 1.0f; + + v2f vert(appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + return o; + } + + fixed4 frag(v2f i) : SV_Target + { + // sample the texture + float4 dest = float4(0,0,0,0); + for (float lod = _MipLevels - 1; lod >= 0; lod -= 1) + { + float4 source = tex2Dlod(_MainTex, float4(i.uv, 0, lod)); + dest = source + (1 - source.a) * dest; + } + if (dest.a > 0) { + dest.rgb /= dest.a; + } + dest.a = 1; + + fixed4 col = dest; + + return col; + } + ENDCG + } + } +} + diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader.meta new file mode 100644 index 0000000..d3d8e7f --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/PushPullMips.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: f4607d86d204bfc428bdea0047aeb380 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc new file mode 100644 index 0000000..7d9cb3b --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc @@ -0,0 +1,129 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Depthkit.cginc" + +#ifndef DK_SOBEL_FILTER_UV +#define DK_SOBEL_FILTER_UV(uv) uv +#endif + +#ifndef DK_SOBEL_FILTER_OUTPUT_COORD +#define DK_SOBEL_FILTER_OUTPUT_COORD(pixel) pixel.xy +#endif + +float4 _MaskTextureTS; +float _SobelInvalidateEdgeWidth; +float _StaticSobelMultiplier = 1.0f; +float _StaticSobelPower = 1.0f; +float _SobelInvalidateStrength = 1.0f; + +StructuredBuffer _SobelMultiplier; + +static const uint BLOCK_THREAD_COUNT = BLOCK_SIZE * BLOCK_SIZE; +static const uint TILE_BORDER = 1; +static const uint TILE_SIZE = BLOCK_SIZE + TILE_BORDER * 2; +static const uint TILE_PIXEL_COUNT = TILE_SIZE * TILE_SIZE; + +groupshared float g_samples[TILE_PIXEL_COUNT]; + +// ------------ +//| 7 | 2 | 5 | +//| 1 | 0 | 3 | +//| 6 | 4 | 8 | +// ------------ + +static const int2 offsets[9] = +{ + { 0, 0 }, //0 + { -1, 0 }, //1 + { 0, -1 }, //2 + { 1, 0 }, //3 + { 0, 1 }, //4 + { 1, -1 }, //5 + { -1, 1 }, //6 + { -1, -1 }, //7 + { 1, 1 } //8 +}; + +// for pixels that have invalid depth values, we don't want to use 0 to compute the sobel, instead we pass in the kernel center depth value. +// This avoids an unecessary dilation of the raw edge due to the sobel detecting the raw edge as an additional edge. +float validFilter(float floorValue, float value) +{ + return value > 0.0 ? value : floorValue; +} + +void SobelFilter(uint3 id, uint3 GroupId, uint3 GroupThreadId, uint GroupIndex) +{ + uint ind; + + ////////////////////////////////////// + //Fill a tile's worth of shared memory + ////////////////////////////////////// + + const int2 tileUpperLeft = int2(GroupId.xy * BLOCK_SIZE) - (int2) TILE_BORDER; + [unroll] + for (ind = GroupIndex; ind < TILE_PIXEL_COUNT; ind += BLOCK_THREAD_COUNT) + { + int2 pixel = tileUpperLeft + (int2) toCoord(ind, TILE_SIZE); + float2 uv = (pixel + 0.5f) * _MaskTextureTS.xy; + uv = DK_SOBEL_FILTER_UV(uv); + float depthMeters; + float2 depthUV; + uint perspectiveIndex; + bool inBounds = any(pixel == clamp(pixel, 0, _MaskTextureTS.zw)); + bool valid = inBounds && dkSampleDepthMeters(uv, depthMeters, depthUV, perspectiveIndex); + + g_samples[ind] = valid ? depthMeters : 0.0f; + } + + GroupMemoryBarrierWithGroupSync(); //wait for everyone + + int2 tileOffset = GroupThreadId.xy + TILE_BORDER; + + uint id0 = toIndex(tileOffset + offsets[0], TILE_SIZE); + uint id1 = toIndex(tileOffset + offsets[1], TILE_SIZE); + uint id2 = toIndex(tileOffset + offsets[2], TILE_SIZE); + uint id3 = toIndex(tileOffset + offsets[3], TILE_SIZE); + uint id4 = toIndex(tileOffset + offsets[4], TILE_SIZE); + uint id5 = toIndex(tileOffset + offsets[5], TILE_SIZE); + uint id6 = toIndex(tileOffset + offsets[6], TILE_SIZE); + uint id7 = toIndex(tileOffset + offsets[7], TILE_SIZE); + uint id8 = toIndex(tileOffset + offsets[8], TILE_SIZE); + + float centralValue = g_samples[id0]; + float sobel_edge_h = validFilter(centralValue, g_samples[id5]) + (2.0 * validFilter(centralValue, g_samples[id3])) + validFilter(centralValue, g_samples[id8]) + - (validFilter(centralValue, g_samples[id7]) + (2.0 * validFilter(centralValue, g_samples[id1])) + validFilter(centralValue, g_samples[id6])); + float sobel_edge_v = validFilter(centralValue, g_samples[id7]) + (2.0 * validFilter(centralValue, g_samples[id2])) + validFilter(centralValue, g_samples[id5]) + - (validFilter(centralValue, g_samples[id6]) + (2.0 * validFilter(centralValue, g_samples[id4])) + validFilter(centralValue, g_samples[id8])); + float sobel = centralValue > 0.0 ? min(abs(sobel_edge_h) + abs(sobel_edge_v), _SobelInvalidateStrength) : _SobelInvalidateStrength; // approximation without sqrt + +#pragma warning (disable : 3571) + float edge = _SobelMultiplier[id.z] * pow(sobel, _StaticSobelPower) * _StaticSobelMultiplier; + + // invalidate edge border + float invalidateEdgeWidthPixels = _SobelInvalidateEdgeWidth * min(_MaskTextureTS.z, _MaskTextureTS.w) * 0.5; + float2 oneOverEdgeWidth = 1.0f / invalidateEdgeWidthPixels; + float2 edgeBorder = saturate((float2(invalidateEdgeWidthPixels, invalidateEdgeWidthPixels) - float2(id.xy)) * oneOverEdgeWidth) + + saturate((float2(id.xy) - (_MaskTextureTS.zw - float2(invalidateEdgeWidthPixels, invalidateEdgeWidthPixels) - 1.0f)) * oneOverEdgeWidth); + float borderMask = min(pow(edgeBorder.x + edgeBorder.y, 2.0), 1.0); + float outputValue = max(edge, borderMask * (_SobelMultiplier[id.z] * 2.0 + 10.0)); + + _MaskTexture[DK_SOBEL_FILTER_OUTPUT_COORD(id)] = centralValue > 0.0 ? outputValue : max(outputValue, 1.0); +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc.meta new file mode 100644 index 0000000..9da3862 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 032f87aa584b5434cbcf6ec466d023f5 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute new file mode 100644 index 0000000..d3c69d3 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute @@ -0,0 +1,54 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#pragma kernel KSobelFilter16x16 BLOCK_SIZE=16 +#pragma kernel KSobelFilter8x8 BLOCK_SIZE=8 +#pragma kernel KSobelFilter4x4 BLOCK_SIZE=4 + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Includes/Defines.cginc" + +RWTexture2DArray _MaskTexture; +int _SliceCount; +float4 _SliceToPerspective[DK_MAX_NUM_PERSPECTIVES]; + +#define DK_SOBEL_FILTER_UV(uv) dkPerspectiveToPackedUV((uint) _SliceToPerspective[clamp(id.z, 0, _SliceCount - 1)].x, uv); + +#define DK_SOBEL_FILTER_OUTPUT_COORD(pixel) pixel.xyz + + +#include "Packages/nyc.scatter.depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.cginc" + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KSobelFilter16x16(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + SobelFilter(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KSobelFilter8x8(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + SobelFilter(id, GroupId, GroupThreadId, GroupIndex); +} + +[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] +void KSobelFilter4x4(uint3 id : SV_DispatchThreadID, uint3 GroupId : SV_GroupID, uint3 GroupThreadId : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex) +{ + SobelFilter(id, GroupId, GroupThreadId, GroupIndex); +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute.meta b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute.meta new file mode 100644 index 0000000..62d9614 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Resources/Shaders/Util/SobelFilter.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6c79fafc0eb47894dad9a6da4b623588 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 4 + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils.meta b/LocalPackages/depthkit.core/Runtime/Utils.meta new file mode 100644 index 0000000..10ebc49 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 259cf4c5ae9a26d4181f52de3c5da830 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs b/LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs new file mode 100644 index 0000000..14a16c4 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs @@ -0,0 +1,180 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using Depthkit; +using System; +using UnityEngine; + +namespace Depthkit +{ + [System.Serializable] + public class GaussianBlurFilter + { + public Clip clip; + + [Range(0.0f, 0.25f)] + public float radius = Metadata.DefaultReconstructionSettingsDefaults.edgeMaskBlurAmount; + + public int slices = 1; + + protected RenderTexture[] m_blurTextures = null; + protected ComputeShader m_blurCompute; + protected ComputeBuffer m_blurRadiusBuffer = null; + + protected static string s_defaultComputeBlurShaderName = "Shaders/Util/MipMapGaussianBlur"; + + internal static class BlurShaderIds + { + internal static readonly int + _InputTexture = Shader.PropertyToID("_InputTexture"), + _OutputTexture = Shader.PropertyToID("_OutputTexture"), + _Slice = Shader.PropertyToID("_Slice"), + _Axis = Shader.PropertyToID("_Axis"), + _MinDim = Shader.PropertyToID("_MinDim"), + _BlurWidth = Shader.PropertyToID("_BlurWidth"); + } + + public bool hasTexture + { + get + { + return m_blurTextures != null && m_blurTextures.Length == 2; + } + } + + RenderTexture InitBlurTexture(RenderTexture tex) + { + RenderTexture newTex = new RenderTexture(Mathf.NextPowerOfTwo(tex.width), Mathf.NextPowerOfTwo(tex.height), tex.depth, tex.format); + newTex.dimension = tex.dimension; + newTex.volumeDepth = tex.volumeDepth; + newTex.filterMode = FilterMode.Trilinear; + newTex.name = tex.name + " blur"; + newTex.enableRandomWrite = true; + newTex.autoGenerateMips = false; + newTex.useMipMap = true; + newTex.Create(); + newTex.GenerateMips(); + return newTex; + } + + void CreateTextures(RenderTexture tex) + { + if (m_blurTextures == null || m_blurTextures.Length != 2) + { + m_blurTextures = new RenderTexture[2]; + } + + if (m_blurTextures[0] != null && m_blurTextures[0].IsCreated()) + { + m_blurTextures[0].Release(); + } + + m_blurTextures[0] = InitBlurTexture(tex); + + if (m_blurTextures[1] != null && m_blurTextures[1].IsCreated()) + { + m_blurTextures[1].Release(); + } + + m_blurTextures[1] = InitBlurTexture(tex); + } + + public void Setup(string computeShader = "") + { + Util.EnsureComputeShader(ref m_blurCompute, computeShader == string.Empty ? s_defaultComputeBlurShaderName : computeShader); + } + + public virtual void EnsureTextures(RenderTexture tex) + { + if (m_blurTextures == null || + m_blurTextures.Length != 2 || + m_blurTextures[0].width != Mathf.NextPowerOfTwo(tex.width) || + m_blurTextures[0].height != Mathf.NextPowerOfTwo(tex.height) || + m_blurTextures[0].dimension != tex.dimension || + m_blurTextures[0].volumeDepth != tex.volumeDepth) + { + CreateTextures(tex); + } + } + + public virtual void DoBlur(RenderTexture tex) + { + EnsureTextures(tex); + + // compute new sobel strength based on scale differences to original texture size + Util.EnsureComputeBuffer(ComputeBufferType.Structured, ref m_blurRadiusBuffer, slices, sizeof(float)); + + float[] radii = new float[slices]; + + for (int i = 0; i < slices; i++) + { + // copy src texture to be blurred into the horizontal input and generate mipmaps + Graphics.CopyTexture(tex, i, 0, 0, 0, tex.width, tex.height, m_blurTextures[0], i, 0, 0, 0); + + // compute the radius for each perspective based on the size differences from the original + ref Metadata.Perspective perspective = ref clip.metadata.perspectives[i]; + float minOriginalDim = Mathf.Min(perspective.depthImageSize.x, perspective.depthImageSize.y); + Vector2 croppedDim = perspective.depthImageSize * new Vector2(perspective.crop.z, perspective.crop.w); + float maxCroppedDim = Mathf.Max(croppedDim.x, croppedDim.y); + + radii[i] = radius * minOriginalDim / maxCroppedDim; + } + + m_blurTextures[0].GenerateMips(); + + m_blurRadiusBuffer.SetData(radii); + m_blurCompute.SetBuffer(0, BlurShaderIds._BlurWidth, m_blurRadiusBuffer); + + // horizontal + m_blurCompute.SetTexture(0, BlurShaderIds._InputTexture, m_blurTextures[0]); + m_blurCompute.SetTexture(0, BlurShaderIds._OutputTexture, m_blurTextures[1]); + m_blurCompute.SetFloat(BlurShaderIds._MinDim, Math.Min(tex.width, tex.height)); + m_blurCompute.SetVector(BlurShaderIds._Axis, new Vector2(1, 0)); + + Util.DispatchGroups(m_blurCompute, 0, m_blurTextures[0].width, m_blurTextures[0].height, slices); + + m_blurTextures[1].GenerateMips(); + + // vertical + m_blurCompute.SetTexture(0, BlurShaderIds._InputTexture, m_blurTextures[1]); + m_blurCompute.SetTexture(0, BlurShaderIds._OutputTexture, tex); + m_blurCompute.SetVector(BlurShaderIds._Axis, new Vector2(0, 1)); + + Util.DispatchGroups(m_blurCompute, 0, tex.width, tex.height, slices); + } + + public void Release() + { + Util.ReleaseComputeBuffer(ref m_blurRadiusBuffer); + if (m_blurTextures != null) + { + //release the copy texture + foreach (RenderTexture tex in m_blurTextures) + { + if (tex != null && tex.IsCreated()) + { + tex.Release(); + } + } + m_blurTextures = null; + } + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs.meta new file mode 100644 index 0000000..61357cb --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/GaussianBlurFilter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b12b5f4f7368155468067d42a93c3148 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/Info.cs b/LocalPackages/depthkit.core/Runtime/Utils/Info.cs new file mode 100644 index 0000000..c2a9b37 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/Info.cs @@ -0,0 +1,197 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +#if UNITY_EDITOR +using UnityEditor; +#endif +using System; +using System.Reflection; +using System.Linq; +using System.Collections.Generic; +using UnityEngine; +public static class Reflector +{ + static Reflector() { } + + public static Dictionary GetDerivedTypeSet() where T : class + { + Dictionary derivedClasses = new Dictionary(); + + Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies(); + + foreach(Assembly asm in asms) + { + Type[] types; + try + { + types = asm.GetTypes(); + } + catch(System.Reflection.ReflectionTypeLoadException) + { + continue; + } + foreach (Type type in types.Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T)))) + { + derivedClasses.Add(type.Name, type.AssemblyQualifiedName); + } + } + return derivedClasses; + } +} + +namespace Depthkit +{ + public enum GammaCorrection + { + None = 0, + LinearToGammaSpace = 1, + GammaToLinearSpace = 2, + //Unity 2017.1 - 2018.2 has a video player bug where Linear->Gamma needs to be applied twice before texture look up in depth + LinearToGammaSpace2x = 3 + + } + + /// + /// A version struct to contain a verison number in major.minor.patch format + /// + /// + /// Version objects are equitable, compareable and implicitly convertable to string + /// + public struct Version : System.IEquatable + { + // Read/write auto-implemented properties. + public byte major { get; private set; } + public byte minor { get; private set; } + public byte patch { get; private set; } + + public Version(byte major, byte minor = 0, byte patch = 0) + : this() + { + this.major = major; + this.minor = minor; + this.patch = patch; + } + + public override string ToString() + { + return major.ToString() + "." + minor.ToString() + "." + patch.ToString(); + } + + public static implicit operator string(Version v) + { + return v.ToString(); + } + + public override bool Equals(object obj) + { + if (obj is Version) + { + return this.Equals((Version)obj); + } + return false; + } + + public bool Equals(Version other) + { + return (major == other.major) && (minor == other.minor) && (patch == other.patch); + } + + public override int GetHashCode() + { + return (int)(major ^ minor ^ patch); + } + + public static bool operator ==(Version lhs, Version rhs) + { + return lhs.Equals(rhs); + } + + public static bool operator !=(Version lhs, Version rhs) + { + return !(lhs.Equals(rhs)); + } + + public static bool operator <(Version lhs, Version rhs) + { + if (lhs.Equals(rhs))return false; + if (lhs.major < rhs.major) { return true; } + else if (lhs.major == rhs.major) + { + if (lhs.minor < rhs.minor) { return true; } + else if (lhs.minor == rhs.minor) + { + if (lhs.patch < rhs.patch) { return true; } + } + } + return false; + } + + public static bool operator >(Version lhs, Version rhs) + { + if (lhs.Equals(rhs))return false; + if (lhs.major > rhs.major) { return true; } + else if (lhs.major == rhs.major) + { + if (lhs.minor > rhs.minor) { return true; } + else if (lhs.minor == rhs.minor) + { + if (lhs.patch > rhs.patch) { return true; } + } + } + return false; + } + + public static bool operator <=(Version lhs, Version rhs) + { + if (lhs == rhs) return true; + return lhs < rhs; + } + + public static bool operator >=(Version lhs, Version rhs) + { + if (lhs == rhs) return true; + return lhs > rhs; + } + } + + public class Info { + public static Version Version = new Version(0, 4, 1); + public static bool IsPlatformValid(ref List whynot) + { + bool valid = true; + if (!SystemInfo.supportsComputeShaders) + { + valid = false; + whynot.Add("Depthkit requires Compute Shader support. This platform does not support compute shaders."); + } + if (SystemInfo.maxComputeBufferInputsVertex < 1) + { + valid = false; + whynot.Add("Depthkit requires binding at least 1 compute buffers in vertex a shader, this platform's binding max: " + SystemInfo.maxComputeBufferInputsVertex); + } + if (SystemInfo.maxComputeBufferInputsCompute < 4) + { + valid = false; + whynot.Add("Depthkit requires binding at least 4 compute buffers in a compute shader, this platform's binding max: " + SystemInfo.maxComputeBufferInputsCompute); + } + return valid; + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Utils/Info.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/Info.cs.meta new file mode 100644 index 0000000..34cb6a4 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/Info.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8b09dfe9fffa9dd48be1d468efbbe51b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs b/LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs new file mode 100644 index 0000000..9dfcad2 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs @@ -0,0 +1,326 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using System.Linq; +using System.Runtime.InteropServices; + +namespace Depthkit +{ + [System.Serializable] + public class Metadata + { + public static readonly int MaxPerspectives = 10; + + [System.Serializable] + public class MetadataVersion + { + public int _versionMajor; + public int _versionMinor; + public string format; + } + + //Used for reading the older single perspective JSON format. + [System.Serializable] + public class MetadataSinglePerspective + { + public int _versionMajor; + public int _versionMinor; + public string format; + + public int numAngles; + public Vector2 depthImageSize; + public Vector2 depthPrincipalPoint; + public Vector2 depthFocalLength; + public float farClip; + public float nearClip; + + public int textureWidth; + public int textureHeight; + + public Matrix4x4 extrinsics; + public Vector3 boundsCenter; + public Vector3 boundsSize; + public Vector4 crop; + public float clipEpsilon; + } + + [System.Serializable] + public class Perspective + { + public Vector2 depthImageSize; + public Vector2 depthPrincipalPoint; + public Vector2 depthFocalLength; + public float farClip; + public float nearClip; + public Matrix4x4 extrinsics; + public Matrix4x4 extrinsicsInv; + public Vector4 crop; + public float clipEpsilon; + public Vector3 cameraNormal; + public Vector3 cameraCenter; + } + + [StructLayout(LayoutKind.Sequential)] + public struct StructuredPerspectiveData + { + public const int size = sizeof(float) * 2 + + sizeof(float) * 2 + + sizeof(float) * 2 + + sizeof(float) + + sizeof(float) + + sizeof(float) * 16 + + sizeof(float) * 16 + + sizeof(float) * 4 + + sizeof(float) + + sizeof(float) * 3 + + sizeof(float) * 3 + + sizeof(float); + + public Vector2 depthImageSize; + public Vector2 depthPrincipalPoint; + public Vector2 depthFocalLength; + public float farClip; + public float nearClip; + public Matrix4x4 extrinsics; + public Matrix4x4 extrinsicsInverse; + public Vector4 crop; + public float clipEpsilon; + public Vector3 cameraPosition; + public Vector3 cameraNormal; + public float padding; + + public StructuredPerspectiveData(Vector2 dImageSize, Vector2 dPrincipalPoint, Vector2 dFocalLength, float fClip, float nClip, Matrix4x4 ex, Vector4 c, float cEpsilon, Vector3 camPos, Vector3 camNorm) + { + depthImageSize = dImageSize; + depthPrincipalPoint = dPrincipalPoint; + depthFocalLength = dFocalLength; + farClip = fClip; + nearClip = nClip; + extrinsics = ex; + extrinsicsInverse = ex.inverse; + crop = c; + clipEpsilon = cEpsilon; + cameraPosition = camPos; + cameraNormal = camNorm; + padding = 0; + } + } + + // This allows other classes to reference the default values while keeping a single source of truth. + public class DefaultReconstructionSettingsDefaults + { + public static readonly float depthBiasAdjustment = 0.008f; + public static readonly float edgeMaskBlurAmount = 0.01f; + public static readonly float edgeMaskSobelMultiplier = 50.0f; + public static readonly float surfaceNormalColorBlendPower = 1.0f; + public static readonly float viewDependentColorBlendPower = 1.0f; + } + + [System.Serializable] + public class DefaultReconstructionSettings + { + // New properties in v0.5 metadata + // Defaults for older versions set here + public float depthBiasAdjustment = DefaultReconstructionSettingsDefaults.depthBiasAdjustment; + public float edgeMaskBlurAmount = DefaultReconstructionSettingsDefaults.edgeMaskBlurAmount; + public float edgeMaskSobelMultiplier = DefaultReconstructionSettingsDefaults.edgeMaskSobelMultiplier; + public float surfaceNormalColorBlendPower = DefaultReconstructionSettingsDefaults.surfaceNormalColorBlendPower; + public float viewDependentColorBlendPower = DefaultReconstructionSettingsDefaults.viewDependentColorBlendPower; + } + + public readonly static uint MAX_PERSPECTIVES = 12; + + private const float eps = 0.00000001f; + + public int _versionMajor; + public int _versionMinor; + public string format; + public int textureWidth; + public int textureHeight; + public Vector3 boundsCenter; + public Vector3 boundsSize; + public Perspective[] perspectives; + public int perspectivesCount; + public int numRows; + public int numColumns; + public int numAngles; + + public DefaultReconstructionSettings defaultReconstructionSettings; + + public bool Valid() + { + return _versionMinor != 0 && perspectives != null; + } + + // Depth and color resolution for each perspective + public Vector2Int perspectiveCPPResolution + { + get + { + if (textureHeight == 0 && textureWidth == 0) return new Vector2Int(0, 0); + return new Vector2Int + { + x = Mathf.Max(textureWidth / Mathf.Max(numColumns, 1), 1), + y = Mathf.Max(textureHeight / Mathf.Max(numRows, 1), 1), + }; + } + } + + public Vector2Int perspectiveResolution + { + get + { + Vector2Int res = perspectiveCPPResolution; + res.y /= 2; + return res; + } + } + + public Vector2Int paddedTextureDimensions + { + get + { + return new Vector2Int( + Util.NextMultipleOfX(perspectiveResolution.x, 8), + Util.NextMultipleOfX(perspectiveResolution.y, 8) + ); + } + } + + static Depthkit.Metadata FromSinglePerspective(MetadataSinglePerspective md) + { + return new Depthkit.Metadata + { + _versionMajor = 0, + _versionMinor = 4, + format = md.format, + boundsCenter = md.boundsCenter, + boundsSize = md.boundsSize, + textureWidth = md.textureWidth, + textureHeight = md.textureHeight, + perspectives = new Perspective[] { + new Perspective { + depthImageSize = md.depthImageSize, + depthPrincipalPoint = md.depthPrincipalPoint, + depthFocalLength = md.depthFocalLength, + farClip = md.farClip, + nearClip = md.nearClip, + extrinsics = md.extrinsics, + crop = md.crop, + clipEpsilon = md.clipEpsilon + } + } + }; + } + + public static Depthkit.Metadata CreateFromJSON(string jsonString) + { + Depthkit.Metadata metadata; + MetadataVersion mdVersion = JsonUtility.FromJson(jsonString); + + // Read and upgrade old single perspective format. + if (mdVersion._versionMajor == 0 && mdVersion._versionMinor < 3) + { + MetadataSinglePerspective md = JsonUtility.FromJson(jsonString); + + //for version 1.0 (from Depthkit Visualize) fill in defaults for missing parameters + if (mdVersion.format == "perpixel" && mdVersion._versionMinor == 1) + { + //set final image dimensions + md.textureWidth = (int)(md.depthImageSize.x); + md.textureHeight = (int)(md.depthImageSize.y) * 2; + + //calculate bounds + md.boundsCenter = new Vector3(0f, 0f, (md.farClip - md.nearClip) / 2.0f + md.nearClip); + md.boundsSize = new Vector3(md.depthImageSize.x * md.farClip / md.depthFocalLength.x, + md.depthImageSize.y * md.farClip / md.depthFocalLength.y, + md.farClip - md.nearClip); + + md.numAngles = 1; + + // check if we have a zero'd crop (is this possible?), if so default to full window + if (md.crop.x <= eps && md.crop.y <= eps && md.crop.z <= eps && md.crop.w <= eps) + { + md.crop = new Vector4(0.0f, 0.0f, 1.0f, 1.0f); + } + + md.extrinsics = Matrix4x4.identity; + } + + if (md.clipEpsilon < eps) + { + md.clipEpsilon = 0.005f; // default depth clipping epsilon, set for older versions of metadata + } + + metadata = Depthkit.Metadata.FromSinglePerspective(md); + metadata.numRows = 1; + metadata.numColumns = 1; + } + else + { + // Read multiperspective format. + metadata = JsonUtility.FromJson(jsonString); + metadata.boundsCenter.z *= -1; + metadata.boundsCenter.y *= -1; + if (mdVersion._versionMinor <= 3) + { + metadata.numRows = 1; + metadata.numColumns = metadata.numAngles; + } + } + + // Convert from Depthkit to Unity coordinate space + for (int i = 0; i < metadata.perspectives.Length; ++i) + { + Matrix4x4 mirror = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1.0f, -1.0f, -1.0f)); + metadata.perspectives[i].extrinsics = mirror * metadata.perspectives[i].extrinsics * mirror; + metadata.perspectives[i].extrinsicsInv = metadata.perspectives[i].extrinsics.inverse; + + metadata.perspectives[i].cameraCenter = (metadata.perspectives[i].extrinsics * new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); + metadata.perspectives[i].cameraNormal = (metadata.perspectives[i].extrinsics * new Vector4(0.0f, 0.0f, 1.0f, 0.0f)).normalized; + } + + metadata.perspectivesCount = metadata.perspectives.Length; + + return metadata; + } + + public static StructuredPerspectiveData[] FillPersistentMetadataFromPerspectives(Perspective[] perspectives) + { + StructuredPerspectiveData[] filledData = new StructuredPerspectiveData[perspectives.Length]; + for (int i = 0; i < perspectives.Length; i++) + { + filledData[i] = new StructuredPerspectiveData(perspectives[i].depthImageSize, + perspectives[i].depthPrincipalPoint, + perspectives[i].depthFocalLength, + perspectives[i].farClip, + perspectives[i].nearClip, + perspectives[i].extrinsics, + perspectives[i].crop, + perspectives[i].clipEpsilon, + perspectives[i].cameraCenter, + perspectives[i].cameraNormal); + } + + return filledData; + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs.meta new file mode 100644 index 0000000..af2b71e --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/Metadata.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 93ddb0312d1a6094f97de7f2968d765c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs b/LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs new file mode 100644 index 0000000..f0a3123 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs @@ -0,0 +1,41 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using System.Collections.Generic; + +namespace Depthkit +{ + [AddComponentMenu("Depthkit/Depthkit Platform Validator")] + public class PlatformValidator : MonoBehaviour + { + void Start() + { + List reasons = new List(); + if(!Info.IsPlatformValid(ref reasons)) + { + foreach(string reason in reasons) + { + Debug.LogError(reason); + } + } + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs.meta new file mode 100644 index 0000000..5fb5985 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/PlatformValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 75fc33f44244c894292bb89cf6227ef0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 42c51ff9981f3e24b83cd7ad3c56e235, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs b/LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs new file mode 100644 index 0000000..6a0e7cf --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs @@ -0,0 +1,55 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEngine.Events; + +namespace Depthkit +{ + [AddComponentMenu("Depthkit/Util/Set Capture Frame Rate")] + public class SetCaptureFrameRate : MonoBehaviour + { + public UnityEvent onFrameBegin; + public UnityEvent onFrameEnd; + + public int captureFramteRate = 60; + + private void Start() + { + Time.captureFramerate = captureFramteRate; + } + + private void Update() + { + if (onFrameBegin != null) + { + onFrameBegin.Invoke(); + } + } + + private void LateUpdate() + { + if(onFrameEnd != null) + { + onFrameEnd.Invoke(); + } + } + } +} diff --git a/LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs.meta new file mode 100644 index 0000000..2c18211 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/SetCaptureFrameRate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf241d84a7145bc4d8ac2a90732801cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs b/LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs new file mode 100644 index 0000000..f514148 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs @@ -0,0 +1,87 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using System; +using System.Runtime.InteropServices; + +namespace Depthkit +{ + [Serializable] + public class SyncedStructuredBuffer + { + public ComputeBuffer buffer; + + [SerializeField] + protected T[] m_data = null; + + bool m_dirty = true; + + [SerializeField] + string m_name; + + public SyncedStructuredBuffer(string name, int count, T[] defaultData = null) + { + m_name = name; + if (defaultData != null) + { + m_data = defaultData; + } + else + { + m_data = new T[count]; + } + MarkDirty(); + } + + public int Length { get { return m_data != null ? m_data.Length : 0; } } + + public void MarkDirty() + { + m_dirty = true; + } + + public bool Sync() + { + if ((m_dirty || buffer == null || !buffer.IsValid()) && m_data != null && m_data.Length > 0) + { + if (Util.EnsureComputeBuffer(ComputeBufferType.Default, ref buffer, m_data.Length, Marshal.SizeOf(typeof(T)), m_data)) + { + if(m_name != string.Empty) + { + buffer.name = m_name; + } + } + m_dirty = false; + return true; + } + return false; + } + + public void Release() + { + if (buffer != null && buffer.IsValid()) + { + buffer.Release(); + } + buffer = null; + } + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs.meta new file mode 100644 index 0000000..8b4b1a6 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/SyncedStructuredBuffer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aabeeac189d70934da4344799f4a0339 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs b/LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs new file mode 100644 index 0000000..6b7390c --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs @@ -0,0 +1,404 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEditor; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System; +using System.Runtime.InteropServices; + +namespace Depthkit +{ + public class TriangleMesh + { + [HideInInspector] + public Depthkit.MeshSource source; + + [System.NonSerialized] + private Mesh m_mesh; + + [HideInInspector, SerializeField] + private int m_triangleCount = 0; + + public int TriangleCount + { + get { return m_triangleCount; } + set + { + EnsureTriangleMesh(value); + } + } + public Mesh mesh + { + get + { + if (m_mesh == null) + { + m_mesh = CreateMesh(); + } + return m_mesh; + } + } + + public void EnsureTriangleMesh() + { + if (source != null && source.clip != null && source.clip.metadata != null && m_triangleCount > 0) + { + if (m_mesh == null) + { + m_mesh = CreateMesh(); + Bounds bounds = source.GetLocalBounds(); + m_mesh.bounds = bounds; + CreateCubeMesh(m_mesh, bounds.center, bounds.size, m_triangleCount); + } + } + } + + public void EnsureTriangleMesh(Vector2 size) + { + if (source != null && source.clip != null && source.clip.metadata != null && size.x > 0 && size.y > 0) + { + if (m_mesh == null) + { + m_mesh = CreateMesh(); + } + int count = ((int)size.x - 1) * ((int)size.y - 1) * 2; + Bounds bounds = source.GetLocalBounds(); + m_mesh.bounds = bounds; + if (m_mesh.vertexCount / 3 == count && m_mesh.name == "Depthkit Mesh") return; //no need to update + m_triangleCount = count; + CreateCubeMesh(m_mesh, bounds.center, bounds.size, m_triangleCount); + } + } + + public void EnsureTriangleMesh(int triangles) + { + if (source != null && source.clip != null && source.clip.metadata != null && triangles > 0) + { + if (m_mesh == null) + { + m_mesh = CreateMesh(); + } + Bounds bounds = source.GetLocalBounds(); + m_mesh.bounds = bounds; + if (m_mesh.vertexCount / 3 == triangles && m_mesh.name == "Depthkit Mesh") return; //no need to update + m_triangleCount = triangles; + CreateCubeMesh(m_mesh, bounds.center, bounds.size, m_triangleCount); + } + } + + static private Mesh CreateMesh() + { + Mesh mesh = new Mesh(); + mesh.name = "Depthkit Mesh"; + mesh.hideFlags = HideFlags.DontSave; + return mesh; + } + + public void ReleaseMesh() + { + if (m_mesh != null) + { + if (Application.isEditor && !Application.isPlaying) + { + UnityEngine.Object.DestroyImmediate(m_mesh); + } + else + { + UnityEngine.Object.Destroy(m_mesh); + } + m_mesh = null; + } + } + + static Vector3[] s_cubeVerts = null; + static int[] s_cubeTriangles = null; + + static Vector3[] GetCubeVerts() + { + if (s_cubeVerts == null) + { + s_cubeVerts = new Vector3[] { + new Vector3 (-0.5f, -0.5f, -0.5f), + new Vector3 (0.5f, -0.5f, -0.5f), + new Vector3 (0.5f, 0.5f, -0.5f), + new Vector3 (-0.5f, 0.5f, -0.5f), + new Vector3 (-0.5f, 0.5f, 0.5f), + new Vector3 (0.5f, 0.5f, 0.5f), + new Vector3 (0.5f, -0.5f, 0.5f), + new Vector3 (-0.5f, -0.5f, 0.5f), + }; + } + return s_cubeVerts; + } + + static int[] GetCubeTriangles() + { + if (s_cubeTriangles == null) + { + s_cubeTriangles = new int[] { + 0, 2, 1, //face front + 0, 3, 2, + 2, 3, 4, //face top + 2, 4, 5, + 1, 2, 5, //face right + 1, 5, 6, + 0, 7, 4, //face left + 0, 4, 3, + 5, 4, 7, //face back + 5, 7, 6, + 0, 6, 7, //face bottom + 0, 1, 6 + }; + } + return s_cubeTriangles; + } + + public void ResetMeshCube(Vector3 center, Vector3 size) + { + if (size == Vector3.zero) return; + + Vector3[] positions = mesh.vertices; + + Vector3[] cubeVerts = GetCubeVerts(); + int[] cubeTriangles = GetCubeTriangles(); + + for (int i = 0; i < 12; ++i) + { + int index = i * 3; + Vector3 v1 = cubeVerts[cubeTriangles[index]]; + positions[index] = new Vector3(v1.x * size.x + center.x, v1.y * size.y + center.y, v1.z * size.z + center.z); + + ++index; + Vector3 v2 = cubeVerts[cubeTriangles[index]]; + positions[index] = new Vector3(v2.x * size.x + center.x, v2.y * size.y + center.y, v2.z * size.z + center.z); + + ++index; + Vector3 v3 = cubeVerts[cubeTriangles[index]]; + positions[index] = new Vector3(v3.x * size.x + center.x, v3.y * size.y + center.y, v3.z * size.z + center.z); + } + + mesh.vertices = positions; + } + + //static factory functions + public static void CreateLattice(Mesh mesh, Vector2 dims, CoordinateRangeType rangeType) + { + + int w = (int)dims.x; + int h = (int)dims.y; + float fw = dims.x; + float fh = dims.y; + int sw = w - 1; + int sh = h - 1; + + Vector3[] positions = new Vector3[w * h]; + Vector2[] texCoords = new Vector2[w * h]; + int indexCount = sw * sh * 6; + int[] indices = new int[indexCount]; + + mesh.Clear(); + mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; + + int a = 0; + int b = 0; + int c = 0; + int tri = 0; + + for (int y = 0; y < sh; y++) + { + for (int x = 0; x < sw; x++) + { + a = x + y * w; + b = (x + 1) + y * w; + c = (x + 1) + (y + 1) * w; + + indices[tri++] = c; + indices[tri++] = b; + indices[tri++] = a; + + a = x + y * w; + b = (x + 1) + (y + 1) * w; + c = x + (y + 1) * w; + + indices[tri++] = c; + indices[tri++] = b; + indices[tri++] = a; + } + } + + for (int y = 0; y < h; y++) + { + for (int x = 0; x < w; x++) + { + + int ind = x + y * w; + switch (rangeType) + { + case CoordinateRangeType.NDC: + positions[ind] = new Vector3(((float)x / fw) * 2.0f - 1.0f, ((float)y / fh) * 2.0f - 1.0f, 0); // NDC space units (-1 .. 1) + break; + case CoordinateRangeType.Normalized: + positions[ind] = new Vector3(((float)x / fw), ((float)y / fh), 0); // normalized space units (0 .. 1) + break; + case CoordinateRangeType.Pixels: + positions[ind] = new Vector3(x, y, 0); // world space units (1 unit / meter per pixel) + break; + } + texCoords[ind] = new Vector2((float)x / fw, (float)y / fh); + } + } + + mesh.vertices = positions; + mesh.uv = texCoords; + mesh.triangles = indices; + mesh.RecalculateNormals(); + } + + internal static void addVertex(int triangle, int tri_pos, int vert, int x, int y, float fw, float fh, Vector3[] positions, Vector2[] uv, int[] indices, CoordinateRangeType rangeType) + { + indices[vert] = vert; + switch (rangeType) + { + case CoordinateRangeType.NDC: + positions[vert] = new Vector3(((float)x / fw) * 2.0f - 1.0f, ((float)y / fh) * 2.0f - 1.0f, 0); // NDC space units (-1 .. 1) + break; + case CoordinateRangeType.Normalized: + positions[vert] = new Vector3(((float)x / fw), ((float)y / fh), 0); // normalized space units (0 .. 1) + break; + case CoordinateRangeType.Pixels: + positions[vert] = new Vector3(x, y, 0); // world space units (1 unit / meter per pixel) + break; + } + uv[vert] = new Vector2((float)triangle, (float)tri_pos); + } + + public static void CreateTriangleLattice(Mesh mesh, Vector2 dims, CoordinateRangeType rangeType) + { + int w = (int)dims.x; + int h = (int)dims.y; + + int vertexCount = (w - 1) * (h - 1) * 6; + Vector3[] positions = new Vector3[vertexCount]; + Vector2[] uv = new Vector2[vertexCount]; + int[] indices = new int[vertexCount]; + + mesh.Clear(); + mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; + + int vert = 0; + int tri = 0; + + for (int y = 0; y < h - 1; y++) + { + for (int x = 0; x < w - 1; x++) + { + addVertex(tri, 0, vert, x, y, dims.x, dims.y, positions, uv, indices, rangeType); + vert++; + + addVertex(tri, 1, vert, x, y + 1, dims.x, dims.y, positions, uv, indices, rangeType); + vert++; + + addVertex(tri, 2, vert, x + 1, y, dims.x, dims.y, positions, uv, indices, rangeType); + vert++; + tri++; + + addVertex(tri, 0, vert, x + 1, y + 1, dims.x, dims.y, positions, uv, indices, rangeType); + vert++; + + addVertex(tri, 1, vert, x + 1, y, dims.x, dims.y, positions, uv, indices, rangeType); + vert++; + + addVertex(tri, 2, vert, x, y + 1, dims.x, dims.y, positions, uv, indices, rangeType); + vert++; + tri++; + } + } + + mesh.vertices = positions; + mesh.uv = uv; + mesh.triangles = indices; + } + + public static void CreateCubeMesh(Mesh mesh, Vector3 center, Vector3 size, int totalTriangles) + { + Vector3[] vertices = new Vector3[totalTriangles * 3]; + Vector2[] uvs = new Vector2[totalTriangles * 3]; + int[] triangles = new int[totalTriangles * 3]; + + Vector3[] cubeVerts = GetCubeVerts(); + int[] cubeTriangles = GetCubeTriangles(); + + int tri = 0; + int i = 0; + for (; i < 12; ++i) + { + int index = i * 3; + Vector3 v1 = cubeVerts[cubeTriangles[index]]; + vertices[index] = new Vector3(v1.x * size.x + center.x, v1.y * size.y + center.y, v1.z * size.z + center.z); + uvs[index] = new Vector2(tri, 0); + triangles[index] = index; + + ++index; + Vector3 v2 = cubeVerts[cubeTriangles[index]]; + vertices[index] = new Vector3(v2.x * size.x + center.x, v2.y * size.y + center.y, v2.z * size.z + center.z); + uvs[index] = new Vector2(tri, 1); + triangles[index] = index; + + ++index; + Vector3 v3 = cubeVerts[cubeTriangles[index]]; + vertices[index] = new Vector3(v3.x * size.x + center.x, v3.y * size.y + center.y, v3.z * size.z + center.z); + uvs[index] = new Vector2(tri, 2); + triangles[index] = index; + + ++tri; + } + + for (; i < totalTriangles; ++i) + { + int index = i * 3; + vertices[index] = new Vector3(0, 0, 0); + uvs[index] = new Vector2(tri, 0); + triangles[index] = index; + + index++; + vertices[index] = new Vector3(0, 0, 0); + uvs[index] = new Vector2(tri, 1); + triangles[index] = index; + + index++; + vertices[index] = new Vector3(0, 0, 0); + uvs[index] = new Vector2(tri, 2); + triangles[index] = index; + + ++tri; + } + + mesh.Clear(); + mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; + mesh.vertices = vertices; + mesh.uv = uvs; + mesh.triangles = triangles; + } + + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs.meta new file mode 100644 index 0000000..f3dfdeb --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/TriangleMesh.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 156488ad24006c04cb7eb3f0a2500654 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/Runtime/Utils/Util.cs b/LocalPackages/depthkit.core/Runtime/Utils/Util.cs new file mode 100644 index 0000000..dd4ad78 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/Util.cs @@ -0,0 +1,426 @@ +/************************************************************************************ + +Depthkit Unity SDK License v1 +Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved. + +Licensed under the the Simile Inc dba Scatter ("Scatter") +Software Development Kit License Agreement (the "License"); +you may not use this SDK except in compliance with the License, +which is provided at the time of installation or download, +or which otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at http://www.depthkit.tv/license-agreement-v1 + +Unless required by applicable law or agreed to in writing, +the SDK distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. + +************************************************************************************/ + +using UnityEngine; +using UnityEngine.Rendering; +using System.Collections.Generic; +using System.Text; +using UnityEngine.XR; +using System.Reflection; +#if UNITY_EDITOR +using UnityEditor; +using System.Linq; +using System.IO; +#endif + +namespace Depthkit { + + public enum CoordinateRangeType + { + NDC, + Normalized, + Pixels + }; + + public enum ImageFormat + { + JPG, + PNG + }; + + public static class Util + { + public static int NextMultipleOfX(int input, int x) + { + return input % x == 0 ? input : ((input / x) + 1) * x; + } + + public static string GetScaled2DKernelName(string baseName) + { + //todo is 16 kernel size more performant than 8? + if (SystemInfo.maxComputeWorkGroupSize >= 256 && SystemInfo.maxComputeWorkGroupSizeX >= 16 && SystemInfo.maxComputeWorkGroupSizeY >= 16) + { + return baseName + "16x16"; + } + + if (SystemInfo.maxComputeWorkGroupSize >= 64 && SystemInfo.maxComputeWorkGroupSizeX >= 8 && SystemInfo.maxComputeWorkGroupSizeY >= 8) + { + return baseName + "8x8"; + } + + return baseName + "4x4"; + } + + public static string GetScaled3DKernelName(string baseName) + { + if (SystemInfo.maxComputeWorkGroupSize >= 512 && SystemInfo.maxComputeWorkGroupSizeX >= 8 && SystemInfo.maxComputeWorkGroupSizeY >= 8 && SystemInfo.maxComputeWorkGroupSizeZ >= 8) + { + return baseName + "8x8x8"; + } + + return baseName + "4x4x4"; + } + + public static void DispatchGroups(ComputeShader compute, int kernel, int threadsX, int threadsY, int threadsZ) + { + uint groupSizeX, groupSizeY, groupSizeZ; + + compute.GetKernelThreadGroupSizes(kernel, out groupSizeX, out groupSizeY, out groupSizeZ); + + // Max(1) since we may have less than THREAD_GROUP_SIZE verts wide or long. + int groupsX = Mathf.Max((int)Mathf.Ceil(threadsX / (float)groupSizeX), 1); + int groupsY = Mathf.Max((int)Mathf.Ceil(threadsY / (float)groupSizeY), 1); + int groupsZ = Mathf.Max((int)Mathf.Ceil(threadsZ / (float)groupSizeZ), 1); + + compute.Dispatch(kernel, groupsX, groupsY, groupsZ); + } + + public static void ClearRenderTexture(RenderTexture renderTexture, Color color) + { + if (!renderTexture) return; + RenderTexture cache = RenderTexture.active; + RenderTexture.active = renderTexture; + GL.Clear(false, true, color); + RenderTexture.active = cache; + } + + public static void ReleaseComputeBuffer(ref ComputeBuffer buffer) + { + if (buffer != null) + { + buffer.Release(); + buffer = null; + } + } + + public static void ReleaseRenderTexture(ref RenderTexture tex) + { + if (tex != null) + { + if (tex.IsCreated()) + { + tex.Release(); + } + tex = null; + } + } + public static RenderTexture CopyFromRenderTextureSettings(RenderTexture tex, Vector2 scale) + { + RenderTexture newTex = new RenderTexture((int)((float)tex.width * scale.x), (int)((float)tex.height * scale.y), tex.depth, tex.format); + newTex.dimension = tex.dimension; + newTex.volumeDepth = tex.volumeDepth; + newTex.filterMode = tex.filterMode; + newTex.name = tex.name + " copy"; + newTex.enableRandomWrite = true; + newTex.autoGenerateMips = tex.autoGenerateMips; + newTex.Create(); + return newTex; + } + + public static Matrix4x4 ComposeExtrinsicsMatrix(Matrix4x4 transformMatrix, Matrix4x4 extrinsics, Bounds bounds) + { + // We translate all geometry by boundsCenter here so that 0,0,0 is the middle of the clip bounds. + var boundsOffset = Matrix4x4.TRS(-bounds.center, Quaternion.identity, Vector3.one); + return transformMatrix * boundsOffset * extrinsics; + } + + public static Bounds TransformBounds(Transform _transform, Bounds _localBounds) + { + var center = _transform.TransformPoint(_localBounds.center); + + // transform the local extents' axes + var extents = _localBounds.extents; + var axisX = _transform.TransformVector(extents.x, 0, 0); + var axisY = _transform.TransformVector(0, extents.y, 0); + var axisZ = _transform.TransformVector(0, 0, extents.z); + + // sum their absolute value to get the world extents + extents.x = Mathf.Abs(axisX.x) + Mathf.Abs(axisY.x) + Mathf.Abs(axisZ.x); + extents.y = Mathf.Abs(axisX.y) + Mathf.Abs(axisY.y) + Mathf.Abs(axisZ.y); + extents.z = Mathf.Abs(axisX.z) + Mathf.Abs(axisY.z) + Mathf.Abs(axisZ.z); + + return new Bounds { center = center, extents = extents }; + } +#if UNITY_EDITOR + public static string IndirectArgsToString(ComputeBuffer buf) + { + if (buf == null) + { + return ""; + } + + int[] args = new int[buf.count]; + buf.GetData(args); + return string.Join(", ", args.Select(i => i.ToString()).ToArray()); + } +#endif + public static RenderTexture CreateRenderTexture(int width, int height, RenderTextureFormat fmt, bool autoMips = false, RenderTextureReadWrite type = RenderTextureReadWrite.Default, FilterMode mode = FilterMode.Point, bool enableRandomWrite = true, int depthBits = 0, TextureDimension dimension = TextureDimension.Tex2D, int volumeDepth = 1) + { + RenderTexture tex = new RenderTexture(width, height, depthBits, fmt, type); + tex.enableRandomWrite = enableRandomWrite; + tex.filterMode = mode; + tex.useMipMap = autoMips; + tex.autoGenerateMips = autoMips; + tex.dimension = dimension; + tex.volumeDepth = volumeDepth; + tex.Create(); + return tex; + } + public static bool EnsureRenderTexture(ref RenderTexture tex, int width, int height, RenderTextureFormat fmt, RenderTextureReadWrite type = RenderTextureReadWrite.Default, bool autoMips = false, FilterMode mode = FilterMode.Point, bool enableRandomWrite = true, RenderTextureFormat fallback = RenderTextureFormat.Default, TextureDimension dimension = TextureDimension.Tex2D, int volumeDepth = 1) + { + bool didCreate = false; + if (width == 0 || height == 0) return didCreate; + if (tex == null || tex.width != width || tex.height != height || tex.format != fmt || tex.dimension != dimension || tex.volumeDepth != volumeDepth) + { + if (tex != null && tex.IsCreated()) + { + tex.Release(); + } + + if (!SystemInfo.SupportsRenderTextureFormat(fmt)) + { + fmt = fallback; + } + + tex = CreateRenderTexture(width, height, fmt, autoMips, type, mode, enableRandomWrite, 0, dimension, volumeDepth); + didCreate = tex.IsCreated(); + if (!didCreate) + { + Debug.LogWarning("Failed to create Render Texture with format: " + fmt.ToString() + " falling back to: " + fallback.ToString() + " ignore previous error."); + tex = CreateRenderTexture(width, height, fallback, autoMips, type, mode, enableRandomWrite); + didCreate = tex.IsCreated(); + } + } + return didCreate; + } + + public static bool EnsureComputeBuffer(ComputeBufferType computeBufferType, ref ComputeBuffer buf, int count, int stride, System.Array defaultValues = null) + { + bool wasNew = false; + + if (buf != null && (buf.count != count || buf.stride != stride)) + { + buf.Release(); + buf = null; + } + + if (buf == null) + { + buf = new ComputeBuffer(count, stride, computeBufferType); + wasNew = true; + } + + if (defaultValues != null) + { + buf.SetData(defaultValues); + } + + return wasNew; + } + + public static Color ColorForCamera(int index) + { + switch (index) + { + case 0: return new Color(1, 0, 0, 1); + case 1: return new Color(0, 1, 0, 1); + case 2: return new Color(0, 0, 1, 1); + case 3: return new Color(1, 1, 0, 1); + case 4: return new Color(0, 1, 1, 1); + case 5: return new Color(1, 0, 1, 1); + case 6: return new Color(0.5f, 1, 0, 1); + case 7: return new Color(0, 1, 0.5f, 1); + case 8: return new Color(1, 0.5f, 0, 1); + case 9: return new Color(1, 0, 0.5f, 1); + case 10: return new Color(0.5f, 0, 1, 1); + case 11: return new Color(0.5f, 0.5f, 1, 1); + case 12: return new Color(1, 0.5f, 0.5f, 1); + default: return new Color(1, 1, 1, 1); + } + } + + public static void RenderPerspectiveGizmo(Depthkit.Metadata.Perspective perspective, Transform transform, Color color, string label) + { +#if UNITY_EDITOR + Handles.Label(transform.TransformPoint(perspective.cameraCenter), label); + + Matrix4x4 storedMatrix = Gizmos.matrix; + Matrix4x4 camMatrix = new Matrix4x4(); + Vector3 nrm = transform.localToWorldMatrix.MultiplyVector(perspective.cameraNormal).normalized; + + Vector3 pos = transform.localToWorldMatrix.MultiplyPoint(perspective.cameraCenter); + + Quaternion q = new Quaternion(); + q.SetLookRotation(nrm); + + camMatrix.SetTRS(pos, q, Vector3.one); + + Gizmos.color = color; + Gizmos.matrix = camMatrix; + + float fov = Mathf.Rad2Deg * (2.0f * Mathf.Atan((perspective.depthImageSize.y * 0.5f) / perspective.depthFocalLength.y)); + + Gizmos.DrawFrustum(Vector3.zero, fov, perspective.farClip, perspective.nearClip, perspective.depthImageSize.x / perspective.depthImageSize.y); + Gizmos.matrix = storedMatrix; + + Vector3 endPoint = perspective.cameraCenter + perspective.cameraNormal * 2; + + Gizmos.DrawLine(transform.TransformPoint(perspective.cameraCenter), transform.TransformPoint(endPoint)); +#endif + } + + public static void RenderMetadataGizmos(Depthkit.Metadata metadata, Transform transform) + { +#if UNITY_EDITOR + for (int i = 0; i < metadata.perspectivesCount; i++) + { + var perspective = metadata.perspectives[i]; + Color camColor = ColorForCamera(i); + RenderPerspectiveGizmo(perspective, transform, camColor, "Perspective " + i); + } +#endif + } + +#if UNITY_EDITOR + public static string GetNextFileName(string filename, string ext) + { + if (!File.Exists(filename + ext)) + { + return filename + ext; + } + int count = 1; + string countSegment = " (" + count + ")"; + while (File.Exists(filename + countSegment + ext)) + { + count++; + countSegment = " (" + count + ")"; + } + return filename + countSegment + ext; + } +#endif + + public static bool IsVisible(Bounds bounds, Camera camera = null) + { + if (camera == null) + { + camera = Camera.main; + } + if (camera == null) return false; + Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera); + return GeometryUtility.TestPlanesAABB(planes, bounds); + } + public static float metersToCm(float meters) + { + return meters * 100.0f; + } + public static float cmToMeters(float cm) + { + return cm / 100.0f; + } + + public static void EnsureKeyword(ref Material material, string keyword, bool enable) + { + bool keywordEnabled = material.IsKeywordEnabled(keyword); + if (!keywordEnabled && enable) + { + material.EnableKeyword(keyword); + } + else if (keywordEnabled && !enable) + { + material.DisableKeyword(keyword); + } + } + + public static void EnsureComputeShader(ref ComputeShader compute, string path, string name = "") + { + if (compute == null) + { + compute = Resources.Load(path, typeof(ComputeShader)) as ComputeShader; + if (compute == null) + { + Debug.LogError("unable to load compute shader: " + path); + } + else + { + if (name != string.Empty) compute.name = name; + } + } + } + + public static class ArgsBufferPrep + { + private static string s_prepareArgsComputeName = "Shaders/Util/PrepareArgs"; + private static ComputeShader s_prepareArgsCompute = null; + private static int s_prepareDrawIndirectArgsKernelId = -1; + private static int s_prepareDispatchIndirectArgsKernelId = -1; + + public static class ShaderIds + { + public static readonly int + _GroupSize = Shader.PropertyToID("_GroupSize"), + _DispatchY = Shader.PropertyToID("_DispatchY"), + _DispatchZ = Shader.PropertyToID("_DispatchZ"), + _SinglePassStereo = Shader.PropertyToID("_SinglePassStereo"); + } + + public static void Setup() + { + if (s_prepareArgsCompute == null) + { + s_prepareArgsCompute = Resources.Load(s_prepareArgsComputeName, typeof(ComputeShader)) as ComputeShader; + if (s_prepareArgsCompute == null) + { + Debug.LogError("unable to load compute shader: " + s_prepareArgsComputeName); + } + } + if (s_prepareDrawIndirectArgsKernelId == -1) + { + s_prepareDrawIndirectArgsKernelId = s_prepareArgsCompute.FindKernel("KPrepareDrawIndirectArgs"); + } + if (s_prepareDispatchIndirectArgsKernelId == -1) + { + s_prepareDispatchIndirectArgsKernelId = s_prepareArgsCompute.FindKernel("KPrepareDispatchIndirectArgs"); + } + } + + public static void PrepareDispatchArgs(ComputeBuffer count, ComputeBuffer dispatchArgs, int groupSize, int dispatchY = 1, int dispatchZ = 1) + { + s_prepareArgsCompute.SetBuffer(s_prepareDispatchIndirectArgsKernelId, SubMesh.TriangleDataShaderIds._TrianglesCount, count); + s_prepareArgsCompute.SetBuffer(s_prepareDispatchIndirectArgsKernelId, SubMesh.TriangleDataShaderIds._TrianglesDispatchIndirectArgs, dispatchArgs); + s_prepareArgsCompute.SetInt(ShaderIds._GroupSize, groupSize); + s_prepareArgsCompute.SetInt(ShaderIds._DispatchY, dispatchY); + s_prepareArgsCompute.SetInt(ShaderIds._DispatchZ, dispatchZ); + s_prepareArgsCompute.Dispatch(s_prepareDispatchIndirectArgsKernelId, 1, 1, 1); + } + + public static void PrepareDrawArgs(ComputeBuffer count, ComputeBuffer drawArgs, bool forceStereo) + { + s_prepareArgsCompute.SetBuffer(s_prepareDrawIndirectArgsKernelId, SubMesh.TriangleDataShaderIds._TrianglesCount, count); + s_prepareArgsCompute.SetBuffer(s_prepareDrawIndirectArgsKernelId, SubMesh.TriangleDataShaderIds._TrianglesDrawIndirectArgs, drawArgs); + s_prepareArgsCompute.SetBool(ShaderIds._SinglePassStereo, forceStereo ? true : (XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.SinglePassInstanced || XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.SinglePassMultiview)); + s_prepareArgsCompute.Dispatch(s_prepareDrawIndirectArgsKernelId, 1, 1, 1); + } + } + public static RangeAttribute GetFieldRange(System.Type type, System.String name) + { + return type.GetField(name).GetCustomAttribute(); + } + } +} // namespace Depthkit diff --git a/LocalPackages/depthkit.core/Runtime/Utils/Util.cs.meta b/LocalPackages/depthkit.core/Runtime/Utils/Util.cs.meta new file mode 100644 index 0000000..87ce2c7 --- /dev/null +++ b/LocalPackages/depthkit.core/Runtime/Utils/Util.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: adf90817f427d0a4bbe2476ecace655d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LocalPackages/depthkit.core/package.json b/LocalPackages/depthkit.core/package.json new file mode 100644 index 0000000..13b5622 --- /dev/null +++ b/LocalPackages/depthkit.core/package.json @@ -0,0 +1,29 @@ +{ + "name": "nyc.scatter.depthkit.core", + "version": "0.14.3", + "displayName": "Depthkit Core", + "description": "Use the Depthkit Core Package to render Depthkit captures from Depthkit Core and Depthkit Cinema in Unity’s Built-in Render Pipeline.\n\nNote that you can only render single-perspective captures with the Depthkit Core package suite. For multi-perspective captures, use Depthkit Studio package suite.", + "unity": "2022.3", + "samples": [ + { + "displayName": "AV Pro 1.x Video Player", + "description": "Integration for Renderhead's AV Pro v1.x Video Player. (Must Have AVProVideo 1.x imported!). This version of AVPro is deprecated. To use this script, you must add DK_AVPROv1 as a macro define in player settings.", + "path": "Samples~/AVProVideoPlayer" + }, + { + "displayName": "Prefabs - Depthkit Core Built-in", + "description": "Prefabs for the Built-in Render Pipeline", + "path": "Samples~/Depthkit Core Built-in Prefabs" + } + ], + "keywords": [ + "Depthkit", + "Volumetric", + "Scatter" + ], + "author": { + "name": "Scatter", + "email": "support@depthkit.tv", + "url": "https://www.depthkit.tv" + } +} \ No newline at end of file diff --git a/LocalPackages/depthkit.core/package.json.meta b/LocalPackages/depthkit.core/package.json.meta new file mode 100644 index 0000000..f271660 --- /dev/null +++ b/LocalPackages/depthkit.core/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 43b090d341a738b4fa5ee1f964695536 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Viagg-io/Packages/manifest.json b/Viagg-io/Packages/manifest.json index 5d122b2..361e2ef 100644 --- a/Viagg-io/Packages/manifest.json +++ b/Viagg-io/Packages/manifest.json @@ -13,8 +13,8 @@ "com.unity.xr.management": "4.4.0", "com.unity.xr.oculus": "4.1.2", "com.unity.xr.openxr": "1.9.1", - "nyc.scatter.depthkit.core": "file:/Users/nadineganz/Documents/viaggio/Depthkit/Depthkit_Expansion_Package_Phase10_021524/depthkit.core", - "nyc.scatter.depthkit.core.shadergraph": "file:/Users/nadineganz/Documents/viaggio/Depthkit/Depthkit_Expansion_Package_Phase10_021524/depthkit.core.shadergraph", + "nyc.scatter.depthkit.core": "file:../../LocalPackages/depthkit.core", + "nyc.scatter.depthkit.core.shadergraph": "file:../../LocalPackages/depthkit.core.shadergraph", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Viagg-io/Packages/packages-lock.json b/Viagg-io/Packages/packages-lock.json index 6d01cfd..b7e9d15 100644 --- a/Viagg-io/Packages/packages-lock.json +++ b/Viagg-io/Packages/packages-lock.json @@ -437,13 +437,13 @@ "url": "https://packages.unity.com" }, "nyc.scatter.depthkit.core": { - "version": "file:/Users/nadineganz/Documents/viaggio/Depthkit/Depthkit_Expansion_Package_Phase10_021524/depthkit.core", + "version": "file:../../LocalPackages/depthkit.core", "depth": 0, "source": "local", "dependencies": {} }, "nyc.scatter.depthkit.core.shadergraph": { - "version": "file:/Users/nadineganz/Documents/viaggio/Depthkit/Depthkit_Expansion_Package_Phase10_021524/depthkit.core.shadergraph", + "version": "file:../../LocalPackages/depthkit.core.shadergraph", "depth": 0, "source": "local", "dependencies": {