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

65 lines
2.1 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
2024-08-26 21:49:09 +02:00
struct StaticMeshVertexData
2023-10-07 19:29:53 +02:00
{
2024-10-01 11:15:38 +02:00
float uint16ToFloat(uint16_t value)
{
return value / 65535.0f;
}
float3 xAxis( float4 qQuat )
{
float fTy = 2.0 * qQuat.y;
float fTz = 2.0 * qQuat.z;
float fTwy = fTy * qQuat.w;
float fTwz = fTz * qQuat.w;
float fTxy = fTy * qQuat.x;
float fTxz = fTz * qQuat.x;
float fTyy = fTy * qQuat.y;
float fTzz = fTz * qQuat.z;
return float3( 1.0-(fTyy+fTzz), fTxy+fTwz, fTxz-fTwy );
}
float3 yAxis( float4 qQuat )
{
float fTx = 2.0 * qQuat.x;
float fTy = 2.0 * qQuat.y;
float fTz = 2.0 * qQuat.z;
float fTwx = fTx * qQuat.w;
float fTwz = fTz * qQuat.w;
float fTxx = fTx * qQuat.x;
float fTxy = fTy * qQuat.x;
float fTyz = fTz * qQuat.y;
float fTzz = fTz * qQuat.z;
return float3( fTxy-fTwz, 1.0-(fTxx+fTzz), fTyz+fTwx );
}
2023-11-27 21:08:27 +01:00
VertexAttributes getAttributes(uint index)
2023-10-07 19:29:53 +02:00
{
2023-11-09 22:15:51 +01:00
VertexAttributes attributes;
2024-10-01 11:15:38 +02:00
attributes.position_MS = float3(positions[index * 3 + 0], positions[index * 3 + 1], positions[index * 3 + 2]);
2024-06-19 10:33:19 +02:00
#ifndef POS_ONLY
2024-10-01 11:15:38 +02:00
float4 qtangent = normalize(qtangents[index]);
attributes.normal_MS = xAxis(qtangent);
attributes.tangent_MS = yAxis(qtangent);
float biNormalReflection = sign(qtangents[index].w);
attributes.biTangent_MS = cross(attributes.normal_MS, attributes.tangent_MS) * biNormalReflection;
2024-05-06 18:36:16 +02:00
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
2024-10-01 11:15:38 +02:00
attributes.texCoords[i] = float2(uint16ToFloat(texCoords[i][index * 2 + 0]), uint16ToFloat(texCoords[i][index * 2 + 1]));
2024-05-06 18:36:16 +02:00
}
2024-10-01 16:56:04 +02:00
attributes.vertexColor = float3(uint16ToFloat(color[index * 3 + 0]), uint16ToFloat(color[index * 3 + 1]) , uint16ToFloat(color[index * 3 + 2]));
2024-06-19 10:33:19 +02:00
#endif
2023-11-09 22:15:51 +01:00
return attributes;
2023-10-07 19:29:53 +02:00
}
2024-10-01 11:15:38 +02:00
StructuredBuffer<float> positions;
StructuredBuffer<float4> qtangents;
StructuredBuffer<uint16_t> color;
StructuredBuffer<uint16_t> texCoords[MAX_TEXCOORDS];
2023-11-08 23:27:21 +01:00
};
2024-08-26 21:49:09 +02:00
layout(set=1)
ParameterBlock<StaticMeshVertexData> pVertexData;