🔒 Locked
About Texture
Advertisement
Original Post
On the UV -> X, Y, Z side, the closest thing you will find is discussions of parametric surfaces. For example, a bicubic B-spline patch or Bezier patch generates (x, y, z) coordinates (+ normals, etc.) given two parameter values that are *like* texture UV coordinates. You should note that in terms of texture mapping it is uncommon that people talk about how to generate (x, y, z) coordinates given UV. There have been some interesting, but not yet totally useful demonstrations that actually embed a mesh within a texture map. For example, the magnitude of the red component of color at a pixel represents the pixel''s x coordinate value, green is y, blue is z. And the mesh connectivity is implicitly defined by the adjacency of pixels in the texture map. One benefit of such an approach is that you can now download a texture and do ray-tracing within pixel/vertex shaders. Head over to www.cgshaders.org, I think there''s a demonstration there.
As far as (x, y, z) to UV goes, there are several traditional types of maps, such as spherical mapping, cubic mapping, cylindrical mapping. Pretty much every good book on 3D graphics will discuss these, and I''m sure a google search on, say, "texture mapping cylindrical" will pop up some links that discuss the standard types of mappings.
In general, these standard mappings don''t work for arbitrary. There are some more complex, numerical mappings that aren''t as simple to describe, Hughes Hoppe''s web page is a good place to look for these:
http://research.microsoft.com/~hoppe/
Now, in games, it is most common that the UV''s are mapped to geometry by an artist. The way this happens is that the artist uses tools such as those build into 3ds max (discreet) or perhaps Deep Paint 3D (Right Hemisphere) or Body Paint 3D (Maxon) to "unwrap" the mesh onto a texture map---this determines the UV''s at each vertex of the mesh. Then, the artist just paints over the top of the unwrapped mesh. Usually the unwrapping tool makes it quite easy to manipulate/customize the unwrapping to minimize stretching of the texture and correct problems/overlaps caused by the automatic unwrap.
http://www.unwrap3d.com/
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
As far as (x, y, z) to UV goes, there are several traditional types of maps, such as spherical mapping, cubic mapping, cylindrical mapping. Pretty much every good book on 3D graphics will discuss these, and I''m sure a google search on, say, "texture mapping cylindrical" will pop up some links that discuss the standard types of mappings.
In general, these standard mappings don''t work for arbitrary. There are some more complex, numerical mappings that aren''t as simple to describe, Hughes Hoppe''s web page is a good place to look for these:
http://research.microsoft.com/~hoppe/
Now, in games, it is most common that the UV''s are mapped to geometry by an artist. The way this happens is that the artist uses tools such as those build into 3ds max (discreet) or perhaps Deep Paint 3D (Right Hemisphere) or Body Paint 3D (Maxon) to "unwrap" the mesh onto a texture map---this determines the UV''s at each vertex of the mesh. Then, the artist just paints over the top of the unwrapped mesh. Usually the unwrapping tool makes it quite easy to manipulate/customize the unwrapping to minimize stretching of the texture and correct problems/overlaps caused by the automatic unwrap.
http://www.unwrap3d.com/
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Thanks! I post my idea here , can u or anybody tell me the mistake I''ve made??
---------------------------------------------------------
| A D G | | A
| C F I | | C
|
==> f < x * D
/ x0 * A
/ x0 * D
/ x0 * G
/***************************************************case1*******************************************************/
if: z0 != 0 && z1 != 0 && z2 != 0
g1
A
C
D
F
G
I
A
C
D
F
B
E
Let: x0 / z0 = q , y0 / z0 = w , u0 / z0 = e
x1 / z1 = r , y1 / z1 = t , u1 / z1 = s
v0 / z0 = h , v1 / z1 = j
B
E
/***************************************************case3*******************************************************/
if: z0 != 0 && z1 == 0 && z2 == 0
g1
A
C
D
F
B
E
===============================================================================================================
case 1 : | x * A
case 2 : | x * A
case 3 : | x * A
case 4 : | x * A
| x * D
---------------------------------------------------------
| A D G | | A
D G|
| x y z | = | u v 1 | * | B E H | ==> | x y z | * | B E H| = | u v 1 || C F I | | C
F I|
/ x * A + y * B + z * C = u|
==> f < x * D
+ y * E + z * F = v
|
\ x * G + y * H + z * I = 1/ x0 * A
+ y0 * B + z0 * C = u0
|
==> g1 < x1 * A + y1 * B + z1 * C = u1
|
\ x2 * A + y2 * B + z2 * C = u2/ x0 * D
+ y0 * E + z0 * F = u0
|
==> g2 < x1 * D + y1 * E + z1 * F = u1
|
\ x2 * D + y2 * E + z2 * F = u2/ x0 * G
+ y0 * H + z0 * I = u0
|
==> g3 < x1 * G + y1 * H + z1 * I = u1
|
\ x2 * G + y2 * H + z2 * I = u2/***************************************************case1*******************************************************/
if: z0 != 0 && z1 != 0 && z2 != 0
g1
, g2 , g3 :
B = (u1 / z1 - u2 / z2) * (x0 / z0 - x1 / z1) / ((x1 / z1 - x2 / z2) * (u0 / z0 - u1 / z1) - (x1 / z1 - x2 / z2) * (y0 / z0 - y1 / z1) + (y1 / z1 - y2 / z2) * (x0 / z0 - x1 / z1));A
= ((u0 / z0 - u1 / z1) - (y0 / z0 - y1 / z1) * B) / (x0 / z0 - x1 / z1);C
= y0 / z0 - x0 / z0 * A - y0 / z0 * B;
E = (v1 / z1 - v2 / z2) * (x0 / z0 - x1 / z1) / ((x1 / z1 - x2 / z2) * (v0 / z0 - v1 / z1) - (x1 / z1 - x2 / z2) * (y0 / z0 - y1 / z1) + (y1 / z1 - y2 / z2) * (x0 / z0 - x1 / z1));D
= ((v0 / z0 - v1 / z1) - (y0 / z0 - y1 / z1) * E) / (x0 / z0 - x1 / z1);F
= y0 / z0 - x0 / z0 * D - y0 / z0 * E;
H = (1 / z1 - 1 / z2) * (x0 / z0 - x1 / z1) / ((x1 / z1 - x2 / z2) * (1 / z0 - 1 / z1) - (x1 / z1 - x2 / z2) * (y0 / z0 - y1 / z1) + (y1 / z1 - y2 / z2) * (x0 / z0 - x1 / z1));G
= ((1 / z0 - 1 / z1) - (y0 / z0 - y1 / z1) * H) / (x0 / z0 - x1 / z1);I
= y0 / z0 - x0 / z0 * G - y0 / z0 * H;
Let: x0 / z0 = q , y0 / z0 = w , u0 / z0 = e
x1 / z1 = r , y1 / z1 = t , u1 / z1 = s
x2 / z2 = d , y2 / z2 = f , u2 / z2 = g
v0 / z0 = h , v1 / z1 = j , v2 / z2 = k
if: z0 != 0 && z1 != 0 && z2 != 0
:
B = (s - g) * (q - r) / ((r - d) * (e - s) - (r - d) * (w - t) + (t - f) * (q - r));A
= ((e - s) - (w - t) * B) / (q - r);C
= w - q * A - w * B;
E = (j - k) * (q - r) / ((r - d) * (h - j) - (r - d) * (w - t) + (t - f) * (q - r));D
= ((h - j) - (w - t) * E) / (q - r);F
= w - q * D - w * E;
/***************************************************case2*******************************************************/
if: z0 != 0 && z1 != 0 && z2 == 0
g1 , g2 , g3 :B
= (x0 * (u0 / z0 - u1 / z1) - u2 * (x0 / z0 - x1 / z1)) / (x0 * (y0 / z0 - y1 / z1) - y2 * (x0 / z0 - x1 / z1));
A (u2 - y2 * B) / x2;
C = u0 / z0 - x0 / z0 * A - y0 / z0 * B;E
= (x0 * (v0 / z0 - v1 / z1) - v2 * (x0 / z0 - x1 / z1)) / (x0 * (y0 / z0 - y1 / z1) - y2 * (x0 / z0 - x1 / z1));
D (v2 - y2 * E) / x2;
F = v0 / z0 - x0 / z0 * D - y0 / z0 * E;Let: x0 / z0 = q , y0 / z0 = w , u0 / z0 = e
x1 / z1 = r , y1 / z1 = t , u1 / z1 = s
v0 / z0 = h , v1 / z1 = j
B
= (x0 * (e - s) - u2 * (q - r)) / (x0 * (w - t) - y2 * (q - r));
A = (u2 - y2 * B) / x2;
C = e - q * A - w * B;E
= (x0 * (h - j) - v2 * (q - r)) / (x0 * (w - t) - y2 * (q - r));
D = (v2 - y2 * E) / x2;
F = h - q * D - w * E;/***************************************************case3*******************************************************/
if: z0 != 0 && z1 == 0 && z2 == 0
g1
, g2 , g3 :
B = (x1 * u2 - u1 * x2) / (x2 * y1 + y2 * x1);A
= (u1 - y1 * B) / x1;C
= u0 / z0 - x0 / z0 * A - y0 / z0 * B;
E = (x1 * v2 - v1 * x2) / (x2 * y1 + y2 * x1);D
= (v1 - y1 * E) / x1;F
= v0 / z0 - x0 / z0 * D - y0 / z0 * E;
/***************************************************case4*******************************************************/
if: z0 == 0 && z1 == 0 && z2 == 0 (z alwary be 0)
g1 , g2 , g3 :B
= (x0 * u1 - x1 * u0) / (x1 * y0 + x0 * y1);
A = (u0 - y0 * B) / x0;E
= (x0 * v1 - x1 * v0) / (x1 * y0 + x0 * y1);
D = (v0 - y0 * E) / x0;===============================================================================================================
case 1 : | x * A
+ y * B + z * C = u
| x * D + y * E + z * F = vcase 2 : | x * A
+ y * B + z * C = u
| x * D + y * E + z * F = vcase 3 : | x * A
+ y * B + z * C = u
| x * D + y * E + z * F = vcase 4 : | x * A
+ y * B = u| x * D
+ y * E = v
front999,
You''ve presented far too much math without discussion to expect anyone to try and figure out what you are trying to do. You''re going to have to explain what you''re trying to do, describe your idea in words, describe your notation for the first section, and perhaps better annotate your code in blocks. I''d even suggest drawing a picture.
Do you realize that your results, cases 1 through 3, are identical?
Since you seem to be looking for help solving a derivation, which is often done for homework/schoolwork, I will also say that if this is a homework problem, you should tell us and review the forum FAQ on homework questions. Forum members are asked not to provide answers to homework, only suggestions/hints. Remember, these forums are focused on game development.
Forum FAQ
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
You''ve presented far too much math without discussion to expect anyone to try and figure out what you are trying to do. You''re going to have to explain what you''re trying to do, describe your idea in words, describe your notation for the first section, and perhaps better annotate your code in blocks. I''d even suggest drawing a picture.
Do you realize that your results, cases 1 through 3, are identical?
Since you seem to be looking for help solving a derivation, which is often done for homework/schoolwork, I will also say that if this is a homework problem, you should tell us and review the forum FAQ on homework questions. Forum members are asked not to provide answers to homework, only suggestions/hints. Remember, these forums are focused on game development.
Forum FAQ
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Thanks for your advices!!
In fact, I am a programmer. Now I am studying 3d graphics technology to develop a 3d engine for mobile platform. I am not experiential with this. I got some confuse about the UV-XYZ mapping. I''ve tried to convert 3DS model coordinate into 3DS UV coordinate. I want to fill the faces(always be a triangle) with the texture map.
The problem is that I do not know how to map model coordinate to UV coordinate. The equations I listed above are some idea of myself. I''v tried to find an affine matrix when I read a triangle from 3DS file. But it dose not work.
So I want to know where can I find some good articles here about this.
Thanks again!
In fact, I am a programmer. Now I am studying 3d graphics technology to develop a 3d engine for mobile platform. I am not experiential with this. I got some confuse about the UV-XYZ mapping. I''ve tried to convert 3DS model coordinate into 3DS UV coordinate. I want to fill the faces(always be a triangle) with the texture map.
The problem is that I do not know how to map model coordinate to UV coordinate. The equations I listed above are some idea of myself. I''v tried to find an affine matrix when I read a triangle from 3DS file. But it dose not work.
So I want to know where can I find some good articles here about this.
Thanks again!
If you are using 3ds max to create your mesh, there is NO NEED to use complex mathematic to map (x, y, z) to (u, v). ALL you need to do is attach a "UVW Map" or "UV Unwrap" modifier to your mesh and use the 3ds max tools to apply the texture. Then, when you export to your own file format for loading onto the cell phone, use MAXScript or the 3ds max SDK to just extract the (u, v) coordinates directly from the mesh.
Once you have your own file, you will have the following information for each triangle:
1) 3 sets of vertex coordinates (x, y, z)---may be specified as an index into an array of vertices
2) 3 sets of texture coordinates (u, v)
From there you can map the triangle into screen space based on your 3D camera, then use a traditional triangle/polygon rasterization algorithm to turn the mapped triangle into pixels---including textures without complex math. Here is a link that discusses triangle rasterization. I believe the articles discusses the use of integer math, which you will need to run this on a cell phone (plus, integer rasterization produces nicer results anyway).
http://www.d6.com/users/checker/pdfs/gdmtex2.pdf
If you wish to find other articles, you can use www.google.com to search on the keywords "triangle rasterization". Those keywords should produce a great many links, and some of them will be very useful.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Once you have your own file, you will have the following information for each triangle:
1) 3 sets of vertex coordinates (x, y, z)---may be specified as an index into an array of vertices
2) 3 sets of texture coordinates (u, v)
From there you can map the triangle into screen space based on your 3D camera, then use a traditional triangle/polygon rasterization algorithm to turn the mapped triangle into pixels---including textures without complex math. Here is a link that discusses triangle rasterization. I believe the articles discusses the use of integer math, which you will need to run this on a cell phone (plus, integer rasterization produces nicer results anyway).
http://www.d6.com/users/checker/pdfs/gdmtex2.pdf
If you wish to find other articles, you can use www.google.com to search on the keywords "triangle rasterization". Those keywords should produce a great many links, and some of them will be very useful.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
If you have a *.3ds file (and are not actually using 3ds max), then the *.3ds file may already include (u, v) coordinates per vertex. If this is true, you still do not need complex math to create the (u, v) coordinates.
If the *.3ds file does not have any (u, v) coordinates and you just want to create some, then you are back to using one of the standard/simple mappings: cylindrical, spherical, planar, cubic, face. I mentioned these before. Anything more complex and you''ll have to dig into Hughes Hoppe''s papers or something similar. Here is a link that visually describes the simple ways to generate texture coordinates for an arbitrary mesh:
http://www.siggraph.org/education/materials/HyperGraph/mapping/r_wolfe/r_wolfe_mapping_1.htm
Hope that helps!
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
If the *.3ds file does not have any (u, v) coordinates and you just want to create some, then you are back to using one of the standard/simple mappings: cylindrical, spherical, planar, cubic, face. I mentioned these before. Anything more complex and you''ll have to dig into Hughes Hoppe''s papers or something similar. Here is a link that visually describes the simple ways to generate texture coordinates for an arbitrary mesh:
http://www.siggraph.org/education/materials/HyperGraph/mapping/r_wolfe/r_wolfe_mapping_1.htm
Hope that helps!
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
You've provided really good stuff! Thanks!
I draw every scanline of the triangles in my system by pixel.
And I transform the coordinates of each pixel back to world coordinate. Then I match the pixels to UV coordinate with a affine matrix. Because the coordinates of pixels is realtime calculated, I need to recalculate corresponding UV coordinate when the camera changed or triangle been changed. Of course , affine matrix is calculated once.
But the result is not what I need. Yes , I can get the UV coordinates of vertices of triangle in .3ds file. But I need to calculate the points in the triangles. So affine matrix is required. I think this is a 3d plan texture mapping. But it really confuses me.
I list the flow below :
1. triange from .3ds (three vertices , three cooresponding UV coordinates)
2. Calculate affine matrix for this triangle
3. world coordinate -> view coordinate
4. view cooridnate -> projection
5. draw every pixel of the projected triangle (2D triangle)
6. pixel coordinate -> view coordinate
7. view coordinate -> world coordinate
|--------------------Affine Matrix----------------|
8. world coordinate --------------> UV coordinate
7. put texture map pixel to screen according to the pixel coordinate
Now , it may be more clear. I think this solution is not the best especially for a mobile set. Do you have any advices?? And I found the affine matrix is not correct. Anyway , thanks!!
[edited by - front999 on December 23, 2003 3:29:41 AM]
[edited by - front999 on December 23, 2003 3:30:40 AM]
I draw every scanline of the triangles in my system by pixel.
And I transform the coordinates of each pixel back to world coordinate. Then I match the pixels to UV coordinate with a affine matrix. Because the coordinates of pixels is realtime calculated, I need to recalculate corresponding UV coordinate when the camera changed or triangle been changed. Of course , affine matrix is calculated once.
But the result is not what I need. Yes , I can get the UV coordinates of vertices of triangle in .3ds file. But I need to calculate the points in the triangles. So affine matrix is required. I think this is a 3d plan texture mapping. But it really confuses me.
I list the flow below :
1. triange from .3ds (three vertices , three cooresponding UV coordinates)
2. Calculate affine matrix for this triangle
3. world coordinate -> view coordinate
4. view cooridnate -> projection
5. draw every pixel of the projected triangle (2D triangle)
6. pixel coordinate -> view coordinate
7. view coordinate -> world coordinate
|--------------------Affine Matrix----------------|
8. world coordinate --------------> UV coordinate
7. put texture map pixel to screen according to the pixel coordinate
Now , it may be more clear. I think this solution is not the best especially for a mobile set. Do you have any advices?? And I found the affine matrix is not correct. Anyway , thanks!!
[edited by - front999 on December 23, 2003 3:29:41 AM]
[edited by - front999 on December 23, 2003 3:30:40 AM]
Hi,
If you are not worried about perspective-correct texture mapping (see Chris Hecker''s article, link above) then there is no need for you to do steps 6-8. All you have to do is interpolate the UV''s as you generate the pixels. Remember that when you map a vertex from world to view space, the UV''s do not change. The UV at vertex 1 remains the same as it is in world space. (Unless you''re doing some kind of strange environment mapping, but I suspect this is not what you want to do.)
Are you doing Z-buffering? If so, just treat the UV''s like you treat the Z value. Of course, the Z value would have to be transformed into view space, while the UV''s are the same in view space as they are in world space, but once everything is in view space you can, for a first try, interpolate UV''s just as you do Z. Once that is working you can review the literature to figure out perspective-correct texture mapping (though this might be too much for the cell phone).
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
If you are not worried about perspective-correct texture mapping (see Chris Hecker''s article, link above) then there is no need for you to do steps 6-8. All you have to do is interpolate the UV''s as you generate the pixels. Remember that when you map a vertex from world to view space, the UV''s do not change. The UV at vertex 1 remains the same as it is in world space. (Unless you''re doing some kind of strange environment mapping, but I suspect this is not what you want to do.)
Are you doing Z-buffering? If so, just treat the UV''s like you treat the Z value. Of course, the Z value would have to be transformed into view space, while the UV''s are the same in view space as they are in world space, but once everything is in view space you can, for a first try, interpolate UV''s just as you do Z. Once that is working you can review the literature to figure out perspective-correct texture mapping (though this might be too much for the cell phone).
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Thanks for your help again!
I''ll test this on my board. I think the problem you mentioned is really a problem for me. I''ll try to simplified this on the mobile set platform.
Before that, I''ll read the articles what you mentioned.
I''ll post the result of my test here.
Davis
I''ll test this on my board. I think the problem you mentioned is really a problem for me. I''ll try to simplified this on the mobile set platform.
Before that, I''ll read the articles what you mentioned.
I''ll post the result of my test here.
Davis
Davis,
If you produce a working demo, I''d love to see the results. Perhaps you can post a screen shot sometime?
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
If you produce a working demo, I''d love to see the results. Perhaps you can post a screen shot sometime?
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Also,
Have you seen Mascot Capsule?
Mascot Capsule
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Have you seen Mascot Capsule?
Mascot Capsule
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
That''s a good first test! This is 100% software rendering, correct?
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
This is the screen shot of my the newest demo game for the engine.
It has not been completed yet.
screen shot
It has not been completed yet.
screen shot
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement