Vernon on 28/9/2011 at 07:00
Both, but I was specifically referring to the stuff in this thread. I like the chunky aesthetic :cool:
Yakoob on 28/9/2011 at 07:06
Quote Posted by Volitions Advocate
I just thought I'd bring this up.
Oh yea. I love MS for those kind of reasons. People shit on MS because they are the big bad corporation but honestly, they treat their devs so damn well. With pretty exhaustive documentation, amazing tools (VS, debugger, PIX), good cross-platform APIs (DX, XAudio, XNA, .Net) and even options for indies to develop on their proprietary console (via XNA), its is really nice developing for their platforms (especially compared to stuff like Wii or PS3 development).
zombe on 28/9/2011 at 19:07
Trying to reinvent the bicycle (as my Google skills fail) and getting sick of it :( - perhaps some of you have experience with it:
Basically, i need to construct a quaternion + handedness to describe the normal and tangent space per vertex. The quaternion MUST preserve the normal (so, the constructed tangent space will pretty much always differ from the surface one - plus the real / surface tangent space is usually sewed anyway).
Probably it will be enough to use the tangent space of the largest relevant triangle, but if anyone knows some fast / dirty way to average it - that would be nice too (probably too expensive tho, as i must recalculate all of it at initialization time).
I'm stuck :( ...
PS. quaternion is the wanted end result, but i do not expect there to be some optimized version for getting it directly - so, first and foremost i need to construct a 3x3 orthogonal rotation matrix for the tangent space (ie, if "quaternion" bothers you [they mostly confuse the shit out of me at least] - ignore i said it. Matrix to quaternion conversion is fairly simple anyway ... not sure how do i get the handedness out of it tho :/).
edit: bullshit
edit: Ok, let's simplify the problem a little more - how do i orthogonalize the matrix preserving the normal?
edit: At least this works (does it?) on paper, but pretty much guaranteed to be the most inefficient way of doing it:
N=normal (normalized), T=tangent (unnormalized), B=bitangent(unnormalized). Using [X] to mean normalize(X):
T' = [ B x N ] // get the tangent on normal's plane according to bitangent
B' = [ N x T ] // get the bitangent on normal's plane according to tangent
L = (B' + T') * 0.5 // half-way diagonal
T'' = [ [ L ] + [ T' - L ] ] // adjusted (basically rotating L 45 degrees towards T' on normal's plane) normalized tangent on normal's plane
B'' = N x T'' // get the accompanying normalized bitangent
... this is just horrible x_x (3 cross products & 5 invsqrt's etc ... just to get the orthogonalized rotation matrix)
edit: Actually .. new plan: calculate tangent only then apply Gram-Schmidt orthogonalization and get the bitangent via cross product.
continuing tomorrow.
Yakoob on 30/9/2011 at 05:40
Quote Posted by zombe
edit: At least this works (does it?) on paper, but pretty much guaranteed to be the most inefficient way of doing it:
N=normal (normalized), T=tangent (unnormalized), B=bitangent(unnormalized). Using [X] to mean normalize(X):
T' = [ B x N ] // get the tangent on normal's plane according to bitangent
B' = [ N x T ] // get the bitangent on normal's plane according to tangent
L = (B' + T') * 0.5 // half-way diagonal
T'' = [ [ L ] + [ T' - L ] ] // adjusted (basically rotating L 45 degrees towards T' on normal's plane) normalized tangent on normal's plane
B'' = N x T'' // get the accompanying normalized bitangent
... this is just horrible x_x (3 cross products & 5 invsqrt's etc ... just to get the orthogonalized rotation matrix)
edit: Actually .. new plan: calculate tangent only then apply Gram-Schmidt orthogonalization and get the bitangent via cross product.
continuing tomorrow.
uugh, ugly ugly. I always hated that part. I'm normally good at maths, but every time I work with tangets and crap I always need to re-look up tutorials. It never sticks.
Tho whenever I was calculating the tangent-space vectors, I'd always take into account the vertex tex-coords to get the proper orientation, which you don't seem to be doing? Maybe you can incorporate that somehow into your math to make it easier.
Also, I would normally pre-compute this stuff somehow if performance was an issue and store it in vertices (remember you only really need the x and y coord since you can reconstruct z in shader - you knw it will always point towards the camera since otherwise you wouldnt be rendering it!)
Hope this is somewhat useful...
zombe on 30/9/2011 at 17:39
Quote Posted by icemann
GLUT
I assume you mean FreeGLUT here (using GLUT today would border insanity - GLUT development was completely abandoned over 12 years ago). Unfortunately, the last time i used anything like that was over 5 years ago - so, can not really say anything helpful :/
Quote Posted by Yakoob
Tho whenever I was calculating the tangent-space vectors, I'd always take into account the vertex tex-coords to get the proper orientation, which you don't seem to be doing?
That math is meant to reorthogonalize the rotation matrix i get by combining vertex (not surface - ie, weighted average of the relevant triangles), tangent and bitangent vectors (calculated in a previous step [plenty of tuts for that, so did not bother to write that down ... yet]).
Quote Posted by Yakoob
Also, I would normally pre-compute this stuff somehow if performance was an issue and store it in vertices
The primary issue is actually storage space - so, most of the world geometry is generated to begin with. Going with the initialization-time re-calculation approach for now.
Quote Posted by Yakoob
remember you only really need the x and y coord since you can reconstruct z in shader - you knw it will always point towards the camera since otherwise you wouldnt be rendering it!
Vertex normal (and the other ones too) does not always point out of the screen ... you forgot smoothing ;)
Also, one quaternion (8B of data, ie. 4 * normalized unsigned short) is enough the define all three vectors. + 1 bit worth of data for handedness somewhere.
Got a bit distracted yesterday doing other stuff (and failing completely ARGH!) - giving it another go now. Will report back if i get anything i am
happy ok with.
zombe on 30/9/2011 at 19:57
Here goes:
vec3: P, Pa, Pb - triangle vertexes CCW: P->Pa->Pb
vec2: Pt, Pta, Ptb - triangle UV coords
Pass1-per triangle:
vec3: TN = (Pa - P) x (Pb - P) // triangle normal (unnormalized).
add TN to each vertex normal (Nv) // TN is essentially normalized-triangle-normal * triangle-size * 2.
float: TA = TN * TN // ( triangle size * 2 ) ^ 2
update vertexes reference to biggest triangle (using TA) and triangle reference count to skip the triangle at Pass3
Pass2-per vertex:
vec3: Nv = normalize(Nv)
Pass3-per triangle (skip triangle if none of the vertexes have it as the biggest one):
vec3: Ea = Pa - P, Eb = Pb - P // calc edge vectors
vec2: Eta = Pta - Pt, Etb = Ptb - Pt // calc UV vectors for the edges (NB! i do not actually intend to use the x axis of thous)
float: D = Eta.y * Etb.x - Eta.x * Etb.y // calc UV coordinate triangle determinant (ie. UV-winding)
if(D > 0) it is CW, but we want CCW: Etb = -Etb, and remember that we use left-hand coordinate system
vec3: T = Ea * Etb.y - Eb * Eta.y // calc unnormalized tangent for the whole triangle. (UV axes are perpendicular, so: take Etb.y worth of Ea and adjust it by removing Eta.y worth of Eb [at least it sounds like pretty standard base change - can anyone confirm?] ... yes, it makes my head hurt and i am not 100% sure i got it right)
per-vertex (only the vertexes that are not done yet):
vec3: Tv = T - Nv * (T * Nv) // adjust the tangent to be perpendicular with the normal (ie. subdract the amount it is not perpendicular [T * Nv] in normal's direction).
Tv = normalize(Tv) // normalize tangent
vec3: Bv = Nv x Tv // calc bitangent. no need to normalize as both Nv & Tv are normalized
vec4: Q = cast the matrix (Nv, Tv, Bv) to quaternion, encode the coordinate system handedness into it afterwards (or just do not use upside down texture mapping to begin with - we are not in DirectX world! get your UV mapping right g*damn-it! would cut out the conditional and the determinant crap)
-----------------------
PS. understanding the simplifications made is strongly advised prior to usage!
PS2. did i fuck up something (0 testing, just used paper and pencil)? the coordinate system base change sounds a bit iffy, but the few test numbers i tried did give the correct results at least.
demagogue on 30/9/2011 at 21:39
Quote Posted by dethtoll
nodding Jay
good lord development advice in a development thread what has the world come to?
Matthew on 30/9/2011 at 22:36
To be fair, that's pretty much exactly what I looked like when reading it. :p
zombe on 30/9/2011 at 22:40
I think he just wanted to, humorously, say - i don't get it (instead of: whatever / right, moving on etc).