OSDN Git Service

Z座標で優先制御できるようにした。
[shooting3/shootinggame.git] / ShootingGame / BasicSprites.GeometryShader.gs.hlsl
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
4 // PARTICULAR PURPOSE.
5 //
6 // Copyright (c) Microsoft Corporation. All rights reserved
7 //----------------------------------------------------------------------
8
9 cbuffer RenderTargetInfoCB
10 {
11     float2 renderTargetSize;
12 };
13
14 struct GeometryShaderInput
15 {
16     float4 origin : TRANSFORM0;
17     float2 offset : TRANSFORM1;
18     float rotation : TRANSFORM2;
19     float4 color : COLOR0;
20 };
21
22 struct PixelShaderInput
23 {
24     float4 pos : SV_POSITION;
25     float2 tex : TEXCOORD0;
26     float4 color : COLOR0;
27 };
28
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.
32
33 [maxvertexcount(4)]
34 void main(point GeometryShaderInput input[1], inout TriangleStream<PixelShaderInput> spriteStream)
35 {
36     float sinRotation;
37     float cosRotation;
38     sincos(input[0].rotation, sinRotation, cosRotation);
39
40     float2 texCoord[4];
41     texCoord[0] = float2(0,0);
42     texCoord[1] = float2(1,0);
43     texCoord[2] = float2(0,1);
44     texCoord[3] = float2(1,1);
45
46     float2 posDelta[4];
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);
51
52     spriteStream.RestartStrip();
53     [unroll]
54     for (int i = 0; i < 4; i++)
55     {
56         posDelta[i] = float2(
57             posDelta[i].x * cosRotation - posDelta[i].y * sinRotation,
58             posDelta[i].x * sinRotation + posDelta[i].y * cosRotation
59             );
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);
67     }
68     spriteStream.RestartStrip();
69 }