Re: [Algorithms] Texel area

 Re: [Algorithms] Texel area From: Diogo de Andrade - 2011-02-17 10:47:14 ```Hi all! I've finally had the time to implement and use all your suggestions, and if you're interested you can see some of the results here: http://shadowcovenant.com/blog/2011/02/10/ambient-occlusion-maps/ Most of the issues I solved by using barycentric coordinates, instead of using just gradients calculated through interpolation... Thanks for all the help everyone! Best regards, Diogo -----Original Message----- From: Olivier Galibert [mailto:galibert@...] Sent: sexta-feira, 4 de Fevereiro de 2011 19:32 To: gdalgorithms-list@... Subject: Re: [Algorithms] Texel area 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. ---------------------------------------------------------------------------- -- The modern datacenter depends on network connectivity to access resources and provide services. The best practices for maximizing a physical server's connectivity to a physical network are well understood - see how these rules translate into the virtual world? http://p.sf.net/sfu/oracle-sfdevnlfb _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list ```