浏览代码
Add a depth gradient shader.
Add a depth gradient shader.
Modify script to update layout of the RawImage to align with the screen orientation./4.1
Todd Stinson
4 年前
当前提交
4236858f
共有 6 个文件被更改,包括 282 次插入 和 19 次删除
-
2Assets/Scenes/Depth/DepthImages.unity
-
83Assets/Scripts/TestDepthImage.cs
-
80Assets/Materials/EnvironmentDepthMaterial.mat
-
8Assets/Materials/EnvironmentDepthMaterial.mat.meta
-
119Assets/Shaders/EnvironmentDepthGradient.shader
-
9Assets/Shaders/EnvironmentDepthGradient.shader.meta
|
|||
%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: EnvironmentDepthMaterial |
|||
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} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1822b099f6c09434b97c31e70184ff72 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Unlit/EnvironmentDepthGradient" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex ("Main Texture", 2D) = "black" {} |
|||
_MinDistance ("Min Distance", Float) = 0.0 |
|||
_MaxDistance ("Max Distance", Float) = 8.0 |
|||
_TextureRotation ("Texture Rotation (Degrees)", Float) = 0.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; |
|||
}; |
|||
|
|||
|
|||
real _TextureRotation; |
|||
|
|||
v2f vert (appdata v) |
|||
{ |
|||
float angle = radians(_TextureRotation); |
|||
float cosrot = cos(angle); |
|||
float sinrot = sin(angle); |
|||
|
|||
float2 tmp = float2(0.5f - v.texcoord.x, v.texcoord.y - 0.5f); |
|||
|
|||
v2f o; |
|||
o.position = TransformObjectToHClip(v.position); |
|||
o.texcoord = float2(tmp.x * cosrot - tmp.y * sinrot + 0.5f, tmp.x * sinrot + tmp.y * cosrot + 0.5f); |
|||
return o; |
|||
} |
|||
|
|||
|
|||
real3 HSVtoRGB(real3 arg1) |
|||
{ |
|||
real4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); |
|||
real3 P = abs(frac(arg1.xxx + K.xyz) * 6.0 - 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.70f, -0.15f, saturate(lerpFactor)); |
|||
if (hue < 0.0f) |
|||
{ |
|||
hue += 1.0f; |
|||
} |
|||
real3 color = real3(hue, 0.9, 0.6); |
|||
|
|||
fragment_output o; |
|||
o.color = real4(HSVtoRGB(color), 1.0); |
|||
return o; |
|||
} |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1aab677bdaaa5470588b1194d3f271be |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue