Skip to content

Commit 1910f7f

Browse files
Update shader style for other shaders to match MonoGame standard
1 parent 6309a45 commit 1910f7f

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
// Pixel shader extracts the brighter areas of an image.
22
// This is the first step in applying a bloom postprocess.
33

4-
sampler TextureSampler : register(s0);
4+
#if OPENGL
5+
#define SV_POSITION POSITION
6+
#define VS_SHADERMODEL vs_3_0
7+
#define PS_SHADERMODEL ps_3_0
8+
#else
9+
#define VS_SHADERMODEL vs_4_0_level_9_1
10+
#define PS_SHADERMODEL ps_4_0_level_9_1
11+
#endif
12+
13+
texture BaseTexture;
14+
15+
sampler2D TextureSampler = sampler_state
16+
{
17+
Texture = <BaseTexture>;
18+
Filter = Linear;
19+
AddressU = clamp;
20+
AddressV = clamp;
21+
};
522

623
float BloomThreshold;
724

25+
struct VS_OUTPUT
26+
{
27+
float4 Position : SV_POSITION0;
28+
float2 TexCoord : TEXCOORD0;
29+
};
830

9-
float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
31+
float4 PixelShaderFunction(VS_OUTPUT input) : COLOR0
1032
{
1133
// Look up the original image color.
12-
float4 c = tex2D(TextureSampler, texCoord);
34+
float4 c = tex2D(TextureSampler, input.TexCoord);
1335

1436
// Adjust it to keep only values brighter than the specified threshold.
1537
return saturate((c - BloomThreshold) / (1 - BloomThreshold));
@@ -20,10 +42,6 @@ technique BloomExtract
2042
{
2143
pass Pass1
2244
{
23-
#if SM4
24-
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
25-
#else
26-
PixelShader = compile ps_2_0 PixelShaderFunction();
27-
#endif
45+
PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
2846
}
2947
}

NeonShooter/NeonShooter.Core/Content/Shaders/GaussianBlur.fx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,44 @@
22
// This is used twice by the bloom postprocess, first to
33
// blur horizontally, and then again to blur vertically.
44

5-
sampler TextureSampler : register(s0);
5+
#if OPENGL
6+
#define SV_POSITION POSITION
7+
#define VS_SHADERMODEL vs_3_0
8+
#define PS_SHADERMODEL ps_3_0
9+
#else
10+
#define VS_SHADERMODEL vs_4_0_level_9_1
11+
#define PS_SHADERMODEL ps_4_0_level_9_1
12+
#endif
13+
14+
texture BaseTexture;
15+
16+
sampler2D TextureSampler = sampler_state
17+
{
18+
Texture = <BaseTexture>;
19+
Filter = Linear;
20+
AddressU = clamp;
21+
AddressV = clamp;
22+
};
623

724
#define SAMPLE_COUNT 15
825

926
float2 SampleOffsets[SAMPLE_COUNT];
1027
float SampleWeights[SAMPLE_COUNT];
1128

29+
struct VS_OUTPUT
30+
{
31+
float4 Position : SV_POSITION0;
32+
float2 TexCoord : TEXCOORD0;
33+
};
1234

13-
float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
35+
float4 PixelShaderFunction(VS_OUTPUT input) : COLOR0
1436
{
1537
float4 c = 0;
1638

1739
// Combine a number of weighted image filter taps.
1840
for (int i = 0; i < SAMPLE_COUNT; i++)
1941
{
20-
c += tex2D(TextureSampler, texCoord + SampleOffsets[i]) * SampleWeights[i];
42+
c += tex2D(TextureSampler, input.TexCoord + SampleOffsets[i]) * SampleWeights[i];
2143
}
2244

2345
return c;
@@ -28,10 +50,6 @@ technique GaussianBlur
2850
{
2951
pass Pass1
3052
{
31-
#if SM4
32-
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
33-
#else
34-
PixelShader = compile ps_2_0 PixelShaderFunction();
35-
#endif
53+
PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
3654
}
3755
}

0 commit comments

Comments
 (0)