Where:
v1, v2, v3 are the triangle world space vertices
t1, t2, t3 are the triangle texcoords
p is the pixel coordinate on the texture in [0-1] range
This code converts a coordinate (in texcoord space) anywhere on a triangle to a world space texel position. It assumes [0,0] lies at the bottom-left of the lightmap texture. You can use the same function to calculate the normal (by passing the vertex normals instead of vertices).
I have used this in a hardware accelerated gi/radiosity (non-realtime) lightmap renderer, loosly based on this excelent article:
Thank for your answer , But I also have another
question.
The only way i can single-passed render the scene with lightmaps combine with base textures, using vertex array or VBO is to create all lightmaps coresponding to base textures right?
I dont think I can use glBineTexture for every triangle when render with vertext array,if i create lightmaps per tringle
You should also keep in mind that you’ll need some padding to avoid bleeding between triangle edge pixels.
Also, try to clamp the texture coordinates to the center of pixels. If the lightmaps are mipmapped, keep in mind that it may still cause some bleeding in some conditions, you can increase padding to counter that.