浏览代码

Merge pull request #67 from unity/add-depth-gradient-shader

Improve the depth images scene
/4.1
GitHub Enterprise 4 年前
当前提交
f291d393
共有 14 个文件被更改,包括 1721 次插入74 次删除
  1. 932
      Assets/Scenes/Depth/DepthImages.unity
  2. 457
      Assets/Scripts/DisplayDepthImage.cs
  3. 2
      ProjectSettings/ProjectSettings.asset
  4. 4
      ProjectSettings/ProjectVersion.txt
  5. 80
      Assets/Materials/DepthGradientMaterial.mat
  6. 8
      Assets/Materials/DepthGradientMaterial.mat.meta
  7. 78
      Assets/Materials/HumanStencil.mat
  8. 8
      Assets/Materials/HumanStencil.mat.meta
  9. 115
      Assets/Shaders/DepthGradient.shader
  10. 9
      Assets/Shaders/DepthGradient.shader.meta
  11. 93
      Assets/Shaders/HumanStencil.shader
  12. 9
      Assets/Shaders/HumanStencil.shader.meta
  13. 0
      /Assets/Scripts/DisplayDepthImage.cs.meta
  14. 0
      /Assets/Scripts/DisplayDepthImage.cs

932
Assets/Scenes/Depth/DepthImages.unity
文件差异内容过多而无法显示
查看文件

457
Assets/Scripts/DisplayDepthImage.cs


using System;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

/// <summary>
/// This component tests getting the latest camera image
/// and converting it to RGBA format. If successful,
/// it displays the image on the screen as a RawImage
/// and also displays information about the image.
///
/// This is useful for computer vision applications where
/// you need to access the raw pixels from camera image
/// on the CPU.
///
/// This is different from the ARCameraBackground component, which
/// efficiently displays the camera image on the screen. If you
/// just want to blit the camera texture to the screen, use
/// the ARCameraBackground, or use Graphics.Blit to create
/// a GPU-friendly RenderTexture.
///
/// In this example, we get the camera image data on the CPU,
/// convert it to an RGBA format, then display it on the screen
/// as a RawImage texture to demonstrate it is working.
/// This is done as an example; do not use this technique simply
/// to render the camera image on screen.
/// This component displays a picture-in-picture view of the environment depth texture, the human depth texture, or
/// the human stencil texture.
public class TestDepthImage : MonoBehaviour
public class DisplayDepthImage : MonoBehaviour
[SerializeField]
[Tooltip("The AROcclusionManager which will produce frame events.")]
AROcclusionManager m_OcclusionManager;
/// <summary>
/// The display mode for the texture widget. Values must match the UI dropdown.
/// </summary>
enum DisplayMode
{
EnvironmentDepth = 0,
HumanDepth = 1,
HumanStencil = 2,
}
/// <summary>
/// Name of the max distance property in the shader.
/// </summary>
const string k_MaxDistanceName = "_MaxDistance";
/// <summary>
/// Name of the display rotation matrix in the shader.
/// </summary>
const string k_DisplayRotationPerFrameName = "_DisplayRotationPerFrame";
/// <summary>
/// The default texture aspect ratio.
/// </summary>
const float k_DefaultTextureAspectRadio = 1.0f;
/// <summary>
/// ID of the max distance property in the shader.
/// </summary>
static readonly int k_MaxDistanceId = Shader.PropertyToID(k_MaxDistanceName);
/// <summary>
/// ID of the display rotation matrix in the shader.
/// </summary>
static readonly int k_DisplayRotationPerFrameId = Shader.PropertyToID(k_DisplayRotationPerFrameName);
/// <summary>
/// A string builder for construction of strings.
/// </summary>
readonly StringBuilder m_StringBuilder = new StringBuilder();
/// <summary>
/// The current screen orientation remembered so that we are only updating the raw image layout when it changes.
/// </summary>
ScreenOrientation m_CurrentScreenOrientation;
/// <summary>
/// The current texture aspect ratio remembered so that we can resize the raw image layout when it changes.
/// </summary>
float m_TextureAspectRatio = k_DefaultTextureAspectRadio;
/// <summary>
/// The mode indicating which texture to display.
/// </summary>
DisplayMode m_DisplayMode = DisplayMode.EnvironmentDepth;
/// <summary>
/// The display rotation matrix for the shader.
/// </summary.
Matrix4x4 m_DisplayRotationMatrix = Matrix4x4.identity;
#if UNITY_ANDROID
/// <summary>
/// A matrix to flip the Y coordinate for the Android platform.
/// </summary>
Matrix4x4 k_AndroidFlipYMatrix = Matrix4x4.identity;
#endif // UNITY_ANDROID
/// <summary>
/// Get or set the <c>AROcclusionManager</c>.

