Jump to content
  • Advertisement
Sign in to follow this  
grill8

Quick questions about DirectX 9 shaders.

This topic is 3665 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

Hello, I have a couple of quick questions about DirectX 9 shaders. I am fairly new to shaders so I do not know what version I need or may need but I plan on developing for DirectX 9. Ok, so here is the scenario ... I have a script that determines a bunch of information about the terrain in my application. One of the script entries (BlockResolution) determines the resolution (in x/z) of each terrain block. The terrain is rendered in batches (blocks) using a vertex shader that needs access to an array of floats [BlockResolution][BlockResolution] in dimension, passed to the shader for each batch. I cannot pass the values in the vertices themselves because each vertex needs access to all the values (not just its own). It is my understanding that I cannot pass by ** (or even *) because that simply cannot be done in shaders. I could have an array of floats that is fixed in size yes ... but ... I do not want to have to change the shader if I change BlockResolution in the script. I would like to be able to change the script without having to change anything else. It just is more neat/tidy that way. So that leaves me with a couple of questions ... QUESTION 1) Can I even have a 2d array of floats in a DirectX shader? Yes, I could have a 1d array of floats and pass a row size, but is a 2d float array even ok? QUESTION 2) How do I pass an arbitrarily sized array (1d or 2d) of floats to a DirectX 9 vertex shader, or does the size have to be known when the shader is compiled? Thank you for your help. Jeremy

Share this post


Link to post
Share on other sites
Advertisement
The way to pass a 2D array to the shader is as a texture. This will limit you to cards which support this (GeForce 6x00 and up, Radeon HD 2x00 and up), and you might not get good performance on some cards. Texture constants, your other options, are limited in number to 256, which makes for a maximum 1024 float values you can pass (and some will be used for other things, probably), so that's not all that practical (although access is faster and the hardware support is better).

Does the vertex really need access to all the values, or just a specific subset of them? (All will certainly imply a slow shader.) If the subset is small and well defined, passing them in the vertex structure could work.

Share this post


Link to post
Share on other sites
Thank you very much. That is very informative. Just what I need.

I analyzed the problem a little more and found that each vertex will need access to at most 3 floats in the array. Those floats never change ... so as you suggest they could be passed in the vertex. It just seems inefficient however to have to store 3 floats per vertex when a 2D array would require one float per vertex.

Out of curiosity ... why would setting large amounts of floats in the shader be any slower than passing those floats in the vertices? To me it seems like it is the same ammount of memory so it should take about the same ammount of time to move them to the shader.

Thank you again for your help.
Jeremy

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!