PDA

View Full Version : Unity3D Tangent Basis Calculator plugin for xNormal


Farfarer
03-02-2012, 09:27 AM
Update
It's out and fully synced to Unity's tangent basis now.

Get it here!
http://www.farfarer.com/temp/unityTangentSpace3.png (http://www.farfarer.com/blog/2012/06/12/unity3d-tangent-basis-plugin-xnormal/)

Frankie
03-04-2012, 06:31 AM
Using objs, I get an 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

when swapping to your tangent calculator.

I also get it when using the mikk-tshape caluclator with fbx and haven't been able to fix that so could be something up with my system...

Nice work trying to fix it though, a bit disappointing how unity haven't bothered to sort it out or help you on the unity community forum.

Farfarer
03-04-2012, 04:57 PM
Yeah, I get that with certain file formats and normal combinations (eg, FBX from 3DS Max and Average Normals setting).

No idea why, but I think it's an issue with xNormal rather than my plugin.

kio
03-05-2012, 01:41 AM
cool stuff - maybe i can give it a try in a few weeks at work, projekt with some normalmapping comming up

Farfarer
03-07-2012, 01:30 PM
Updated the plugin to v0.2.

Implemented a more robust unique vertex identifier method (some folk reported issues due to it assigning the same ID to two different unique verts).

http://www.farfarer.com/temp/UnityTSpace.zip

Ged
03-15-2012, 09:11 AM
cool, I havent used normals in unity much, partly because Im on a mac at work and dont have a way to bake normals on a mac :(

gregs
03-17-2012, 02:38 AM
Thank you so much for this!

Justin DeVore
05-09-2012, 08:57 AM
Hi, Talon - The latest version of xNormal(3.17.13) doesn't seem to recognize the plugin (it doesn't show up anywhere in settings). I tried it on an older version (3.17.9) and it did find it successfully.

bugo
05-09-2012, 09:40 AM
Talon, correct if I'm wrong, but doesn't Unity have the "about" the same tangent basis normals as Maya does?

Farfarer
05-09-2012, 09:53 AM
Might do, I'd have to look into how Maya calculates it to be sure. I managed to get it pretty close, but I don't really want to release another version until I've properly worked it out. Seems kinda pointless otherwise.

I've had to shelf this for the time being as I've got other stuff with tight deadlines but I'll be back on it in a couple of weeks.

bugo
05-13-2012, 01:45 PM
That's fine, but if you actually do it, I could have the use not only for Unity but as well for Maya ;) (if both are the same)

Farfarer
05-21-2012, 06:28 AM
Well, I worked up a Maya tangent basis calculator as well as I could based on the code here: http://download.autodesk.com/us/maya/2011help/index.html?url=./files/Appendix_A_Tangent_and_binormal_vectors.htm,topicN umber=d0e227193.

It seems to give vastly different results to Unity's method, so I suspect it's not using that.

The fact it's so different makes me suspect I'm doing something wrong, but I haven't got access to Maya at the moment to test that suspicion.

I'll fiddle some more but I wouldn't hold your breath :P

bugo
05-22-2012, 08:57 AM
You are right, i did some tests and I could see why they are slightly different, but at least is not as different as Max or Xnormal.

Farfarer
06-07-2012, 02:38 PM
With the help of the Unity devs, I've managed to get this working right.

Got some final tweaks to make to it to speed it up some more before I release it, though :)

http://www.farfarer.com/temp/unityTangentSpace.png

seforin
06-07-2012, 02:54 PM
Im tackling this EXACT issue right now but unfortantely Im working on the max side of things...

I have been trying to figure out ways to have it import my mesh without horrible seam screw ups etc and not pre calculating my tangents (Seriously unity wtf man)


I dont suppose you can toss up examples of what you did so I can maybe squeeze that into a max script eventually?

We can talk in pms if you dont wanna clutter this chat.


edit:I also tried chaning up the way the Nmap bakes to keep it Y positive so that unity wouldnt need a flipped Y channel to see if that fixes it , but it still gives me weirdness going on.

Example of what I mean

https://dl.dropbox.com/u/11483203/deper01.JPG


as you can see on the left side of that box Im having a harsh seam line there as if it has a smoothing group split, but lord and behold everything (but the bottom) has smoothing group 1 assigend to it and smoothing group 2 on the bottom.


And every time I import a .max file or .fbx it keeps setting tangents to "calculate" vs import...seriously I want to smack unity right now this is really hindering progress of the current project I am on!

Farfarer
06-08-2012, 12:17 AM
Well, you won't be able to fix this with Maxscript or on the Max side easily.

