Problem with Lightmaps

Started by
1 comment, last by Phillip Schuster 24 years, 7 months ago
I just had to push the texture coordinates on the lightmap inwards a bit so the bilinear wouldn't wrap around to the other side. It's not perfect because the colors aren't continuous but certainly better.
Author of Power Render (http:/www.powerrender.com)
Advertisement
Hi !!

I have programmed my own terrain engine. It uses Lightmaps for realistic lighting. But I have a problem. My Terrain Engine is tilebased. Now, I have this problem:
Each tile has it's own lightmap which is pasted completely on the tile. So, the "left, top" border has 0,0 as UV and the right,top border has 1,0 , the right bottom border has UV 1,1 and the left bottom border gets 0,1 !! So, this works fine. The Lightmaps look great, but there is one problem:
There are black or white lines at the edges of the lightmaps. It's funny, the lightmaps that are overall completely the same (so, every pixel in the lightmap has the same color), do not have these edges, just the lightmaps where a few pixels aren't the same compared with the other pixels in the lightmap.
I disabled bilinear filtering and with Point Sampling it looks good (so, no edges). I also saved my lightmaps to a BMP-File and checked with a Paint-Program, there aren't any edges drawn, so my Lightmap-Generator works perfectly.

It's a problem with bilinear filtering. It's ok, because the filter cannot, of course, step one tile further to use the pixels in that lightmap as a source for it's algo !! So, I really have a problem here.

Does anyone know how to tweek it, that these edges are gone ??? By the way it's created with D3D.


Thanks very much,


Phillip

Phillip Schuster
Hi !!

As nearly always I have figured it out myself with a very good solution. Before rendering my landscape with:

PR_TransformEntity(terrain_ent);
PR_RenderEntity(terrain_ent);

I have put the line:
wgtd3ddev->SetTextureStageState((DWORD)1,D3DTSS_ADDRESS, D3DTADDRESS_CLAMP);

so it looks like that:

wgtd3ddev->SetTextureStageState((DWORD)1,D3DTSS_ADDRESS, D3DTADDRESS_CLAMP);
PR_TransformEntity(terrain.m_PREntity);
PR_RenderEntity(terrain.m_PREntity);
wgtd3ddev->SetTextureStageState((DWORD)1,D3DTSS_ADDRESS, D3DTADDRESS_WRAP);

This sets the Direct3D TextureMode for Stage 1 (Lightmaps) to CLAMP-Mode and after rendering the terrain it's set back to default (WRAP-Mode).

Clamp -Mode means, that for texels lying on an edge (so the bilinear filter cannot find the next pixel, because it's the last pixel) that the same pixel is being taken for bilinear filtering.

Example:
The texture is 64x64. The pixel at x=63,y=63 has to be filtered. This is not correctely possible, because it cannot find the next pixel to the right (which would be 64 and that's not ok), so Clamp-Mode takes the same pixel.

This solves my problem in a very easy, yet very effective way. By the way, OpenGL supports the same mode.
It simply looks amazing now.

Chris, in your terrain-engine you use textures for each "tile". This results in the same effect I have with my lightmaps. There are small lines (error in filtering), showing the tiles. Chris, if you use that mode, this will be solved )


Phillip

Phillip Schuster

This topic is closed to new replies.

Advertisement