OutlineOpaque.shader
1.78 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//===============================================================================
//Copyright (c) 2017 PTC Inc. All Rights Reserved.
//
//Confidential and Proprietary - Protected under copyright and other laws.
//Vuforia is a trademark of PTC Inc., registered in the United States and other
//countries.
//===============================================================================
//==============================================================================
//Copyright (c) 2013-2014 Qualcomm Connected Experiences, Inc.
//All Rights Reserved.
//==============================================================================
Shader "Custom/OutlineOpaque"
{
Properties
{
_SilhouetteSize ("Size", Float) = 0.0
_SilhouetteColor ("Color", Color) = (1,1,1,1)
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f
{
float4 position : POSITION;
float4 color : COLOR;
};
struct vertIn
{
float4 position : POSITION;
float3 normal : NORMAL;
};
uniform float _SilhouetteSize;
uniform float4 _SilhouetteColor;
ENDCG
SubShader
{
Tags { "Queue" = "Geometry" }
Pass
{
Cull Back
Blend Zero One
}
Pass
{
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
v2f vert(vertIn input)
{
v2f output;
// unmodified projected position of the vertex
output.position = UnityObjectToClipPos(input.position);
output.color = _SilhouetteColor;
// calculate silhouette in image space
float2 silhouette = TransformViewToProjection(mul((float3x3)UNITY_MATRIX_IT_MV, input.normal).xy) * _SilhouetteSize;
// add silhouette offset
output.position.xy += output.position.z * silhouette;
return output;
}
half4 frag(v2f input) :COLOR
{
return input.color;
}
ENDCG
}
}
Fallback "Diffuse"
}