Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Fr Apr 26, 2024 19:54

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 7 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: u,v -> s,t
BeitragVerfasst: Fr Sep 09, 2005 01:34 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Im wondering how to convert u,v to s,t coords. Searching the net has come up with nothing helpful.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Sep 09, 2005 11:36 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
What are s,t coordinates?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Sep 09, 2005 13:34 
Offline
DGL Member

Registriert: So Sep 26, 2004 05:57
Beiträge: 190
Wohnort: Linz
What are u, v coords? :-)

They are just other letters for the same thing. OpenGL uses s,t,r and some graphic editors and D3D are using u,v,w. Maybe there are small varieties in the meaning of (0;0) = (left;top) or (0;0) = (right;bottom) and you have to be carefull with the usage of non power of two textures too.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Sep 09, 2005 14:11 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
I thought u,v are in world space and s,t are in texture coords.

Zitat:
The texinfo lump (6) contains an array of texinfo_t structures:

typedef struct texinfo_s
{
float textureVecsTexelsPerWorldUnits[2][4]; // [s/t][xyz offset]
float lightmapVecsLuxelsPerWorldUnits[2][4]; // [s/t][xyz offset] - length is in units of texels/area
int flags; // miptex flags + overrides
int texdata; // Pointer to texture name, size, etc.
} texinfo_t;

Each texinfo is 72 bytes long.

The first array of floats is in essence two vectors that represent how the texture is orientated and scaled when rendered on the world geometry. The two vectors, s and t, are the mapping of the left-to-right and down-to-up directions in the texture pixel coordinate space, onto the world. Each vector has an x, y, and z component, plus an offset which is the "shift" of the texture in that direction relative to the world. The length of the vectors represent the scaling of the texture in each direction.

The 2D coordinates (u, v) of a texture pixel (or texel) are mapped to the world coordinates (x, y, z) of a point on a face by:
u = tv0,0 . x + tv0,1 . y + tv0,2 . z + tv0,3
v = tv1,0 . x + tv1,1 . y + tv1,2 . z + tv1,3

where tvA,B is textureVecs[A][B].


The U,V calculation uses the Vertex's position which doesn't give s,t coords. (Insted of having a nice texture its basicaly one colour).

Code:
  1.  
  2. P := {Normalize2}(RenderVerts[rendervertno].Position);
  3.  
  4. RenderVerts[rendervertno].TextureCoord.X := (TexInfo[Faces[x].TexInfo].TextureVects[0][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[0][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[0][2] * P.Z) + TexInfo[Faces[x].TexInfo].TextureVects[0][3];
  5. RenderVerts[rendervertno].TextureCoord.Y := (TexInfo[Faces[x].TexInfo].TextureVects[1][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[1][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[1][2] * P.Z) + TexInfo[Faces[x].TexInfo].TextureVects[1][3];
  6.  


The above code gives the following result:

Bild

The best i can get it is with the following code:
Code:
  1.  
  2. RenderVerts[rendervertno].TextureCoord.Y := (TexInfo[Faces[x].TexInfo].TextureVects[0][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[0][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[0][2] * P.Z)/TexData[TexInfo[Faces[x].TexInfo].texdata].Height + TexInfo[Faces[x].TexInfo].TextureVects[0][3];
  3. RenderVerts[rendervertno].TextureCoord.X := -(TexInfo[Faces[x].TexInfo].TextureVects[1][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[1][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[1][2] * P.Z)/TexData[TexInfo[Faces[x].TexInfo].texdata].Width + TexInfo[Faces[x].TexInfo].TextureVects[1][3];
  4.  


Bild

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Sep 09, 2005 15:30 
Offline
DGL Member

Registriert: So Sep 26, 2004 05:57
Beiträge: 190
Wohnort: Linz
Ok, this is a very special usage of s,t,u and v :-).

[edit] forget it ... bullshit

[edit2] ok I don't know what exactly these values are meant for, but at least I think to normalize the vertex position isn't a good idea. But I guess you've already tried this?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Sep 09, 2005 16:47 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Yep, normalising it makes the texture pure one colour (dependant on the texture)

I can give the source if needed (well the VBSP unit and VTF unit. with a small amount of modification it would work in any app)

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Sep 12, 2005 04:42 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
fixed it. I forgot to change the Y and Z around in the textures rotation thingy. Correct code is:

Code:
  1.  
  2. RenderVerts[rendervertno].TextureCoord.X := (TexInfo[Faces[x].TexInfo].TextureVects[0][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[0][2] * P.Y + -TexInfo[Faces[x].TexInfo].TextureVects[0][1] * P.Z)/TexData[TexInfo[Faces[x].TexInfo].texdata].Width + TexInfo[Faces[x].TexInfo].TextureVects[0][3]/TexData[TexInfo[Faces[x].TexInfo].texdata].Width;
  3. RenderVerts[rendervertno].TextureCoord.Y := -(TexInfo[Faces[x].TexInfo].TextureVects[1][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[1][2] * P.Y + -TexInfo[Faces[x].TexInfo].TextureVects[1][1] * P.Z)/TexData[TexInfo[Faces[x].TexInfo].texdata].Height + 1 - TexInfo[Faces[x].TexInfo].TextureVects[1][3]/TexData[TexInfo[Faces[x].TexInfo].texdata].Height;
  4.  


And heres how it looks:
Bild

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 7 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 33 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.058s | 17 Queries | GZIP : On ]