Discovering DX10 or beginner shader questions

Started by
0 comments, last by mososky 14 years, 1 month ago
I had a few years back coded a bit in OpenGL and I recently decided to give DX10 a try. It took me a while to realize that all the transformations were done by shaders now, it's very nice! I coded a heightmap renderer and until I tried to add textures all was going very smoothly. Then an issue occured when I tried to map textures to it. Until now for each section of the heightmap(it's cut in different sections because each section can have 9 independant textures) I'd take the same shader, update the world var and render it using the same shader(or effect as DX seem to call it). For loading textures I use D3DX10CreateShaderResourceViewFromFile with .dds files. And for each section I tried to call theeffect->SetResource(theshaderresource) for each of the 9 textures(thus calling it 9*n times for n sections). As you probably know this function is very slow(I suppose it moves the entire texture to the video memory each time?). Anyway I was wondering how I should change the program? Should I make one effect for each section of the heightmap, thus calling SetResource only once for each? Should I find a way to just load the texture into video memory and pass only a pointer to the shader? Hopefully it's a very dumb question and there is a very simple answer :).
Advertisement
I'm not sure from your post but if you are calling D3DX10CreateShaderResourceViewFromFile everyframe thats a big mistake. That should only be called once, when you need to load the texture into video mem.

When you set a ID3D10ShaderResourceView, it's just like a pointer. A pointer to whatever you have setup in your shader with D3DX10CreateShaderResource~
So there should be no/little performance hit unless your texture (or shader state in general) exceed the limits of video memory and need to be swapped out in main mem. In my game engine I usually work with several shaders that use a global Texture2D varibale in the shader file. So as i move onto differnt objects I simple switch the main Texture2D variable each shader is programmed to use. With your shader, an option would be to setup 9 Texture2D variables, then set them all a single time to whatever texture they need, so changing it would not be necessary, but this might not have any performance increase.

Having more than one effect will only slow the process down. You should be able to do everything in one shader.

good luck

This topic is closed to new replies.

Advertisement