Mipmapping/anti-aliasing projected textures?

Started by
3 comments, last by andrew111 14 years, 2 months ago
Hi, in my program for a torch light, I'm projecting a texture so that the torch can have various rings, etc like a real torch would have, (as a result of the light bulb and lens). But those features are coming out very pixelated, so I was wondering there any techniques I could use to anti-alias it or use mipmapping? I'm using GLSL shaders. In the fragment shader I'm just mixing the projected texture colour with the light colour.

lightCol = mix(texture2D(torchTexture,projCoords.st),lightCol,0.3);
I've tried mixing the average of the surrounding colours of each pixel, but I was having trouble with that since it's hard to tell how far away the neighboring pixels are in the projected texture. Thanks.
Advertisement
Simple question before talking about aliasing , what is your texture resolution ?

The aliasing with projected texture come from the fact that you project a -x/x range onto a 0/1 range depending on the distance of the projector to the object that receive the texture.

As you do a perspective projection it will scale your -x/x range with distance, producing a more and more difference between -x/x range and 0/1 range giving you the aliasing.

The same arrive in shadow mapping techniques and some cleverer algorithm fight against this aliasing either averaging the surrounding pixels but for colors it won't produce a good solution (ie for depth it's ok since we don't need to be conservative) , some other algo will split the shadow maps into multiple map with the distance (i suggest you to do this if u want a neat effect).

If you have constraint like memory so u will probably not want to do that but here is my idea on this :

Complex solution :

i would take the texture to different sizes(1024/512/256/128/64) and sample the right map depending on distance of receiver, the difficulty will be to fight against zooming and finding a way to downsample the hires texture to produce a projected motif that has the same size and handling smooth transition with displacement (mipmapping with linear interpolation ;-)).

Easy solution :

Increase texture size.

Other thoughts :
switch to another algorithm like decals generation ?

"Bon courage" (french traduction : good luck)






It sounds like you're just using nearest-neighbour filtering on your texture. Changing it to linear should fix this without any shader changes.
Quote:Original post by andrew111
I've tried mixing the average of the surrounding colours of each pixel, but I was having trouble with that since it's hard to tell how far away the neighboring pixels are in the projected texture.
That's what linear filtering should be doing automatically. If you ever do have to do this manually though, you can use use the dFdx and dFdy instructions to find the neighbouring texels.
Quote:Original post by nini
i would take the texture to different sizes(1024/512/256/128/64) and sample the right map depending on distance of receiver
If you enable mip-mapping, this should happen automatically as well, without any manual management or changes to the shader.
Quote:If you enable mip-mapping, this should happen automatically as well, without any manual management or changes to the shader.


yep u are right on this.

So just try to generate the mip and apply linear filtering on it.
Quote:Original post by nini
Simple question before talking about aliasing , what is your texture resolution ?

1024

Quote:Original post by nini
Other thoughts :
switch to another algorithm like decals generation ?


I'll have to read up on that.


Quote:Original post by Hodgman
It sounds like you're just using nearest-neighbour filtering on your texture. Changing it to linear should fix this without any shader changes.
Quote:Original post by andrew111
I've tried mixing the average of the surrounding colours of each pixel, but I was having trouble with that since it's hard to tell how far away the neighboring pixels are in the projected texture.
That's what linear filtering should be doing automatically.


Oh, I was thinking the projected texture wouldn't use the automatic mip mapping etc, but now that I think about it, it shouldn't be any different to general texture mapping.

Linear has a huge difference over nearest, but it still looks a bit blocky when looking close.
I realised blockiness that's left is about the same amount of blockiness of the torch texture when zoomed in the same amount as it is seen in the scene.
A much larger texture should fix that.


Thanks alot for the help guys.

This topic is closed to new replies.

Advertisement