Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 00:09

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: 23.11.2011, 10:51 
Offline

Joined: 10.02.2011, 07:53
Posts: 2
Hello,
I found a Bug in the animation system, more precisely in the computation for the remainingWeight for animation layers

Now, the Horde3D goes through all stages, stating at the highest layer and going down to the lowest. While doing this the remainingWeight gets computed.
The way I see it, the remainingWeight should work like this: The highest Layer has priority so it takes as much weight as it needs from the remainingWeight Bucket. The second highest layer check if there is still something left and if so, has its pick. And so on.

If I understood this correctly, the remainingWeight should start at 1.0 and should steadily empty till reaching 0.
The thing is that this is not case with the current implementation (file egAnimation.cpp):

The Bug

Code:
remainingWeight *= 1.0f - minf( layerWeightSum, 1.0f );
//layerWeightSum = total weight of previous layer


This looks like the remainingWeight is indented to be used as a weight for layers weights. However, even if this is the case, there is a bug with the computation of the final weight:

Code:
weight = (curStage.weight / layerWeightSum) * remainingWeight;
//curStage.weight = weight of current stage
/layerWeightSum = total weight of current Layer


This calculation causes that each layer will render with the whole remaining weight, no matter how much weight it actually needs.
This means that the remainingWeight isn't used as a weight of the layer.

Example
Code:
Layer 3
remainingWeight = 1.0 * (1.0 - 0.0) = 1.0
curStage.weight = layerWeightSum = 0.5
-------------------------------------------------
render weight = 1 * remainingWeight = 1.0

Layer 2
remainingWeight = 1.0 * (1.0 - 0.5) = 0.5
curStage.weight = layerWeightSum = 0.6
-------------------------------------------------
render weight = 1 * remainingWeight = 0.5

Layer 1
remainingWeight = 0.5 * (1.0 - 0.6) = 0.2
curStage.weight = layerWeightSum = 0.3
-------------------------------------------------
render weight = 1 * remainingWeight = 0.2


Solution 1

To fix this bug we must alter the render weight computation:
Code:
weight = curStage.weight * (curStage.weight / layerWeightSum) * remainingWeight;

Now the System uses the remainingWeight as a weight for each layer.

Example:
Code:
Layer 3
remainingWeight = 1.0 * (1.0 - 0.0) = 1.0
curStage.weight = layerWeightSum = 0.5
-------------------------------------------------
render weight = 0.5 * 1 * remainingWeight = 0.5

Layer 2
remainingWeight = 1.0 * (1.0 - 0.5) = 0.5
curStage.weight = layerWeightSum = 0.6
-------------------------------------------------
render weight = 0.6 * 1 * remainingWeight = 0.3

Layer 1
remainingWeight = 0.5 * (1.0 - 0.6) = 0.2
curStage.weight = layerWeightSum = 0.3
-------------------------------------------------
render weight = 0.3 * 1 * remainingWeight = 0.06


Solution 2

However, I still find this wrong because it doesn't implement the remaining weight behavior as one would assume. Much better would be to implement the remainingWeight as some sorts of bucket from which the layers can take out weight in order of their priority (ids)
To achieve this I would change the calculations for the remainingWeight and weight:

Code:
remainingWeight = maxf(remainingWeight - minf( layerWeightSum, 1.0f ), 0.0f);


Code:
//render weight
if(layerWeightSum >= remainingWeight) //this layer will use all of the remaining weight
   weight = (curStage.weight / layerWeightSum) * remainingWeight;
else //weight will still be available for lower layer
   weight = curStage.weight;


And here is the example now with the proposed changes:
Code:
Layer 3
remainingWeight = 1.0 - 0.0 = 1.0
curStage.weight = layerWeightSum = 0.5
-------------------------------------------------
render weight = 0.5

Layer 2
remainingWeight = 1.0 - 0.5 = 0.5
curStage.weight = layerWeightSum = 0.6
-------------------------------------------------
render weight = 1 * remainingWeight = 0.5

Layer 1
remainingWeight = maxf(0.5 - 0.6) = 0
curStage.weight = layerWeightSum = 0.3
-------------------------------------------------
render weight = 1 * remainingWeight = 0


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group