Jump to content


Box texture mapping


12 replies to this topic

#1 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 10 April 2008 - 01:31 PM

Hi!
Anyone know a "box" texture mapping representation?
If I have a model, how can I implement this method?
For example:
1) I make 6 images of the model (front, back, left, right, top, bottom). This image must made in orthographic mode?
2) With this 6 images, how can I implement the box texture mapping?
Thanks!

#2 marek-knows.com

    Valued Member

  • Members
  • PipPipPip
  • 189 posts
  • LocationOntario, Canada

Posted 11 April 2008 - 12:07 PM

Have a look at VMK19 and VMK24 on my website. These will show you how to texture an object (19), and how to apply a texture onto a box (24)
3D OpenGL, C++ Game Development Video Tutorials @
www.marek-knows.com

#3 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 11 April 2008 - 03:49 PM

mmakrzem said:

Have a look at VMK19 and VMK24 on my website. These will show you how to texture an object (19), and how to apply a texture onto a box (24)
No, I don't want apply a texture onto a box.
I report a paper description:

Quote

We have implemented two schemes for representing the surface texture data. The
first is a “box” scheme that represents the surface textures using 6 orthographic (nonperspective)
“canonical” views of the model (top view, front view etc). For each triangle
we texture map using the “best” view for that triangle. This is the canonical view with
the highest texture resolution out of all views in which the triangle is completely visible
(no occlusion). The benefits of this approach are that it is very simple and the 2D texture
coordinates can be calculated implicitly from the 3D vertex data.
I hope to being more clear!
Thanks!

#4 marek-knows.com

    Valued Member

  • Members
  • PipPipPip
  • 189 posts
  • LocationOntario, Canada

Posted 11 April 2008 - 04:17 PM

ahh I see. What you need to do, if go through ever face of your model. At each face determine which of the six "box" planes this face is facing. Then project all points from the face onto your box plane. where the points land on your orthogonal plane gives you the UV coordinate for that face.

Repeat over your entire model and then render!
3D OpenGL, C++ Game Development Video Tutorials @
www.marek-knows.com

#5 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 12 April 2008 - 09:30 AM

mmakrzem said:

ahh I see. What you need to do, if go through ever face of your model. At each face determine which of the six "box" planes this face is facing. Then project all points from the face onto your box plane. where the points land on your orthogonal plane gives you the UV coordinate for that face.

Repeat over your entire model and then render!
Ok, but we can see this step by step? :)
1) I must make the six images of my model. This images must be taken in orthographic mode, it's correct? What paramaters of orthographic mode I must use? It's correct save those images in a texture, by reading the frame buffer?
2) Now I have the six images (front, back, top, bottom, lef right).
I go throught ever triangle (face) of my model, and I must determine which of the six "box" planes this triangle is facing. I must use the normals?
Then I project my triangle points on my box plane, otherwise on my camera plane, it's correct? With this projection I obtain new 2D points, this are the UV coordinate, and I can have the acces to the texture.
Thanks!!! ;)

#6 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 13 April 2008 - 09:10 PM

TBH it sounds like cubic environment mapping. Usually when you do that sort on env mapping you'd use the normal to calcualte a reflction into the cube. With the method suggested there couldn't you just use the normal directly (ie not perform the reflection calculation) to look up the texture in the cube?

#7 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 14 April 2008 - 02:24 PM

Goz said:

TBH it sounds like cubic environment mapping. Usually when you do that sort on env mapping you'd use the normal to calcualte a reflction into the cube. With the method suggested there couldn't you just use the normal directly (ie not perform the reflection calculation) to look up the texture in the cube?
How I must use the normals?

#8 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 14 April 2008 - 02:42 PM

Well instead of passing a reflection vector into your texCube call (assuming HLSL) you pass the world space normal in.

If i'm understand the problem properly. A link to the actual paper migt be handy.

#9 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 14 April 2008 - 02:51 PM

The paper is this:
http://www.bmva.ac.u.../49/full_49.pdf
See "Texture representation" (1.3)

#10 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 15 April 2008 - 06:19 AM

Hi!
I'm trying to implement the method advised by mmakrzem!
But I've some problems with the generation of the texture data.
My windows is 1024,768, and by default I use gluPerspective() function.
I use glReadPixels() function to read the frame buffer and save them in to an image.
The paper say to use the orthographic mode for the texture generation.
I can use glOrtho() function, but with parameters?
Help me please!
Thanks!

#11 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 15 April 2008 - 08:01 AM

I've tried a simple example.
My model is a cube of unitary lenght, and it's positioned at the center of the scene (0, 0, 0).
I use the orthographic projection with this parameters:

glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

This is the screen: (the windows dimension is 512x512)
Posted Image
Then I applied the method advised by mmakrzem. I've projected each point and I used new point coordinate for texture mapping.
I've added to the precedent image eight green points, four at the square corners and four at the image corners.
This is the screen:
Posted Image
Sorry for the color of the square.
The mapping looks not correctly. Where is the problem? (In the texture generation?)
Thanks!

#12 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 15 April 2008 - 04:15 PM

I've solved the past problem in this manner: I project each vertex and then if this new vertex is less then zero I set them to zero and if the vertex is greater then one I set them to one.
Probably is wrong!
I've tried with a new model, a cylinder of lenght, width and depth two.
My windows is 512x512.
This is the correct rendering of the model, no texture, only light.
Posted Image
This is the texture created using the orthographic projection set to (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0).
Posted Image
It's correct?
And this is a model textured, using the precedent image.
Posted Image
It's wrong... :(:(
Where is the problem? Or... where are the problems?
Thanks!

#13 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 18 April 2008 - 11:00 AM

Well you "could" use that texture to texture the cylinder correctly but its a bit specific to the task.

Look up environment mapping. You can easily add lights to the correct places in a cubic environment map and then just us that env map directly on your object. Its really a simple way of doing lighting with textures.

If you want to get more complicated you can fill a flat 2D texture with lighting data and then use simple spherical env mapping to light an object too ... This method is far more complex than generating a cubic environment mapping with your lighting data in it.

I'd strongly recommend looking into how normalisation cubemaps work and then see if you can display the normal data from a normalisation cubemap. Then to do lighting that way you can replace the normals with lights. This will give you a good idea on how to set up environment map based lighting.

Give this a try first because in my mind you need to learn the basics before diving into something like you are trying. I, for example, still don't have any idea what you are trying to do. The method you described earlier require cube mapping and yet you are workig with a simple 2D texture.

Good luck.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users