Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / LEES CHALLENGE : Fast Quality Shadow Trick

Author
Message
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 25th Oct 2005 01:40 Edited at: 25th Oct 2005 04:02
I have been hacking at this a few hours, and I thought it might be interesting to open up one of my coding problems to the vast community of DBP users out there. I usually hammer at stuff like this until it works, but it takes me time as my brain is quite slow. I thus challenge anyone to cut and paste my code into their DBPro editors and take a look at the challenge. If you can get it to work, and send it to me at lee@thegamecreators.com I will make a small prize for the one solution I ultimately use. For the rest, I will post the final solution and you guys can use if your 3D games. Shadows are getting more demanding these days, and we all want both quality and speed, and this little prototype should help us get there! If this works, you will be able to drop soft shadows onto your static scenes at top speed, no shaders required

For additional fun, under the line:

rotate limb 11,lm,0,0,rnd(360)

add this line:

scale limb 11,lm,100+(lm*10),100-(lm*5),100+(rnd(5)*10)

which introduces a scaling ingredient to the polygon which now represents any possible triangle in a generic scene.

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Oct 2005 01:47
that's a tough one. well, im off work for the week, so....


Deadly Night Assassins
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Oct 2005 01:50 Edited at: 25th Oct 2005 01:57
There is a minor issue before you start...it only works at 640 * 480

If you increase the display size, it's way off track. Apologies for not being more constructive, but I can't get my head around the calculation for mouse position. I would blame the time of night, but I still won't get it in the morning.

LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 25th Oct 2005 03:58
No sooner was I ready to log off, that I was emailed with a solution. Incredible! So quick was the reply I felt it only fair I increase the difficulty of the challenge slightly to add an extra scaling effect to the polygons to create additional fun [edited in the original code]. With the solution to hand, I should be able to muggle my way through the rest now but it would save more time if that TOO was dropped into my inbox. This community never ceases to amaze me

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
CPU
20
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Carlsbad, CA
Posted: 25th Oct 2005 04:07 Edited at: 25th Oct 2005 04:52
Lee - I don't see anything different between the first and second code, no scaling?

CPU

[edit]
Sent an e-mail to ya Lee, and added a random scaling of the limb cause it doesn't seem like you changed the code hardly at all.

[center]K-OS Battlefields
IS
///---///---///---UNDER CONSTRUCTION---\\\---\\\---\\\
[center]
CPU
20
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Carlsbad, CA
Posted: 25th Oct 2005 16:04
Lee?

[center]K-OS Battlefields
IS
///---///---///---UNDER CONSTRUCTION---\\\---\\\---\\\
[center]
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 25th Oct 2005 18:38
Thanks for the guys who took up the challenge so quickly. I now have the solution I was after, submitted less than an hour after posting this item. A small present goes out to Paul Johnston, aka Sparky, for providing the code I will ultimately be exploiting in my next shadow prototype. I have attached the solution as code below, in case anyone wants to investigate this approach to fast soft shadows as well. Thanks all!

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
Nicholas Thompson
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 25th Oct 2005 18:44
Not wanting to be picky - but that code only works in the default resolution. I use a TFT and TFT's aren't very keen on non-maximum resolutions. When I changed it to 1280x1024 it doesn't work - the block doesn't line up with the mouse.

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Oct 2005 18:53
don't you meed lee's challenge

sorry, I feel "cool" when I pretend to be a smart-ass


CPU
20
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Carlsbad, CA
Posted: 25th Oct 2005 18:56
Lee, don't know if you got my e-mail, but I seriously think sparky overdid himself...

replace sparky's loop with this and see how it measures up...



Oh and Nicholas T, the reason it doesn't work is because lee calculates the mouse pos based on where the mouse is on the screen, if you increase the resoulution it screws up the where the 'mouse pos' is.

CPU

