68 lines
1.8 KiB
HLSL
68 lines
1.8 KiB
HLSL
#include "bindless_structs.hlsli"
|
|
|
|
struct VS_Input
|
|
{
|
|
uint VertexIndex : SV_VertexID;
|
|
};
|
|
|
|
struct VS_Output
|
|
{
|
|
float4 WorldPosition : POSITION;
|
|
float4 WorldNormal : NORMAL;
|
|
float4 VertexColor : COLOR0;
|
|
float2 UV0 : TEXCOORD0;
|
|
float4 VertexPosition : SV_Position;
|
|
};
|
|
|
|
float2 GetUV(uint VertexIdx)
|
|
{
|
|
uint BufferId = PushConstant.VertexDataHandle;
|
|
return VertexDataBuffer[BufferId][VertexIdx].TexCoord0.xy;
|
|
}
|
|
|
|
float4 GetPosition(uint VertexIdx)
|
|
{
|
|
uint BufferId = PushConstant.VertexBufferHandle;
|
|
return float4(VertexBuffer[BufferId][VertexIdx].xyz, 1.0f);
|
|
}
|
|
|
|
float4 GetNormal(uint VertexIdx)
|
|
{
|
|
uint BufferId = PushConstant.VertexDataHandle;
|
|
return VertexDataBuffer[BufferId][VertexIdx].Normal;
|
|
}
|
|
|
|
float4 GetColor(uint VertexIdx)
|
|
{
|
|
uint BufferId = PushConstant.VertexDataHandle;
|
|
return VertexDataBuffer[BufferId][VertexIdx].Color0;
|
|
}
|
|
|
|
float4x4 GetNodeTransform(uint NodeIndex)
|
|
{
|
|
uint BufferId = PushConstant.NodeBufferHandle;
|
|
return NodeBuffer[BufferId][NodeIndex].Transform;
|
|
}
|
|
|
|
float4x4 GetNormalTransform(uint NodeIndex)
|
|
{
|
|
uint BufferId = PushConstant.NodeBufferHandle;
|
|
return NodeBuffer[BufferId][NodeIndex].NormalTransform;
|
|
}
|
|
|
|
VS_Output main(VS_Input StageInput)
|
|
{
|
|
VS_Output Output;
|
|
|
|
float4 GlobalPosition = mul(GetNodeTransform(PushConstant.NodeIdx), GetPosition(StageInput.VertexIndex));
|
|
float4 ClipSpace = mul(Camera.View, GlobalPosition);
|
|
|
|
Output.VertexPosition = mul(Camera.Projection, ClipSpace);
|
|
Output.WorldPosition = GlobalPosition;
|
|
Output.UV0 = GetUV(StageInput.VertexIndex);
|
|
Output.VertexColor = GetColor(StageInput.VertexIndex);
|
|
|
|
Output.WorldNormal = mul(GetNormalTransform(PushConstant.NodeIdx), GetNormal(StageInput.VertexIndex));
|
|
return Output;
|
|
}
|