Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture alignment problem

Started by gdpost778 May 20, 2003 at 7:06 AM 3 replies 850+ views
Original Post
gdpost778
gdpost778
Hi, With directX 8, i''m using several regtangular textures representing, when coast to coast, a uniform image. Each texture surface is completely filled with image data. I''m using the following code as texture stages for each frame: device.SetTextureStageState(0,D3DTSS_ADDRESSU, D3DTADDRESS_BORDER); device.SetTextureStageState(0,D3DTSS_ADDRESSV, D3DTADDRESS_BORDER); I''m also using the proper texel to pixel mapping removing 0.5f for each frame vertex x and y coordinate. When the frames are displayed without artificial scaling, everything''s fine. Using a 2x scaling, things look ok aswell. When I use a 4x scaling, i''m beginning to see black border on the edges of every frames. Using D3DTADDRESS_CLAMP instead of D3DTADDRESS_BORDER covers the black boders with data, but this is a not really a solution, since the image is distorted. Indeed my problem seems to be that for some reason, after scaling, the textures do not "fit" their frames as they should. Any idea what the problem is how to solve it? Thanks. gdpost778.
gdpost778
gdpost778
Precisions: the problem occurs even after a 2x scaling. When I''m taking about scaling, I mean I''m applying a scaling transformation matrix during the rendering.
I''m using untransformed vertices.
gdpost778
gdpost778
Damn! It seems the problem is due to the texture filteting mode I''m using: D3DTEXF_LINEAR. Indeed, using D3DTEXF_POINT, there is no problem!
Any idea how to make it work with a neat filtering (D3DTEXF_LINEAR) ?

thx.
S1CA
S1CA
quote:
Original post by gdpost778
Damn! It seems the problem is due to the texture filteting mode I''m using: D3DTEXF_LINEAR. Indeed, using D3DTEXF_POINT, there is no problem!
Any idea how to make it work with a neat filtering (D3DTEXF_LINEAR) ?

thx.



1) do remember to check that BORDER mode is actually supported on your target hardware. It isn''t on most older chips - instead it either gets ignored or pixels come out white/black.

2) Each sample of a texel comes from the **centre** of the texel. Bilinear filtering needs to take the samples of the neighbours of the current texel. Think of what happens when the current texel is the leftmost one in the map and the filtering needs to get its left neighbour - that''s where the wrap mode comes in:
a) With WRAP (the default), the filtering fetches the next texel from the other side of the map (e.g. for the leftmost texel, it''s left neighbour is the rightmost texel in the map). If one side of your map has a fairly different colour to the other then the filtered result will be a noticable seam, particularly for coordinates outside of the 0.0 to 1.0 range (which will extend the number of pixels in the seam area).

b) With BORDER, the filtering gets the border colour for neighbours that are off the edge of the map. If the border colour isn''t carefully chosen, at least one part of the texture will show seams.

c) With CLAMP, the filtering repeats the current texel for use as the neighbour. However if you specify coordinates (or your texture transforms do) that are outside of the 0.0 to 1.0 range then those texels get repeated for more than just the half a texel required for the filtering and turn into a stretched look.


3) Unfortunately the above is the state of play, but for most apps that''s enough:

a) Check your texture coordinates extremely carefully. The mapping texels to pixels section in the D3D docs is talking about screen space stuff (i.e. 2D), in 3D things are a tad more complicated due to things such as perspective correction. Some of the docs on the developer.nvidia.com site explain screenspace mapping better than the D3D docs do.

b) Most games manage to avoid seams by using very carefully created texture maps, very carefully set texture coordinates and CLAMP mode. If your texture coordinates are ending up outside of the 0.0 to 1.0 range (i.e. clamp is only repeating for HALF a texel), then it indicates you''re doing something wrong somewhere.

c) Ensuring that the edges of your texture maps filter nicely helps a lot - even to the point of manually creating a 1 pixel border around all your textures. [remember to take mipmapping into account here].

d) Some seams can be covered - use multitexturing to blend a texture over the seam halfway before the join - sort of like detail texturing. It can be highly effective in covering all seams.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
gdpost778
gdpost778
Thanks a lot Simon for this anwser.

So i guess i''d better not use the BORDER mode. In fact, I was using CLAMP before but i noticed some discrepancies at the borders when the textures were scaled, so I changed to BORDER and noticed the black areas. In fact for the moment I''m going to disable filtering, also because each texture is filtered separately, leading to a tiling effect when they are presented coast to coast to render a single uniform image. There are probably ways to avoid that, by overlapping probably, but that''s a little too complex for the moment.

Thanks again,

gdpost778.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.