tangent interpolation fix

This commit is contained in:
Turánszki János
2023-07-29 08:15:56 +02:00
parent 18d5264129
commit c518e9db4e
4 changed files with 28 additions and 24 deletions
+2 -2
View File
@@ -206,10 +206,10 @@ struct VertexSurface
color *= input.GetVertexColor();
}
normal = normalize(mul((float3x3)input.GetInstance().transformInverseTranspose.GetMatrix(), normal));
normal = mul((float3x3)input.GetInstance().transformInverseTranspose.GetMatrix(), normal);
tangent = input.GetTangent();
tangent.xyz = normalize(mul((float3x3)input.GetInstance().transformInverseTranspose.GetMatrix(), tangent.xyz));
tangent.xyz = mul((float3x3)input.GetInstance().transformInverseTranspose.GetMatrix(), tangent.xyz);
uvsets = input.GetUVSets();
uvsets.xy = mad(uvsets.xy, material.texMulAdd.xy, material.texMulAdd.zw);
+6 -1
View File
@@ -328,6 +328,7 @@ struct Surface
const bool is_hairparticle = geometry.flags & SHADERMESH_FLAG_HAIRPARTICLE;
const bool is_emittedparticle = geometry.flags & SHADERMESH_FLAG_EMITTEDPARTICLE;
const bool simple_lighting = is_hairparticle || is_emittedparticle;
const bool is_backface = flags & SURFACE_FLAG_BACKFACE;
float3 n0 = unpack_unitvector(asuint(data0.w));
float3 n1 = unpack_unitvector(asuint(data1.w));
@@ -335,7 +336,7 @@ struct Surface
N = attribute_at_bary(n0, n1, n2, bary);
N = mul((float3x3)inst.transformInverseTranspose.GetMatrix(), N);
N = normalize(N);
if ((flags & SURFACE_FLAG_BACKFACE) && !is_hairparticle && !is_emittedparticle)
if (is_backface && !is_hairparticle && !is_emittedparticle)
{
N = -N;
}
@@ -393,6 +394,10 @@ struct Surface
const float4 t2 = buf[i2];
T = attribute_at_bary(t0, t1, t2, bary);
T.xyz = mul((float3x3)inst.transformInverseTranspose.GetMatrix(), T.xyz);
if (is_backface)
{
T.xyz = -T.xyz;
}
T.xyz = normalize(T.xyz);
B = normalize(cross(T.xyz, N) * T.w);
const float3x3 TBN = float3x3(T.xyz, B, N);
+19 -20
View File
@@ -497,7 +497,10 @@ namespace wi::scene
struct Vertex_POS
{
XMFLOAT3 pos = XMFLOAT3(0.0f, 0.0f, 0.0f);
uint32_t normal_wind = 0;
uint8_t n_x = 0;
uint8_t n_y = 0;
uint8_t n_z = 0;
uint8_t w = 0;
constexpr void FromFULL(const XMFLOAT3& _pos, const XMFLOAT3& _nor, uint8_t wind)
{
@@ -517,32 +520,28 @@ namespace wi::scene
}
constexpr void MakeFromParams(const XMFLOAT3& normal)
{
normal_wind = normal_wind & 0xFF000000; // reset only the normals
normal_wind |= uint32_t((normal.x * 0.5f + 0.5f) * 255.0f) << 0;
normal_wind |= uint32_t((normal.y * 0.5f + 0.5f) * 255.0f) << 8;
normal_wind |= uint32_t((normal.z * 0.5f + 0.5f) * 255.0f) << 16;
n_x = uint8_t((normal.x * 0.5f + 0.5f) * 255.0f);
n_y = uint8_t((normal.y * 0.5f + 0.5f) * 255.0f);
n_z = uint8_t((normal.z * 0.5f + 0.5f) * 255.0f);
}
constexpr void MakeFromParams(const XMFLOAT3& normal, uint8_t wind)
{
normal_wind = 0;
normal_wind |= uint32_t((normal.x * 0.5f + 0.5f) * 255.0f) << 0;
normal_wind |= uint32_t((normal.y * 0.5f + 0.5f) * 255.0f) << 8;
normal_wind |= uint32_t((normal.z * 0.5f + 0.5f) * 255.0f) << 16;
normal_wind |= uint32_t(wind) << 24;
n_x = uint8_t((normal.x * 0.5f + 0.5f) * 255.0f);
n_y = uint8_t((normal.y * 0.5f + 0.5f) * 255.0f);
n_z = uint8_t((normal.z * 0.5f + 0.5f) * 255.0f);
w = wind;
}
constexpr XMFLOAT3 GetNor_FULL() const
{
XMFLOAT3 nor_FULL(0, 0, 0);
nor_FULL.x = (float((normal_wind >> 0) & 0xFF) / 255.0f) * 2.0f - 1.0f;
nor_FULL.y = (float((normal_wind >> 8) & 0xFF) / 255.0f) * 2.0f - 1.0f;
nor_FULL.z = (float((normal_wind >> 16) & 0xFF) / 255.0f) * 2.0f - 1.0f;
nor_FULL.x = (float(n_x) / 255.0f) * 2.0f - 1.0f;
nor_FULL.y = (float(n_y) / 255.0f) * 2.0f - 1.0f;
nor_FULL.z = (float(n_z) / 255.0f) * 2.0f - 1.0f;
return nor_FULL;
}
constexpr uint8_t GetWind() const
{
return (normal_wind >> 24) & 0xFF;
return w;
}
static constexpr wi::graphics::Format FORMAT = wi::graphics::Format::R32G32B32A32_FLOAT;
@@ -622,10 +621,10 @@ namespace wi::scene
XMStoreFloat4(&t, T);
t.w = tan.w;
x = int8_t(t.x * 127.0f);
y = int8_t(t.y * 127.0f);
z = int8_t(t.z * 127.0f);
w = int8_t(t.w * 127.0f);
x = int8_t(t.x * 127.5f);
y = int8_t(t.y * 127.5f);
z = int8_t(t.z * 127.5f);
w = int8_t(t.w * 127.5f);
}
static constexpr wi::graphics::Format FORMAT = wi::graphics::Format::R8G8B8A8_SNORM;
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 262;
const int revision = 263;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);