How does Hammer project UVs?

Grab your favourite IDE and tinker with the innards of game engines

How does Hammer project UVs?

Postby fry_ on Tue Jun 12, 2012 4:23 am

I'm attempting to replicate the UV mapping behavior of brushes in Hammer, and I figured the easiest way to do so would be to figure what algorithm Hammer uses. My first thought was a tri-planar projection, but now I'm not so sure that's the proper approach. Does anyone here have solid info on the UV unwrapping method used in Hammer?
User avatar
fry_
Regular
Regular
 
Joined: Thu Aug 06, 2009 2:56 am

Re: How does Hammer project UVs?

Postby Gary on Tue Jun 12, 2012 5:37 am

You could look at the HL2 beta leak code. I would assume it hasn't changed since then.
Have a question related to modding or something I posted? Something that needs staff attention? I haven't been active lately, but feel free to PM me or message me on Steam(link below)

User avatar
Gary
Interlopers Staff
Interlopers Staff
 
Joined: Wed Dec 16, 2009 12:40 am
Location: USA, FL

Re: How does Hammer project UVs?

Postby Jordash on Tue Jun 12, 2012 6:35 am

Have a look at this guy https://developer.valvesoftware.com/wik ... at#Texinfo

I know it's BSP, but hammer would use a similar system, also look at how it's stored in the VMFs
User avatar
Jordash
Been Here A While
Been Here A While
 
Joined: Mon Sep 21, 2009 10:36 am
Location: Perth, Australia

Re: How does Hammer project UVs?

Postby zombie@computer on Tue Jun 12, 2012 8:14 am

Gary wrote:You could look at the HL2 beta leak code. I would assume it hasn't changed since then.

This. Its about ten lines of code.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: How does Hammer project UVs?

Postby fry_ on Tue Jun 12, 2012 9:41 pm

I hadn't thought to actually look at the source... good idea.

Aha! This is exactly what I was looking for:

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:
Code: Select all
u = tv0,0 * x + tv0,1 * y + tv0,2 * z + tv0,3
v = tv1,0 * x + tv1,1 * y + tv1,2 * z + tv1,3

(ie. The dot product of the vectors with the vertex plus the offset in that direction. Where tvA,B is textureVecs[A][B].
Furthermore, after calculating (u, v), to convert them to texture coordinates which you would send to your graphics card, divide u and v by the width and height of the texture respectively.
User avatar
fry_
Regular
Regular
 
Joined: Thu Aug 06, 2009 2:56 am

Re: How does Hammer project UVs?

Postby fry_ on Tue Jun 12, 2012 10:57 pm

Alright, one more quick question. I wasn't able to get my hands on the source code (unfortunately...that would be a great read), but I did attempt an implementation of the Wiki UV formula. My trouble is figuring how to get the data for textureVec[][]. So say I'm given a plane, and wish to calculate UVs. Say the vertices are at
Code: Select all
point 0 - (0,0,0)
point 1 - (1,0,0)
point 2 - (0,0,1)
point 3 - (1,0,1)

with no offset or rotation.

Would the UVs for point 0 look like this?

Code: Select all
float tv[2][4];  // textureVecs

tv[0][0] = 1f;   // s
tv[0][1] = 0f;   // x
tv[0][2] = 0f;   // y
tv[0][3] = 0f;   // z

tv[1][0] = 1f;   // t
tv[1][1] = 0f;   // x
tv[1][2] = 0f;   // y
tv[1][3] = 0f;   // z

float x = 0f, y = 0f, z = 0f;

u = tv[0][0] * x + tv[0][1] * y + tv[0][2] * z + tv[0][3];
v = tv[1][0] * x + tv[1][1] * y + tv[1][2] * z + tv[1][3];
User avatar
fry_
Regular
Regular
 
Joined: Thu Aug 06, 2009 2:56 am

Return to Programming

Who is online

Users browsing this forum: No registered users