Importing .FBX files, you have to export them with normals, tangents and binormals otherwise Unity'll generate it's own. You can fairly write an Editor script to set models to always import tangents on import, too.

Also, Unity doesn't import the binormal that's in the FBX file, it only uses it to figure out whether to flip the binormal that's generated in the shader.

Importing .max files, Unity just fires up Max in the background and gets it to export an FBX file for it to import.

cupsster
06-08-2012, 04:58 AM
TRUE

seforin
06-08-2012, 08:49 AM
Well, you won't be able to fix this with Maxscript or on the Max side easily.

Importing .FBX files, you have to export them with normals, tangents and binormals otherwise Unity'll generate it's own. You can fairly write an Editor script to set models to always import tangents on import, too.

Also, Unity doesn't import the binormal that's in the FBX file, it only uses it to figure out whether to flip the binormal that's generated in the shader.

Importing .max files, Unity just fires up Max in the background and gets it to export an FBX file for it to import.

yeah but even still it disables them upon import...the only solution I have read for it to read proper is that your meshes need to be set on "editable mesh" vs poly (Which I find kinda BS and thats a FBX issue on autodesks side that I believe there not addressing)

theres a ton of info on this in this thread and a bit of the reason why im going buggy

http://forum.unity3d.com/threads/96239-seams-apparent-in-Unity-when-I-put-on-my-mesh-s

Frankie
06-08-2012, 09:06 AM
Nice one Talon!

Haha seforin longest sig ever!

Farfarer
06-08-2012, 05:10 PM
Strange, I've had no issues using FBX exported from 3DSMax or modo.

You're definitely using the latest FBX plugin?

seforin
06-09-2012, 12:29 PM
yea after reading some more into this I found some weirdness and solutions to it.

the major being that for some reason when you have your project set to defered lighting, and shader model 2 and you export lets just say a box 2 smoothing groups and a normal map etc baked, and you export that as a FBX when it imports it in and applies it, the model comes out messed up and it gets bad lighting information etc.

After trying a few tricks...in the end (more by accident then anything else)setting your model as "editable mesh" vs editable poly adn exporting out as a FBX and it works fine.

This is infact using max 2012 and its newer FBX settings, and its not just pc dependant I have done tests both at my home pc and work.

its quite strange...but luckly that whole thread you made with the unity coder messaging you on there forums helped me out alot since they droped there info on how they are handling there tangents and such....so my coder friend is thinking of just writing his own importer/exporter for unity and max.

Gonna Call it Derp format (Doing Everything Right Project)

Justin DeVore
06-09-2012, 05:44 PM
Great to hear you've made some more progress, Talon! I eagerly await your next release. Any chance it will work with xNormal 3.17.13 this time around?

Farfarer
06-10-2012, 02:55 AM
Yep, I've ported it over to the latest version (.13). I'll release it early next week after I've had time to fix up some stuff.

Farfarer
06-12-2012, 10:25 AM
http://www.farfarer.com/blog/2012/06/12/unity3d-tangent-basis-plugin-xnormal/ :D

funshark
06-12-2012, 01:10 PM
What about the Maya version? :D

Farfarer
06-12-2012, 02:56 PM
I thought Maya was pretty good with itself between baker/renderer?

funshark
06-12-2012, 03:26 PM
Yes it is, but with very high res meshes, you have to deal with Xnormal at the end. and Xnormal produces better AO andplenty of different useful maps you know :)

renderhjs
06-12-2012, 05:53 PM
just saw the post on your blog Talon
http://www.farfarer.com/blog/2012/06/12/unity3d-tangent-basis-plugin-xnormal/

nice one :thumbup:

bugo
06-12-2012, 07:15 PM
To be true if you are using the advantage package of 2012 and 2013 you got Turtle, best/fastest baker of nmaps and AO ever! (believe me, I tried all of 'em)

Justin DeVore
06-13-2012, 04:23 AM
Great! So glad you stuck with this!

cupsster
06-13-2012, 10:10 AM
you are my hero of the day! :)

jderiggi
06-21-2012, 08:13 AM
Hey Talon. Thx so much for the great plugin! I have seen it work for a coworker, but I am still getting the memory error mentioned very early in this thread when using the 32bit version of the newest Xnormal. I am not using Average Normals or FBXs. Both high and low res meshes are objs: high exported from Zbrush, and low exported from Maya. Thanks for any help!

Farfarer
06-21-2012, 08:22 AM
I think this is an issue with the files not having exported normals, which my plugin is trying to access.

