Re: [Algorithms] Texel area
Brought to you by:
vexxed72
From: Olivier G. <gal...@po...> - 2011-02-04 19:51:26
|
On Fri, Feb 04, 2011 at 10:50:08AM -0000, Diogo de Andrade wrote: > So, what I want to do is, given > > - triangle T=(V1,V2,V3), in which V1, V2, V3 are vertexes that have some > properties (world space position, normal, diffuse color, texture coordinates > 0 (in uniform space), texture coordinates 1 (in texture space, [0..texture > size[), etc), > > - texture size > > - position inside the triangle (absolute value in texture space) > > is to find out the rectangle that bounds the texel in world space (origin+2 > vectors)... If that's your real problem, the solution is reasonably simple and has nothing to do with the rasterization. You have three points when space/texture coordinates: (x0, y0, z0, u0, v0) (x1, y1, z1, u1, v1) (x2, y2, z2, u2, v2) Given u, v the position in texture space, you first want to find the barycentric coordinates (t1, t2): | u0 + t1*(u1-u0) + t2*(u2-u0) = u | v0 + t1*(v1-v0) + t2*(v2-v0) = v That's a rather usual linear system. Noting the inverse determinant di: di = 1/((v2-v0)*(u1-u0) - (u2-u0)*(v1-v0)) then: | t1 = di*((v2-v0)*(u-u0) - (u2-u0)*(v-v0)) | t2 = di*((v1-v0)*(u-u0) - (u1-u0)*(v-v0)) >From these, you can easily find the world coordinates: | x = x0 + t1*(x1-x0) + t2*(x2-x0) | y = y0 + t1*(y1-y0) + t2*(y2-y0) | z = z0 + t1*(z1-z0) + t2*(z2-z0) You'll notice that all these are linear systems, which means a texel rectangle size is independant of its position. So you can get your vector once by computing the position differences between (0, 0), (0.5, 0) and (0, 0.5) for instance. You'll notice the equations simplify nicely when computing deltas if you do the math. I suspect it's not your real problem though, so feel free to correct it :-) OG. |