Game Development Community

Dynamic-decal jittering

by Lukas Joergensen · in Torque 3D Professional · 06/02/2013 (3:35 pm) · 19 replies

I have an issue where I have a decal that is placed underneath a player to indicate that, that player have been targetted.

In the advancetime call I have the following code:
if(mDecalInstance)
	{
		if(!mDecalInstance->mDataBlock)
		{
			gDecalManager->removeDecal(mDecalInstance);
			Initialize(mTarget); // Creates the mDecalInstance
		}
		mDecalInstance->mPosition = mTarget->getRenderPosition();
		gDecalManager->clipDecal( mDecalInstance, NULL, NULL );
	}
However this results in a terrible jittering of the decal. I thought this would be solved by using getRenderPosition instead of getPosition but clearly this is not the case.. Any ideas on how to avoid this jittering on dynamic decals?

(It's all client-side btw so it is not a warping issue)

#1
06/05/2013 (3:11 pm)
Bump
Currently, I set the position of the decal in every call to interpolateTick and clip the decal in the prepRenderImage call in the DecalManager.

It looks like moving the decal without moving the camera (dragging the objects the decal's position is bound to in the world editor) doesn't cause any jitter.

Any ideas at all? Completely lost on this!
#2
06/05/2013 (4:31 pm)
Mount the decal to the player?
#3
06/06/2013 (1:42 am)
Do you update the position on other places like interpolatetick() ?
#4
06/06/2013 (9:02 am)
@Richard I will try and mount the decal and see if it makes any difference!

@Ivan I have tried both having it solemnly in advanceTime, interpolateTick and processTick, and I have tried combining the 3 in a variety of possible combinations, nothing seems to work.
#5
06/06/2013 (11:18 am)
@Richard, I created a DynamicDecal SceneObject class and mounted it to the player, yet still no improvement.
#6
06/06/2013 (6:59 pm)
<shrug> Thought it might be worth a try. What about a projected texture instead?
#7
06/07/2013 (9:39 am)
I can now confirm it's not decal-specific, tried it with the RenderObjectExample class aswell, also jitters so it's something about where and when to update the position of the object. Do I need to make sure it is processed before or after the player is processed?
#8
06/07/2013 (11:23 am)
Just a shot in the dark- might the decal be z-fighting with the terrain? You might try to transform it slightly higher on the z axis.
#9
06/07/2013 (11:29 am)
Hmm I doubt it unless that would affect the RenderObjectExample class aswell?
#10
06/07/2013 (1:40 pm)
Does anyone have a sample code where they move one object relative to another?

Right now I'm just trying to mimic the mountobject code which doesn't bring me any luck.
#11
06/07/2013 (5:02 pm)
IIRC the mounting code involves the mounted object reporting its position differently in getRenderTransform - are you doing that? It's not just a case of the mount continually setting the mountee's position, but the mountee actually reports its position relative to the mount.

Any chance we could have a video of the jittering?
#12
06/07/2013 (5:08 pm)
just a shot in the dark here, but could it be a rounding error?

try positioning the player at 0 0 0 and seeing if he still jitters, if it dose its not a rounding error :-)
#13
06/07/2013 (7:19 pm)
As I recall it(I'd need to re-read through my code to confirm)

You need to a) make sure that the mounted object(in this case, the decal) is flagged to be processed after the object it's mounted to, so in your mount code for the decal, call the processAfter(playerObj) [if you ever un-mount it, make sure to clearProcessAfter() on it]

And then b) you need to make sure that in processTick, you update the transform, and in interpolate tick, you update the RENDER transform.

I can't remember if I had anything else, but that's how I mounted items to player objects and avoided it jittering around.
#14
06/07/2013 (11:58 pm)
I can almost say with 95% certainty the problem is Z-fighting. The code that counteracts Z fighting is NOT as accurate as it could maybe be. Then again, I am not 100% sure how to improve it without losing FPS and MSPF.

You see this issue with far more than just decals. Heck, rise more than a few units above a coastline and you will see a similar issue with water meeting the 'shoreline'. (This would be your (renderobject issue) I suspect it has to do with LOD versus actual collision geometry or like DRP said, a rounding error.... Just have not had time to dig into it fully.

Just my two cents.

Ron
#15
06/08/2013 (1:14 am)
In case of Z-fighting,if you render the decal after the terrain without a depth test, this will fix the problem. But you are going to lose FPS, because you skip discarding for many fragments and that leads to overdraw.
#16
06/08/2013 (2:43 am)
Wow thanks everyone for the inputs!

I converted my decalmanager to a SceneObject so I would have access to the ProcessObject class instead of using the ITickable class (which doesn't support processAfter)

Btw ProcessObject only supports SceneObjects whats up with that?

But now I'm facing a totally different issue, the game freezes completely when I call:
processAfter(mTarget.mTargetObj);
I checked that the main loop is still running, and it is so it is not because of an endless loop somewhere, somehow calling processAfter seems to mess up the processList so that nothing is processed. Any ideas on this one?
#17
06/08/2013 (6:31 am)
ok, maybe im confused then. there are other targeting systems. I know AFX has one at least and there are prolly a few others. how are those working without this issue?
#18
06/09/2013 (5:16 am)
It seems that when I call processAfter, isBackLogged in the MoveList becomes true and thus the simulation freezes.

What I think is happening is that the player is added to the the processlist twice and thus it tries to process the moves twice and when it on the second time doesn't find any moves, it backlogs the move.

Why it is added to the processlist twice I have yet to find out, it's possibly a bug.

Edit fixed now, I messed it up.
Still jitters tho... Current status:
I update the position to the RenderPosition in InterpolateTick and I update it to the Position in ProcessTick.
I set it to processAfter the player, it processes right after the camera aswell.
And I have offset it off the terrain by 1 meter (not a decal, just using a mesh) to avoid z-conflicts.
Still jitters... This is horrible..
#19
06/09/2013 (6:53 am)
Ah it works now!
It did fix it to set it to process after the player I just used the mesh instead and it was not a client only code so it updated the position on the client, then updated the position on the server then updated the position on the client again (localconnection mind you).
With the decal it works fine!