68 lines
1.7 KiB
HLSL
68 lines
1.7 KiB
HLSL
#include "bindless_structs.hlsli"
|
|
|
|
struct VS_Input
|
|
{
|
|
uint vertexIndex : SV_VertexID;
|
|
};
|
|
|
|
struct VS_Output
|
|
{
|
|
float4 worldPosition : POSITION;
|
|
float4 worldNormal : NORMAL;
|
|
float4 outColor : COLOR0;
|
|
float2 outUV : TEXCOORD0;
|
|
float4 screenPosition : SV_Position;
|
|
};
|
|
|
|
float2 GetUV(uint vertexIdx)
|
|
{
|
|
uint bufferId = pcb.vertexDataHandle;
|
|
return vertexDataBuffer[bufferId][vertexIdx].m_TexCoord0.xy;
|
|
}
|
|
|
|
float4 GetPosition(uint vertexIdx)
|
|
{
|
|
uint bufferId = pcb.vertexBufferHandle;
|
|
return float4(vertexBuffer[bufferId][vertexIdx].xyz, 1.0f);
|
|
}
|
|
|
|
float4 GetNormal(uint vertexIdx)
|
|
{
|
|
uint bufferId = pcb.vertexDataHandle;
|
|
return vertexDataBuffer[bufferId][vertexIdx].m_Normal;
|
|
}
|
|
|
|
float4 GetColor(uint vertexIdx)
|
|
{
|
|
uint bufferId = pcb.vertexDataHandle;
|
|
return vertexDataBuffer[bufferId][vertexIdx].m_Color0;
|
|
}
|
|
|
|
float4x4 GetModelTransform(uint index)
|
|
{
|
|
uint bufferId = pcb.nodeBufferHandle;
|
|
return nodeBuffer[bufferId][index].transform;
|
|
}
|
|
|
|
float4x4 GetNormalTransform(uint index)
|
|
{
|
|
uint bufferId = pcb.nodeBufferHandle;
|
|
return nodeBuffer[bufferId][index].normalTransform;
|
|
}
|
|
|
|
VS_Output main(VS_Input stage_input)
|
|
{
|
|
VS_Output output;
|
|
|
|
float4 globalPosition = mul(GetModelTransform(pcb.m_NodeIdx), GetPosition(stage_input.vertexIndex));
|
|
float4 clipSpace = mul(camera.view, globalPosition);
|
|
|
|
output.screenPosition = mul(camera.proj, clipSpace);
|
|
output.worldPosition = globalPosition;
|
|
output.outUV = GetUV(stage_input.vertexIndex);
|
|
output.outColor = GetColor(stage_input.vertexIndex);
|
|
|
|
output.worldNormal = mul(GetNormalTransform(pcb.m_NodeIdx), GetNormal(stage_input.vertexIndex));
|
|
return output;
|
|
}
|