-
Notifications
You must be signed in to change notification settings - Fork 5
/
SpriteFragmentProgram.cg
105 lines (84 loc) · 1.97 KB
/
SpriteFragmentProgram.cg
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
struct vertin
{
float4 position : POSITION;
float4 color0 : COLOR0;
float4 params : COLOR1;
float4 texcoord0 : TEXCOORD0;
float4 params2 : TEXCOORD1;
};
struct fragout
{
float4 color : COLOR;
};
void main_pass1(vertin IN,
out float4 color: COLOR,
out float depth : DEPTH,
uniform sampler2D text //incoming texture
)
{
float alpha = tex2D( text, IN.texcoord0.xy).a;
//discard fragments with small alpha
if( alpha < 0.1 )
{
discard;
}
depth = IN.color0.w;
//IN.params.z > 0.5 means that a fragment is past the splat rotation cutoff distance and it does not have to be rotated
if( IN.params.z > 0.5 )
{
color = float4(IN.color0.xyz, alpha );
return;
}
//parametrized coordinates
float i = (IN.texcoord0.x - 0.5)*2;
float j = (IN.texcoord0.y - 0.5)*2;
float dz = IN.params.x*i - IN.params.y*j;
float l = length(float3(i,j,2*dz));
if( l <1 )
{
color = float4(IN.color0.xyz, alpha );
}
else
{
discard;
}
}
void main_pass2(vertin IN,
out float4 color: COLOR,
out float depth : DEPTH,
uniform sampler2D text //incoming texture
)
{
float alpha = tex2D( text, IN.texcoord0.xy).a;
//discard fragments with small alpha
if( alpha < 0.1 )
{
discard;
}
depth = IN.color0.w;
//IN.params.z > 0.5 means that a fragment is past the splat rotation cutoff distance and it does not have to be rotated
if( IN.params.z > 0.5 )
{
color = float4(IN.color0.xyz, alpha );
return;
}
//parametrized coordinates
float i = (IN.texcoord0.x - 0.5)*2;
float j = (IN.texcoord0.y - 0.5)*2;
//float r2 = i*i+j*j;
float dz = IN.params.x*i - IN.params.y*j;
float l = length(float3(i,j,2*dz));
if( l < 1 )
{
color = float4(IN.color0.xyz, alpha );
}
else
{
discard;
}
}
void main_pass3(vertin IN,
out float4 color: COLOR
)
{
}