Lightmapping - texture bleeding ???
Blitz3D Forums/Blitz3D Programming/Lightmapping - texture bleeding ???
| ||
Hello. Iīm trying to develope a lightmapping system, mainly for learning purpose, a just-for-fun-project. But now there is one problem i just cannot solve: A mesh gets lightmapped, the maps are displayed, the textures seem to fit - but the lightmaps seem to bleed. Iīve read all i could find (blitzbasic.com-forum, blitzcoder-forum, other graphics-boards,...) about this problem, but none of my wannabe-solutions fixed the problem. Maybe somebody of the b3d-masters can help me out? The code to create a lightmap image and setup of texture coords: Function create_lightmap(meshobj,size#,lmsize#,cset=0) fnt=LoadFont("arial",10) SetFont fnt For sys.lmsystem=Each lmsystem tricount=sys\tris Next mapw#=tricount*size maph#=size x#=0 y#=0 lm=CreateTexture(lmsize,lmsize,512) SetBuffer TextureBuffer(lm) For tri.triangle=Each triangle DebugLog "Tri: "+t+" X:"+x CopyRect(0,0,size,size,x,y,TextureBuffer(tri\lightmap),TextureBuffer(lm)) ;********************************** ;right here seems to be the problem For vert=0 To 2 u#=((tri\pu[vert] * (size /lmsize) )+(x/lmsize)) v#=((tri\pv[vert] * (size / lmsize) )+(y/lmsize)) DebugLog "VERTEX "+tri\vert[vert]+" Texturcoord: "+u*mapw+" "+v*maph+" - "+tri\pu[vert]+" "+tri\pv[vert] VertexTexCoords(tri\surface,tri\vert[vert],u,v,1,cset) ;********************************* Next ;Color 255,255,255 ;Rect x,y,size,size,0 DebugLog "" x=x+size t=t+1 Next SetBuffer BackBuffer() TextureCoords lm,cset TextureBlend(lm,3) EntityTexture(meshobj,lm,0,cset) mapimage=CreateImage(mapw+20,maph+20) CopyRect(0,0,mapw+20,maph+20,0,0,TextureBuffer(lm),ImageBuffer(mapimage)) Return(lm) End Function Itīs just the code, working (with bleeding), erased my attempts - better to read... Screenshot: Any help would really be appreciated. Cy |
| ||
I think the bleeding may have to do with the bilinear filtering...I cant think of many ways around it aside from leaving 1 pixel borders between each lightmapped face... |
| ||
Little success: Got rid of the dark edges, but the slightly colored edges remain. Does ANYBODY have an idea ????? For vert=0 To 2 If minu#>tri\pu[vert] Then minu#=tri\pu[vert] If maxu#<tri\pu[vert] Then maxu#=tri\pu[vert] If minv#>tri\pv[vert] Then minv#=tri\pv[vert] If maxv#<tri\pv[vert] Then maxv#=tri\pv[vert] Next For vert=0 To 2 If minu#=tri\pu[vert] Then addu#=(1/lmsize)*.5 If maxu#=tri\pu[vert] Then addu#=-(1/lmsize)*.5 If minv#=tri\pv[vert] Then addv#=(1/lmsize)*.5 If maxv#=tri\pv[vert] Then addv#=-(1/lmsize)*.5 u#=((tri\pu[vert] * (size /lmsize) )+(x/lmsize))+addu# v#=((tri\pv[vert] * (size / lmsize) )+(y/lmsize))+addv# DebugLog "VERTEX "+tri\vert[vert]+" Texturcoord: "+u*mapw+" "+v*maph+" - "+tri\pu[vert]+" "+tri\pv[vert] VertexTexCoords(tri\surface,tri\vert[vert],u,v,1,cset) Next Changes: Searching vor min/max uvīs of tri, then adding .5 texel for min-u/v, substracting .5 texel of every max-u/v Cy |
| ||
See if texel can see light source, not if light source can see texel. |
| ||
Thanks, works now without black borders/bleeding colors (tried chanching direction before, you mentioned it in another old thread, but didnīt work at that time...?) But - surprise - another problem. Looks like the lightmapping algorithm dosnīt work if i rotate the mesh before lightmapping. Textures get totally distorted, looks like there is an error in the planar mapping code...will post code later, iīm at work right now... Anybody had a similar problem? |