For the platform I'm targeting with MonoGame, I'm needing to replace all tex2d calls with a call to Sample from a Texture2D object.
Right now I'm trying to update my shaders in the PC/XNA4 version of my game. I'm trying to update the BloomCombine.fx shader from the XNA Bloom sample but all I'm seeing right now is a black screen.
The culprit is these lines:
float4 bloom = bloomTexture.Sample(BloomSampler, texCoord);
float4 base = baseTexture.Sample(BaseSampler, texCoord
I had to make new Texture2D objects, seperate from the samplers, but do I need to set these from my XNA code? I'm setting them to a register, so to my understanding it should work fine, just like how the samplers are set to a register.
Here's what I have so far:
// Pixel shader combines the bloom image with the original
// scene, using tweakable intensity levels and saturation.
// This is the final step in applying a bloom postprocess.
SamplerState BloomSampler : register(s0);
SamplerState BaseSampler : register(s1);
Texture2D<float4> bloomTexture : register(t0);
Texture2D<float4> baseTexture : register(t1);
float BloomIntensity;
float BaseIntensity;
float BloomSaturation;
float BaseSaturation;
// Helper for modifying the saturation of a color.
float4 AdjustSaturation(float4 color, float saturation)
{
// The constants 0.3, 0.59, and 0.11 are chosen because the
// human eye is more sensitive to green light, and less to blue.
float grey = dot(color, float4(0.3, 0.59, 0.11, 1));
return lerp(grey, color, saturation);
}
float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
{
// Look up the bloom and original base image colors.
//float4 bloom = tex2D(BloomSampler, texCoord);
//float4 base = tex2D(BaseSampler, texCoord); << Old code
float4 bloom = bloomTexture.Sample(BloomSampler, texCoord);
float4 base = baseTexture.Sample(BaseSampler, texCoord);
// Adjust color saturation and intensity.
bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;
// Darken down the base image in areas where there is a lot of bloom,
// to prevent things looking excessively burned-out.
base *= (1 - saturate(bloom));
// Combine the two images.
return base + bloom;
}
technique BloomCombine
{
pass Pass1
{
#if SM4
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
#elif SM3
PixelShader = compile ps_3_0 PixelShaderFunction();
#else
PixelShader = compile ps_2_0 PixelShaderFunction();
#endif
}
}