OSDN Git Service

XAudio2を試す前のバックアップ。
[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 textureCellInfo : TRANSFORM3;
20         float4 color : COLOR0;
21 };
22
23 struct PixelShaderInput
24 {
25     float4 pos : SV_POSITION;
26     float2 tex : TEXCOORD0;
27     float4 color : COLOR0;
28 };
29
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.
33
34 [maxvertexcount(4)]
35 void main(point GeometryShaderInput input[1], inout TriangleStream<PixelShaderInput> spriteStream)
36 {
37     float sinRotation;
38     float cosRotation;
39     sincos(input[0].rotation, sinRotation, cosRotation);
40
41     float2 texCoord[4];
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);
46
47     float2 posDelta[4];
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);
52
53     spriteStream.RestartStrip();
54     [unroll]
55     for (int i = 0; i < 4; i++)
56     {
57         posDelta[i] = float2(
58             posDelta[i].x * cosRotation - posDelta[i].y * sinRotation,
59             posDelta[i].x * sinRotation + posDelta[i].y * cosRotation
60             );
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);
68     }
69     spriteStream.RestartStrip();
70 }