Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////// gpu side
- struct sprite // vertex shader input type ("sprite encoded vertex")
- {
- int vertexID : SV_VERTEXID; // system generated, does not need to be passed / be a member in cpu struct
- float4 pos : POSITION; // contains all four coordinates needed (left, top, right, bottom)
- float4 tex : TEXCOORD; // aka (x0, y0, x1, y1) - and ditto for texture coords
- };
- struct vertex // vertex shader output type (i.e. the pixel shader input)
- {
- float4 pos : SV_POSITION;
- float2 tex : TEXCOORD;
- };
- vertex main(sprite input) // vertex shader, will be run 4 x per sprite, with SV_VERTEXID going from 0-3
- {
- vertex output;
- int x = input.vertexID & 2; // will output vertices in this order:
- int y = ((input.vertexID & 1) << 1) ^ 3; // (x0, y1), (x0, y0), (x1, y1), (x1, y0)
- output.pos = float4(input.pos[x], input.pos[y], 0.0f, 1.0f);
- output.tex = float2(input.tex[x], input.tex[y]);
- return output;
- }
- ////////// cpu side
- sprite mySprite; // similar to the vertex shader input type (minus vertexID)
- mySprite.pos = { posleft, postop, posright, posbottom }; // or x0, y0, x1, y1, if you will
- mySprite.tex = { texleft, textop, texright, texbottom }; // or u0, v0, u1, v1, if you will
- // add sprites like that to vertex buffer ^
- DrawInstanced(4, sprite_count, 0, 0) // 4 = vertices per instance, making SV_VERTEXID go from 0 to 3
Advertisement
Add Comment
Please, Sign In to add comment