pp bloom in gamestudio

Posted By: Scorpion

pp bloom in gamestudio - 11/24/07 13:44

Here i wrote some post processing shaders, which become combined a bloom effect.

1. The normal screen is rendered


2. All Pixels are darker then a specific value become black


3.Vertical Blur


4.Horizontal Blur


3.The pixel value of this picture is now added to the orginal picture + some color corrections


Hope you like it :]

PS: that white thing is a unskinned goblet test model^^
Posted By: broozar

Re: pp bloom in gamestudio - 11/24/07 14:47

code! code! code! only for a7 and a6 pro with rtt? or a6 comm as well (yummie!)?
Posted By: Endgegner

Re: pp bloom in gamestudio - 11/24/07 15:05

Nice stuff =). By the way, is this how "real" bloom shaders work?
Posted By: Slin

Re: pp bloom in gamestudio - 11/24/07 15:19

Nothing special, but looks good

@Endgegner: I think that this is how bloom works.

Just have a look at the wiki. I added a bloom shader there. It does everything in one stage which causes lower quality but makes it easier to use it without the latest beta version of A7.
Posted By: Scorpion

Re: pp bloom in gamestudio - 11/24/07 15:24

it's how "real" bloom works

I tried out the new pp-feature with view of the latest A7-beta, so not everyone can really use that code

Code:
BMAP* FirstScreen = "#1024x768x32";

var blurStrongness = 40;
var blurRadius = 0.3;
var blurAlpha = 40;
var darken = 90;
var greyOut = 90;

MATERIAL* mtlBlackout =
{
effect = "
Texture TargetMap;
sampler2D smpSource = sampler_state { texture = <TargetMap>; };
float4 vecViewPort; // contains viewport pixel size in zw components
float4 vecSkill1;
float4 BlackoutPS( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color = tex2D(smpSource,Tex.xy-vecViewPort.zw);
if((Color.r+Color.g+Color.b)/3<vecSkill1.x)
{
Color.rgb = 0;
}
return Color;
}

technique emboss { pass one { PixelShader = compile ps_2_0 BlackoutPS(); } }
technique fallback { pass one { } }";
}

MATERIAL* mtlBlurH =
{
effect = "
float4 vecViewPort;
float4 vecSkill1;
static int blurRadius = 5;//number of px

Texture TargetMap;
sampler2D smpSource = sampler_state{texture=<TargetMap>;};

float4 BlurHPS( float2 Tex: TEXCOORD0):COLOR0
{
float4 Color = tex2D(smpSource,Tex.xy-vecViewPort.zw);
float2 tempTex;
tempTex.y = Tex.y;
for(int i=-blurRadius;i<=blurRadius;i++)
{
tempTex.x = Tex.x+i*vecSkill1;
Color += tex2D(smpSource,tempTex.xy-vecViewPort.zw);
}
return Color/(blurRadius*2+1);
}

technique Blackout { pass one { PixelShader = compile ps_2_0 BlurHPS();}}
technique fallback { pass one { } }";
}

MATERIAL* mtlBlurV =
{
effect = "
float4 vecViewPort;
float4 vecSkill1;
static int blurRadius = 5;//number of px

Texture TargetMap;
sampler2D smpSource = sampler_state{texture=<TargetMap>;};

float4 BlurVPS( float2 Tex: TEXCOORD0):COLOR0
{
float4 Color = tex2D(smpSource,Tex.xy-vecViewPort.zw);
float2 tempTex;
tempTex.x = Tex.x;
for(int i=-blurRadius;i<=blurRadius;i++)
{
tempTex.y = Tex.y+i*vecSkill1.x;
Color += tex2D(smpSource,tempTex.xy-vecViewPort.zw);
}
return Color/(blurRadius*2+1);
}

technique Blackout { pass one { PixelShader = compile ps_2_0 BlurVPS();}}
technique fallback { pass one { } }";
}

