it works now???

This commit is contained in:
Dynamitos
2023-11-27 21:08:27 +01:00
parent 2ad7eae60b
commit 54e66df4cd
7 changed files with 66 additions and 86 deletions
+9 -6
View File
@@ -51,28 +51,31 @@ struct FragmentParameter
// data retrieved from VertexData
struct VertexAttributes
{
float3 position_MS;
float3 normal_MS;
float3 tangent_MS;
float3 biTangent_MS;
float3 position_WS;
float4 position_CS;
float2 texCoords;
float3 vertexColor;
FragmentParameter getParameter(float4x4 transformMatrix)
{
float4 modelPos = float4(position_MS, 1);
float4 worldPos = mul(transformMatrix, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
float3 tangent_WS = mul(transformMatrix, float4(normalize(tangent_MS), 0)).xyz;
float3 biTangent_WS = mul(transformMatrix, float4(normalize(biTangent_MS), 0)).xyz;
float3 normal_WS = mul(transformMatrix, float4(normalize(normal_MS), 0)).xyz;
// Transforms from world space into tangent space
float3x3 tbn = transpose(float3x3(tangent_WS, biTangent_WS, normal_WS));
FragmentParameter result;
result.position_TS = mul(tbn, position_WS);
result.viewDir_TS = mul(tbn, pViewParams.cameraPos_WS.xyz - position_WS);
result.position_TS = mul(tbn, worldPos.xyz);
result.viewDir_TS = mul(tbn, pViewParams.cameraPos_WS.xyz - worldPos.xyz);
result.normal_WS = normal_WS;
result.tangent_WS = tangent_WS;
result.biTangent_WS = biTangent_WS;
result.position_WS = position_WS;
result.position_CS = position_CS;
result.position_WS = worldPos.xyz;
result.position_CS = clipPos;
result.texCoords = texCoords;
result.vertexColor = vertexColor;
return result;
+2 -7
View File
@@ -4,18 +4,13 @@ import MaterialParameter;
struct StaticMeshVertexData : IVertexData
{
VertexAttributes getAttributes(uint index, float4x4 transform)
VertexAttributes getAttributes(uint index)
{
VertexAttributes attributes;
float4 modelPos = float4(positions[3 * index + 0], positions[3 * index + 1], positions[3 * index + 2], 1);
float4 worldPos = mul(transform, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
attributes.position_MS = float3(positions[3 * index + 0], positions[3 * index + 1], positions[3 * index + 2]);
attributes.normal_MS = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
attributes.tangent_MS = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
attributes.biTangent_MS = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
attributes.position_WS = worldPos.xyz;
attributes.position_CS = clipPos;
attributes.texCoords = float2(texCoords[2 * index + 0], texCoords[2 * index + 1]);
attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
return attributes;
+1 -1
View File
@@ -2,7 +2,7 @@ import MaterialParameter;
interface IVertexData
{
VertexAttributes getAttributes(uint index, float4x4 transform);
VertexAttributes getAttributes(uint index);
};
layout(set = 1)
ParameterBlock<IVertexData> pVertexData;