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

51 lines
1.3 KiB
Plaintext
Raw Normal View History

2023-10-07 19:29:53 +02:00
import Common;
2023-11-08 23:27:21 +01:00
import VertexData;
import MaterialParameter;
2023-10-07 19:29:53 +02:00
2023-11-08 23:27:21 +01:00
struct StaticMeshVertexAttributes : IVertexAttributes
2023-10-07 19:29:53 +02:00
{
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;
2023-11-08 23:27:21 +01:00
MaterialParameter create()
2023-10-07 19:29:53 +02:00
{
2023-11-08 23:27:21 +01:00
MaterialParameter result;
result.worldPosition = worldPosition;
result.texCoords = texCoords;
result.normal = normal;
result.tangent = tangent;
result.biTangent = biTangent;
return result;
2023-10-07 19:29:53 +02:00
}
2023-11-08 23:27:21 +01:00
};
struct StaticMeshVertexData : IVertexData
2023-10-07 19:29:53 +02:00
{
2023-11-08 23:27:21 +01:00
typedef StaticMeshVertexAttributes VertexAttributes;
2023-10-24 15:01:09 +02:00
StaticMeshVertexAttributes getAttributes(uint index, float4x4 transform)
2023-10-07 19:29:53 +02:00
{
StaticMeshVertexAttributes attr;
2023-10-09 17:20:30 +02:00
float4 localPos = float4(positions[index], 1);
2023-10-24 15:01:09 +02:00
float4 worldPos = mul(transform, localPos);
2023-11-08 23:27:21 +01:00
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.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-11-08 23:27:21 +01:00
};