Jump to content
  • Advertisement
Sign in to follow this  
schupf

DX10 shader/effect file questions

This topic is 3451 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 some questions about effect files in DX10: 1) Setting a shader resource looks like this:
shaderResourceVar->SetResource(shaderResourceView);  // A

technique->GetPassByIndex(0)->Apply(0);              // B

d3d10Device->DrawIndexed(indexCount, 0, 0);          // C
When is the resource actually copied from system memory to VRAM? After line A,B or C? 2) As you know the resource only has to be set once, so it is absolutely fine to call SetResource() once during initialization and never set it again during the whole lifetime of the application. But what do I do if I don't need that resource any longer? Is calling
shaderResourceVar->SetResource(NULL); 
technique->GetPassByIndex(0)->Apply(0);
the only way? 3) Lets say I want to use a 2D texture array and want to sample the 3rd texture. Is the following line correct and are there any other steps required in the shader?
myTexture.Sample(mySampler, float3(input.texCoords, 2) ); // Texture2DArray myTexture
Is there an upper bound of allowed textures in a texture array? 4) Does anyone has some sample code that shows how to create and fill a texture array (the Texture2D object) in the host application? 5) Lets assume there is a big terrain that is subdivided into 8x8 patches, where each patch has its own textures. I can think about 2 approaches to texture the terrain: A: Before each patch is rendered the patch's textures are set. So this looks something like this:
// per patch (this code is called every frame):
texture0->SetResource( patchTextues0[patchNumber] ); // texture0 is a 2D texture
texture1->SetResource( patchTextues1[patchNumber] ); // texture1 is a 2D texture
...
technique->GetPassByIndex(0)->Apply(0);

d3d10Device->DrawIndexed(indexCount, 0, 0);
And approach 2 looks something like this:
// initialization (this code is only called once when the application starts):
textureArray0->SetResource( texArray0 ); // Set all textue arrays (I dont know
textureArray1->SetResource( texArray1);  // how this code actually looks like. See question 4)

...
// per patch (this code is called every frame):
patchNumber->SetInt( patchNumber );  // Set number of this patch

technique->GetPassByIndex(0)->Apply(0);

d3d10Device->DrawIndexed(indexCount, 0, 0); // The shader uses patchNumber to
// sample the right texture in the texture array
So approach A only sets the textures that are currently required (for example if every patch needs 2 textures, then at every moment there are 2 textures set) and approach B sets ALL required textures (in this example: 8x8 patches with 2 per patch => 128 textures are set at initialization) and just picks the right one at runtime. Which approach is better? How costly/slow are the SetResource calls? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Well, the problem is that most people are "self-taught", meaning the use online tutorials, and as you may be aware... online tutorials simply don't go into details such as this. Your choices are:

- Be patient and hope someone here does actually know
- Get a load of books and see if any of them have your answer
- Get into a class
- Go and register your self in many forums and ask the same question(this I believe is most likely to work, although I wouldn't really reccomend it)

I'm sorry if this post was useless but I thought it was better than nothing.

Sorry again,
Fissure.

Share this post


Link to post
Share on other sites
1) I don't know

2) As far as I know, yeah that's how to do it

3) Yup

4)

As for the texture arrays, there is a good sample in the nvidia sdk. The single pass cubemap sample in the dx sdk also uses them. I believe they setup the texture descriptor using the D3D10_TEXTURE2D_DESC::ArraySize when they create the textures with a normal ID3D10Texture2D pointer and d3d handles the array. Then you can just call SetResource() with the srv you make like that and you use Texture2DArray in the shader and sample it like above.

You can also just create an array of srv's (eg ID3D10ShaderResourceView* someSRVs[arraySize]), and have an array of textures in your shader (Texture2D someTextures[arraysize]) and use SetResourceArray to set them. This is how I handle my materials, since there could be any of textures used, and its perfectly fine to have some of the ID3D10ShaderResourceView's in the array set to NULL with the rest active. And to read sample from them its just someTextures[index].Sample.

5) Well, would you really need to sample from all of those textures during a single draw call? That also seems like a huge number of textures to need for a given visible area of terrain. I would say it would be better to only have the textures set that you need to use at any given time and just page them in and out as needed.

Hope that helps some

[Edited by - Leafteaner on January 11, 2009 3:46:50 AM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!