[center]K-OS Battlefields
IS
///---///---///---UNDER CONSTRUCTION---\\\---\\\---\\\
[center]
Nicholas Thompson
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 25th Oct 2005 18:56
Tweaked code - resolution independant now. I dont like the hacked constants on the offsetting of x# and y# but without looking at the code in more detail - I cant see precisely what they represent. Maybe world coords?!

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 25th Oct 2005 19:27 Edited at: 25th Oct 2005 19:27
@CPU - I love it, such a simple idea, just overlay the texture on the polygons and work out the uv offsets from the mouse, beautiful. Wish I'd thought of that, instead I did the opposite and transformed the points back to the origin to work out their uv points.

Although you can simplify it a bit more and remove the -1.0*

But it's a technicality

@Lee - what are you going to do? I won't blame you if you declare CPU the winner, his code is more efficient. Unless you have a need for anything my code does but his doesn't.
CPU
20
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Carlsbad, CA
Posted: 25th Oct 2005 20:06
@Sparky - Thanks, I was going through the code and remember thinking, no... it can't be that simple...

- But good job yourself Sparky, I know all the transformations you did would have tied my head in a knot...

@Lee - So... what now? I wouldn't want to take the prize away from sparky since you already declared him the winner... But a comment or two would be nice

Cheers,

CPU

[center]K-OS Battlefields
IS
///---///---///---UNDER CONSTRUCTION---\\\---\\\---\\\
[center]
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 25th Oct 2005 20:31
No sweat CPU, you can have a prize too. I will email you personally with more info. Thanks again. If I knew solving problems was this easy, I would probably post here more often Challenge officially over, otherwise I will have no presents left for Christmas!

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 25th Oct 2005 20:42 Edited at: 25th Oct 2005 20:43
OK - three things:

1. Could someone explain to me in simple terms what this proves/acheives? I can't be alone in being puzzled by what's going on here. Part of the challenge almost makes sense: By playing with the code it looks like you've textured your "floor" with a shadow texture, clamped it and un-tiled it (un-tiled == clamping?) but you're moving the UVs so that it looks like you're moving the "shadow". You want to use collision data to find out the orientation of of the current polygon which is "underneath" the "shadow". I put quotes around "underneath" and "shadow" because it's all virtual, there's no shadow object so it's not necessarily on something... it's all done with UV jiggery pokery. Anyway, the bit I really don't get (assuming I'm correct above) is how you mask parts of the shadow when you don't want it to be shown.

My understanding of UVs is fairly simplistic, and I can only visualise regular "planar" mappings, where a polygon's 3 vertices map to 3 UV coordinates on the texture map.

2. Am I right in thinking this therefore works for arbitrarily complex "floors" (i.e the surface onto which the shadow is cast needn't be flat), providing the floor uses the one UVset?

3. I do believe Lee just did a zenicanin14.

New 'n' Improved sig details how little I accomplish
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 26th Oct 2005 15:08
This community is definitely amazing. It includes, for example, the world's only known coding jam sandwich eating picnic basket stealing vector math proficient Bear.

Cheer if you like bears! Cheer if you like jam sandwiches!
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 26th Oct 2005 16:35
He's modest as well.

"A book. If u know something why cant u make a kool game or prog.
come on now. A book. I hate books. book is stupid. I know that I need codes but I dont know the codes"
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 26th Oct 2005 17:34
I just went through the whole zenicanin14 thing. That was wild. Was that a joke?

adr, a question. How did Lee do anything on the same planet as zenicanin14? I must be missing something.

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 26th Oct 2005 17:43
Cash, if only it was a joke! - we've had some right windowlickers in the DB community .

I'm afraid to look closely at the code until I'm in the proper frame of mind, usually found at the end of a bottle of scotch .


Van-B

Put those fiery biscuits away!
Undercover Steve
18
Years of Service
User Offline
Joined: 6th Jun 2005
Location: Vancouver, Little Canada(Washington)
Posted: 26th Oct 2005 17:48
It is the same, because basically lee "showed us da codez" (like jetski ), then we told him teh codez!

Your signature has been erased by a mod because it advocates spamming other forums...
Nicholas Thompson
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Oct 2005 17:56
the zenicanin14 thing?

Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 27th Oct 2005 01:34
@DavidT

"He's modest as well."

Yup. I'm the most modest person around. Without exception.

Cheer if you like bears! Cheer if you like jam sandwiches!
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 28th Oct 2005 20:13
REM
REM BRAND NEW CHALLENGE FOR YOU!
REM

Given the success of the last challenge, I have decided to extend the concept to include my next hurdle. Rather than bash my head against the problem, I will open the wall to the public and let everyone have a tup. The code explains all, and which ever solution I use, I will give a small prize to the person whos code I use to further my work on this technique. Good luck and have fun!

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
French gui
19
Years of Service
User Offline
Joined: 11th May 2004
Location: France
Posted: 28th Oct 2005 21:11
JoelJ
20
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 28th Oct 2005 21:25
come on Lee, you know the rules, post exactly what is wrong and don't ask for people to do things for you.

I'll give you some toast
My BLOG really sucks...
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 28th Oct 2005 22:03 Edited at: 28th Oct 2005 22:04
Well this one's a little more tricky!

This time instead of rotating the polygons, the texture is effectively rotating instead. So I can't see a way of doing it without transforming the points. Although it is much simpler than my last attempt



As for the bonus, I can imagine it would be very difficult to distort the texture so much using only the UV co-ordinates, individual axes are possible, but not all combined. So that bit's got me stumped.
French gui
19
Years of Service
User Offline
Joined: 11th May 2004
Location: France
Posted: 28th Oct 2005 22:07
Wow Sparky, it's awesome!

MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 28th Oct 2005 23:13
What´s with all this shadow stuff? Aren´t shadows working properly in DBPro? And since Lee reads this thread. Update your diary! My favorite source of daily entertainment has been taken away from me and I´m very sad.

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
French gui
19
Years of Service
User Offline
Joined: 11th May 2004
Location: France
Posted: 28th Oct 2005 23:16
They aren't working on every graphics cards!

Me!
18
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 28th Oct 2005 23:22 Edited at: 28th Oct 2005 23:27
that code (sparkys) gives me errors

system 3.1ghz
512mb ram
GeForce 6200 card
latest DX and other drivers (Nvidia Beta for B&W2 since old one crashes under HL2)
blue ide

when I try to run it it compiles then drops back to the IDE after flashing a blank window up, I either get no message or the message "runtime error 1512 display is not supported by available hardware at line 0", once this happens I can`t run/compile anything until I have rebooted (I keep getting the same 1512 error), then after the reboot other code will compile but this bit still won`t, makes no difference what screen mode I am using either, no error message in the temp folder.



Tyger software
JoelJ
20
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 28th Oct 2005 23:32
Quote: " What´s with all this shadow stuff? Aren´t shadows working properly in DBPro? "

and I think it has something to do with speed

I'll give you some toast
My BLOG really sucks...
Mr Scarab
18
Years of Service
User Offline
Joined: 11th Jun 2005
Location: Kent, UK
Posted: 28th Oct 2005 23:47
And this from the guy that invented 3D

Sig removed by Mod. Please do not use offensive language in your signature (sic).
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 29th Oct 2005 00:37 Edited at: 29th Oct 2005 00:37
@Sparky

Surely for the bonus, its just a matter of projecting the effect of the 3d cube onto a 2d plane? Think about what the 3d cube could look like if you could flatten it down into a 2d plane. Assuming there is only one light source, that should also be the shape of the shadow underneath the object.

Anyway, how come the object produces a shadow effect even when it is BENEATH the object? A bug, surely?

Cheer if you like bears! Cheer if you like jam sandwiches!
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 29th Oct 2005 01:44
Lee's idea is to use an image of a black square, textured onto the object beneath, and scale the uv to put the texture in the right spot.

This means it's difficult (if not impossible) to distort the shape beyond anything that has four corners as Lee won't let us fiddle with the image Whilst the cube has eight corners to create a shadow with.

The shadow appears when the object is below the floor because the texture is placed using only the x and z positions of the cube.
Coding Fodder
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 29th Oct 2005 03:56
Good work sparky, And you are correct about the "bonus challenge". It requires the ability to transform from a square to a hexagon. That transformation is quite impossible with uv manipulation.

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"

Login to post a reply

Server time is: 2024-04-19 02:32:36
Your offset time is: 2024-04-19 02:32:36