Jump to content
  • Advertisement
Sign in to follow this  
Malonn

HLSL Bloom Shader Help

This topic is 2149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry if this isn't the most fitting place to post an HLSL shader question.  If there is a better forum, please let me know.  I'm brand new to GameDev.net.  Anyway, I found a bloom shader that I am trying to convert to run under OBGEv3 (ES IV: Oblivion).  The syntax is mostly HLSL with a few key differences specific to Oblivion Graphics Extender.  You can kinda look at the shader and tell where there's a difference.  Here's the shader:

static const bool description < string help = "Makes bright lights bleed their light into their surroundings."; > = true;

iface float BloomIntensity
< string help = "Controls the intensity of the bloom texture."; >
	= 1.30;

iface float OriginalIntensity
< string help = "Controls the intensity of the original scene texture."; >
	= 1.00;
	
iface float BloomSaturation
< string help = "Saturation amount on bloom."; >
	= 1.00;
	
iface float OriginalSaturation
< string help = "Saturation amount on original scene."; >
	= 1.00;
	

sampler BloomSampler : register(s0);

texture2D obge_LastRendertarget0_EFFECTPASS;

sampler2D ColorMapSampler = sampler_state {
	texture = <obge_LastRendertarget0_EFFECTPASS>;
	AddressU  = CLAMP;
	AddressV  = CLAMP;
	MINFILTER = LINEAR;
	MAGFILTER = LINEAR;
	MIPFILTER = LINEAR;
};

struct VSOUT {
	float4 vertPos : POSITION;
	float2 UVCoord : TEXCOORD0;
};

struct VSIN {
	float4 vertPos : POSITION0;
	float2 UVCoord : TEXCOORD0;
};

VSOUT DummyVS(VSIN IN) {
	VSOUT OUT = (VSOUT)0.0f;	// initialize to zero, avoid complaints.
	OUT.vertPos = IN.vertPos;
	OUT.UVCoord = IN.UVCoord;
	return (OUT);
}

float4 AdjustSaturation(float4 Color, float Saturation) {
	float Grey = dot(Color.rgb, float3(0.3, 0.59, 0.11));
	return lerp(Grey, Color, Saturation);
}

float4 BloomShader(float2 Tex : TEXCOORD0) : COLOR0 {
	float4 bloomColor = tex2D(BloomSampler, Tex);
	float4 originalColor = tex2D(ColorMapSampler, Tex);
	bloomColor = AdjustSaturation(bloomColor, BloomSaturation) * BloomIntensity;
    originalColor = AdjustSaturation(originalColor, OriginalSaturation) * OriginalIntensity;
	originalColor *= (1 - saturate(bloomColor));
	return originalColor + bloomColor;
}

technique main <
	int group = EFFECTGROUP_POST;
	int fxclass = EFFECTCLASS_COLOR;
>

{
	pass p0 {
		VertexShader = compile vs_1_1 DummyVS();
		PixelShader  = compile ps_2_0 BloomShader();
	}
}

It compiles and actually gets applied to the scene.  BUT, a serious problem is there.  Circling (well, ovaling) my crosshair is a big solid white oval.  It blocks the scene wherever it moves, which is wherever my crosshair moves.  I can still see my crosshair, but the rest of the scene is blocked wherever I move the croshair.  I can provide a screenshot if you need one to better see what I'm talking about.  I know very little about HLSL, and have exhausted the only guesses I have as to the problem.  So I'm hoping someone here can see a glaring error as to what would cause a pure white oval "attached" to my crosshair.

 

Thanks,

Malonn

Share this post


Link to post
Share on other sites
Advertisement

Ok. Update time. I figured out that -- keep in mind I have next to no HLSL experience, so even this may be wrong -- the vanilla oblivion game uses sampler s1 for bloom. So I changed:

sampler BloomSampler : register(s0);

to:

sampler BloomSampler : register(s1);

-and that got rid of the solid white oval that was in the middle of the screen.  But through this I realized that the shader effect is NOT being applied to the scene.  I fear it is the OBGE specific elements of the shader.  I understand that many of you may not be familiar with the Oblivion Graphics Extender version 3.1, so may not be able to help.  But I may as well post anything I find along the way just in case.

 

Hopefully someone will come along later and see something.

Share this post


Link to post
Share on other sites

First off, welcome to the community :)  Second, you are right that most people probably aren't familiar with the framework you are using.  Even so, there are some pretty knowledgeable people hanging around here, so there should be some help for you somewhere...

 

It isn't really clear to me what the problem is now - do you have a problem with the shader itself, or is it that you aren't able to get the shader to be applied at all?  The former can probably be helped here in the forums, whereas the latter is probably something better in the game developers forums (the Oblivion forums I mean).

 

Perhaps a screenshot would help us to understand the problem.

Share this post


Link to post
Share on other sites
Thanks! Well the OP problem was that there was a solid white oval in the middle of my screen "attached" to my crosshair. I fixed that. Now the problem is that the bloom effect is not being applied to the scene, at all. I adjust the settings and there is no change to the image. I guess this forum is going to be more helpful with HLSL specific problems, and not so much OBGEv3 specific problems. At first I thought it was an HLSL problem, but now I'm thinking it's OBGEv3. Hopefully I can figure it out, or someone around these here parts is familiar with OBGEv3. Gotta try, you know how it is.

Share this post


Link to post
Share on other sites

Ok. Another update for those who may potentially see the problem: I got the shader to have an effect on the scene. Problem is, it's a negative effect. It's just a completely pitch black screen now. I kinda take that as something positive; better than not doing anything to the scene. Here's the updated shader (as you can see there is less of the OBGE semantics):

// Simple Bloom Shader obtained from XNA Shader Programming

static const bool description < string help = "Makes bright lights bleed their light into their surroundings."; > = true;

iface float BloomIntensity
< string help = "Controls the intensity of the bloom texture."; >
	= 1.30;

iface float OriginalIntensity
< string help = "Controls the intensity of the original scene texture."; >
	= 1.00;
	
iface float BloomSaturation
< string help = "Saturation amount on bloom."; >
	= 1.00;
	
iface float OriginalSaturation
< string help = "Saturation amount on original scene."; >
	= 1.00;
	
texture2D ColorMap;
	
sampler2D BloomSampler : register(s1);

sampler2D ColorMapSampler = sampler_state {
	texture = <ColorMap>;
	AddressU  = CLAMP;
	AddressV  = CLAMP;
	MINFILTER = LINEAR;
	MAGFILTER = LINEAR;
	MIPFILTER = LINEAR;
};

struct VSOUT {
	float4 vertPos : POSITION;
	float2 UVCoord : TEXCOORD0;
};

struct VSIN {
	float4 vertPos : POSITION0;
	float2 UVCoord : TEXCOORD0;
};

VSOUT DummyVS(VSIN IN) {
	VSOUT OUT = (VSOUT)0.0f;	// initialize to zero, avoid complaints.
	OUT.vertPos = IN.vertPos;
	OUT.UVCoord = IN.UVCoord;
	return (OUT);
}

float4 AdjustSaturation(float4 Color, float Saturation) {
	float Grey = dot(Color, float4(0.3, 0.59, 0.11, 0.0));
	return lerp(Grey, Color, Saturation);
}

float4 BloomShader(float2 Tex : TEXCOORD0) : COLOR0 {
	float4 bloomColor = tex2D(BloomSampler, Tex);
	float4 originalColor = tex2D(ColorMapSampler, Tex);
	bloomColor = AdjustSaturation(bloomColor, BloomSaturation) * BloomIntensity;
    originalColor = AdjustSaturation(originalColor, OriginalSaturation) * OriginalIntensity;
	originalColor *= (1 - saturate(bloomColor));
	return originalColor + bloomColor;
}

technique main <
	int group = EFFECTGROUP_POST;
	int fxclass = EFFECTCLASS_COLOR;
>

{
	pass p0 {
		VertexShader = compile vs_1_1 DummyVS();
		PixelShader  = compile ps_2_0 BloomShader();
	}
}

Well, hopefully a guru will peek at this thread and see something glaring.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!