Game Development Community

Moving decals realtime.

by Lukas Joergensen · in Torque 3D Professional · 04/04/2012 (3:09 pm) · 11 replies

So i am working on a prototype system to make some simple and fast spell effects.
I will eventually port over to AFX 2.0 but for the time being i decided to go with my own system.

However, i came across some trouble when i wanted to have a decal on the ground. I wanted it to be an AoE indicator (like when casting blizzard in WoW or other range AoE's)
I found a working solution doing this:
function spawnIndicatorDecal()
{
   if($SpellDecal $= "")
   {
      %player = $Pref::PlayerID;
      %pos = castrayfromNPC(%player, "point");
      %norm = castrayfromNPC(%player, "normal");
      $SpellDecal = decalManagerAddDecal( %pos, %norm, 0, 1, "NewDecalData", true );
      schedule(20, 0, updateSpellDecal);
   }
}

function updateSpellDecal()
{
   if($SpellDecal !$= "")
   {
      %player = $Pref::PlayerID;
      decalManagerRemoveDecal( $SpellDecal );
      %pos = castrayfromNPC(%player, "point");
      %norm = castrayfromNPC(%player, "normal");
      $SpellDecal = decalManagerAddDecal( %pos, %norm, 0, 1, "NewDecalData", true );
      schedule(20, 0, updateSpellDecal);
   }
}
(Yes my naming is kindda awkward, will clean it sometime)
But it gives alot of flickr, and i believe Raycasts only runs over the server (not sure about this) if so it would create a lot of traffic between the client and the server.

So wanted to know if there was anyone who had figured a better way to do this :)
This code is fine for prototyping, but i were considering to clean up the code and release it as a resource for beginners like me who haven't got their hands in to the source code yet.
But i believe that AoE indicator is too ineffective.

#1
04/05/2012 (10:22 am)
I believe the way I resolved this in the past, was to add a client raycast function that operated on the client-side and I used that...it worked well enough.
#2
04/05/2012 (4:28 pm)
"Flicker" might be caused by having the decal located at the actual position returned by the raycast - it's z-fighting the terrain. Try adding a small amount to the z component of the position to have it "float" a little above the ground.
#3
04/06/2012 (4:21 am)
@Richard I will try that thank you! Will reply here if it works with the altered code.

@Bryan Hmm, i believe i found a thread on that during my research, that might be optimizing it enough to be a workable resource!
#4
04/06/2012 (5:44 am)
Changed the updateSpellDecal() code to this:
function updateSpellDecal()
{
   if($SpellDecal !$= "")
   {
      %player = $Pref::PlayerID;
      decalManagerRemoveDecal( $SpellDecal );
      %pos = castrayfromNPC(%player, "point");
      %norm = castrayfromNPC(%player, "normal");
      %pos = setWord(%pos, 2, (getWord(%pos,2) + 1));
      $SpellDecal = decalManagerAddDecal( %pos, %norm, 0, 1, "NewDecalData", true );
      schedule(20, 0, updateSpellDecal);
   }
}

Didn't help on the flickering, haven't come around testing the clientside raycasting yet. :/

Edit: Seems like the clientside raycasting was fairly easy to solve.
I found in the source code that in Torque3D 1.2 there is an additional parameter on ContainerRayCast which specifies wether to search on the server or the clientside. So this:
ContainerRayCast(%start, %end, %typemasks , %player, true);
made the raycast clientside! :)
#5
04/07/2012 (8:06 am)
So, i tried to define an engine function and see if that got rid of the flickering, but it didn't unfortunately :(
#6
04/08/2012 (10:18 am)
Quote:
@Bryan Hmm, i believe i found a thread on that during my research, that might be optimizing it enough to be a workable resource!

can u give link of that thread?
may be that will help me to understand it more deeply.
#7
04/08/2012 (10:20 am)
@ahsan, well what version of Torque are you using?
#8
04/08/2012 (10:23 am)
t3d 1.1
#9
04/08/2012 (10:26 am)
Ok so, i took a look at your other threads. Are you trying to optimize the raytracing or the decals?
What i commented on was the raytracing :)
I don't know if i can optimize the decals more than i did. I didn't try to put decals on shapebase objects.
#10
04/08/2012 (10:32 am)
@ahsan
I digged this up for you:
Enhanced Projectil System for TGE and TGEA
I think it got what you need, the downside is you have to port it from TGE/TGEA
Edit: Reposted it in your own thread so other users can find it there.
#11
04/08/2012 (10:39 am)
Quote:Are you trying to optimize the raytracing or the decals?
no
i only want to add bullet spot or bullet hole on moving objects.so after adding decals(blood/bullet hole) was thinking to move decal with objects.
in that case i thought your last resource could be helpful.

but that will also need a function which will always update the decal depending on objects position.not a good idea.
now i think i have to think another way.
may be adding extra material layers on objects skin will do the work.
i do not know much on t3d's material system.
have to do some research.