mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40:14 +00:00
Extends the WMO normal mapping/POM system to character M2 models with bone-skinned tangents. Auto-generates normal/height maps from diffuse textures using luminance→height, Sobel→normals (same algorithm as WMO). - Expand vertex buffer from M2Vertex (48B) to CharVertexGPU (56B) with tangent vec4 computed via Lengyel's method in setupModelBuffers() - Tangents are bone-transformed and Gram-Schmidt orthogonalized in the vertex shader, output as TBN for fragment shader consumption - Fragment shader gains POM ray marching, normal map blending, and LOD crossfade via dFdx/dFdy (identical to WMO shader) - Descriptor set 1 extended with binding 2 for normal/height sampler - Settings (enable, strength, POM quality) wired from game_screen.cpp to both WMO and character renderers via shared UI controls
63 lines
1.7 KiB
GLSL
63 lines
1.7 KiB
GLSL
#version 450
|
|
|
|
layout(set = 0, binding = 0) uniform PerFrame {
|
|
mat4 view;
|
|
mat4 projection;
|
|
mat4 lightSpaceMatrix;
|
|
vec4 lightDir;
|
|
vec4 lightColor;
|
|
vec4 ambientColor;
|
|
vec4 viewPos;
|
|
vec4 fogColor;
|
|
vec4 fogParams;
|
|
vec4 shadowParams;
|
|
};
|
|
|
|
layout(push_constant) uniform Push {
|
|
mat4 model;
|
|
} push;
|
|
|
|
layout(set = 2, binding = 0) readonly buffer BoneSSBO {
|
|
mat4 bones[];
|
|
};
|
|
|
|
layout(location = 0) in vec3 aPos;
|
|
layout(location = 1) in vec4 aBoneWeights;
|
|
layout(location = 2) in ivec4 aBoneIndices;
|
|
layout(location = 3) in vec3 aNormal;
|
|
layout(location = 4) in vec2 aTexCoord;
|
|
layout(location = 5) in vec4 aTangent;
|
|
|
|
layout(location = 0) out vec3 FragPos;
|
|
layout(location = 1) out vec3 Normal;
|
|
layout(location = 2) out vec2 TexCoord;
|
|
layout(location = 3) out vec3 Tangent;
|
|
layout(location = 4) out vec3 Bitangent;
|
|
|
|
void main() {
|
|
mat4 skinMat = bones[aBoneIndices.x] * aBoneWeights.x
|
|
+ bones[aBoneIndices.y] * aBoneWeights.y
|
|
+ bones[aBoneIndices.z] * aBoneWeights.z
|
|
+ bones[aBoneIndices.w] * aBoneWeights.w;
|
|
|
|
vec4 skinnedPos = skinMat * vec4(aPos, 1.0);
|
|
vec3 skinnedNorm = mat3(skinMat) * aNormal;
|
|
vec3 skinnedTan = mat3(skinMat) * aTangent.xyz;
|
|
|
|
vec4 worldPos = push.model * skinnedPos;
|
|
mat3 modelMat3 = mat3(push.model);
|
|
FragPos = worldPos.xyz;
|
|
Normal = modelMat3 * skinnedNorm;
|
|
TexCoord = aTexCoord;
|
|
|
|
// Gram-Schmidt re-orthogonalize tangent w.r.t. normal
|
|
vec3 N = normalize(Normal);
|
|
vec3 T = normalize(modelMat3 * skinnedTan);
|
|
T = normalize(T - dot(T, N) * N);
|
|
vec3 B = cross(N, T) * aTangent.w;
|
|
|
|
Tangent = T;
|
|
Bitangent = B;
|
|
|
|
gl_Position = projection * view * worldPos;
|
|
}
|