Jump to content

  • Log In with Google      Sign In   
  • Create Account


gnomgrol

Member Since 16 Jun 2012
Offline Last Active Sep 19 2014 08:44 AM

Topics I've Started

Bone based animation confusion

21 August 2014 - 05:03 AM

Well met!

 

I have some questions on bone-based animating.

 

The process I got (in short):

 

- Export the vertices with boneweights and also the skeleton, with the bones as worldmatrices (position, rotation, scale),  as a "basemesh" (from the modeling program)

- Export an animation as the bone-worldmatrices for each frame

- For playing an animation, transform every vertex by ((bonematrices of the current frame) - (bonematrices of the baesmesh)) for each bone assigned to it, using the weights

 

The reason that this isn't working is that, when transforming one vertex of a mesh with a matrix, the rotation and scaling will be applied from the origin of the mesh as the origin, not the position of the bone.

 

I thought that could be fixed with relative ease, by constructing the worldmatrix for each bone like this:

// Answer from a question on stackoverflow
mat4 result = glm::translate(-pivot) *
glm::scale(..) *
glm::rotate(..) *
glm::translate(pivot) *
glm::translate(..);

 

Where pivot would just be the position of the bone. But when applying this, there is no change to the final result. Stuff still uses the center of the model as pivot-point for scaling/rotating.

 

Also, this method of animating completly ignores the parent-child-relations that bones hold to each other. Is there something gained from using those relations when computing the rendering?

I understand why they are extremly helpful when modeling in the modelingprogram, but is there a reason to also use them when rendering?

 

 

Your help is, as always, greatly appreciated!

Have a nice day!

 


Quaternion-Rotation to Degree (Edge-jump)

28 July 2014 - 12:28 PM

Well met!

 

This may seem like a rather simple thing, but I can't seem to figure it out or find an answer.

 

I'm trying to write an exporter for 3ds MAX, but it stores its rotations in quaternions while I need angles.

It does provide you with a function to convert them, which gives you bad angles at the edges.

 

A simple rotation around the Y axis jumps like this:

...
(quat -0.0222105 -0.706758 -0.0222105 0.706758)
(eulerAngles 90.0001 86.4 90.0001)

(quat 2.30405e-007 -0.707107 2.30405e-007 0.707107)
(eulerAngles 0 90 0)

(quat 0.0230636 -0.706731 0.0230636 0.706731)
(eulerAngles -90 86.2617 -90)
...

After some research I got told that that is the expected behavior. I tried to write my own conversion function and catch the bad angles, but failed. What exactly should I do to get the degrees?

 

I hope you can help me with this!

Thank you in advance and have a nice day!


[Optimising] Bone based Animation

25 July 2014 - 09:40 AM

Well met!

 

I recently started to optimise my Engine. Using VS2012 Performance analysing tool, I quickly found the biggest bottlenecks.

 

By far the biggest one are my animations. I already managed to go up from 100Fps with 1 simple animated model to 150Fps with 50. While that is not bad, I still need it to get better. 

I fixed everything I could, but I don't know how to continue. The major performance-eaters are 

 D3DXQuaternionInverse

and

 D3DXQuaternionMultiply

which are an essential part of the computation that bone-based animations need, right?

Is there a way to work around those or are there cheaper ways to compute bb animations?

 

Those two take around 50%, the other 50% are beeing lost to stuff like

tempVert->pos.x += ( tempJoint->pos.x + rotatedPoint.x ) * tempWeight->bias;
// or
tempVert->normal.x -= rotatedPoint2.x * tempWeight->bias;
// or
currentSubset->vertices[i]->normal = -tempVert->normal;

( All CPU % in %-of-the-full-time in an uncapped application )

With 5% of the complete CPU time each. I don't understand why those are so very expensive.

Stuff like sqrt, sin and maybe even / are concidered expensive, but why are the basic math operations also a problem?

I am adding the full code of the function in question below, adding the % of CPU to the end of each line which is over 0.1%.

I tried to make it as readable as possible, but the Copy-paste into this forum still screws it up, I'm sorry.

 

Spoiler

 

 

I am new to profiling and optimising, so any tips are welcome! 

Thanks for your time!

 


Decent animation formats

04 July 2014 - 07:34 AM

Well met!

 

I implemented .md5 as the (bone-based) animationformat for my engine quite some time ago, but I need something a little more up to date now (which supports scaling as part of the animations and subsets with independent bonegroups).

I was looking through formats used by big companies (Blizzard, Riotgames, ...), and all of them obviously have their own. I was hoping to be able to find specifications for those, but no luck. 

 

What formats are you using and which ones would you suggest for a 3D game with mid-level graphics (compareable to the new WoWs)? Any good tutorials on implementing one/writing your own, or specifications for a decent one?

Anything will be highly appreciated!

 

Have a nice day!


Specular Mapping on terrain

04 May 2014 - 07:07 AM

Well met!

 

Sorry to be bothering you again - I've been working on this for quite some time now, frustrating myself to great extends.

Let me visualize what I want and what I've got:

 

I want the terrain the reflect the sun, using regular specular-mapping. In WoW, it looks like this:

 

bk3bzeap.jpg

 

 

However, what I get is this: 

 

n4cecvht.jpg

 

I've tuned up the reflection color, so it's better visible where the light reflects. 

 

Here is my pixelshader (the important parts):

/* 

// FROM THE VERTEX-SHADER

output.vertexWorldPosition = mul(input.position, worldMatrix);
output.normal = normalize(input2.normal);
 
 
output.lightViewPosition = mul(input.position, worldMatrix);
    output.lightViewPosition = mul(output.lightViewPosition, shadowView);
    output.lightViewPosition = mul(output.lightViewPosition, shadowProj);
 
 
    float4 worldPosition = mul(input.position, worldMatrix);
    output.viewDirection = cameraPosition.xyz - worldPosition.xyz;
    output.viewDirection = normalize(output.viewDirection);
*/


float4 TerrainPixelShader(PixelInputType input) : SV_TARGET {

float4 finalColor; float4 textureColors[4];  
for(int i=0;i<4;i++){    
textureColors[i] = terrainTextures[i].Sample(SampleType, input.tex);
}
 
 // Ids add up to 1.0f    
finalColor =  (textureColors[0] * input.ids.r) + (textureColors[1] * input.ids.g) + (textureColors[2] * input.ids.b)  + (textureColors[3] * input.ids.a);      
float depthValue, lightDepthValue, lightIntensity;
float3 lightDir = -lightDirection;    
lightIntensity = saturate(dot(input.normal, lightDir));  
finalColor = float4(finalColor.r*(lightIntensity+0.5f), finalColor.g*(lightIntensity+0.5f), finalColor.b*(lightIntensity+0.5f), 1.0f);    
 
if(lightIntensity > 0.0f){
 
//Adds up to 1.0f, calculated on CPU
float specularIntensity = (input.ids.r * specularMaps[0].Sample(SampleType, input.tex).r) +(input.ids.g * specularMaps[1].Sample(SampleType, input.tex).r) +(input.ids.b * specularMaps[2].Sample(SampleType, input.tex).r) +(input.ids.a * specularMaps[3].Sample(SampleType, input.tex).r);    
 
// Calculate the reflection vector based on the light intensity, normal vector, and light direction.
float3 reflection = normalize(2 * lightIntensity * input.normal - lightDir);  
float4 specular = pow(saturate(dot(reflection, input.viewDirection)), specularPower); 
 
specular = specular * specularIntensity;  
specular = saturate(specular);
finalColor = saturate(finalColor + specular);
}  
return finalColor;
}    

The reflections I get look very choppy, and they are nearly everywhere. To get the ray-like reflection, I guess I have to compute some kind of clipping from the viewDirection.

I couldn't get anything to work, thou. I also didn't manage to smooth out the amount of reflection of each pixel - they either get 1 or 0, so I suppose a pixel either reflects or does not? But that means, that I get really visible edges between areas with reflected light, and such which do not.

 

Is there a way to smooth this out, without having to do some kind of post-processing? 

Is it really plane-clipping, or is there some other way of achieving the ray-like reflection?

 

If you could help me out here, that would be as always highly appreciated!

 

Have nice day, and thank you for your kindness smile.png

-gnomgrol

 

 


PARTNERS