MATERIAL* mtlAdd =
{
skin1 = FirstScreen;
effect = "
float4 vecViewPort;
float4 vecSkill1;

Texture TargetMap;
Texture mtlSkin1;
sampler2D smpSource = sampler_state{texture=<TargetMap>;};
sampler2D firstScreen = sampler_state{texture=<mtlSkin1>;};

float4 AddPS( float2 Tex: TEXCOORD0):COLOR0
{
float4 Color = tex2D(firstScreen,Tex);
Color += vecSkill1.x*tex2D(smpSource,Tex);
return lerp(Color,(Color.r+Color.g+Color.b)/3,vecSkill1.z)*vecSkill1.y;
}
technique Blackout { pass one { PixelShader = compile ps_2_0 AddPS();}}
technique fallback { pass one { } }";
}

VIEW* viewBlackout = { material = mtlBlackout; flags = PROCESS_TARGET; }
VIEW* viewBlurH = { material = mtlBlurH; flags=PROCESS_TARGET;}
VIEW* viewBlurV = { material = mtlBlurV; flags=PROCESS_TARGET;}
VIEW* viewAdd = { material = mtlAdd; flags=PROCESS_TARGET;}

void controlBloomSettings()
{
camera.bmap = FirstScreen;
camera.stage = viewBlackout;
viewBlackout.stage = viewBlurH;
viewBlurH.stage = viewBlurV;
viewBlurV.stage = viewAdd;
while(1)
{
mtlBlackout.skill1 = floatv((100-blurStrongness)/100);
mtlBlurH.skill1 = floatv(blurRadius/100);
mtlBlurV.skill1 = floatv(blurRadius/100);
mtlAdd.skill1 = floatv(blurAlpha/100);
mtlAdd.skill2 = floatv(darken/100);
mtlAdd.skill3 = floatv((100-greyOut)/100);
wait(1);
}
}


PS: I use vars, because only then the panel elements show right results...
Posted By: mpdeveloper_B

Re: pp bloom in gamestudio - 11/24/07 15:57

wow, this is a real bloom shader, finally someone made one, also, is it possible to convert this to a6 code?
Posted By: Scorpion

Re: pp bloom in gamestudio - 11/24/07 16:34

no, not without a dll or sth.
Posted By: mpdeveloper_B

Re: pp bloom in gamestudio - 11/24/07 17:32

k, thanks
Posted By: HeelX

Re: pp bloom in gamestudio - 11/24/07 18:23

Very nice! I hope JCL releases a public version before Christmas..
Posted By: frazzle

Re: pp bloom in gamestudio - 11/24/07 19:05

Interesting concept Shorpion
This really encourages me to update asap to A7 commercial, but I'm waiting untill most issue are cleared out

Cheers

Frazzle
Posted By: JibbSmart

Re: pp bloom in gamestudio - 11/24/07 22:54

just one (two-part) question:

why are the horizontal and vertical blurs done separately? wouldn't it be faster to use one less view and do them together?

julz
Posted By: Scorpion

Re: pp bloom in gamestudio - 11/24/07 23:39

no, it uses a lot less texture lookups...it's a little loss in quality, but a big benefit in speed.here is a nice site about it:
http://www.blackpawn.com/texts/blur/default.html

and i did a shader, that does it all in one pass, but the quality is worse. But this way you can use it in A6, too.

Code:
float4x4 matWorldViewProj;
float4 vecSkill1;
float4 vecSkill5;

texture entSkin1;

sampler2D colorMap = sampler_state{Texture=<entSkin1>;};

void bloomVS( in float4 pos :POSITION,
in float2 tex :TEXCOORD0,
out float4 oPos :POSITION,
out float2 oTex :TEXCOORD0)
{
oPos=mul(pos,matWorldViewProj);
oTex=tex;
}

float4 isBlack(uniform float4 lookup)
{
if((lookup.r+lookup.g+lookup.b)/3>vecSkill1.x)
{
return lookup;
}
else
{
return 0;
}
}

float4 bloomPS( in float2 texcrd :TEXCOORD0):COLOR
{
float4 Color = tex2D(colorMap,texcrd);
float4 Blurred = isBlack(Color);
Blurred += isBlack(tex2D(colorMap,texcrd+vecSkill1.y));
Blurred += isBlack(tex2D(colorMap,texcrd-vecSkill1.y));
Blurred += isBlack(tex2D(colorMap,texcrd+vecSkill1.y*2));
Blurred += isBlack(tex2D(colorMap,texcrd-vecSkill1.y*2));

//here you could add 4 more texlookups for the other "side" => looks better,worse performance
/*float2 tempCrd;
tempCrd.x = vecSkill1.y;
tempCrd.y = -vecSkill1.y;
Blurred += isBlack(tex2D(colorMap,texcrd+tempCrd));
tempCrd.x = -vecSkill1.y;
tempCrd.y = vecSkill1.y;
Blurred += isBlack(tex2D(colorMap,texcrd-tempCrd));
tempCrd.x = vecSkill1.y*2;
tempCrd.y = -vecSkill1.y*2;
Blurred += isBlack(tex2D(colorMap,texcrd+tempCrd));
tempCrd.x = -vecSkill1.y*2;
tempCrd.y = vecSkill1.y*2;
Blurred += isBlack(tex2D(colorMap,texcrd-tempCrd));*/

//here you can add as much texlookups as you want...

Blurred/=5;
Color += vecSkill1.z*Blurred;
Color=lerp(Color,(Color.r+Color.g+Color.b)/3,vecSkill5.x)*vecSkill1.w;
Color.w = 1;
return Color;//
}

technique bloom
{
pass p0
{
vertexShader = compile vs_1_0 bloomVS();
pixelShader = compile ps_2_0 bloomPS();
}
}



Have fun!
Posted By: BoH_Havoc

Re: pp bloom in gamestudio - 11/25/07 02:43

Quote:

why are the horizontal and vertical blurs done separately? wouldn't it be faster to use one less view and do them together?





First it would be kinda slow as Scorpion already mentioned.
Second you would get a "star-shaped" bloom effect and not a "circular" one as you aren't able to use the blurred scene again in the same pass and blur it again horizontally/vertically

Oh and btw you can do this in A6, but you have to use some workarounds. As you aren't able to use stages as in A7 beta, you have to render PPEed scene to a plane, put a view in front of that plane, render the plane through the view and use this rendertarget in the next step. It works, but you also get some kind of "bloom-motionblur" effect, as you need 3 frames to compute the whole bloom thing (brightpass,hblur,vblur+combine)... sooo.... go for A7
Posted By: JibbSmart

Re: pp bloom in gamestudio - 11/25/07 03:52

okay cool.

and yeah, a7 rules.

julz
Posted By: Excessus

Re: pp bloom in gamestudio - 11/25/07 13:43

Quote:

if((Color.r+Color.g+Color.b)/3<vecSkill1.x)
{
Color.rgb = 0;
}




I think you will get a better quality bloom if you just calculate the luminance instead of making dark parts black. You can calculate luminance like this:
float lum = dot(color, float3(0.299f, 0.587f, 0.114f);
return (float3)lum;

Then just blur it and blend with the original render like you already do.
Posted By: Scorpion

Re: pp bloom in gamestudio - 11/28/07 15:31

thank you, that really looks better :]
Posted By: Inestical

Re: pp bloom in gamestudio - 11/28/07 17:07

also you should try to bloom only REAALLY white'n bright colours, since from the shots, it looks pretty bad, even though the effect is correctly rendered
Posted By: Scorpion

Re: pp bloom in gamestudio - 11/28/07 18:24

You can control that by a value from 0-1 passed to the shader. So maybe I set it a bit too height in the shots...
Posted By: Inestical

Re: pp bloom in gamestudio - 11/28/07 22:53

no, it's too low in the shots
Posted By: Gumby22don

Re: pp bloom in gamestudio - 11/29/07 11:59

That is cool. I wasn't going to comment, but it suddenly occured to me.

I've never touched shaders, but could this sort of thing be used in conjunction with the old "flame" effect that used to go around in the mid 90's? I imagine the right sort of algorithm would give a heat haze sort of effect.

Anyone remember what I'm talking about and think it would work?

Don
have a great day
Posted By: Slin

Re: pp bloom in gamestudio - 11/29/07 15:26

@Scorpion: Would you mind adding the code to the 3DGS Wiki? If you donīt have the time to but donīt mind, I could do it as well.

@Gumby22don: I donīt know what you are talking about, but Iīm actually learning some more about shaders and am going to create some heat haze effect. But it isnīt really possible with this effect. I will add it to the wiki than, though it probably takes some more time until than...
Posted By: Scorpion

Re: pp bloom in gamestudio - 11/29/07 15:37