get { return m_OcclusionManager; }
set { m_OcclusionManager = value; }
get => m_OcclusionManager;
set => m_OcclusionManager = value;
RawImage m_RawImage;
[Tooltip("The AROcclusionManager which will produce depth textures.")]
AROcclusionManager m_OcclusionManager;
/// <summary>
/// Get or set the <c>ARCameraManager</c>.
/// </summary>
public ARCameraManager cameraManager
{
get => m_CameraManager;
set => m_CameraManager = value;
}
[SerializeField]
[Tooltip("The ARCameraManager which will produce camera frame events.")]
ARCameraManager m_CameraManager;
/// <summary>
/// The UI RawImage used to display the image on screen.

get { return m_RawImage; }
set { m_RawImage = value; }
get => m_RawImage;
set => m_RawImage = value;
Text m_ImageInfo;
RawImage m_RawImage;
/// <summary>
/// The UI Text used to display information about the image on screen.

get { return m_ImageInfo; }
set { m_ImageInfo = value; }
get => m_ImageInfo;
set => m_ImageInfo = value;
}
[SerializeField]
Text m_ImageInfo;
/// <summary>
/// The depth material for rendering depth textures.
/// </summary>
public Material depthMaterial
{
get => m_DepthMaterial;
set => m_DepthMaterial = value;
}
[SerializeField]
Material m_DepthMaterial;
/// <summary>
/// The stencil material for rendering stencil textures.
/// </summary>
public Material stencilMaterial
{
get => m_StencilMaterial;
set => m_StencilMaterial = value;
void LogTextureInfo(StringBuilder stringBuilder, string textureName, Texture2D texture)
[SerializeField]
Material m_StencilMaterial;
/// <summary>
/// The max distance value for the shader when showing an environment depth texture.
/// </summary>
public float maxEnvironmentDistance
stringBuilder.AppendFormat("texture : {0}\n", textureName);
if (texture == null)
{
stringBuilder.AppendFormat(" <null>\n");
}
else
{
stringBuilder.AppendFormat(" format : {0}\n", texture.format.ToString());
stringBuilder.AppendFormat(" width : {0}\n", texture.width);
stringBuilder.AppendFormat(" height : {0}\n", texture.height);
stringBuilder.AppendFormat(" mipmap : {0}\n", texture.mipmapCount);
}
get => m_MaxEnvironmentDistance;
set => m_MaxEnvironmentDistance = value;
}
[SerializeField]
float m_MaxEnvironmentDistance = 8.0f;
/// <summary>
/// The max distance value for the shader when showing an human depth texture.
/// </summary>
public float maxHumanDistance
{
get => m_MaxHumanDistance;
set => m_MaxHumanDistance = value;
}
[SerializeField]
float m_MaxHumanDistance = 3.0f;
void Awake()
{
#if UNITY_ANDROID
k_AndroidFlipYMatrix[1,1] = -1.0f;
k_AndroidFlipYMatrix[2,1] = 1.0f;
#endif // UNITY_ANDROID
}
void OnEnable()
{
// Subscribe to the camera frame received event, and initialize the display rotation matrix.
Debug.Assert(m_CameraManager != null, "no camera manager");
m_CameraManager.frameReceived += OnCameraFrameEventReceived;
m_DisplayRotationMatrix = Matrix4x4.identity;
// When enabled, get the current screen orientation, and update the raw image UI.
m_CurrentScreenOrientation = Screen.orientation;
UpdateRawImage();
}
void OnDisable()
{
// Unsubscribe to the camera frame received event, and initialize the display rotation matrix.
Debug.Assert(m_CameraManager != null, "no camera manager");
m_CameraManager.frameReceived -= OnCameraFrameEventReceived;
m_DisplayRotationMatrix = Matrix4x4.identity;
// If we are on a device that does supports neither human stencil, human depth, nor environment depth,
// display a message about unsupported functionality and return.
if ((m_OcclusionManager.descriptor?.supportsHumanSegmentationStencilImage == false)
&& (m_OcclusionManager.descriptor?.supportsHumanSegmentationDepthImage == false)
&& (m_OcclusionManager.descriptor?.supportsEnvironmentDepthImage == false))
switch (m_DisplayMode)
if (m_ImageInfo != null)
{
m_ImageInfo.text = "Depth functionality is not supported on this device.";
}
return;
case DisplayMode.HumanDepth:
case DisplayMode.HumanStencil:
if ((m_OcclusionManager.descriptor?.supportsHumanSegmentationStencilImage == false)
&& (m_OcclusionManager.descriptor?.supportsHumanSegmentationDepthImage == false))
{
LogText("Human segmentation is not supported on this device.");
m_RawImage.texture = null;
if (!Mathf.Approximately(m_TextureAspectRatio, k_DefaultTextureAspectRadio))
{
m_TextureAspectRatio = k_DefaultTextureAspectRadio;
UpdateRawImage();
}
return;
}
break;
case DisplayMode.EnvironmentDepth :
default:
if (m_OcclusionManager.descriptor?.supportsEnvironmentDepthImage == false)
{
LogText("Environment depth is not supported on this device.");
m_RawImage.texture = null;
if (!Mathf.Approximately(m_TextureAspectRatio, k_DefaultTextureAspectRadio))
{
m_TextureAspectRatio = k_DefaultTextureAspectRadio;
UpdateRawImage();
}
return;
}
break;
StringBuilder sb = new StringBuilder();
// Get all of the occlusion textures.
LogTextureInfo(sb, "stencil", humanStencil);
LogTextureInfo(sb, "depth", humanDepth);
LogTextureInfo(sb, "env", envDepth);
// Display some text information about each of the textures.
m_StringBuilder.Clear();
BuildTextureInfo(m_StringBuilder, "stencil", humanStencil);
BuildTextureInfo(m_StringBuilder, "depth", humanDepth);
BuildTextureInfo(m_StringBuilder, "env", envDepth);
LogText(m_StringBuilder.ToString());
// Decide which to display based on the current mode.
Texture2D displayTexture;
switch (m_DisplayMode)
{
case DisplayMode.HumanStencil:
displayTexture = humanStencil;
break;
case DisplayMode.HumanDepth:
displayTexture = humanDepth;
break;
case DisplayMode.EnvironmentDepth:
default:
displayTexture = envDepth;
break;
}
// Assign the texture to display to the raw image.
Debug.Assert(m_RawImage != null, "no raw image");
m_RawImage.texture = displayTexture;
// Get the aspect ratio for the current texture.
float textureAspectRatio = (displayTexture == null) ? 1.0f : ((float)displayTexture.width / (float)displayTexture.height);
// If the raw image needs to be updated because of a device orientation change or because of a texture
// aspect ratio difference, then update the raw image with the new values.
if ((m_CurrentScreenOrientation != Screen.orientation)
|| !Mathf.Approximately(m_TextureAspectRatio, textureAspectRatio))
{
m_CurrentScreenOrientation = Screen.orientation;
m_TextureAspectRatio = textureAspectRatio;
UpdateRawImage();
}
}
/// <summary>
/// When the camera frame event is raised, capture the display rotation matrix.
/// </summary>
/// <param name="cameraFrameEventArgs">The arguments when a camera frame event is raised.</param>
void OnCameraFrameEventReceived(ARCameraFrameEventArgs cameraFrameEventArgs)
{
Debug.Assert(m_RawImage != null, "no raw image");
if (m_RawImage.material != null)
{
// Copy the display rotation matrix from the camera.
Matrix4x4 cameraMatrix = cameraFrameEventArgs.displayMatrix ?? Matrix4x4.identity;
Vector2 affineBasisX = new Vector2(1.0f, 0.0f);
Vector2 affineBasisY = new Vector2(0.0f, 1.0f);
Vector2 affineTranslation = new Vector2(0.0f, 0.0f);
#if UNITY_IOS
affineBasisX = new Vector2(cameraMatrix[0, 0], cameraMatrix[1, 0]);
affineBasisY = new Vector2(cameraMatrix[0, 1], cameraMatrix[1, 1]);
affineTranslation = new Vector2(cameraMatrix[2, 0], cameraMatrix[2, 1]);
#endif // UNITY_IOS
#if UNITY_ANDROID
affineBasisX = new Vector2(cameraMatrix[0, 0], cameraMatrix[0, 1]);
affineBasisY = new Vector2(cameraMatrix[1, 0], cameraMatrix[1, 1]);
affineTranslation = new Vector2(cameraMatrix[0, 2], cameraMatrix[1, 2]);
#endif // UNITY_ANDROID
// The camera display matrix includes scaling and offsets to fit the aspect ratio of the device. In most
// cases, the camera display matrix should be used directly without modification when applying depth to
// the scene because that will line up the depth image with the camera image. However, for this demo,
// we want to show the full depth image as a picture-in-picture, so we remove these scaling and offset
// factors while preserving the orientation.
affineBasisX = affineBasisX.normalized;
affineBasisY = affineBasisY.normalized;
m_DisplayRotationMatrix = Matrix4x4.identity;
m_DisplayRotationMatrix[0,0] = affineBasisX.x;
m_DisplayRotationMatrix[0,1] = affineBasisY.x;
m_DisplayRotationMatrix[1,0] = affineBasisX.y;
m_DisplayRotationMatrix[1,1] = affineBasisY.y;
m_DisplayRotationMatrix[2,0] = Mathf.Round(affineTranslation.x);
m_DisplayRotationMatrix[2,1] = Mathf.Round(affineTranslation.y);
#if UNITY_ANDROID
m_DisplayRotationMatrix = k_AndroidFlipYMatrix * m_DisplayRotationMatrix;
#endif // UNITY_ANDROID
// Set the matrix to the raw image material.
m_RawImage.material.SetMatrix(k_DisplayRotationPerFrameId, m_DisplayRotationMatrix);
}
}
/// <summary>
/// Create log information about the given texture.
/// </summary>
/// <param name="stringBuilder">The string builder to which to append the texture information.</param>
/// <param name="textureName">The semantic name of the texture for logging purposes.</param>
/// <param name="texture">The texture for which to log information.</param>
void BuildTextureInfo(StringBuilder stringBuilder, string textureName, Texture2D texture)
{
stringBuilder.AppendLine($"texture : {textureName}");
if (texture == null)
{
stringBuilder.AppendLine(" <null>");
}
else
{
stringBuilder.AppendLine($" format : {texture.format}");
stringBuilder.AppendLine($" width : {texture.width}");
stringBuilder.AppendLine($" height : {texture.height}");
stringBuilder.AppendLine($" mipmap : {texture.mipmapCount}");
}
}
/// <summary>
/// Log the given text to the screen if the image info UI is set. Otherwise, log the string to debug.
/// </summary>
/// <param name="text">The text string to log.</param>
void LogText(string text)
{
m_ImageInfo.text = sb.ToString();
m_ImageInfo.text = text;
Debug.Log(sb.ToString());
Debug.Log(text);
}
// To use the stencil, be sure the HumanSegmentationStencilMode property on the AROcclusionManager is set to a
// non-disabled value.
m_RawImage.texture = envDepth;
/// <summary>
/// Update the raw image with the current configurations.
/// </summary>
void UpdateRawImage()
{
Debug.Assert(m_RawImage != null, "no raw image");
// To use the depth, be sure the HumanSegmentationDepthMode property on the AROcclusionManager is set to a
/// non-disabled value.
// m_RawImage.texture = eventArgs.humanDepth;
// Determine the raw imge rectSize preserving the texture aspect ratio, matching the screen orientation,
// and keeping a minimum dimension size.
float minDimension = 480.0f;
float maxDimension = Mathf.Round(minDimension * m_TextureAspectRatio);
Vector2 rectSize;
switch (m_CurrentScreenOrientation)
{
case ScreenOrientation.LandscapeRight:
case ScreenOrientation.LandscapeLeft:
rectSize = new Vector2(maxDimension, minDimension);
break;
case ScreenOrientation.PortraitUpsideDown:
case ScreenOrientation.Portrait:
default:
rectSize = new Vector2(minDimension, maxDimension);
break;
}
// Determine the raw image material and maxDistance material parameter based on the display mode.
float maxDistance;
Material material;
switch (m_DisplayMode)
{
case DisplayMode.HumanStencil:
material = m_StencilMaterial;
maxDistance = m_MaxHumanDistance;
break;
case DisplayMode.HumanDepth:
material = m_DepthMaterial;
maxDistance = m_MaxHumanDistance;
break;
case DisplayMode.EnvironmentDepth:
default:
material = m_DepthMaterial;
maxDistance = m_MaxEnvironmentDistance;
break;
}
// Update the raw image dimensions and the raw image material parameters.
m_RawImage.rectTransform.sizeDelta = rectSize;
material.SetFloat(k_MaxDistanceId, maxDistance);
material.SetMatrix(k_DisplayRotationPerFrameId, m_DisplayRotationMatrix);
m_RawImage.material = material;
}
/// <summary>
/// Callback when the depth mode dropdown UI has a value change.
/// </summary>
/// <param name="dropdown">The dropdown UI that changed.</param>
public void OnDepthModeDropdownValueChanged(Dropdown dropdown)
{
// Update the display mode from the dropdown value.
m_DisplayMode = (DisplayMode)dropdown.value;
// Update the raw image following the mode change.
UpdateRawImage();
}
}
}

