-
Notifications
You must be signed in to change notification settings - Fork 229
/
DecalPainter.shader
36 lines (33 loc) · 1.05 KB
/
DecalPainter.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Shader "DecalPainter"
{
SubShader
{
Pass
{
ZTest Off
ZWrite Off
Cull Off
CGPROGRAM
#pragma vertex VSMain
#pragma fragment PSMain
float4x4 _MeshModelMatrix, _DecalViewMatrix, _DecalProjectionMatrix;
sampler2D _DecalTexture;
void VSMain (inout float4 vertex:POSITION, inout float2 uv:TEXCOORD0, out float4 worldPos:TEXCOORD1, out float4 clipPos:TEXCOORD2)
{
worldPos = mul(_MeshModelMatrix, vertex);
clipPos = mul(_DecalViewMatrix, worldPos);
clipPos = mul(_DecalProjectionMatrix, clipPos);
float2 texcoord = uv.xy;
texcoord.y = 1.0 - texcoord.y;
texcoord = texcoord * 2.0 - 1.0;
vertex = float4(texcoord, 0.0, 1.0);
}
float4 PSMain (float4 vertex:POSITION, float2 uv:TEXCOORD0, float4 worldPos:TEXCOORD1, float4 clipPos:TEXCOORD2) : SV_TARGET
{
float2 tc = float2( clipPos.x / clipPos.w, clipPos.y / clipPos.w) / 2.0 + 0.5;
return (tc.x > 0.0 && tc.x < 1.0 && tc.y > 0.0 && tc.y < 1.0) ? tex2D(_DecalTexture, tc) : float4(1, 0, 0, 1);
}
ENDCG
}
}
}