16 C
New York
Wednesday, October 15, 2025

directx – D3D11 batching with texture arrays


What you are able to do Is supplying a buffer, corresponding to Buffer that accommodates texture IDs.
You’ll be able to then use the vertex shader’s SV_InstanceID to index into this explicit buffer and might write the Texture ID moreover to the UV Coordinates (float3 consisting of UV and Texture ID), the fragment shader doesn’t have to be modified apart from the brand new float3 and the feel array sampling. Tough instance:


// buffer containing texture IDs per occasion
Buffer InstanceTextureIDs : register(t0);

// Texture2DArray for all occasion textures
Texture2DArray textureArray : register(t1);
SamplerState samplerState : register(s0);

// Vertex enter construction
struct VSInput
{
    float3 place : POSITION;
    float2 texcoord : TEXCOORD0;
    uint instanceID : SV_InstanceID;
};

// Vertex to pixel shader output
struct PSInput
{
    float4 place : SV_POSITION;
    float3 texcoord3D : TEXCOORD0; // xy = UV, z = texture slice
};

// Vertex Shader
PSInput VSMain(VSInput enter)
{
    PSInput output;

    //...//
    // Fetch texture ID and pack it with UV right into a float3
    uint texID = InstanceTextureIDs[input.instanceID];
    output.texcoord3D = float3(enter.texcoord, texID);

    return output;
}


float4 PSMain(PSInput enter) : SV_TARGET
{
    // Pattern from the feel array utilizing the packed float3
    return textureArray.Pattern(samplerState, enter.texcoord3D);
}

```

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles