PDA

View Full Version : detail textures



zen
03-19-2002, 08:52 AM
Some searching on google and in the archives here(btw aren't the arcives of gd-algorithms searchable any more?) turned out two methods for aplying detail textures.
1)Use mipmapping with alpha fading to 1.0 as the levels increase.This ones seems to suck generally.
2)Use the distance from camera of each vertex to calculate an alpha value for the detail texture.
Now since distance calculations aren't very cheap(even if you don't take the final sqrt,can this be done?) and since opengl does this anyway to calculate miplevels/magnification factors etc. isn't there a way to use that info?
I know there is a SGI_Detail_Texture extension but it doesn't seem to be widely implemented.Can I use core functionality to achieve this?

zeckensack
03-19-2002, 09:12 AM
Have you tried to unconditionally apply the detail texture with a standard mipmap filter? Just a thought, but I'd imagine that a texture fetch from the smallest 1x1 mip level (when far away) shouldn't hurt performance that much.

zed
03-19-2002, 10:10 AM
>>Now since distance calculations aren't very cheap(even if you don't take the final sqrt,can this be done?)<<

dist = SQUAREDLENGTHOFVECTOR(A-camera)

very cheap to do per vertex, theres no need for sqrt as distance will remain relative to each other

Korval
03-19-2002, 11:18 AM
I think I'd rather let mipmapping cover it. By that, I mean load the actual texture into the high LOD (or high 2 LOD's), but make all the rest simply white. So, when the bitmap goes out of the high LODs, it doesn't look detailed.

fenris
03-19-2002, 12:08 PM
Is there a reason why you want to fade out the detail texture? With any modern multi-texturing card, it doesn't cost much of anything to just render the detail texture all the time. It'll surely save you from the overhead of figuring out how to apply the detail texture per vertex per frame. Anyhow, I have done this before. For the mipmaps of the detail texture, fade out your alpha as you state in your first example, but use TRILINEAR filtering for your detail map mips. It will transition the alpha smoothly per texel. This method using bilinear filtering is disgustingly artifact prone.

zen
03-19-2002, 01:57 PM
Hmmmm,looks like method 1) doesn't suck that bad.In some previous posts it was reffered to as the quick and dirty way.I'm not sure why.
fenris:From what I read about detail textures it isn't a very good idea to use'em when the base texture isn't magnified.So at some point the detail texture has to fade out.But your(and that of the rest of you) way does this fading as well.I can only see three issues:
1)Performance on non-mutitexturing cards will suck,but that's not really a problem since most cards which are less than 2-3 years or so old supprot it.
2)It will use up a texture unit for nothing for far away tris but that also doesn't matter unless you have a special code path for these tris which actually does something usefull with this unit.But then again the extra code/calculations to do the sorting will propably make things worse.
3)It won't work w/o mipmapping.Then again,if you don't have mipmapping then detail textures aren't your biggest problem.
Alright you convinced me!I'm going to give it a try.Thanks for the prompt replies.

zed
03-19-2002, 09:28 PM
fading out details maps looks far better that leaving them on on 'far away geometry'
also fading out with mipmapping is not good cause its calculated on more than just disatnce ie polygon angle to camera also plays a part, thus different mipmap levels will be side by side but one will be showing more (if u catch my drift)

zen
03-20-2002, 05:21 AM
zed:you're right,but unless the angles(or the area in screen pixels,I think that is used for LOD calculations) of two nearby tris are very different there won't be a big difference(with trilinear filtering at least).And if they are thenthe difference in the detail texture alpha won't show that much anyway.At least that's what I think.I agree that it is not the best way to do it but the simplicity/efficiency might be worth the less-than-optimal results.

zen
03-21-2002, 06:13 AM
I have one more question and I don't want to start a nwe topic.I know that I'm supposed to use either multitexturing or multipass rendering to apply the detail textures.In the first case I can use the texture environment combiner functions and I suppose that in the second case I should use the blending functions.I'm not sure as to which functions are used though in either case.
The only usefull info I could come up with was "advanced graphics prog. techniques '98" and a russian page(which wasn't really that usefull but looked like it could be usefull if I could speak russian"

fenris
03-21-2002, 07:25 AM
zen,

I'd use the multitexturing approach, with help from ARB_texture_env_combine. Any OpenGL 1.3 driver will support it, and most 1.2 drivers will at least have EXT_texture_env_combine. I'd use a grayscale detail texture, with a low contrast and the ADD_SIGNED_ARB combine method. Like:


glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, colorMap);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, detailMap);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD_SIGNED_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);


With the color texture in unit0, and the detail texture in unit1. For your detail texture using this method, rather than fading out the alpha channel in your mipmaps, you'll want to fade the color to 0.5 gray (127).

[This message has been edited by fenris (edited 03-21-2002).]

zen
03-21-2002, 08:56 AM
fenris:Thanks,I have seen this in a demo somewhere.The only problems are:
1)What about non-mutitexturing hardware?Can this be implemented with blending an 2 passes?
2)Fading the alpha channel can easily be implemented using a detail map with zero alpha and glPixelTransfer with GL_ALPHA_BIAS.Also why fade to gray?Fading the alpha channel would make the detail map contribute less with each level until it doesn't show up at all at some level.Wouldn't that work as well?

BTW regarding this GL_PREVIOUS:the specs say it's the color from the prev. texture environment.Does that mean the previous texture unit?

fenris
03-21-2002, 11:39 AM
Originally posted by zen:
fenris:Thanks,I have seen this in a demo somewhere.The only problems are:
1)What about non-mutitexturing hardware?Can this be implemented with blending an 2 passes?
2)Fading the alpha channel can easily be implemented using a detail map with zero alpha and glPixelTransfer with GL_ALPHA_BIAS.Also why fade to gray?Fading the alpha channel would make the detail map contribute less with each level until it doesn't show up at all at some level.Wouldn't that work as well?

BTW regarding this GL_PREVIOUS:the specs say it's the color from the prev. texture environment.Does that mean the previous texture unit?

The reason why I said to fade to gray is because of the combiner method used.
ADD_SIGNED_ARB = source0 + source1 - 0.5
And that it is operating on the RGB components, rather than alpha. A completely gray (0.5 for R, G and B) detail map in unit 1 will contribute nothing to the RGB in the first texture unit.

For two passes, I would use a high contrast version of the detail texture, and blend with ZERO, SRC_COLOR.

But alas, to make things simple, you can just use 1 high contrast detail map. For two passes, use the blend method I described above, and for multitexture, just modulate the detail texture with the color texture, fading the mipmaps to white.


glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, colorMap);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, detailMap);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);


PREVIOUS_ARB is exactly that, PREVIOUS_ARB on texture unit 1 means the result of texture unit 0. For texture unit 0, it maps to the primary color.

zen
03-21-2002, 01:32 PM
so I can use RGB instead of RGBA maps and GL_RED/GREEN/BLUE_BIAS to fade to white,right?Although (DST_COLOR,SRC_COLOR) might work better by doubling the overall texture intensity.
BTW what blenfing/environment function would be used with an alpha fade as the others suggested?