I don't mind if you do it.^^
maybe it would be good to write a hint: only aviable @ A7.07 and above or sth.
Posted By: Slin

Re: pp bloom in gamestudio - 11/29/07 15:58

I am not done with that wiki section yet (adding "my" shadercollection and try to put some of the shaders to an other site, so that on the main shadersection is only a selection of the most usable shaders and so on...) and it will take me some time to add the code, since Iīm learning for school at the moment (you see why I am posting that much )...^^
But I will definatly add it soon

Sorry for going off-topic...
Posted By: Frederick_Lim

Re: pp bloom in gamestudio - 12/21/07 02:37

A7.07 really looks good with this effect, my scene looks really good with these parameters.
Code:
var blurStrongness = 60;
var blurRadius = 0.5;
var blurAlpha = 80;
var darken = 90;
var greyOut = 140;


Posted By: William

Re: pp bloom in gamestudio - 12/21/07 02:53

How would someone add Excessus's suggestion to the A7 code? I really like this effect, but I need the areas that are not white(for example, a sandy color, or the skycube) to brighten/bloom up as well. Because on some textures, the white is a bit too spotty, so the bloom looks like it's spotted allover the ground.
Posted By: Frederick_Lim

Re: pp bloom in gamestudio - 12/21/07 05:57

Quote:

float lum = dot(color, float3(0.299f, 0.587f, 0.114f);
return (float3)lum;



Sorry I am newbie in shader programming, which lines should I replace with the above?
Posted By: Frederick_Lim

Re: pp bloom in gamestudio - 12/27/07 15:24

Quote:

Quote:

if((Color.r+Color.g+Color.b)/3<vecSkill1.x)
{
Color.rgb = 0;
}




I think you will get a better quality bloom if you just calculate the luminance instead of making dark parts black. You can calculate luminance like this:
float lum = dot(color, float3(0.299f, 0.587f, 0.114f);
return (float3)lum;

Then just blur it and blend with the original render like you already do.




If I try to replace the lines I got the error:

Quote:

mtlBlackout(15): error X3017: cannot implicitly convert from 'float3' to 'float4'
> return (float3)lum; <




Please help. Thanks in advance.
Posted By: xXxGuitar511

Re: pp bloom in gamestudio - 12/28/07 06:11

float lum = dot(color.rgb, float3(0.299f, 0.587f, 0.114f));

Color is usually a float4 (R G B A), but here you only need (R G B)
Posted By: Frederick_Lim

Re: pp bloom in gamestudio - 12/28/07 10:27

After add the rgb I still get the same error
Posted By: xXxGuitar511

Re: pp bloom in gamestudio - 12/28/07 17:03

oh, sorry. my mistake... I should have paid more attention. The problem is in the return (as highlighted by the error ).

return float4((float3)lum, 1.0);

The shader expects a return value for alpha transparency. Since it's bloom, we don't need transparency.
Posted By: Frederick_Lim

Re: pp bloom in gamestudio - 12/28/07 17:38

Wow it works now. Thank you so much
Posted By: SurudoiRyu

Re: pp bloom in gamestudio - 01/15/08 22:18

Hi, can someone explain how to place this in my script ?

must i put this in a FX file ? or just in a wdl file
must i include the fx file ?
How does this work ?

Im new to this so some help will be handy ^-^ thnx alrleady,
Posted By: Migueljb01

Re: pp bloom in gamestudio - 01/16/08 07:02

Yes I am at the same problem. How does this work? Do I copy and paste this code snippet and name it say Bloom.c for A7. Then from there how would I call it in my main file. OR would it be called Bloom.fx then in the main file call up the fx file somehow. Just a simple step by step on how to set this up would be great plz. Its always great when people post there code but they never set up a step by step on how to set it up for non coders. Thanks.
Posted By: Scorpion

Re: pp bloom in gamestudio - 01/16/08 16:36

I also had to read into it and not just asked can you plz tell me how...you should really try to do things by yourself first.

The >=7.07 bloom you just have to call the function controlBloomSettings and it will (/should) work.

In versions <7.07 you have to create a screen alignedquad.If this description is not enough ask someone else |: /

1.open a paint programm and create a 32-bit tga (not important which content-can be black)

2.define a screen-entity by script, that uses this tga

as example:
Code:
ENTITY* screenQuad =
{
type="black.tga";
flags2=VISIBLE;
x=878;//the right distance to cover the whole screen
}



3. then set up a secons view and set the texture of the screen entity as rendertarget
Code:
theOtherNewCreatedView.bmap = bmap_for_entity(screenQuad,0);



4.give the screenQuad the material with the *.fx file(you know MATERIAL* blub = {effect="effect.fx";})

5. start a loop that sets the new view every frame to the cameras position and angle. look up proc_mode in the manual and use it to avoid a one-frame-delay

I hope I forgot nothing...have fun
Posted By: nalan

Re: pp bloom in gamestudio - 01/20/08 03:02

I can't see the images,can anyone post again?Thx a lot!
Posted By: Scorpion

Re: pp bloom in gamestudio - 01/20/08 11:44

which images?
Posted By: nalan

Re: pp bloom in gamestudio - 01/21/08 02:18

Quote:

which images?



I means the images pp bloom in GS engine,

Posted By: JibbSmart

Re: pp bloom in gamestudio - 01/21/08 11:02

they work here mate.
Posted By: Frederick_Lim

Re: pp bloom in gamestudio - 01/22/08 04:11

Is this effect same as glow? I am not sure how to distinguish bloom and glow.
Real-Time Glow
Posted By: xXxGuitar511

Re: pp bloom in gamestudio - 01/22/08 04:19

...same
Posted By: edlucas1988

Re: pp bloom in gamestudio - 05/01/09 02:02

Hey can anyone help me with the shader that scorpion wrote for A6 and lower versions of A7, this one:

float4x4 matWorldViewProj;
float4 vecSkill1;
float4 vecSkill5;

texture entSkin1;

sampler2D colorMap = sampler_state{Texture=<entSkin1>;};

void bloomVS( in float4 pos :POSITION,
in float2 tex :TEXCOORD0,
out float4 oPos :POSITION,
out float2 oTex :TEXCOORD0)
{
oPos=mul(pos,matWorldViewProj);
oTex=tex;
}

float4 isBlack(uniform float4 lookup)
{
if((lookup.r+lookup.g+lookup.b)/3>vecSkill1.x)
{
return lookup;
}
else
{
return 0;
}
}

float4 bloomPS( in float2 texcrd :TEXCOORD0):COLOR
{
float4 Color = tex2D(colorMap,texcrd);
float4 Blurred = isBlack(Color);
Blurred += isBlack(tex2D(colorMap,texcrd+vecSkill1.y));
Blurred += isBlack(tex2D(colorMap,texcrd-vecSkill1.y));
Blurred += isBlack(tex2D(colorMap,texcrd+vecSkill1.y*2));
Blurred += isBlack(tex2D(colorMap,texcrd-vecSkill1.y*2));

//here you could add 4 more texlookups for the other "side" => looks better,worse performance
/*float2 tempCrd;
tempCrd.x = vecSkill1.y;
tempCrd.y = -vecSkill1.y;
Blurred += isBlack(tex2D(colorMap,texcrd+tempCrd));
tempCrd.x = -vecSkill1.y;
tempCrd.y = vecSkill1.y;
Blurred += isBlack(tex2D(colorMap,texcrd-tempCrd));
tempCrd.x = vecSkill1.y*2;
tempCrd.y = -vecSkill1.y*2;
Blurred += isBlack(tex2D(colorMap,texcrd+tempCrd));
tempCrd.x = -vecSkill1.y*2;
tempCrd.y = vecSkill1.y*2;
Blurred += isBlack(tex2D(colorMap,texcrd-tempCrd));*/

//here you can add as much texlookups as you want...

Blurred/=5;
Color += vecSkill1.z*Blurred;
Color=lerp(Color,(Color.r+Color.g+Color.b)/3,vecSkill5.x)*vecSkill1.w;
Color.w = 1;
return Color;//
}

technique bloom
{
pass p0
{
vertexShader = compile vs_1_0 bloomVS();
pixelShader = compile ps_2_0 bloomPS();
}
}

I cant figure out why it turns out like this:

http://www.freewebs.com/ed1988/New%20Stuff/example.jpg

Any help would be greatly appreciated.
© 2024 lite-C Forums