Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
dim::matrix4f getTangentSpace( const dim::vector3df PosA, const dim::vector3df PosB, const dim::vector3df PosC, // Pos -> Vertex position (in ObjectSpace) const dim::point2df MapA, const dim::point2df MapB, const dim::point2df MapC, // Map -> Texture koordinaten dim::vector3df &Tangent, dim::vector3df &Binormal, dim::vector3df &Normal) { const dim::vector3df v1(PosB - PosA); const dim::vector3df v2(PosC - PosA); const dim::point2df st1(MapB - MapA); const dim::point2df st2(MapC - MapA); Normal = v1.cross(v2); f32 coef = 1.0f / (st1.X * st2.Y - st2.X * st1.Y); Tangent.X = coef * ((v1.X * st2.Y) + (v2.X * -st1.Y)); Tangent.Y = coef * ((v1.Y * st2.Y) + (v2.Y * -st1.Y)); Tangent.Z = coef * ((v1.Z * st2.Y) + (v2.Z * -st1.Y)); Binormal = Normal.cross(Tangent); Tangent .normalize(); Binormal.normalize(); Normal .normalize(); return dim::matrix4f( Tangent.X, Binormal.X, Normal.X, 0, Tangent.Y, Binormal.Y, Normal.Y, 0, Tangent.Z, Binormal.Z, Normal.Z, 0, 0, 0, 0, 1 ); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
// Tangent und Binormal uebergebe ich per Texture Koordinaten weil ich keine "attribute" verwenden kann/will. vec3 Tangent = gl_MultiTexCoord3.xyz; vec3 Binormal = gl_MultiTexCoord4.xyz; vec3 Normal = gl_Normal.xyz; mat3 NormalMatrix; // Dies ist ein "varying" damit ich sie im PixelShader verwenden kann NormalMatrix[0] = mat3(WorldMatrix) * Tangent; NormalMatrix[1] = mat3(WorldMatrix) * Binormal; NormalMatrix[2] = mat3(WorldMatrix) * Normal; |
C-/C++-Quelltext |
|
1 2 3 |
Binormal.X = -(v1.X * st2.X) + (v2.X * st1.X); Binormal.Y = -(v1.Y * st2.X) + (v2.Y * st1.X); Binormal.Z = -(v1.Z * st2.X) + (v2.Z * st1.X); |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »LukasBanana« (05.01.2011, 18:49)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige