cg shaders & textures

Started by
5 comments, last by RAZORUNREAL 18 years, 8 months ago
Hi, 2 shader questions: 1) When doing normal maps & parallax maps (or fake displacement maps), is it best to store the normal map & the height map in two different textures, or to have the height map as the fourth channel in the normal map texture? I mean, will it be faster to do a texture lookup in a one channel texture to get the height & calculate the UV offset and then get the normal from a different texture with 3 channels? Or will it be faster to get the fourth channel from the texture, calculate the offset & then get the 3 normal channels from the same texture? 2) I've heard that when you do a texture lookup, becouse its a rather slow function, if you put some unrelated calculations right after it, they can run in paralell? Is this true? And if it is, do I have to worry about squeezing all those paralell calculations there myself, or are the high level language compilers (like cg, glsl...) advanced enough that they will do it for me? Thanks!
"A screen buffer is worth a thousand char's" - me
Advertisement
Where have you been dude ? long time, no see :P
Quote:Original post by Bouga
Hi,


Hi.

Quote:
2 shader questions:

1) When doing normal maps & parallax maps (or fake displacement maps), is it best to store the normal map & the height map in two different textures, or to have the height map as the fourth channel in the normal map texture? I mean, will it be faster to do a texture lookup in a one channel texture to get the height & calculate the UV offset and then get the normal from a different texture with 3 channels? Or will it be faster to get the fourth channel from the texture, calculate the offset & then get the 3 normal channels from the same texture?


I've only written in shaders in glsl, but I think the same should apply to cg. Intuitively, I'd say that it would be best to store the heightmap and normalmap in the same texture. That will save you a texture unit, and also you can get all the information with a single texture read, rather than two.

Quote:
2) I've heard that when you do a texture lookup, becouse its a rather slow function, if you put some unrelated calculations right after it, they can run in paralell? Is this true? And if it is, do I have to worry about squeezing all those paralell calculations there myself, or are the high level language compilers (like cg, glsl...) advanced enough that they will do it for me?


I'm not entirely sure about that. However, I would write the code in a readable manner and leave the optimization to the compiler.
Thanks for your reply. However, wouldnt it be wrong to get the normal map value and the height map value at the same UV's? Isn't it the whole point of displacement mapping, to get the height, offset the UV's accordingly & then get the normal map & diffuse & whatever else values at the new UV's?

Quote:I'm not entirely sure about that. However, I would write the code in a readable manner and leave the optimization to the compiler.

Thats what I hoped somenoe would say :) Then so it is, atleast until proven otherwise.
"A screen buffer is worth a thousand char's" - me
Quote:Original post by Bouga
Thanks for your reply. However, wouldnt it be wrong to get the normal map value and the height map value at the same UV's? Isn't it the whole point of displacement mapping, to get the height, offset the UV's accordingly & then get the normal map & diffuse & whatever else values at the new UV's?


Ah, I'm sorry, I obviously didn't read your first post right. I'm afraid I'm not familiar with the inner workings of parallax mapping and displacement mapping. But if it is as you say, and you must use two different UV-coordinates, then you cannot avoid two texture reads, and so you probably should use two seperate textures.
hi
could anyone tell me how to read the neighbouring pixels' colour in cg (pixel/fragment) shader?

thanks
credo
I wouldn't be surprised if it was faster to read from the same texture twice than from 2 different textures, like it might be more likely to be cached. And you may even find you have some use for the height at your result uv, I've seen an implementation that darkened the lower pixels.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!

This topic is closed to new replies.

Advertisement