您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
125 行
3.4 KiB
125 行
3.4 KiB
Shader "Unlit/DepthGradient"
|
|
{
|
|
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);
|
|
|
|
float3x3 textureXformMatrix = float3x3(
|
|
float3(cosrot, -sinrot, 0.5f),
|
|
float3(sinrot, cosrot, 0.5f),
|
|
float3(0.0f, 0.0f, 1.0f)
|
|
);
|
|
|
|
float3 tmp = float3(v.texcoord.x - 0.5f, 0.5f - v.texcoord.y, 1.0f);
|
|
|
|
v2f o;
|
|
o.position = TransformObjectToHClip(v.position);
|
|
o.texcoord = mul(textureXformMatrix, tmp).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
|
|
}
|
|
}
|
|
}
|