1 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
2 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
3 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
6 // Copyright (c) Microsoft Corporation. All rights reserved
7 //----------------------------------------------------------------------
9 cbuffer RenderTargetInfoCB
11 float2 renderTargetSize;
14 struct GeometryShaderInput
16 float4 origin : TRANSFORM0;
17 float2 offset : TRANSFORM1;
18 float rotation : TRANSFORM2;
19 float4 color : COLOR0;
22 struct PixelShaderInput
24 float4 pos : SV_POSITION;
25 float2 tex : TEXCOORD0;
26 float4 color : COLOR0;
29 // This shader generates two triangles that will be used to draw the sprite.
30 // The vertex properties are calculated based on the per-sprite instance data
31 // passed in from the vertex shader.
34 void main(point GeometryShaderInput input[1], inout TriangleStream<PixelShaderInput> spriteStream)
38 sincos(input[0].rotation, sinRotation, cosRotation);
41 texCoord[0] = float2(0,0);
42 texCoord[1] = float2(1,0);
43 texCoord[2] = float2(0,1);
44 texCoord[3] = float2(1,1);
47 posDelta[0] = float2(-input[0].offset.x, input[0].offset.y);
48 posDelta[1] = float2( input[0].offset.x, input[0].offset.y);
49 posDelta[2] = float2(-input[0].offset.x, -input[0].offset.y);
50 posDelta[3] = float2( input[0].offset.x, -input[0].offset.y);
52 spriteStream.RestartStrip();
54 for (int i = 0; i < 4; i++)
57 posDelta[i].x * cosRotation - posDelta[i].y * sinRotation,
58 posDelta[i].x * sinRotation + posDelta[i].y * cosRotation
60 posDelta[i] /= renderTargetSize;
61 PixelShaderInput streamElement;
62 // streamElement.pos = float4(input[0].origin.x + posDelta[i].x,input[0].origin.y + posDelta[i].y, input[0].origin.z, input[0].origin.w);
63 streamElement.pos = float4(input[0].origin.x + posDelta[i].x,input[0].origin.y + posDelta[i].y, input[0].origin.z, input[0].origin.w);
64 streamElement.tex = texCoord[i];
65 streamElement.color = input[0].color;
66 spriteStream.Append(streamElement);
68 spriteStream.RestartStrip();