Jump to content
  • Advertisement
Sign in to follow this  
boboS

Hardware instanced font

This topic is 2366 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, 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. Edited by boboS

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by boboS

Share this post


Link to post
Share on other sites
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!