Sign in to follow this  

Binding Textures to DirectX 10

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

I have a buffer (and some other 1D textures) that I'm trying to bind to DirectX. ID3D10Device::PSSetShaderResources binds resources to the pipeline, but I don't see how it binds the resource to a name (like lights). Is this the correct way to do this, or is there another way? For several (probably not great) reasons I am not using the FX framework. I am instead setting shaders using ID3D10Device::PSSetShader and such, so I can't bind textures and resources the way that it is shown in the DirectX 10 tutorials.
Buffer <float4> lights;

float4 PS( PS_INPUT input) : SV_Target
{
	float4 lightCount = lights.Load(0);
	float4 color = defaultColor * kAmbient;
	for (float i = 0; i < lightCount.x; i++)
	{
		float4 lightPosition = lights.Load(2*i + 1);
		float4 lightColor = lights.Load(2*1 + 2);
		float4 position = input.pos / input.pos.w;
		float4 n = input.norm;
		float4 l = lightPosition - position;
		float4 r = l - 2 * n * dot(n, l);
		float4 v = -position;
		color += kDiffuse * dot(l, n) * lightColor
			+ kSpecular * pow(dot(r, v), alpha) * lightColor;
	}
	return color;
}

Share this post


Link to post
Share on other sites
Hi, I am not too sure about this, but i think you have to use the shader reflection to get the information on which shader resource to bind to. I think you can call GetResourceBindingDesc() which gives you information on the resource slots.

For me, I decided to stick to the effect framework for now because it seems abit tedious to go through the shader reflection and its variables. Maybe in the near future I would try out managing the effects manually through the Shader Reflection interface

Hope this help

Share this post


Link to post
Share on other sites
It looks like the ID3D10ShaderReflection interface only allows you to get information about the shader and the resources bound to it. It doesn't appear (to me) to actually let you bind a resource.

Share this post


Link to post
Share on other sites
If I am not wrong, you have to use the shader reflection to get the information on which slots relates to which resource. For example, slot0 corresponds to your 'light texture' in your shader. Next you then use the PSSetShaderResource to bind the resource to the proper slot. The shader reflection is used heavily if you handles shader manually.

Another example is the usage of constant buffers. Shader reflection interface allows you to know where to write the appropiate data in the constant buffer. Only once with the location known, you can copy the data into your constant buffer and then bind it to the relevant shader.

Hope this clears a bit of your question.

Share this post


Link to post
Share on other sites
So, I've been playing around with this a bit more. It looks like one way to do this is to put a register() bit after the declaration of the texture, constant buffer, etc. The code would look like:

Buffer <float4> lights : register(t0);
Buffer <float4> otherData : register(t1);



This would bind lights to texture slot 0, and otherData to texture slot 1.

Do things actually work this way or is it some coincidence that makes it appear to work this way?

I think I see what you are talking about. You can find out what the name and slots the textures are bound to and use those to put the right slots in the right locations. That will probably work, but I'm still interested if anybody knows if the above is correct.

Share this post


Link to post
Share on other sites
If I am not wrong, your method works as what the shader code is doing is forcing the location to bind that particular variable to. This works the same as in constant buffer where you use the packoffset(c#) to specify the location to store the variable.

In my opinion, one possible downside is that this method is not so flexible. For example in writing the shader, you have to enforce that all diffuse texture goes to slot0 etc.

Share this post


Link to post
Share on other sites

This topic is 3296 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this