• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Texture coordinate scaling + TBN calculation

2 posts in this topic

My TBN (tangent-bitangent-normal) calculation works correctly for planar texture mapping and axis-aligned box mapping, including arbitrary rotations applied via a texture matrix. However, I'm getting an angular shift when I apply scaling to the texture coordinates and then try to calculate the TBN values.


My little brain can't seem to be able to chew through this - as best I can tell the distortion caused by scaling and box mapping (eg projection onto the primary plane) should be implicit in the coordinates themselves and should be handled naturally, but it isn't. The (currently per-face) TBN calculation is based on this and the code looks like this:



face->vNormal = VecNormalize(VecCrossProduct(vertices[face->indexes[0]] - vertices[face->indexes[1]], vertices[face->indexes[1]] - vertices[face->indexes[2]]));
IVector3D v0 = vertices[face->triindexes[0]];
IVector3D v1 = vertices[face->triindexes[1]];
IVector3D v2 = vertices[face->triindexes[2]];
IUVCoords2D uv0, uv1, uv2;
uv0 = face->uv0[0];
uv1 = face->uv0[1];
uv2 = face->uv0[2];
TReal x1 = v1.x - v0.x;
TReal x2 = v2.x - v0.x;
TReal y1 = v1.y - v0.y;
TReal y2 = v2.y - v0.y;
TReal z1 = v1.z - v0.z;
TReal z2 = v2.z - v0.z;
TReal s1 = uv1.u - uv0.u;
TReal s2 = uv2.u - uv0.u;
TReal t1 = uv1.v - uv0.v;
TReal t2 = uv2.v - uv0.v;
TReal r = 1.0f / (s1 * t2 - s2 * t1);
IVector3D tan0((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
IVector3D tan1((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
IVector3D n = face->vNormal;
face->vTangent = (tan0 - n * VecDotProduct(n, tan0)).Normalize();
//calculate handedness
face->vTangent.w = (VecDotProduct(VecCrossProduct(n, tan0), tan1) < 0.0f) ? -1.0f : 1.0f;
face->vBitangent = VecCrossProduct(face->vNormal.AsNormalized(), IVector3D(face->vTangent).AsNormalized());IEditablePolyFace* face = faces[i];
Since the texture looks exactly the way it should, I'm assuming the fault lies with the TBN calculation. I've attached a screenshot taken at an oblique angle of a wall with planar UV mapping. The texture has been arbitrarily rotated. The left image has vertical scaling of 1.4, the right image is unscaled. Red = normal, blue = tangent, green = bitangent.
Any ideas what might be wrong?




Share this post

Link to post
Share on other sites

Are you scaling after the rotation, so as to cause a skew? This would cause the tangent and bitangent to no longer be perpendicular, so calculating the bitangent as the cross product between the normal and tangent won't quite work. Instead, if you calculate the bitangent in terms of tan1 just like you calculated the tangent in terms of tan0, you'll get the right vector. But then you can no longer assume that the inverse of the TBN matrix is just its transpose when you do your shading.


Share this post

Link to post
Share on other sites

Ah ! Yes, I was indeed scaling after rotation. Swapping the order fixes the problem. Can't believe the solution was so obvious :).


How would I go about conforming the box UV mapper (UV-s projected onto the geometry from an axis-aligned cube) to a stable TBN matrix, though? As best I can tell it's not possible as the projection introduces warping. If anything, I'm wondering how 3D programs like Maya and 3DS max handle this (or do they?).


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0