-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurface.fx
171 lines (141 loc) · 3.65 KB
/
Surface.fx
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
DepthStencilState EnableDepth
{
DepthEnable = TRUE;
DepthWriteMask = ALL;
DepthFunc = LESS_EQUAL;
};
DepthStencilState DisableDepth
{
DepthEnable = FALSE;
DepthWriteMask = ZERO;
};
RasterizerState CullNone
{
MultiSampleEnable = True;
CullMode = None;
};
RasterizerState Wireframe
{
FillMode = WIREFRAME;
};
BlendState AlphaBlending
{
AlphaToCoverageEnable = FALSE;
BlendEnable[0] = TRUE;
SrcBlend = SRC_ALPHA;
DestBlend = INV_SRC_ALPHA;
BlendOp = ADD;
SrcBlendAlpha = SRC_ALPHA;
DestBlendAlpha = INV_SRC_ALPHA;
BlendOpAlpha = ADD;
RenderTargetWriteMask[0] = 0x0F;
};
SamplerState textureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
AddressW = Wrap;
BorderColor = float4(0,0,0,0);
};
matrix ModelViewProjectionMatrix;
matrix NormalMatrix;
bool bIsTextured;
Texture2D SurfaceTexture;
//--------------------------------------------------------------------------------------
struct VsInput
{
float3 Pos : POSITION;
float2 TexCoord : TEXCOORD;
float4 Color : COLOR;
};
struct VsOutput
{
float4 Pos : SV_POSITION;
float2 TexCoord : TEXCOORD;
float4 Color : COLOR;
};
struct PsOutput
{
float4 Color : SV_Target0;
};
//--------------------------------------------------------------------------------------
// Vertex Shaders
//--------------------------------------------------------------------------------------
VsOutput VS_COLOR(VsInput input)
{
VsOutput output;
output.Pos = mul(float4(input.Pos, 1.0f), ModelViewProjectionMatrix);
output.TexCoord = input.TexCoord;
output.Color = input.Color;
return output;
}
VsOutput VS_WIREFRAME(VsInput input)
{
VsOutput output;
output.Pos = mul(float4(input.Pos, 1.0f), ModelViewProjectionMatrix);
output.Color = input.Color;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shaders
//--------------------------------------------------------------------------------------
PsOutput PS_COLOR( VsOutput input )
{
PsOutput output;
if(bIsTextured)
{
output.Color = SurfaceTexture.Sample(textureSampler, input.TexCoord);
output.Color.a = 1.0f;
}
else
{
//output.Color = float4(input.Color.r, 0.0, 0.0, 1.0);
//output.Color = float4(input.Color.g, 0.0, 0.0, 1.0);
//output.Color = float4(input.Color.b, 0.0, 0.0, 1.0);
output.Color = input.Color;
}
output.Color.a = 0.25f;
return output;
}
PsOutput PS_WIREFRAME(VsOutput input)
{
PsOutput output;
if(bIsTextured)
{
output.Color = SurfaceTexture.Sample(textureSampler, input.TexCoord);
output.Color.a = 1.0f;
}
else
{
//output.Color = float4(input.Color.r, 0.0, 0.0, 1.0);
//output.Color = float4(input.Color.g, 0.0, 0.0, 1.0);
//output.Color = float4(input.Color.b, 0.0, 0.0, 1.0);
//output.Color = float4(input.Color.a, 0.0, 0.0, 1.0);
output.Color = input.Color;
}
return output;
}
//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique10 RenderColor
{
pass
{
SetVertexShader( CompileShader( vs_4_0, VS_COLOR() ) );
SetGeometryShader(NULL);
SetPixelShader( CompileShader( ps_4_0, PS_COLOR() ) );
SetBlendState(AlphaBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
SetDepthStencilState( DisableDepth, 0 );
SetRasterizerState(CullNone);
}
pass
{
SetVertexShader(CompileShader(vs_4_0, VS_COLOR()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PS_WIREFRAME()));
SetDepthStencilState(DisableDepth, 0);
SetRasterizerState(Wireframe);
}
}