Files
Seele/res/shaders/lib/StaticMeshVertexData.slang
T

58 lines
1.3 KiB
Plaintext
Raw Normal View History

2023-10-07 19:29:53 +02:00
import VertexData;
import Common;
import Scene;
struct StaticMeshVertexAttributes : VertexAttributes
{
2023-10-09 17:20:30 +02:00
float4 clipPosition: SV_Position;
float3 worldPosition: POSITION0;
2023-10-07 19:29:53 +02:00
float2 texCoords: TEXCOORD0;
float3 normal: NORMAL0;
2023-10-09 17:20:30 +02:00
float3 tangent: TANGENT0;
float3 biTangent: BITANGENT0;
float3 getWorldPosition()
2023-10-07 19:29:53 +02:00
{
2023-10-09 17:20:30 +02:00
return worldPosition;
2023-10-07 19:29:53 +02:00
}
2023-10-09 17:20:30 +02:00
float2 getTexCoords()
2023-10-07 19:29:53 +02:00
{
return texCoords;
}
float3 getNormal()
{
return normal;
}
2023-10-09 17:20:30 +02:00
float3 getTangent()
{
return tangent;
}
float3 getBiTangent()
{
return biTangent;
}
2023-10-07 19:29:53 +02:00
}
struct StaticMeshVertexData : VertexData
{
StaticMeshVertexAttributes getAttributes(uint index, InstanceData inst)
{
StaticMeshVertexAttributes attr;
2023-10-09 17:20:30 +02:00
float4 localPos = float4(positions[index], 1);
float4 worldPos = mul(inst.transformMatrix, localPos);
2023-10-07 19:29:53 +02:00
float4 viewPos = mul(viewParams.viewMatrix, worldPos);
float4 clipPos = mul(viewParams.projectionMatrix, viewPos);
2023-10-09 17:20:30 +02:00
attr.clipPosition = clipPos;
attr.worldPosition = worldPos.xyz;
2023-10-07 19:29:53 +02:00
attr.texCoords = texCoords[index];
attr.normal = normals[index];
2023-10-09 17:20:30 +02:00
attr.tangent = tangents[index];
attr.biTangent = biTangents[index];
2023-10-07 19:29:53 +02:00
return attr;
}
2023-10-09 17:20:30 +02:00
StructuredBuffer<float3> positions;
2023-10-07 19:29:53 +02:00
StructuredBuffer<float2> texCoords;
StructuredBuffer<float3> normals;
2023-10-09 17:20:30 +02:00
StructuredBuffer<float3> tangents;
StructuredBuffer<float3> biTangents;
2023-10-07 19:29:53 +02:00
}
ParameterBlock<StaticMeshVertexData> vertexData;