Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Bug Reports / Incorrect Tangent space for skinned objects

Author
Message
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 24th Dec 2010 09:35 Edited at: 24th Dec 2010 09:44
In this example I exported two spinning cubes from 3ds Max 2010. The cube on the left is skinned to a bone that is rotating while the cube on the right is just a regular rotating cube.

the normal map on the cube on the right is lit correctly while the one on the left breaks at most angles. Looks like tangent space calculations are wrong for skinned meshes.

This has been a huge setback on my current game...i've tried rewriting my shaders like 30 times. This example makes it clear that it must be an issue with dark basic.

Please please please fix

db code


shader code

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Dec 2010 16:58
Are you sure the UV coords aren't screwed up? Your object seems to have three meshes and here are their UV coords:



Also, why does the third "box" have 28 sets of UV coords?

Normal mapping assumes that the UV coords have the correct winding order on all polys. Do they on each part of your model?
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 24th Dec 2010 19:32
i re-exported a new model with three boxes...this time the box on the top right has flipped UV coordinates the one on the bottom is just a regular box. They look the same...I attached the .x file.

The "box" with 28 sets of UV coordinates is just a clone of the first box with the skin modifier. I'm not sure why it would have 28 verts. I'm using KWXporter and 3ds max 2010. Maybe it's my exporter... Can you create a similar .X file with your software?

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Dec 2010 19:59
Could you reproduce the same problem with two separate models? At the moment it's hard to see which mesh is which and hence where the problem is exactly. (I can see there is a problem though.)
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 24th Dec 2010 20:07
Okay I exported the two boxes separately.

on a side note, i tried exporting the same art with pandaxporter and I got the same result...skinned mesh wouldn't light correctly.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Dec 2010 21:35
Ok, I'll test that later this evening. Busy right now.
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 28th Dec 2010 20:21
Any luck with this, I've tried several different methods and every time I get the same results. Do you think it's a problem with the exporters or do you think it's an issue with Dark Basic?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Dec 2010 12:46
Sorry, I've been taking a brief break for some reason (). I'll try to find time to look at this again today or tomorrow.

Quote: "Do you think it's a problem with the exporters or do you think it's an issue with Dark Basic?"


Not sure what the problem is. It may be that you need to add something to the shader. I doubt it's your exporter. It could be a DBPro limitation. I vaguely recall that some animated models need to be handled differently.

I suspect you might be right about the tangent space suggestion. Perhaps DBPro doesn't update those correctly. Anyway, I'll look into it and report back.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Dec 2010 13:57 Edited at: 30th Dec 2010 18:54
I've played around with this for a while and have exactly the same problem you've been experiencing. I'm not sure what the essential difference is between the two models - both seem to be lit correctly using standard lighting but, as you say, the skinned version isn't lit correctly when tangent space bumpmapping is used. I've tried to adjust the tangent space calculations in the shader but have only succeeded in making matters worse .

I've very little experience of working on animated models with shaders so it's quite possible (likely even? ) that I'm just showing my ignorance. Some time back VanB posted a demo of a "fastbone.fx" shader which I believe works with skinned models. It's just possible that something similar might be needed here - but it's equally likely that I'm barking up the wrong tree.

[
Edit Here's the link for VanB's demo. The discussion suggests that it might indeed be relevant but at the moment I'm not sure how to implement the changes needed for tangent space bumpmapping. Food for thought.

VanB's fastbone shader demo

]

Can anyone else cast light on this? I think it ought to be flagged as a DBPro bug/limitation till we are proved wrong.

I'll come back to this if I have anything more useful to say. I'll post my demo later today which shows the problem.

Edit2 Here's the demo. I've tried to remove all unnecessary code from the dba and fx files.

Edit3 If I'm right about the relevance of VanB's demo then the "bumpbone.fx" shader that comes with DarkShader (and FPSCreator I believe) may be just what you need (with minor edits possibly ). I'll see if I can get it working with your models.

Edit4 Just tested that bumpbone shader and it seems to be exactly what you need (plus lots of additional features ). You'll still need the other shader for unboned models though.

