Carmack's Reverse - (stencil shadows) here it is.

Blitz3D Forums/Blitz3D Programming/Carmack's Reverse - (stencil shadows) here it is.

Braincell(Posted 2005) [#1]
After a number of weeks of trying to optimize a number of different 'routines' i came up with for creating shadow volumes of unboned meshes, i concluded that a fast way of dynamicaly drawing a satisfactory number of shadows is not really possible using b3d commands alone. I only have partialy done a routine to build a volume with a minimum number of polys but this is for levels only - where the level and the light source is stationary. I don't think too many people would have a use for that. It (probably) IS possible to have fast stencil shadows in b3d but with help from a very good c++ coder who can make a number of DLLs that will work well with blitz3d.

Anyway, here is the code based on Tom's code, only now Depth-Fail (Carmacks reverse) technique is used. This way its very robust, and when you enter the volumes (in this example 2 cylinders) they dont disappear or get drawn incorrectly, as was the case with original Tom's code which used the Depth-Pass technique. I have included basic code to make shadow volumes in b3d so if you want to test around yourself, do it. It can be useful for very simple objects (if you get it to work like you want it).

EDIT: The first code i posted i forgot to include the ATI fix. This one should work, try it and tell me.

If youre interested in what problems i ran into, read on. If not, get the code from the box below and the needed userlibs from:
http://www.geocities.com/spirala7/dx7sshad.htm



The main problem is that commercial games which are written in c++ have a number of keywords and maths that are integral to the language. For example there is the D3DMATRIX which is used to take positions of vertices (directly using D3DVERTEXBUFFER... , CreateVertexBuffer() ) and simply extrude them by a vector, when the volume is capped as well. In Blitz however we have to use TFormPoint to even get the global position of a vertex, and then TFormVector to even stand a chance of checking where the edges are, or which triangles are facing the light source, etc. You COULD do it without TFormVector also perhaps, but the maths would be as slow as that command. I tried everything possible. It's not to blame blitz for not having this kind of thing, if it did it would be a considerably more complex language. Another thing which i find is pretty slow is creation of triangles. In C++ the vertexes are just copied and then "extruded" or projected, this includes creation of the triangles and is obviously faster.

In other words, Mark! Do something :D make us stencil shadows for blitz3d, you see how simple it is if you know c++? Yeah! COME ON!

Here's the code (should work on ATI?):




Beaker(Posted 2005) [#2]
Looks very corrupt on my machine.


jfk EO-11110(Posted 2005) [#3]
hey, that's dead easy. just tell me what's this c++. Seriously - I'm looking forward to finally see smooth shadows with blitz3D. Especially something that would work nicely with an FPS enviroment.


VIP3R(Posted 2005) [#4]
Corrupt display here too, probably an ATI thing?


wizzlefish(Posted 2005) [#5]
Function "SetRenderState" not found.


JoshK(Posted 2005) [#6]
You have to download the userlibs.

I get a MAV on SetRenderState().


Picklesworth(Posted 2005) [#7]
Um... I'm guessing that I do not see it properly. Basically all I am getting is a very white sort of thing that looks like garbag eand a ton of messed up charcters overlappig eachother at the top. I can still recognise and move about what I'm guessing is the cylinder, but that's about it.
I have a Radeon 9600 Pro as well, so I would guess that it very probably is an ATI thing.

I hope this can be made working across all platforms :D


Genexi2(Posted 2005) [#8]
Works here on my nVidia Geforce6800 GT....



I'm guessin card-compatiblity would be the biggest pain in te rear here, considerin alot of the people who posted received graphical glitches...


Beaker(Posted 2005) [#9]
I think Tom (who made the original DLL) sorted any ATI glitch issues.


Braincell(Posted 2005) [#10]
Yes, i just posted the wrong version which was not fixed. Here is the fixed version,it should work, tell me if it doesnt:



You also need V1.88 of blitz3d running.

jfk, i heard Mark may be working on stencil shadows for BMax and may just convert them to blitz3d so lets wait for a bit and see what he does. If you dont want to wait, email me (email provided in my details) and i'll reply to you with the stuff i think can be done.


BlitzSupport(Posted 2005) [#11]
Yep, that works here on ATI where the previous one didn't. Nice!


Braincell(Posted 2005) [#12]
Good!


jfk EO-11110(Posted 2005) [#13]
Lenn, thanks. Well, I think I'll wait and see :)


Beaker(Posted 2005) [#14]
Works fine now.


VIP3R(Posted 2005) [#15]
Great stuff Lenn, works fine here now :)


Kalisme(Posted 2005) [#16]
wasn't someone trying to get this code working with animated *.B3d files? I'm still very interested in that... and I agree... this should be intergrated into Bitz3d... (that would make it faster, right?) Very kewl... it does remind me of the shadows in DOOM3... great work :D


Canali(Posted 2005) [#17]
Still gettin function "setrenderstate" no found.
:(


Rook Zimbabwe(Posted 2005) [#18]
I think the important thing is :

Did you update your drivers for ATI?

I had no probs. I am using an ATI Radeon 7000 on a Athlon 64 3200+ with 1 gig...etc...

-RZ


Braincell(Posted 2005) [#19]
Canali, you should read the first post completely and it says

get the code from the box below and the needed userlibs from:
www.geocities.com/spirala7/dx7sshad.htm


make sure you do that, and put the files into the userlibs folder


VIP3R(Posted 2005) [#20]
Rook, you should read the entire thread, it says...

Beaker: I think Tom (who made the original DLL) sorted any ATI glitch issues...

Lenn: Yes, i just posted the wrong version which was not fixed. Here is the fixed version...


Make sure you do that and you'll discover it was fixed well before you posted ;)


Shifty Geezer(Posted 2005) [#21]
You also need V1.88 of blitz3d running.

Where does one get v1.88 from?


Caff(Posted 2005) [#22]
Check the forum called 'Blitz 3d Updates' - there's a post in there with the latest upgrades in.


Shifty Geezer(Posted 2005) [#23]
I get a "function SetRenderState not found" error even after updating to 1.88


RiverRatt(Posted 2005) [#24]
The example runs, but I don,t see shadows, like the screenshot has. I just see two alpha cylinders.
Prosavage graphics.


cermit(Posted 2005) [#25]
It works for me, i have geforce fx 5200 or something. just had to update blitz3d and put the dll and decls file in the userlib folder : )


Zmatrix(Posted 2005) [#26]
@RiverRatt
Prosavage onboard video or (savage4 cards) , have a stencil buffer.
You may need to turn it on in the cards control panel.
and on some cards it wont work with a 32bit Zbuffer

Zmatrix


Spacemonkey(Posted 2005) [#27]
Hi there,

If you want to test my shadow contribution to this thread, please download the file.
http://www.spacemonkeys.dk/blitz/CVC-SDtest.rar

I want to improve my edge method before a release :)


First Anim Test... use key 1,2,3
http://www.spacemonkeys.dk/blitz/CVC-SDtestAnim.rar


Stevie G(Posted 2005) [#28]
This is what I see with the Amin Test



I have a Geforce 440mx so it should support stencil shadows .. at least all the other demos I tried worked?


RGR(Posted 2005) [#29]
@Spacemonkey
I have about the same picture as Stevie G - a green donut and a cute figure appears after long press on 2 running the Anim
The other shows 2 donuts (red and green) but the result on the floor looks as in the above picture.
The Demos above were working.


Spacemonkey(Posted 2005) [#30]
Strange! I use the same main loop as Lenn..
Is this the same all over?


bytecode77(Posted 2006) [#31]
hm... if i use this, the self-shadding looks a lil bit strange!?!
why is this so?


Chroma(Posted 2006) [#32]
Very nice work here. I'm wondering though. Can that shader.dll be used to allow us tron glow effects that are stated here in this thread?

http://collective.valve-erc.com/index.php?go=tron2