Quick bloom q

Started by
11 comments, last by matches81 17 years, 9 months ago
Ive only been reading up on bloom for a few days now so forgive my noobness. The problem is, I want to add a bloom effect to the engine im working in, but I dont have direct access to the frame buffer. I can however render the screen to a texture, and then slap that image onto a billboard/sprite infront of a the camera (hacky I know, but what are you gonna do). So, assuming I could get a image of the screen (prolly max 512x512 res), texture it to a sprite infront of the camera, would it then be possible to write a pixel shader that does the bloom (blurs the image, sets transparency, ect...)?
Advertisement
Quote:hacky I know, but what are you gonna do

that's the standard way of doing it with any post process effect.
Quote:
So, assuming I could get a image of the screen (prolly max 512x512 res), texture it to a sprite infront of the camera, would it then be possible to write a pixel shader that does the bloom (blurs the image, sets transparency, ect...)?

yes. i think u usually sample the texture down first and then blur it.

regards,
m4gnus
"There are 10 types of people in the world... those who understand binary and those who don't."
Wait, I thought "real" post process effects manipulated the frame buffer directly (I guess I was wrong)? So its not really hacky to slap a full screen plain infront of the camera, and do all yer post process effects there? Thats good to hear...
Boy this is harder than I thought... so I stream the output of my camera to a texture, and slap that on a fullscreen quad, looks good. Now I apply my bloom shader to the quad, ok so far. The problem is, im looking at some of the bloom shaders that are in the direct x sdk, and they all seem to be sampling MANY different textures. Shouldnt the shader only need one texture sample (the camera output)?

Does anyone have a no fuss no muss bloom shader (hlsl pref)? One that takes a image, "blooms"/blurs it, and NOTHING else would be perfect.
Quote:Original post by ZealousEngine
The problem is, im looking at some of the bloom shaders that are in the direct x sdk, and they all seem to be sampling MANY different textures. Shouldnt the shader only need one texture sample (the camera output)?

Typically you only use one texture as input (the one grabbed from the framebuffer you want to blur), but to perform the blur you need to take multiple samples and avarage the result.

The arangement and weighting of the samples determines how the end result looks.
Quote:Original post by OrangyTang
Quote:Original post by ZealousEngine
The problem is, im looking at some of the bloom shaders that are in the direct x sdk, and they all seem to be sampling MANY different textures. Shouldnt the shader only need one texture sample (the camera output)?

Typically you only use one texture as input (the one grabbed from the framebuffer you want to blur), but to perform the blur you need to take multiple samples and avarage the result.

The arangement and weighting of the samples determines how the end result looks.


I´ve also read about a bloom effect that uses the framebuffer grab to generate a second texture called "bright-pass", which is usually a lower resolution and contains the parts of the image with a brightness higher than a certain threshold. This bright-pass texture is then blurred and added onto the original framebuffer grab to do the bloom effect.
That would explain using more than one texture for bloom, right?
Quote:Original post by matches81
I´ve also read about a bloom effect that uses the framebuffer grab to generate a second texture called "bright-pass", which is usually a lower resolution and contains the parts of the image with a brightness higher than a certain threshold. This bright-pass texture is then blurred and added onto the original framebuffer grab to do the bloom effect.
That would explain using more than one texture for bloom, right?

Yeah, to get a nice bloom effect you usually need some way of indicating which bits are 'bright' and which aren't. I usually do this by rendering the scene with a separate set of 'bright' textures, which are usually mostly black with the glowing bits in bright colours. Then the blur just needs the one input texture. However you could always use the regular framebuffer and a separate brightness texture when doing the blur. Whether thats more efficient is probably going to depend on whether you can reuse some bits from the rest of the rendering (like, say, reusing the framebuffer texture you're also using for a heat-haze effect).
Quote:Original post by ZealousEngine
Boy this is harder than I thought... so I stream the output of my camera to a texture, and slap that on a fullscreen quad, looks good. Now I apply my bloom shader to the quad, ok so far. The problem is, im looking at some of the bloom shaders that are in the direct x sdk, and they all seem to be sampling MANY different textures. Shouldnt the shader only need one texture sample (the camera output)?

Does anyone have a no fuss no muss bloom shader (hlsl pref)? One that takes a image, "blooms"/blurs it, and NOTHING else would be perfect.


Bloom can consist of several passes depending on how you do it, and often times each pass samples the texture produced by the previous pass, and renders to a new texture to be used by the next pass.

OrangyTang's method eliminates the need for a bright pass (which is otherwise essential: it's a key element that differentiates Bloom from simple blurring) so he doesn't need as many textures or passes.

The blur itself can be done in many ways. I do mine as a separable Gaussian blur, meaning the bright-pass texture is blurred horizontally and then vertically.
Thanks for the info guys! Im afraid im gonna need a quick "shaders 101" if im going to proceed any further, maybe one of you can help me out. Here is what my bloom shader looks like right now (just a bare bones template)...

/***************************************   Bloom Shader                *******************************************   Written by - Jeff Wieland   ******   07.08.06                    ***************************************///=========//UN-TWEAKS//=========matrix WorldViewProj:	WorldViewProjection;matrix World:		World;//======//TWEAKS//======//========//TEXTURES//========//frame imagetexture frameImg <string name = ""; >;sampler frameImgSamp = sampler_state { texture = (frameImg); };//============//DATA STRUCTS//============//application to vertex shaderstruct a2v {	double4 pos:		POSITION;	float2 uv:		TEXCOORD0;}; //vertex shader to pixel shaderstruct v2p {	double4 pos:		POSITION;	float2 uv:		TEXCOORD0;};//pixel shader to framestruct p2f {	float4 color:		COLOR;};//=============//VERTEX SHADER//=============void VS( in a2v IN, out v2p OUT ) {	//project the vertex onto the screen	OUT.pos = mul(IN.pos,WorldViewProj);	OUT.uv = IN.uv;} //end VS()//============//PIXEL SHADER//============void PS( in v2p IN, out p2f OUT ) {	OUT.color = tex2D( frameImgSamp, IN.uv );} //end PS()//=========//TECHNIQUE//=========technique T {	pass p0 {				VertexShader = compile vs_2_0 VS(); 		PixelShader = compile ps_2_0 PS(); 			}}


It works great! Its only missing one thing.. the uh.. bloom.

Anyway, ive been reading up on the 'post process' sample included in the directx sdk, and they have a lot of shaders that are confusing me. They look VERY different from my 'template', and have lots of little sub functions scattered all over the place. Like this one...

//-----------------------------------------------------------------------------// Pixel Shader: DownFilter// Desc: Perform a high-pass filter and on the source texture and scale down.//-----------------------------------------------------------------------------float4 DownFilter( in float2 Tex : TEXCOORD0 ) : COLOR0{    float4 Color = 0;    for (int i = 0; i < 16; i++)    {        Color += tex2D( g_samSrcColor, Tex + TexelCoordsDownFilter.xy );    }    return Color / 16;}


I know I need to down sample my frame image in order to do the blur ect, but how do I "use" this function/code in my existing template.

I really like MY template, I think its very neat and organized. The way the sdk example is doing things scares me.
Im gonna give this another shot today. Im still a little fuzzy on the whole technique and multipass thing... I know I need to do each blur 'horizontal and vertical' one at a time, but I dont have a lot of experience with 'multi pass' effects. I think I could pluck out the effects from the directx sdk, but how do I 'order' them so they are run one at a time?

This topic is closed to new replies.

Advertisement