About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Muzzle flash
Author Message
DES Offline
Member

Post: #1
Muzzle flash
I've never faced this problem before so i'm trying to find the best solution to obtain muzzle flahes with Esenthel. I will have machine guns with high fire rate and probably there will be a lot of them so i need an efficient solution to draw muzzle flashes.
I thought that it would be a good idea to use drawVolume() (adding some random factors) but obviously i need an image in IMAGE_3D mode. I saw in the "Holographic images" tutorial how to manual edit one of them, but is there a way to automatic build it?
Thanks for your help!

P.S.: the Holographic images tutorial had a problem with my esenthel: i had to change the image.x(), .y(), .z() functions with .w(), .h(), .d() functions, don't know if it was an update problem.
12-26-2013 01:18 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: Muzzle flash
I've created muzzle flashes for a singleplayer game where the player has a pistol. so I didn't bother with creating the most efficient code. However, I'll post some code when I get back home in a few hours.
12-26-2013 02:50 PM
Find all posts by this user Quote this message in a reply
Marbasoft Offline
Member

Post: #3
RE: Muzzle flash
(12-26-2013 01:18 PM)DES Wrote:  I've never faced this problem before so i'm trying to find the best solution to obtain muzzle flahes with Esenthel. I will have machine guns with high fire rate and probably there will be a lot of them so i need an efficient solution to draw muzzle flashes.
I thought that it would be a good idea to use drawVolume() (adding some random factors) but obviously i need an image in IMAGE_3D mode. I saw in the "Holographic images" tutorial how to manual edit one of them, but is there a way to automatic build it?
Thanks for your help!

P.S.: the Holographic images tutorial had a problem with my esenthel: i had to change the image.x(), .y(), .z() functions with .w(), .h(), .d() functions, don't know if it was an update problem.

It's a name change : http://www.esenthel.com/community/showth...5#pid44625

just look at the last post smile
12-26-2013 04:49 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #4
RE: Muzzle flash
Ok, so..

In my pistol class (which handles the drawing of the gun in the hand + firing (and effects) + hits), I have an imagePtr for my muzzle flash (m_MuzzleFlash). I also have a bool that indicates when the muzzle flash will be drawn (m_DrawMuzzleFlash) and a timer for the duration.

On my gun model, I've created a slot facing away from the barrel (m_BulletSlot).

When you fire the gun, I do some raytesting, .. but also set the m_DrawMuzzleFlash to true. In the update, I now start the timer and check for the duration + a small random value. If the timer is finished, set back to false.

Then, in drawBlend(), I draw my imagePtr (m_MuzzleFlash), like so:
Code:
if(m_DrawMuzzleFlash)
{
   // Set identity matrix before drawing an image in worldSpace
   SetMatrix();
   m_MuzzleFlash->draw3D(Color(255, 255, 255, 128), 0.1f, 0, m_BulletSlot.pos);
}
Don't forget to request RM_BLEND in drawPrepare for this.

In drawPrepare(), I also draw a lightSqr to add a small light to the scene, like so:

Code:
if(m_DrawMuzzleFlash)
{
   Vec color(1, 0.9f, 0.5f);
   LightSqr(0.9f, m_BulletSlot.pos, color).add();
}

I hope that helps. I know you just asked for the most optimal way to do it, but I don't know how well your programming is. So that's just how I did it. smile
12-26-2013 06:20 PM
Find all posts by this user Quote this message in a reply
DES Offline
Member

Post: #5
RE: Muzzle flash
@Marbasoft: ok, i saw, thanks smile

@Tottel: i understand your method, your help is very appreciated smile I have implemented it in my gamesmile I think it is a very good method to get muzzle flashes, but i'm thinking if a volumetric effect would be better. The structure of your method would be the same, but the drawing function would be drawVolume() ad i described before.

For example if you see the muzzle flash from a different point of view than the "First person" camera with a volumetric image you get a more realistic effect...what do you think?
12-26-2013 08:17 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #6
RE: Muzzle flash
(12-26-2013 08:17 PM)DES Wrote:  For example if you see the muzzle flash from a different point of view than the "First person" camera with a volumetric image you get a more realistic effect...what do you think?

Definitely. I think this could look a lot better. pfft

However, everything volumetric seems to be quite FPS-draining and you would probably very quickly find yourself at the lower end of the FPS spectrum.

Then again, you can always try! It's not like it would take a few weeks to implement anyway. smile
12-26-2013 08:44 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Muzzle flash
The best way to do muzzle flashes is to make 3 axis aligned planes, and put textures on them.
You'll not notice this in the game.
You can also adjust transparency for each plane depending on angle to the camera.


Attached File(s) Image(s)
           
12-26-2013 11:52 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #8
RE: Muzzle flash
Care to post some more info about those screens, Esenthel? pfft
12-27-2013 12:07 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Muzzle flash
Hi smile what kind of info would you like?
12-27-2013 06:18 AM
Find all posts by this user Quote this message in a reply
DES Offline
Member

Post: #10
RE: Muzzle flash
You're right, it is a great effect smile so this is just a model with 3 planes with a texture if i fully understood...and to add random factosr you may just scale the the model or apply other transformation right?
12-27-2013 11:06 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #11
RE: Muzzle flash
Yes, that's what I do smile control scale and transparency of those planes depending on the time, and angle to the camera.
12-27-2013 11:54 PM
Find all posts by this user Quote this message in a reply
Post Reply