Jump to content
  • Advertisement
Sign in to follow this  
mike74

triangle slices

This topic is 4845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let's say you have a 3d triangle. Let's also say you have a 3d procedural texture generator. Now let's say you want to figure out what the triangular slice of the 3d texture looks like in 2d. Any ideas on how to do this? For instance, if your procedure function uses perlin noise to generate marble, the triangle will be like a slice of marble. mike http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Advertisement
mike,

When drawing the triangle, send the 3d coordinates of each pixel to the Perlin function to derive its color. Are you asking how to find the coordinates of each pixel?

What you're describing can also be accomplished very quickly with a ray-tracer, if you just want to see what it might look like.

Share this post


Link to post
Share on other sites
I want an easy way to correlate the 3d triangle coordinates with the 2d coordinates in a texture map. I want to create a 2d texture of the triangle slice.

mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Quote:
Original post by mike74
I want an easy way to correlate the 3d triangle coordinates with the 2d coordinates in a texture map. I want to create a 2d texture of the triangle slice.

mike
http://www.coolgroups.com/


3D textures have 3D texture coordinates. Simply use glTexcoord3f(x, y, z) (or whatever the equivalent in Direct3D is if you use that) for each vertex where (x,y,z) is a point in the 3D texture. The 3D texture coordinates should be similar to the use of 2D textures: they are all normalized between 0.0 and 1.0. Using for example the texcoords: (0,0,1)(1,0,1)(0,1,1) on a triangle will give you part of the back quad of the texture cube (as z is maxed in all 3 vectors).

Tom

Share this post


Link to post
Share on other sites
If you have 3D texture support you could just render the triangle and take a screenshot.

Share this post


Link to post
Share on other sites
I don't have 3d texture support, so I need to make a 2d texture of it.

mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Quote:
I don't have 3d texture support, so I need to make a 2d texture of it.
That sounds kind of difficult. I don't know what the standard solution is (if there is one), but here's what I would try:

1. Find the plane of the triangle.

2. Create an orthonormal basis about the normal of the plane.

3. Create a square on the plane and built around the basis that completely 'includes' the cube (I assume the 3d texture is a cube).

4. Decide on a resolution for the 2d texture.

5. 'Walk' back and forth along the square at the desired resolution. At each step, find the corresponding voxel in the 3d texture and assign that color to the texel.

6. Transform the triangle vertices to the 2d basis and find the corresponding texture coordinates.

On the other hand, if you're just interested in seeing the interior of the 3d texture, rather than some specific arbitrarily oriented slice, perhaps you could just slice along a cardinal plane. In that case pretty much all of the above complexity drops out, and you have a very simple solution.

Share this post


Link to post
Share on other sites
I already have a solution to it that I used in my program at http://www.coolgroups.com/giftwrap/. The problem with it is that it's inefficient.

Right now, I'm looping through a lot of the barycentric coordinates, but I'm repeating the filling of some pixels in the texture multiple times. Currently, I'm looping 1,000,000 times to generate a triangle that only has an area of 116,281 pixels. Ideally, there would be one loop per pixel. Does anyone know the standard ways of looping through barycentric coordinates?

mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you should be doing the oposite. looping through s, t in your 2d texture map, then
from that, you calculate bery centric coodrs, then ref the texture for that value. you probably want to take several jittered s, t positions within each pixel so you can get some AA action.

Share this post


Link to post
Share on other sites
1m times? =) hehe to add to my previous post suppose we want to map the top point of the triangle to (.5, 1) the left most bottom to (0,0) the right most bottom to (1, 0)

I'm assuming s,t referenced left to right, down to up. it really depend on how you want to map your s,t but assume you do this, which seems that it will be more uniform then say(0,1), (0,0),(0,1) I'd pick the former but that's up to you.

loop through the image and for each pixel calculate s,t(obviously only pick s,t that are in the triangle) you can check if a s, t is in this configuration by

[s,t] = A*[.5,1] + B*[0,0] + C*[1,0]
calculating a,b,c just as you would bary coorids and if A + B + C > 0 && < 1
then it's in the triangle, so now you take that valid s,t and reference it in the triangle. if you didn't notice the A, B, C we calculated to determin if the s,t was actually in the triange, is exactly the barycentric cooridnates of the point on the triangle that maps to that s, t in the image. so P = A*V1 + B*V2 + C*V3;

so we loop throgh s, t of the image
determin A, B, C
use that A, B, C to calculate P(the point in the 3D triange that maps to the TextureCoorid s, t)

evaluate Nosie(P) and store that result to the pixel (int)s*WIDTH, (int)t*Height

you might want to take the average or 4 or so values for each pixel ro AA purposes


on second thought I think I'd pick the mapping (0,1), (0,0), (1,0) this way you can map two triangles texutres in one rectuanlar texture map.. either way you got distortion. if you got questions dont hesitate to ask.


Tim

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!