Skip to content

Commit 6f499ee

Browse files
authored
Optimize vision and range-ring shaders (FAForever#4073)
1 parent 88ae13a commit 6f499ee

File tree

2 files changed

+32
-70
lines changed

2 files changed

+32
-70
lines changed

effects/range.fx

+9-28
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Vertex vertexShader( float3 vertex : POSITION0, float2 coeff : TEXCOORD0, float2
2626

2727
technique Cast
2828
{
29-
pass FrontFace
29+
pass P0
3030
{
31-
CullMode = CCW;
31+
CullMode = none;
3232

3333
ColorWriteEnable = 0x00;
3434

@@ -37,38 +37,19 @@ technique Cast
3737
ZFunc = less;
3838

3939
StencilEnable = true;
40-
StencilFunc = notequal;
41-
StencilRef = 0xFF;
42-
StencilMask = 0x80;
43-
4440
StencilWriteMask = 0x7F;
45-
StencilFail = zero;
46-
StencilPass = keep;
47-
48-
StencilZFail = incr;
49-
50-
VertexShader = compile vs_2_0 vertexShader();
51-
}
52-
pass BackFace
53-
{
54-
CullMode = CW;
55-
56-
ColorWriteEnable = 0x00;
57-
58-
ZWriteEnable = false;
59-
ZEnable = true;
60-
ZFunc = less;
61-
62-
StencilEnable = true;
63-
StencilFunc = notequal;
6441
StencilRef = 0xFF;
6542
StencilMask = 0x80;
6643

67-
StencilWriteMask = 0x7F;
44+
TwoSidedStencilMode = true;
6845
StencilFail = zero;
46+
StencilZFail = incr;
6947
StencilPass = keep;
70-
71-
StencilZFail = decr;
48+
StencilFunc = notequal;
49+
CCW_StencilFail = zero;
50+
CCW_StencilZFail = decr;
51+
CCW_StencilPass = keep;
52+
CCW_StencilFunc = notequal;
7253

7354
VertexShader = compile vs_2_0 vertexShader();
7455
}

effects/vision.fx

+23-42
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
////////////////////////////////////////////////////////////////////////////////
1010

1111
#define CCW_BOUNDARY_BIAS 0.00001
12-
#define CW_BOUNDARY_BIAS -0.00001
12+
#define CW_BOUNDARY_BIAS -0.00001
1313

1414
float4x4 viewMatrix;
1515
float4x4 projMatrix;
@@ -25,20 +25,20 @@ typedef Vertex Pixel;
2525
Vertex boundaryVertexShader( float3 vertex : POSITION0 )
2626
{
2727
Vertex result = (Vertex)0;
28-
28+
2929
float3 position = boxExtent * vertex + boxCenter;
3030
result.position = mul(float4(position,1),mul(viewMatrix,projMatrix));
31-
31+
3232
return result;
3333
}
3434

3535
Vertex visionVertexShader( float3 vertex : POSITION0, float2 position : POSITION1, float radius : TEXCOORD0 )
3636
{
3737
Vertex result = (Vertex)0;
38-
38+
3939
vertex.xz = radius.xx * vertex.xz + position.xy;
4040
result.position = mul(float4(vertex,1),mul(viewMatrix,projMatrix));
41-
41+
4242
return result;
4343
}
4444

@@ -49,53 +49,34 @@ float4 pixelShader( Pixel pixel) : COLOR0
4949

5050
technique CastVision
5151
{
52-
pass FrontFace
52+
pass P0
5353
{
54-
CullMode = CCW;
55-
54+
CullMode = none;
55+
5656
AlphaBlendEnable = false;
5757
AlphaTestEnable = false;
58-
59-
ColorWriteEnable = 0x00;
58+
59+
ColorWriteEnable = 0x00;
6060

6161
ZWriteEnable = false;
6262
ZEnable = true;
6363
ZFunc = less;
64-
64+
6565
StencilEnable = true;
6666
StencilWriteMask = 0xFF;
6767
StencilMask = 0xFF;
6868
StencilRef = 0x00;
69-
StencilFunc = always;
69+
70+
TwoSidedStencilMode = true;
7071
StencilFail = keep;
7172
StencilZFail = incr;
7273
StencilPass = keep;
73-
74-
VertexShader = compile vs_2_0 visionVertexShader();
75-
PixelShader = compile ps_2_0 pixelShader();
76-
}
77-
pass BackFace
78-
{
79-
CullMode = CW;
80-
81-
AlphaBlendEnable = false;
82-
AlphaTestEnable = false;
83-
84-
ColorWriteEnable = 0x00;
85-
86-
ZWriteEnable = false;
87-
ZEnable = true;
88-
ZFunc = less;
89-
90-
StencilEnable = true;
91-
StencilWriteMask = 0xFF;
92-
StencilMask = 0xFF;
93-
StencilRef = 0x00;
9474
StencilFunc = always;
95-
StencilFail = keep;
96-
StencilZFail = decr;
97-
StencilPass = keep;
98-
75+
CCW_StencilFail = keep;
76+
CCW_StencilZFail = decr;
77+
CCW_StencilPass = keep;
78+
CCW_StencilFunc = always;
79+
9980
VertexShader = compile vs_2_0 visionVertexShader();
10081
PixelShader = compile ps_2_0 pixelShader();
10182
}
@@ -106,10 +87,10 @@ technique CastBoundaryCCW
10687
pass FrontFace
10788
{
10889
CullMode = CCW;
109-
90+
11091
ColorWriteEnable = 0x00;
11192
DepthBias = CCW_BOUNDARY_BIAS;
112-
93+
11394
ZWriteEnable = false;
11495
ZEnable = true;
11596
ZFunc = less;
@@ -129,7 +110,7 @@ technique CastBoundaryCCW
129110
pass BackFace
130111
{
131112
CullMode = CW;
132-
113+
133114
ColorWriteEnable = 0x00;
134115
DepthBias = CW_BOUNDARY_BIAS;
135116

@@ -156,7 +137,7 @@ technique CastBoundaryCW
156137
pass FrontFace
157138
{
158139
CullMode = CW;
159-
140+
160141
ColorWriteEnable = 0x00;
161142
DepthBias = CW_BOUNDARY_BIAS;
162143

@@ -179,7 +160,7 @@ technique CastBoundaryCW
179160
pass BackFace
180161
{
181162
CullMode = CCW;
182-
163+
183164
ColorWriteEnable = 0x00;
184165
DepthBias = CCW_BOUNDARY_BIAS;
185166

0 commit comments

Comments
 (0)