Skip to content

Commit 2d9f52a

Browse files
Merge branch '3.8.4' of https://github.com/MonoGame/MonoGame.Samples into feature/NeonShoorter-bloom-patch
2 parents 1e41a58 + ce86f31 commit 2d9f52a

File tree

4 files changed

+77
-91
lines changed

4 files changed

+77
-91
lines changed

NeonShooter/NeonShooter.Core/Content/Shaders/BloomCombine.fx

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,24 @@
1+
///-------------------------------------------------------------------------------------------------
2+
/// <remarks>
3+
/// Charles Humphrey, 12/07/2025.
4+
/// Fixes for DX implementation.
5+
/// </remarks>
6+
///-------------------------------------------------------------------------------------------------
7+
#include "PPVertexShader.fxh"
8+
19
// Pixel shader combines the bloom image with the original
210
// scene, using tweakable intensity levels and saturation.
311
// This is the final step in applying a bloom postprocess.
412

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-
Texture2D BloomTexture;
15-
Texture2D BaseTexture;
16-
17-
SamplerState BloomSampler = sampler_state
18-
{
19-
Texture = <BloomTexture>;
20-
Filter = Linear;
21-
AddressU = clamp;
22-
AddressV = clamp;
23-
};
24-
25-
SamplerState BaseSampler = sampler_state
26-
{
27-
Texture = <BaseTexture>;
28-
Filter = Linear;
29-
AddressU = clamp;
30-
AddressV = clamp;
31-
};
13+
sampler BloomSampler : register(s0);
14+
sampler BaseSampler : register(s1);
3215

3316
float BloomIntensity;
3417
float BaseIntensity;
3518

3619
float BloomSaturation;
3720
float BaseSaturation;
3821

39-
struct VS_OUTPUT
40-
{
41-
float4 Position : SV_POSITION0;
42-
float2 TexCoord : TEXCOORD0;
43-
};
4422

4523
// Helper for modifying the saturation of a color.
4624
float4 AdjustSaturation(float4 color, float saturation)
@@ -52,12 +30,17 @@ float4 AdjustSaturation(float4 color, float saturation)
5230
return lerp(grey, color, saturation);
5331
}
5432

33+
///-------------------------------------------------------------------------------------------------
34+
/// <summary> Function now uses correct vertex input structure for both OGL and DX </summary>
35+
///
36+
/// <remarks> Charles Humphrey, 12/07/2025. </remarks>
37+
///-------------------------------------------------------------------------------------------------
5538

56-
float4 PixelShaderFunction(VS_OUTPUT input) : SV_TARGET0
39+
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
5740
{
5841
// Look up the bloom and original base image colors.
59-
float4 bloom = BaseTexture.Sample(BloomSampler, input.TexCoord);
60-
float4 base = BaseTexture.Sample(BaseSampler, input.TexCoord);
42+
float4 bloom = tex2D(BloomSampler, input.TexCoord);
43+
float4 base = tex2D(BaseSampler, input.TexCoord);
6144

6245
// Adjust color saturation and intensity.
6346
bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;

NeonShooter/NeonShooter.Core/Content/Shaders/BloomExtract.fx

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,26 @@
1-
// Pixel shader extracts the brighter areas of an image.
2-
// This is the first step in applying a bloom postprocess.
1+
///-------------------------------------------------------------------------------------------------
2+
/// <remarks>
3+
/// Charles Humphrey, 12/07/2025.
4+
/// Fixes for DX implementation.
5+
/// </remarks>
6+
///-------------------------------------------------------------------------------------------------
7+
#include "PPVertexShader.fxh"
38

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-
};
9+
sampler TextureSampler : register(s0);
2210

2311
float BloomThreshold;
2412

25-
struct VS_OUTPUT
13+
///-------------------------------------------------------------------------------------------------
14+
/// <summary> Function now uses correct vertex input structure for both OGL and DX </summary>
15+
///
16+
/// <remarks> Charles Humphrey, 12/07/2025. </remarks>
17+
///-------------------------------------------------------------------------------------------------
18+
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
2619
{
27-
float4 Position : SV_POSITION0;
28-
float2 TexCoord : TEXCOORD0;
29-
};
30-
31-
float4 PixelShaderFunction(VS_OUTPUT input) : COLOR0
32-
{
33-
// Look up the original image color.
3420
float4 c = tex2D(TextureSampler, input.TexCoord);
35-
36-
// Adjust it to keep only values brighter than the specified threshold.
3721
return saturate((c - BloomThreshold) / (1 - BloomThreshold));
3822
}
3923

40-
4124
technique BloomExtract
4225
{
4326
pass Pass1

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1+
///-------------------------------------------------------------------------------------------------
2+
/// <remarks>
3+
/// Charles Humphrey, 12/07/2025.
4+
/// Fixes for DX implementation.
5+
/// </remarks>
6+
///-------------------------------------------------------------------------------------------------
7+
#include "PPVertexShader.fxh"
8+
19
// Pixel shader applies a one dimensional gaussian blur filter.
210
// This is used twice by the bloom postprocess, first to
311
// blur horizontally, and then again to blur vertically.
412

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-
};
13+
sampler TextureSampler : register(s0);
2314

2415
#define SAMPLE_COUNT 15
2516

2617
float2 SampleOffsets[SAMPLE_COUNT];
2718
float SampleWeights[SAMPLE_COUNT];
2819

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

35-
float4 PixelShaderFunction(VS_OUTPUT input) : COLOR0
21+
///-------------------------------------------------------------------------------------------------
22+
/// <summary> Function now uses correct vertex input structure for both OGL and DX </summary>
23+
///
24+
/// <remarks> Charles Humphrey, 12/07/2025. </remarks>
25+
///-------------------------------------------------------------------------------------------------
26+
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
3627
{
3728
float4 c = 0;
3829

3930
// Combine a number of weighted image filter taps.
4031
for (int i = 0; i < SAMPLE_COUNT; i++)
4132
{
42-
c += tex2D(TextureSampler, input.TexCoord + SampleOffsets[i]) * SampleWeights[i];
33+
// Charles Humphrey, altered this to give a better effect with the blur. Was too heavy before.
34+
// This should really be done where the offsets and weights are calculated.
35+
c += tex2D(TextureSampler, input.TexCoord + SampleOffsets[i] * .0125) * SampleWeights[i] * 5;
36+
37+
// Was:
38+
//c += tex2D(TextureSampler, input.TexCoord + SampleOffsets[i]) * SampleWeights[i];
4339
}
4440

4541
return c;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
///-------------------------------------------------------------------------------------------------
2+
/// <summary>
3+
/// This header file is for used to ensure vertex patching in the DX build.
4+
/// </summary>
5+
///
6+
/// <remarks> Charles Humphrey, 12/07/2025. </remarks>
7+
///-------------------------------------------------------------------------------------------------
8+
9+
10+
#if OPENGL
11+
#define SV_POSITION POSITION
12+
#define VS_SHADERMODEL vs_3_0
13+
#define PS_SHADERMODEL ps_3_0
14+
#else
15+
#define VS_SHADERMODEL vs_4_0_level_9_1
16+
#define PS_SHADERMODEL ps_4_0_level_9_1
17+
#endif
18+
19+
struct VertexShaderOutput
20+
{
21+
float4 Position : SV_POSITION;
22+
float4 Color : COLOR0;
23+
float2 TexCoord : TEXCOORD0;
24+
};

0 commit comments

Comments
 (0)