I've got a check in for that in my local build of the plugin, but I'll have to do a bit of testing before I release it.

For the time being, if you select Average Normals, does the issue go away?

Farfarer
06-21-2012, 08:24 AM
Also, there's a bit of an issue with the way Unity handles the smoothing angle at the moment.

Here's how to work around it until I get a proper fix in;
http://www.farfarer.com/temp/unityTangentSpaceIssue.png

jderiggi
06-21-2012, 09:21 AM
Thx for the quick reply. I tested both high and low res meshes with Average Normals, then just the low res mesh with it on. Neither option works unfortunately. The low res mesh obj was exported from Maya with Smoothing and Normals turned on as well. Thx again for any further info!

Farfarer
06-21-2012, 09:39 AM
Hmm... what happens if you try another file format, FBX for example?

HotSizzlingJaz
06-27-2012, 01:28 PM
Big thanks for creating this wonderful little plugin!!! I made a test example to prove it works. The example is a simple window baked on a very low poly mesh with very soft normals. I made it into two smoothing groups to not stress the normals too much. But I am very happy about the result. Cheers!

http://www.jenzolsson.se/Concept/Polycount/UnityNormals.jpg

/Jenz

jderiggi
07-03-2012, 06:42 AM
Thanks for the idea Talon. Fbx files do seem to work for the low poly with a cage exported from Maya loaded into Xnormal, with one smoothing group on the low poly mesh. If I follow your steps within Unity for the model (setting Tangents to Calculate and the Smoothing Angle to 180), it seems to work overall.

Myself and a coworker also tried the 2 cage types that Xnormal can create, SBM and OVB. Both of these throw the memory read error with the Unity plugin. So I guess it's FBX all the way! Thanks again!

MrOneTwo
07-05-2012, 03:09 AM
Do you plan making 64 bit version ? I installed x86 version of Xn only for this plugin.

Farfarer
07-05-2012, 03:25 AM
Ehr, I might do. Right now, I don't actually know how.

Making this has been the first time I've ever written C++ or used Visual C++... it's all totally foreign to me. I know next to nothing about proper programming.

I'll see if I can figure it out.

MrOneTwo
07-05-2012, 03:29 AM
Ohhh... nice results for programming noobie. Thanks anyway. Its a great plugin.

Farfarer
07-09-2012, 03:31 AM
So it turns out I can't make 64bit stuff with the free version of Visual C++. I'll need to source access to the full version and then export there.

I'll keep you posted :)

MrOneTwo
07-09-2012, 03:35 AM
Yay cool to hear you wanted to sink your teeth into 64 bit version so soon. Thanks!

Farfarer
07-16-2012, 07:15 AM
I managed to get the 90 day trial version of Visual Studio 2008 and figured out how to build x64 versions of the plugin.

http://www.farfarer.com/blog/2012/06/12/unity3d-tangent-basis-plugin-xnormal/

MrOneTwo
07-25-2012, 06:34 AM
Great news! Thanks man.

monster
10-26-2012, 02:18 PM
Any plans to update for xNormal 3.17.14?

Farfarer
10-26-2012, 02:59 PM
Yeah, made a start on that yesterday but it was throwing some errors at me, I'll need to take a proper look at it.

Farfarer
11-07-2012, 09:29 AM
Sorry this took so long, the Visual Studio project ended up with wrong settings somehow having set it up in 2008 rather than Enterprise but I finally sorted it out (it's all complete jargon to me).

Also discovered the versions I'd released previously were still in unoptimised debug mode, so hopefully this'll be a little faster now, too.

http://www.farfarer.com/blog/2012/06/12/unity3d-tangent-basis-plugin-xnormal/

monster
11-07-2012, 07:57 PM
Awesome thanks!

bb0x
01-08-2013, 08:34 AM
Hey,

This is awesome, thanks for this. =]

I was wondering if the Unity guys ever released their tangent basis that they use or is what you have a super close "guess" that looks ok 99% of the time.

-edit-
Actually... never mind, just checked out your blog post where it says the unity guys released the source code.

Farfarer
01-09-2013, 03:25 AM
Yeah, Aras posted it up on Github.

Check it out here if you're interested :)

https://gist.github.com/2843984

Farfarer
04-30-2013, 04:03 AM
By the way, I updated this recently - fixed a silly bug that cropped up now and then (trying to optimise the optimising too much :P).

Still for 3.17.15, I'll update it for 3.18.1 later.

Farfarer
04-30-2013, 09:02 AM
And updated to 3.18.1 same link as before.

monster
05-03-2013, 02:12 AM
Thanks for the updates!