Sign in to follow this  
Neometron

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

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

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