/
MultiMeshShader.xksl
49 lines (40 loc) · 1.48 KB
/
MultiMeshShader.xksl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace XenkoByteSized
{
shader MultiMeshShader
{
struct TransformData
{
float4x4 Matrix;
};
stream uint InstanceID : SV_InstanceID;
stream float4 ShadingPosition : SV_Position;
stream float3 Position : POSITION;
stream float3 Normal : NORMAL;
stream float2 TexCoord : TEXCOORD;
stream float4 Color : COLOR;
StructuredBuffer<TransformData> ModelTransforms;
StructuredBuffer<float4> ModelColors;
void VSMain()
{
float4x4 iw = ModelTransforms[streams.InstanceID].Matrix;
streams.ShadingPosition = mul(float4(streams.Position, 1), iw);
streams.Normal = mul(float4(streams.Normal, 0), iw).xyz;
streams.Color = ModelColors[streams.InstanceID];
}
[StreamOutput("0:SV_Position.xyz;0:NORMAL.xyz;0:TEXCOORD.xy;0:COLOR.xyzw")]
[maxvertexcount(3)]
void GSMain(triangle Input input[3], inout TriangleStream<Output> vertexStream)
{
/* we make it explicit that THEY ARE BEING USED or the other fields will be optimized out*/
for (int i = 0; i < 3; ++i)
{
Input v = input[i];
streams.ShadingPosition = v.ShadingPosition;
streams.Normal = v.Normal;
streams.TexCoord = v.TexCoord;
streams.Color = v.Color;
vertexStream.Append(streams);
}
}
};
}