Jump to content
  • Advertisement
Sign in to follow this  
Neometron

Is it possible to pass an index to a texture array through instancing?

This topic is 564 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 everyone,
It has been some time since I have been on gamedev and programming in D3D. In the last month or so I have been working on a voxel terrain of 512x512x256 placed within a home brewed octree. I'm currently using D3D11 with instancing and batch based on textures. I discovered that I could bind multiple textures into a texture array. I attempted to pass an unsigned int as a texture index value along with my instance data, but I hit a wall trying to receive that uint in the pixel shader as it will not compile. I have read that the pixel shader does not take uint as input. However, the compile error is X3512: sampler array index must be a literal expression. Which I figure that the array index must be known during compile time.

Either way, I ask:

Is it possible to pass an index to a texture array through instancing?

PS code:

Texture2D texture_data[2];
SamplerState sample_state;

struct PS_INPUT
{
	float4 position : SV_POSITION;
	float4 normal   : NORMAL;
	float2 uv       : TEXCOORD0;
        uint instance_texture : TEXCOORD1;
};

float4 main(PS_INPUT input) : SV_TARGET
{
	float4 light = { 0.707f, -0.707f, 0.0f, 0.0f }; // In World Space //0 = Vector : 1 = Point
	light = normalize(-light);

        float4 texture_color = texture_data[input.instance_texture].Sample(sample_state, input.uv);

	float  ambient_scalar = 0.5f;
	float4 ambient_color = ambient_scalar * texture_color;

	float  light_scalar = dot(light, input.normal);
	float4 light_color  = light_scalar * texture_color;
	
	if (light_scalar > 0.0f)
		return saturate(ambient_color + light_color);
	else
		return saturate(ambient_color);
}

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!