Author Topic: Bloom Shader test  (Read 14789 times)

0 Members and 1 Guest are viewing this topic.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Bloom Shader test
« on: March 07, 2008 »
I'm slowly learning GLSL language, today I've finished a bloom/glow effect test, the shader code itself it's not mine (can't remember the autor :P) but I can fully understand how it works on the glsl pipeline and how I can use it with my framework. I just not sure if it will work on other graphics card.

Requirements:
d3dx9_32.dll  -> to load png files (Thx Jim for that).
Pixel Shader 2.0

Use keys "1 to 6" to change texture and key "S" to enable/disable shader program.

« Last Edit: March 09, 2008 by rbraz »
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Bloom Shader test
« Reply #1 on: March 07, 2008 »
Rbraz,

I have d3dx9_32.dll but all I get is a black screen. I guess the shader is Nvidia specific right now as Im running on a x600 ati, drivers from feb 2008.

Tried it on x1950 too - still just a black screen, no images or shader.

Taj
« Last Edit: March 08, 2008 by taj »
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: Bloom Shader test
« Reply #2 on: March 07, 2008 »
It works fine with nvidia 8800gt cards.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Bloom Shader test
« Reply #3 on: March 08, 2008 »
About 6fps on my 8600GT, with or without the shader!
Jim
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Bloom Shader test
« Reply #4 on: March 08, 2008 »
The only thing that did anything here was 6 and that displayed an orange cube, S key didnt change anything.

I have an ATI card (X1650)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Bloom Shader test
« Reply #5 on: March 08, 2008 »
About 6fps on my 8600GT, with or without the shader!
Jim
OMG Jim  :o, only 6 fps, it run at fixed 60fps here on my old 6600GT, and I just use a trivial "glCopyTexImage2D" to copy textures, apply shader prog to texture and display it  ???

The only thing that did anything here was 6 and that displayed an orange cube, S key didnt change anything.

I have an ATI card (X1650)
There's bug for ATI cards in that shader code...

...
Tried it on x1950 too - still just a black screen, no images or shader.

Taj
Can you help me to fix it for ATI, check the code below.

Code: [Select]
char *vert="\
void main()\
{\
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\
gl_TexCoord[0]  = gl_MultiTexCoord0;\
}";

char *frag="\
uniform sampler2D bgl_RenderedTexture;\
float samples[] ={\
0.0222244,0.0378346,0.0755906,0.1309775,0.1756663,\
0.1974126,\
0.1756663,0.1309775,0.0755906,0.0378346,0.0222244\
};\
void main()\
{\
vec4 sum = vec4(0);\
vec2 texcoord = vec2(gl_TexCoord[0]);\
int j;\
int i;\
for( i= -5 ;i < 5; i++)\
{\
for( j= -5 ;j < 5; j++)\
{\
sum += texture2D(bgl_RenderedTexture, texcoord + vec2(j, i)*0.004) * samples[j+5];\
}\
}\
gl_FragColor = clamp(sum*sum*0.04 + texture2D(bgl_RenderedTexture, texcoord),0.0,1.0);\
}";
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Bloom Shader test
« Reply #6 on: March 08, 2008 »
Rbraz,

in order to help fix this the whole code would be much easier, otherwsie I have to go and write quite a bit of c code around it.

Taj
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Bloom Shader test
« Reply #7 on: March 08, 2008 »
On second thoughts, debugging by eye - so highly unlikely to be right but the line
Code: [Select]
gl_FragColor = clamp(sum*sum*0.04 + texture2D(bgl_RenderedTexture, texcoord),0.0,1.0);\

looks unlikely to be right to me. How many components does your texture have? I guess 4 as you are loading PNGs, so this line would try to stuff 6 components into into a vec4 and fail I guess.

ATi drivers have always been less forgiving of type conversions than Nvidia ones.
« Last Edit: March 08, 2008 by taj »
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Bloom Shader test
« Reply #8 on: March 08, 2008 »
I have updated the archive, I was passing a non power of two texture to the shader program, it might fix slowdown for Jim.

@Taj: I did some changes in the shader code too, not sure if it will work, anyway I will send all code for you to check. Thanks for your help.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Bloom Shader test
« Reply #9 on: March 09, 2008 »
It's still incredibly slow, even on the orange cube.

Jim
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Bloom Shader test
« Reply #10 on: March 09, 2008 »
Hmm ???   Anyway, I will try to convert the "copy2texture" part using frame buffer object method and check if there's any performance change...
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Bloom Shader test
« Reply #11 on: March 09, 2008 »
Can you send an image of what it should look like - I just get a red (pink) circle. The shader doesnt seem to work so Im trying things but an image for final goal would be good.
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Bloom Shader test
« Reply #12 on: March 09, 2008 »
Ok, here one screenshot of that example test I sent to you.
Challenge Trophies Won:

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: Bloom Shader test
« Reply #13 on: March 10, 2008 »
Hey rbraz,

Firstly, I love the bloom effect.  IMO the best looking one is number 4 (the granite-like texture).

On my NV GeForce 7300 GS, (full screen version), I get 30 FPS on all 6 with the shader active, and 45 FPS without.

Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Bloom Shader test
« Reply #14 on: March 10, 2008 »
Thx Voltage


Due to my lack of experience using shader language and make it compatible everywhere, I took another direction and made this effect using only software, looks much nicer and more like what I was looking for.

The idea is to draw main scene, copy to an image buffer, blur that image buffer (vertically and horizontally), apply luminance, and display all scene.

Still, I need some tests   :skint:

(Run at fixed 60 fps here)
« Last Edit: March 12, 2008 by rbraz »
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: Bloom Shader test
« Reply #15 on: March 10, 2008 »
full 60 fps here, nvidia 8800gt in sli setup.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Bloom Shader test
« Reply #16 on: March 10, 2008 »
What would you say if I told you that this one (software) is actually showing what I think is a bloom effect - which the other isn't showing properly - I get no halo on the PS one - but that it is still 6fps?  ???

Jim
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Bloom Shader test
« Reply #17 on: March 10, 2008 »
Thx zawran

What would you say if I told you that this one (software) is actually showing what I think is a bloom effect - which the other isn't showing properly - I get no halo on the PS one - but that it is still 6fps?  ???

Jim
I agree, the PS version isn't working like I want, the software version is exactly what I need.

About speed, are you saying that this software version runs only at 6 fps on your PC ??? You will give me a heart attack!

I've tested it on a notebook with bad ATI 915gm something and it run at 53 fps...

I'll wait for more feedback about speed :) ....
« Last Edit: March 10, 2008 by rbraz »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Bloom Shader test
« Reply #18 on: March 10, 2008 »
tested the software one on my old ti4600 rig and it runs smooth i would guess 50 - 60 fps,

looks really cool and gives the texture a prince of persia style of look.
Challenge Trophies Won:

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: Bloom Shader test
« Reply #19 on: March 11, 2008 »
The software version does look lots better (more pronounced halo).

I get 47 FPS. (P4 3.00Ghz)

Looking really nice RbRaz.
Challenge Trophies Won: