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.

Code Snippets / [DBP] Advanced Muzzleflash System (uses matrices)

Author
Message
kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 14th Jul 2009 01:40 Edited at: 18th Jul 2009 20:48
Let me introduce to you my solution to a well known problem with muzzleflashes!

The problem is caused by having a single plain to represent a flash. Sometimes the camera cannot see it! Most people make loads of flashes and point them in different directions, hoping that the camera will see one. This doesnt look very good, plus the extra polys cant help on FPS.

My solution uses only one flash object. And uses Matrix algebra to calculate which direction the flash should face. Its alot like billboarding but it will work in any angle you point it in.


Demo Attached.


Enjoy!



Attachments

Login to view attachments
Maxicube
14
Years of Service
User Offline
Joined: 16th Jul 2009
Location:
Posted: 16th Jul 2009 17:12
I'm not sure how to use this example...
I don't think its DBP
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 18th Jul 2009 00:24 Edited at: 18th Jul 2009 00:24
Awesome! I'll be sure to save this for my planned FPS project...maybe even for Fields if it's fast enough .

I did notice a little problem with the transparency on the objects:



It's a DBP glitch, I thought the fix was to use transparency mode 5 but that doesn't seem to be working.



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?

Attachments

Login to view attachments
kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 18th Jul 2009 02:36 Edited at: 18th Jul 2009 20:04
Quote: "I'm not sure how to use this example...
I don't think its DBP "


It is DBP. Its just my weird coding style.


BMacZero, Thanks.

The problem can be solved, but it isn't easy, You have to detect if the camera is in front of or behind the backplane. Then disable the Zwrite. Then using the information gathered by detecting weather or not the camera is in front or behind, swap the limbs to change the render order. Otherwise you might get parts rendering in front of others. Also, Disabling Zwrite will not only mess up limb render orders, but also object render orders. The only way to solve that is doing 'Set global object creation 6' at the beginning of your code. This should make DBPro render all the further away objects first, and the nearest last which will correct this issue.

After all that, you will have the best muzzle flash system possible in DBPro.


(I havn't actually tested the above, just made it up on the spot, may test later though)


EDIT: ADDING IN THE ABOVE!

kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 18th Jul 2009 20:48
Alright, a quick update.

Now, it checks if the camera is infront of or behind the back plane. If its infront, the limbs get swapped. This solves the bug reported by BmacZero.



Attachments

Login to view attachments
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 20th Jul 2009 03:19
That seems to fix it, with one little glitch - you switched the two objects, so the wrong one is given render priority. I just switched the two object numbers:

MF_Main.objnum2=freeobject
MF_Main.objnum=freeobject2


And it worked great! Thanks!



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
TuPP3
17
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 4th Nov 2009 21:17
I did muzzleflash by making plane object in my gun model to tip of my weapon barrel, then just show and hide that limb for second after shot.
But I found it troublesome if you are trying to modify that limb, like rotate and resize it after each shot, rotational axis is gun center axis, which makes muzzle plane swivel off the tip of the gun.
kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 4th Nov 2009 22:14
This code makes sure the plane always faces the camera. A big problem with muzzle flashes is that you have to get loads of plains facing different directions to beable to see it.

The technique is alot like billboarding, but more complicated. The gun has control of the objects x and y rotation but the system has to try and find the z rotation.

gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 13th Nov 2009 00:44
Nice!

This system could also be used for a lot of things, not just muzzleflashes. A simple lightsaber using just one "hilt" object and a muzzleflash-plain representing the beam would look mighty good with this.

Login to post a reply

Server time is: 2024-05-04 21:04:44
Your offset time is: 2024-05-04 21:04:44