Attachments

Login to view attachments
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 30th Dec 2010 21:22
Awesome thanks man! I'll try it out as soon as I get back to Irvine on the 4th. Seems a bit strange that the two models would need different shaders but as long as the results work, i'm all for it! thanks again!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Dec 2010 22:30
Post back if you need help getting it working. It's a great shader with several handy features.
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 4th Jan 2011 12:08
yeah i'm having a lot of trouble getting this working ...do i need to pass any special matrix to the shader? do you have any examples of this shader working?

when i transfer the bonematrix calculations over to my shader, the end position is just very wrong. It's all over the place.

another issue may be the number of bones i am using in one .x file. I know the one character has 75ish bones.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Jan 2011 13:44
Quote: "do i need to pass any special matrix to the shader?"


I don't think so.

Quote: "do you have any examples of this shader working?"


I've got a simplified version working (I removed several features that weren't relevant to your initial problem). I'll tidy it up and post it later today.

Quote: "when i transfer the bonematrix calculations over to my shader, the end position is just very wrong. It's all over the place."


Not sure what you mean - it should be done automatically by DBPro. VanB's demo shows you what to do. This one merely has bumpmapping and a few other "bells and whistles" added to it.

Quote: "another issue may be the number of bones i am using in one .x file. I know the one character has 75ish bones."


If you think that's the issue why not try a less complicated model first? It's always a good idea to practise a new technique with something simple first.

Off-hand I'm not sure what the limit of 60 refers to in the shader, the number of bones or the number of levels in the bone heirarchy. I would expect it to be the latter but I might be wrong. The important thing should be the number of rotation matrices that need to be multiplied together in order to find the position and angle of a distant bone. So you could have hundreds of bones on your monster but each bone might need at most a dozen bone rotation matrices.

If I get time I'll see if I have any suitably complicated boned models lying around.
Duke E
15
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 5th Jan 2011 11:56 Edited at: 5th Jan 2011 12:01
With skinned boned models one have to iterate trough vertexes in the bonematrix to get the average angle/position and calculate the (bi)normal, tangents etc from there.

I tried a shader I think i got from a demo in one of the newsletters, probably originally from FPSC. I added specular and emissive plus extra lightsources though.
(found it - Lee's Tip of the Month - Big bag of shaders:
http://www.thegamecreators.com/pages/newsletters/newsletter_issue_62.html)

Anyway i tried to apply it to your testobjectskinned.x, however it seems not to be valid, MView spits the model out pretty instantly too .

Regards
Duke
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Jan 2011 13:54
provoststeven

My apologies. What I said in my previous post was completely wrong.


The BoneMatrixPalette uses the frame matrices in the x file and at most 4 are used per vertex in the shader. The current FPSC version of the shader uses a maximum of 60 matrices so I guess if your model uses more then it won't work.

Have a look at the attached demo. It uses two copies of the "tiny.x" model that comes with the MS DX9 SDK. I have applied both shaders (i.e. your original one and a shortened version of the FPSC one) to the model. The model has about 49 frame matrices and looks the same using both shaders. Press and hold "r" to rotate the light or "o" to rotate the objects.

If you change the "60" in the shader to "32" then the "tiny" model screws up. This sounds like your problem so perhaps you were right about the number of bones being the problem.

The main difference between those two shaders is the frame rate - the FPSC boned one runs about 3 times faster than your original one on my machine (2500 fps versus 870 uncapped).

However, when I use your much simpler model I seem to need the boned version. The upshot of all this is that there seems to be something special about your boned model. I've no idea what for the moment. If you're familiar with the layout of X files you might be able to spot the key difference in a text editor (I find WordPad is good for this).

Attachments

Login to view attachments
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 6th Jan 2011 05:16
it's difficult to judge the tiny model, the problem is that the limbs always stay close to their base rotation, and the normal map is very noisy. The rotation that is occurring is applied to the whole model and is not a result of skinning, so it would mask the error if it is still occurring.

I tested this using the skinned .x file i provided, and the shader with the bone matrix calculations worked correctly. The shader without bone matrix calculations was still broken. This leads me to believe that there is no error with my .x file. If the gpu can calculate correct tangent space matrices for it, then so can the cpu...the error must be in darkbasic's calculations.

I am relieved that there is a work around for objects with 60 bones or less , however, this work around does not solve my problem...is there any way i can edit the tangent space calculations in dark basic? This 60 bone limitation is not something i can easily remedy. I've been working on this fighting game for close to 2 years, and i have just recently finished 2 characters with 119 animations a piece. To re-rig the models with less bones and redo the animations would be a huge step backwards that i cannot afford to take.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Jan 2011 13:19 Edited at: 6th Jan 2011 13:33
Quote: "it's difficult to judge the tiny model, the problem is that the limbs always stay close to their base rotation, and the normal map is very noisy. The rotation that is occurring is applied to the whole model and is not a result of skinning, so it would mask the error if it is still occurring."


Fair point. I didn't think of that.

Quote: "I tested this using the skinned .x file i provided, and the shader with the bone matrix calculations worked correctly. The shader without bone matrix calculations was still broken."


Yes, I'd already said that.

Quote: "This leads me to believe that there is no error with my .x file. If the gpu can calculate correct tangent space matrices for it, then so can the cpu...the error must be in darkbasic's calculations."


On reflection I think you may be right. Unfortunately I don't have any other boned animated models to test with (except other characters which will have the same problem you mentioned).

You might get more help on one of the other boards where people do lots of 3D modelling - to confirm your findings if nothing else. I'm out of ideas now (other than the bug possibility).

Quote: "This 60 bone limitation is not something i can easily remedy. I've been working on this fighting game for close to 2 years, and i have just recently finished 2 characters with 119 animations a piece. To re-rig the models with less bones and redo the animations would be a huge step backwards that i cannot afford to take."


I agree - but I have no experience of such models. I don't know off-hand where the 60 bone limit comes from, DirectX or DBPro. I'll try to find out and report back. However, it may be like other fixed limitations in DBPro - you just have to work within them.

One outside possibility is that you might be able to bypass the limit by using set limb effect instead of set object effect. That seems to work with the demo I posted yesterday, i.e.



(the "tiny.x" model has 49 limbs).

Let me know if that works.

[Edit I suspect it won't - the limb effects seem to be either applied to the whole boned model or to none of it. For example, if I include limb 48 the whole model has the shader otherwise none of it has. Still worth a try though. Only takes a moment to test.]
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 6th Jan 2011 21:52
That will work! the set limb effect may not work, but the idea of dividing the model into more managable sections definitely will. This is actually how my company exports objects with more than 64 bones, it divides the mesh and exports the required bones separately...all of the information of the two meshes is contained in a single M3 file. It's a bit of a pain in the butt, but i can manually divide and export my characters.

The only downside would be losing the ability to have a single smoothing group for the entire object...however, i know it is possible to edit the normals of points in 3ds max to make them line up correctly accross separate meshes.

I'll try it later on tonight...but i can't see any reason for this to fail. Thanks man!!!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Jan 2011 02:02
I didn't actually suggest splitting the model because I wasn't sure how practical that would be - but you've obviously realised it is in your case. That's good news. Let us know how you get on since the information would be very useful to others I'm sure.

I believe the DBPro limit is 60 bones per limb mesh for this shader (64 seems to make more sense in this byte based world but I've seen 60 mentioned in a few places in connection with FPSC including a note from Lee and of course the shader code itself).
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 7th Jan 2011 12:21
It worked!...i'm exhausted so i'll put up a working example tomorrow or saturday. It was a huge pain in the butt because of the way i was testing collisions, but the important thing is, it worked

naptime

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Jan 2011 13:11
Fantastic! Well done. Looking forward to the demo.

Login to post a reply

Server time is: 2024-04-24 22:15:20
Your offset time is: 2024-04-24 22:15:20