2
ProjectSettings/ProjectSettings.asset


switchNVNShaderPoolsGranularity: 33554432
switchNVNDefaultPoolsGranularity: 16777216
switchNVNOtherPoolsGranularity: 16777216
switchNVNMaxPublicTextureIDCount: 0
switchNVNMaxPublicSamplerIDCount: 0
stadiaPresentMode: 0
stadiaTargetFramerate: 0
vulkanNumSwapchainBuffers: 3

4
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2020.1.0f1
m_EditorVersionWithRevision: 2020.1.0f1 (2ab9c4179772)
m_EditorVersion: 2020.1.1f1
m_EditorVersionWithRevision: 2020.1.1f1 (2285c3239188)

80
Assets/Materials/DepthGradientMaterial.mat


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

8
Assets/Materials/DepthGradientMaterial.mat.meta


fileFormatVersion: 2
guid: 1822b099f6c09434b97c31e70184ff72
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

78
Assets/Materials/HumanStencil.mat


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

8
Assets/Materials/HumanStencil.mat.meta


fileFormatVersion: 2
guid: c0be8d44aefaa41a79f40f503f63619b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

115
Assets/Shaders/DepthGradient.shader


Shader "Unlit/DepthGradient"
{
Properties
{
_MainTex ("Main Texture", 2D) = "black" {}
_MinDistance ("Min Distance", Float) = 0.0
_MaxDistance ("Max Distance", Float) = 8.0
}
SubShader
{
Tags
{
"Queue" = "Geometry"
"RenderType" = "Opaque"
"ForceNoShadowCasting" = "True"
}
Pass
{
Cull Off
ZTest Always
ZWrite Off
Lighting Off
LOD 100
Tags
{
"LightMode" = "Always"
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#define real half
#define real3 half3
#define real4 half4
#define TransformObjectToHClip UnityObjectToClipPos
#define DECLARE_TEXTURE2D_FLOAT(texture) UNITY_DECLARE_TEX2D_FLOAT(texture)
#define DECLARE_SAMPLER_FLOAT(sampler)
#define SAMPLE_TEXTURE2D(texture,sampler,texcoord) UNITY_SAMPLE_TEX2D(texture,texcoord)
struct appdata
{
float3 position : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
struct fragment_output
{
real4 color : SV_Target;
};
CBUFFER_START(DisplayRotationPerFrame)
float4x4 _DisplayRotationPerFrame;
CBUFFER_END
v2f vert (appdata v)
{
v2f o;
o.position = TransformObjectToHClip(v.position);
o.texcoord = mul(float3(v.texcoord, 1.0f), _DisplayRotationPerFrame).xy;
return o;
}
real3 HSVtoRGB(real3 arg1)
{
real4 K = real4(1.0h, 2.0h / 3.0h, 1.0h / 3.0h, 3.0h);
real3 P = abs(frac(arg1.xxx + K.xyz) * 6.0h - K.www);
return arg1.z * lerp(K.xxx, saturate(P - K.xxx), arg1.y);
}
DECLARE_TEXTURE2D_FLOAT(_MainTex);
DECLARE_SAMPLER_FLOAT(sampler_MainTex);
real _MinDistance;
real _MaxDistance;
fragment_output frag (v2f i)
{
// Sample the environment depth (in meters).
float envDistance = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord).r;
real lerpFactor = (envDistance - _MinDistance) / (_MaxDistance - _MinDistance);
real hue = lerp(0.70h, -0.15h, saturate(lerpFactor));
if (hue < 0.0h)
{
hue += 1.0h;
}
real3 color = real3(hue, 0.9h, 0.6h);
fragment_output o;
o.color = real4(HSVtoRGB(color), 1.0h);
return o;
}
ENDHLSL
}
}
}

9
Assets/Shaders/DepthGradient.shader.meta


fileFormatVersion: 2
guid: 1aab677bdaaa5470588b1194d3f271be
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

93
Assets/Shaders/HumanStencil.shader


Shader "Unlit/HumanStencil"
{
Properties
{
_MainTex ("Main Texture", 2D) = "black" {}
}
SubShader
{
Tags
{
"Queue" = "Geometry"
"RenderType" = "Opaque"
"ForceNoShadowCasting" = "True"
}
Pass
{
Cull Off
ZTest Always
ZWrite Off
Lighting Off
LOD 100
Tags
{
"LightMode" = "Always"
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#define real half
#define real3 half3
#define real4 half4
#define TransformObjectToHClip UnityObjectToClipPos
#define DECLARE_TEXTURE2D_FLOAT(texture) UNITY_DECLARE_TEX2D_FLOAT(texture)
#define DECLARE_SAMPLER_FLOAT(sampler)
#define SAMPLE_TEXTURE2D(texture,sampler,texcoord) UNITY_SAMPLE_TEX2D(texture,texcoord)
struct appdata
{
float3 position : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
struct fragment_output
{
real4 color : SV_Target;
};
CBUFFER_START(DisplayRotationPerFrame)
float4x4 _DisplayRotationPerFrame;
CBUFFER_END
v2f vert (appdata v)
{
v2f o;
o.position = TransformObjectToHClip(v.position);
o.texcoord = mul(float3(v.texcoord, 1.0f), _DisplayRotationPerFrame).xy;
return o;
}
DECLARE_TEXTURE2D_FLOAT(_MainTex);
DECLARE_SAMPLER_FLOAT(sampler_MainTex);
fragment_output frag (v2f i)
{
float stencilValue = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord).r;
fragment_output o;
o.color = real4(stencilValue, stencilValue, stencilValue, 1.0h);
return o;
}
ENDHLSL
}
}
}

9
Assets/Shaders/HumanStencil.shader.meta


fileFormatVersion: 2
guid: 100cb03e868ab4dd78fa474037e0f92c
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

/Assets/Scripts/TestDepthImage.cs.meta → /Assets/Scripts/DisplayDepthImage.cs.meta

/Assets/Scripts/TestDepthImage.cs → /Assets/Scripts/DisplayDepthImage.cs

正在加载...
取消
保存