Jump to content
  • Advertisement
Sign in to follow this  
Bouga

cg shaders & textures

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
hi
could anyone tell me how to read the neighbouring pixels' colour in cg (pixel/fragment) shader?

thanks

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!