Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float BloomThreshold;
- float BloomIntensity;
- float BaseIntensity;
- float BloomSaturation;
- float BaseSaturation;
- float sceneX, sceneY;
- texture procScene;
- texture blur;
- sampler scene = sampler_state
- {
- texture = <procScene>;
- };
- sampler TextureSampler2 = sampler_state
- {
- texture = <blur>;
- };
- #define SAMPLE_COUNT 15
- float2 SampleOffsetsX[SAMPLE_COUNT];
- float2 SampleOffsetsY[SAMPLE_COUNT];
- float SampleWeights[SAMPLE_COUNT];
- float4 AdjustSaturation(float4 color, float saturation)
- {
- float grey = dot(color, float3(0.3, 0.59, 0.2));
- return lerp(grey, color, saturation);
- }
- float4 Extract(float2 texCoord : TEXCOORD0) : COLOR0
- {
- // Look up the original image color.
- float4 c = tex2D(scene, texCoord);
- // Adjust it to keep only values brighter than the specified threshold.
- return saturate((c - BloomThreshold) / (1 - BloomThreshold));
- }
- float4 BlurHorz(float2 texCoord : TEXCOORD0) : COLOR0
- {
- float4 c = 0;
- for (int i = 0; i < SAMPLE_COUNT; i++)
- {
- c += tex2D(TextureSampler2, texCoord + SampleOffsetsX[i]) * SampleWeights[i];
- }
- return c;
- }
- float4 BlurVert(float2 texCoord : TEXCOORD0) : COLOR0
- {
- float4 c = 0;
- for (int i = 0; i < SAMPLE_COUNT; i++)
- {
- c += tex2D(TextureSampler2, texCoord + SampleOffsetsY[i]) * SampleWeights[i];
- }
- return c;
- }
- float4 Combine (float2 texCoord : TEXCOORD0) : COLOR0
- {
- float4 bloom = tex2D(TextureSampler2, texCoord);
- float4 base = tex2D(scene, texCoord);
- bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
- base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;
- base *= (1 - saturate(bloom));
- return base + bloom;
- }
- technique Bloom
- {
- pass Pass1
- {
- PixelShader = compile ps_2_0 Extract();
- }
- pass Pass2
- {
- PixelShader = compile ps_2_0 BlurHorz();
- }
- pass Pass3
- {
- PixelShader = compile ps_2_0 BlurVert();
- }
- pass Pass4
- {
- PixelShader = compile ps_2_0 Combine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement