Hardware instanced font

Started by
1 comment, last by boboS 11 years, 11 months ago
Hello, I was trying to create a hardware instanced font like this:

- Create a single buffer that contains vertices for a quad.
- Create a buffer for instancing that contains position data and UV for mapping the right letter.

But I dont know how to send a big buffer for the instanced data. Since now I only send a position buffer for instanced data in the shader using TEXTCOORD1. So I was using TEXTCOORD1 for x,y and z . But If I create a bigger instance buffer like

struct InstancedBuffer{
D3DXVECTOR2 position;
D3DXVECTOR2 texture_map;
int letter_size;
}

How Would I send that to the shader ? Making another TEXTXOORDx ? or creating a struct in the shader and replacing float 3 TEXTCOORD with myStruct TEXTCOORD ?


Or should I make multiple simple buffers? One for position , on for texture mapping and in the shader send them as TEXTCOORD1, TEXTCOORD2 etc.

Im using DirectX 11.
Advertisement
A semantic can be bound to at most a float4/int4/uint4. You can see this when you set up your D3D11_INPUT_ELEMENT_DESC for creating your input layout, since you have to use a DXGI_FORMAT which as at most 4 components. So you couldn't just use a single semantic for all of your instance data, you'd have to split it up. It would be possible to use DXGI_FORMAT_R32G32B32A32_FLOAT so that position and texture_map were packed into the same semantic, but that would mean you would have to access them as a single float4 variable in your shader code. Instead I think that you should just have an input element for each member of your struct, so that can take the 3 variables seperately as inputs to your vertex shader. Like this:


struct VSInput {
// Non-instance data
float4 VertexPosition : POSITION;
float2 UV : UV;

// Instance data
float2 TextPosition : TEXTCOORD0;
float2 TextureMap : TEXTCOORD1;
int LetterSize : TEXTCOORD2;
};


You just need to make sure that you set up your input layout to match this.
Thnaks for the answer.
Would it make any difference? I mean sending a big buffer (non editable) for some text or making instanced traingles. Its a draw call for a instanced sentence and a draw call for a big buffer that contains all the triangles for the sentence.

This topic is closed to new replies.

Advertisement