Surface texture seams
Blitz3D Forums/Blitz3D Programming/Surface texture seams
| ||
Hi everyone. I've got a weird problem that I've been stuck on for a couple of days now. Here is a zoomed in screengrab of a texture that has been PaintSurface'd onto a surface. And here it is with seams. I'm creating a mesh made up of surfaces created with AddVertex in the usual manner, and then using a brush to paint the textures onto the surfaces. In the first screenshot, I have used large textures so I could demonstrate what the image looks like without seams. The 2nd shot represents what my program is actually doing: using textures of 256x256. At each of the surface boundaries I get this seam happening. Does anyone know how to get around this? (Note that the closer the camera is to the mesh, the more obvious the effect). Thanks for any help. |
| ||
Try using the CLAMPU and CLAMPV settings when loading or creating the textures, this should hopefully stop the blending with the opposite edge. |
| ||
I'm creating the textures like this:tmpTexture=CreateTexture(texSize,texSize,1+16+32+256)Is this the right way to use ClampU and ClampV? It's with these flags that I'm getting the seams. |
| ||
Given the very small errors that create the seams I think the texture mapping may be off by half a texel. Try adjusting the u,v values by one part in 512 for the 256 x 256 textures. A texture with diagonal lines might help you see exactly where it goes wrong. |
| ||
I have ran into some strange issues when using .png files for textures when the uv map is zero'd on an axis. For instance if anyone models with maya, stretch the uv and snapping it to the farthest most axis when using a png file it will have such a tinny little seam. Its annoying, crunching the uvs in a bit or using like bmp was the only way I found around my issue. |
| ||
Thanks guys. I'll give these suggestions a go. |
| ||
im fighting the same problem. if I use one texture in an image . meaning no texture packing into a larger image, everything looks great , when i pack textures into an image nomatter how perfect the UVs are set up, with/without clamping flags I get ugly lines between textures on the mesh. If you figure this out, let me know please. I would love to pack textures on export to reduce surface count |
| ||
Hi RifRaf. I've been testing a solution for the last 2 days - I think I have it figured out. Once I have finished testing, I'll post some info. |
| ||
Sweet, thanks. [EDIT] I actually found a solution to this. When I was packing my textures i was putting them flush with each other.. next I tried putting a gap between them. both had lines in the rendering. So what I did was this. I left 5 spaces between each texture, when I copied the original texture onto the new master packed texture I simply copied it 5 times, once one pixel off in each direction and then exactly where I wanted to set the UVs, this gave the blead off pixel the same colors as those directly on the UV bounding box, and looks great now. with mipmapping on I have to extend the overdraw to about 5 pixels in each direction ! |
| ||
My solution is a little bit different as I have mipmapping turned off. My problem is related specifically to texture filtering. More soon... |
| ||
dont leave us hanging ervin, what was your solution ? |
| ||
Okey dokey. It's taken a lot of research, and trawling through forum posts looking for clues. People like Stevie G have posted a lot of useful information over the years - thanks everyone! The first thing to note is that in my project I am using a texture size of 256 by 256 (texSize=256). I have tried other sizes just for testing, and my technique doesn't seem to work for other sizes. I guess the offset needs to be adjusted or something... I'll use the x direction of an image to describe what I'm doing. I'm actually grabbing 257 x 257 pixels at a time, and grab (N+1) will start with the 2nd last pixel from grab N. ie. - 1st grab will be 0 to 256 - 2nd grab will be 255 to 511 - 3rd grab will be 510 to 766 etc. The I have to use an offset when setting the uv coordinates in the AddVertex commands. I sort of understand why this is required (directx filtering etc etc), but not well enough to explain it here without sounding silly. Note that I am using the FreeImage library in my project, but this technique works with Blitz's normal image handling as well. I hope someone out there finds this helpful. If anyone can think of any improvements, or thinks I've done something wrong (or indeed if what I've done is nonsense), I'd love to hear any suggestions. If I come up with any improvements, I'll stick them here as well. Function getImage() Local xCount,yCount Local imgHandle,imgWidth,imgHeight Local texLeft,texTop,texRight,texBottom Local tmpBitmap,tmpImage,tmpTexture,tmpBrush Local uvOffset#=0.5/texSize Local xDone,yDone imgHandle=FreeImage_LoadFunction("test image.png") imgWidth=FreeImage_GetWidth(imgHandle) imgHeight=FreeImage_GetHeight(imgHandle) If imgWidth<>0 Then If imgHeight<>0 Then mesh=CreateMesh() xDone=False xCount=0 While xDone=False yDone=False yCount=0 While yDone=False qd.quad=New quad qd\surface=CreateSurface(mesh) qd\vertex[0]=AddVertex(qd\surface,0+xCount,1+yCount,0,0+uvOffset#,0+uvOffset#) qd\vertex[1]=AddVertex(qd\surface,1+xCount,1+yCount,0,1-uvOffset#,0+uvOffset#) qd\vertex[2]=AddVertex(qd\surface,1+xCount,0+yCount,0,1-uvOffset#,1-uvOffset#) qd\vertex[3]=AddVertex(qd\surface,0+xCount,0+yCount,0,0+uvOffset#,1-uvOffset#) AddTriangle(qd\surface,qd\vertex[0],qd\vertex[1],qd\vertex[3]) AddTriangle(qd\surface,qd\vertex[2],qd\vertex[3],qd\vertex[1]) texLeft=(xCount*texSize)-xCount texRight=texLeft+texSize If texRight>=imgWidth Then texRight=imgWidth xDone=True EndIf texBottom=imgHeight-((yCount*texSize)-yCount) texTop=texBottom-texSize If texTop<=0 Then texTop=0 yDone=True EndIf tmpBitmap=FreeImage_Copy(imgHandle,texLeft,texTop,texRight,texBottom) tmpImage=FreeImage_ReadFunction(tmpBitmap) tmpTexture=CreateTexture(texSize,texSize,1+16+32+256) SetBuffer TextureBuffer(tmpTexture) If texTop=0 Then DrawImage tmpImage,0,texSize-texBottom Else DrawImage tmpImage,0,0 EndIf tmpBrush=CreateBrush() BrushTexture tmpBrush,tmpTexture BrushFX tmpBrush,1 PaintSurface qd\surface,tmpBrush If tmpBitmap<>0 Then FreeImage_Unload(tmpBitmap) EndIf If tmpImage<>0 Then FreeImage tmpImage EndIf If tmpTexture<>0 Then FreeTexture tmpTexture EndIf If tmpBrush<>0 Then FreeBrush tmpBrush EndIf yCount=yCount+1 Wend xCount=xCount+1 Wend EndIf EndIf If imgHandle<>0 Then FreeImage_Unload(imgHandle) EndIf End Function |
| ||
thanks for sharing |