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 textureCellInfo : TRANSFORM3;
20 float4 color : COLOR0;
23 struct PixelShaderInput
25 float4 pos : SV_POSITION;
26 float2 tex : TEXCOORD0;
27 float4 color : COLOR0;
30 // This shader generates two triangles that will be used to draw the sprite.
31 // The vertex properties are calculated based on the per-sprite instance data
32 // passed in from the vertex shader.
35 void main(point GeometryShaderInput input[1], inout TriangleStream<PixelShaderInput> spriteStream)
39 sincos(input[0].rotation, sinRotation, cosRotation);
42 texCoord[0] = float2(input[0].textureCellInfo.x ,input[0].textureCellInfo.y);
43 texCoord[1] = float2(input[0].textureCellInfo.x + input[0].textureCellInfo.z,input[0].textureCellInfo.y);
44 texCoord[2] = float2(input[0].textureCellInfo.x ,input[0].textureCellInfo.y + input[0].textureCellInfo.w);
45 texCoord[3] = float2(input[0].textureCellInfo.x + input[0].textureCellInfo.z,input[0].textureCellInfo.y + input[0].textureCellInfo.w);
48 posDelta[0] = float2(-input[0].offset.x, input[0].offset.y);
49 posDelta[1] = float2( input[0].offset.x, input[0].offset.y);
50 posDelta[2] = float2(-input[0].offset.x, -input[0].offset.y);
51 posDelta[3] = float2( input[0].offset.x, -input[0].offset.y);
53 spriteStream.RestartStrip();
55 for (int i = 0; i < 4; i++)
58 posDelta[i].x * cosRotation - posDelta[i].y * sinRotation,
59 posDelta[i].x * sinRotation + posDelta[i].y * cosRotation
61 posDelta[i] /= renderTargetSize;
62 PixelShaderInput streamElement;
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.pos = float4(input[0].origin.x + posDelta[i].x,input[0].origin.y + posDelta[i].y, input[0].origin.z, input[0].origin.w);
65 streamElement.tex = texCoord[i];
66 streamElement.color = input[0].color;
67 spriteStream.Append(streamElement);
69 spriteStream.RestartStrip();