Author Topic: Depth Shadows and Framebuffers [BMAX]  (Read 5670 times)

0 Members and 1 Guest are viewing this topic.

Offline a

  • ZX 81
  • *
  • Posts: 21
  • Karma: 0
    • View Profile
Depth Shadows and Framebuffers [BMAX]
« on: January 06, 2008 »
ok, so ive downloaded a source from blitzbasic.com(http://www.blitzbasic.com/Community/posts.php?topic=60672) which showed really pretty depth shadows. i changed more and more stuff and finally wanted to add framebuffers instead of using the default copytex-method to get even better performance, but it doesnt seem to work: as it seems, the FBO-method copies the whole buffer and not only the depth buffer and projects this finally. so ive got 2 options now (this is where someone of you should help me ;)):
either, i use the color buffer to make soft shadows, or, the probably faster method: i let the FB not use a color-buffer and do it as i did before and make those hard-edged shadows

ok enough said now:
heres the source and the keys are: [1]=show shadowmap, [2]=enable/disable shadows, [3]=wireframe on/off
also, theres the old method included in this which copies the texture(does work for me)

PS: sorry for the crappy code, but its very experimental!

EDIT: ok, ive found a good code sample that does exactly what i want. thy for your help anyway!
PS: ill report in, if i have it working
« Last Edit: January 09, 2008 by DrFreak339 »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17426
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Depth Shadows and Framebuffers [BMAX]
« Reply #1 on: January 09, 2008 »
PS: ill report in, if i have it working

Please do.
When you get it going an exe would be great too for those of us who don't have Bmax :) Cheers!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: Depth Shadows and Framebuffers [BMAX]
« Reply #2 on: January 10, 2008 »
maybe it's your ATI, maybe not.. but definitely FBOs are much much faster that copying the framebuffer in a texture. At least on NVidias... I did not test your code.... 'cause I do not code with BMax.. but did you try using pixel shaders? I had some performance differences when using pixel shaders and when not using them. Pixel shaders are always faster (again on Nvidia). It seems that manufacturers keep on improving pixel shader processing and tend to forget about performance when not using them...
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline a

  • ZX 81
  • *
  • Posts: 21
  • Karma: 0
    • View Profile
Re: Depth Shadows and Framebuffers [BMAX]
« Reply #3 on: January 12, 2008 »
well its faster on my ATI, too of course :) that's why i want to do this!
and shaders... i'm not really good at writing them. actually i'm a noob at this and didn't really write at least one^^ also i don't know how to implement them properly. of course i downloaded toms mini-shader-engine from bb.com and it did work on the fly(with a toon and a perpixel-lighting shader) but i still have no idea how to pass textures to shaders which is a big problem when i HAVE to pass them (i'd try to write/steal a *good* parallax shader then, too[see the link downwards])...

oh and i noticed something: the FBO's done in bmax work on my fathers pc (ati x600 se) but not the original source from ati.com (http://ati.amd.com/developer/SDK/Samples_Documents.html#opengl theres an FBO sample). well it does work but the cubemapping and the shadows dont...

sorry for not posting an exe but my webspace (ok its the webspace from devils child^^ but he gave me 30mb ;)) had some problems. here is it:
http://www.dev-ch.de/upload/files/DrFreak339/bmax_ogl_depth_shadows.rar

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: Depth Shadows and Framebuffers [BMAX]
« Reply #4 on: January 12, 2008 »
In my experience, some features do not work without shaders.... or only a small number of combinations. Shaders are (un)fortunately the only way these days.. because: ATI & Nvidia want big sales => the only market to give them great figures is the games industry => almost all game engines use shaders for special effects...

pixel (fragment) shaders are not difficult. All the information you need is here: http://oss.sgi.com/projects/ogl-sample/registry/ARB/fragment_program.txt

there are different methods to program shaders (CG, GLSL, etc). My preferred one is still to write assembler (as described in the document linked above). Shaders are just small programs that get executed per pixel (fragment) after the rasterization (once all 3d calculation has been done and 2d projection performed).

To create a shader program, you just need a text editor (or you can embed you shader code in your prod). It's just a text string written in assembler.

To use a shader, you need to create an ID for it (just like for a texture). Use glGetProgramsARB() for this.

Then to activate a shader, you need to bind it (again just like for a texture). Use glBindProgramARB() for this.

In order to have your shader assembled on the graphics card's GPU, you need to assemble it using glProgramStringARB(). Obviously you need to have a shader ID generated before and the ID bound (active shader, see above)

Once the program is properly assembled (no errors) it can be bound when needed and whatever drawing command is performed, the active shader shader will be used for it.

If your shader uses one or more textures, then you need to bind your textures in the right texture slots. Use glActiveTextureARB() for this. Moderns graphics cards support up to 16 textures at the same time in a shader (although 32 will be possible quite soon).

In your shader program, you can use the TEX mnemonic to sample the texture in the right texture slot. Beware that the sampling method used by TEX depends on the texture format. if your texture is a power of 2 texture, then the sampling method has to be 2D, for rectangular textures, it has to be RECT (see documentation). If you mix this up, results are unpredictable (can work on some graphics card, or not work at all).

The GPU processes 4D vectors (x,y,z,w or r,g,b,a) entitities. Some instructions work on scalars, but most of them work on vectors, again see documentation for this.

Here is an example of a simple shader:


   "!!ARBfp1.0\n"
   "TEMP original_color;\n"
   "# sample texture in slot 0, at fragemnt texture coordinates using RECT sampling \n"
   "TEX original_color,fragment.texcoord,texture[0],RECT;\n"
   /* final color */
   "MOV result.color,original_color;\n"
   /* end of shader */
   "END\n\0"
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline a

  • ZX 81
  • *
  • Posts: 21
  • Karma: 0
    • View Profile
Re: Depth Shadows and Framebuffers [BMAX]
« Reply #5 on: January 20, 2008 »
wow! thanks man! this will help me a lot!

unfortunatelly my pc at home broke and i just cant get to work(im on a secondary system here; only at weekends...). it will probably take a bit longer to do/finish this stuff. also, ive decided, to make a little opengl-engine which includes some of the basic stuff(meshes(->entities), cameras, lights, textures,...) first and if this all works, i'll add the shaders and the special effects and all of this stuff

Offline a

  • ZX 81
  • *
  • Posts: 21
  • Karma: 0
    • View Profile
Re: Depth Shadows and Framebuffers [BMAX]
« Reply #6 on: February 11, 2008 »
ok. as you can see in my sig, ive got a new machine (well, some new parts :D)
problem: the video card. it just sucks. i thought it would be ok, but... cs1.6 on lowest graphics and 1024x768: max 25fps
and so is the compatibility: shaders work (still no idea which version), but somehow it just cant manage the framebuffer extension, even after installing the newest drivers (before, it couldnt even manage opengl at all, with the CD drivers, which is also strange, because opengl even worked on a pc without any gfx drivers installed...)

the thing now is: is it really useful to develop framebuffers if they dont work on some X 1000 chipsets? or is it just another driver issue here???

EDIT: seemed to have problems with the shared memory. when set to 32mb it didnt work, but in 128mb it did (a bit ;))...
« Last Edit: February 25, 2008 by DrFreak339 »