Graphics: Add skinning support to DepthMaterial
This commit is contained in:
parent
99c9df5731
commit
a8c54abdd0
|
|
@ -2,13 +2,20 @@
|
||||||
module DepthMaterial;
|
module DepthMaterial;
|
||||||
|
|
||||||
import InstanceData from Engine.InstanceData;
|
import InstanceData from Engine.InstanceData;
|
||||||
|
import SkeletalData from Engine.SkeletalData;
|
||||||
import ViewerData from Engine.ViewerData;
|
import ViewerData from Engine.ViewerData;
|
||||||
|
|
||||||
option HasBaseColorTexture: bool = false;
|
option HasBaseColorTexture: bool = false;
|
||||||
option HasAlphaTexture: bool = false;
|
option HasAlphaTexture: bool = false;
|
||||||
option AlphaTest: bool = false;
|
option AlphaTest: bool = false;
|
||||||
|
|
||||||
|
option PosLocation: i32;
|
||||||
|
option UvLocation: i32 = -1;
|
||||||
|
option JointIndicesLocation: i32 = -1;
|
||||||
|
option JointWeightsLocation: i32 = -1;
|
||||||
|
|
||||||
const HasUV = AlphaTest && (HasBaseColorTexture || HasAlphaTexture);
|
const HasUV = AlphaTest && (HasBaseColorTexture || HasAlphaTexture);
|
||||||
|
const HasSkinning = (JointIndicesLocation >= 0 && JointWeightsLocation >= 0);
|
||||||
|
|
||||||
[layout(std140)]
|
[layout(std140)]
|
||||||
struct BasicSettings
|
struct BasicSettings
|
||||||
|
|
@ -25,6 +32,7 @@ external
|
||||||
[binding(3)] TextureOverlay: sampler2D[f32],
|
[binding(3)] TextureOverlay: sampler2D[f32],
|
||||||
[binding(4)] instanceData: uniform[InstanceData],
|
[binding(4)] instanceData: uniform[InstanceData],
|
||||||
[binding(5)] viewerData: uniform[ViewerData],
|
[binding(5)] viewerData: uniform[ViewerData],
|
||||||
|
[binding(6)] skeletalData: uniform[SkeletalData]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fragment stage
|
// Fragment stage
|
||||||
|
|
@ -58,8 +66,16 @@ fn main() {}
|
||||||
// Vertex stage
|
// Vertex stage
|
||||||
struct VertIn
|
struct VertIn
|
||||||
{
|
{
|
||||||
[location(0)] pos: vec3[f32],
|
[location(PosLocation)] pos: vec3[f32],
|
||||||
[location(1), cond(HasUV)] uv: vec2[f32]
|
|
||||||
|
[cond(HasUV), location(UvLocation)]
|
||||||
|
uv: vec2[f32],
|
||||||
|
|
||||||
|
[cond(HasSkinning), location(JointIndicesLocation)]
|
||||||
|
jointIndices: vec4[i32],
|
||||||
|
|
||||||
|
[cond(HasSkinning), location(JointWeightsLocation)]
|
||||||
|
jointWeights: vec4[f32],
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertOut
|
struct VertOut
|
||||||
|
|
@ -71,7 +87,25 @@ struct VertOut
|
||||||
[entry(vert)]
|
[entry(vert)]
|
||||||
fn main(input: VertIn) -> VertOut
|
fn main(input: VertIn) -> VertOut
|
||||||
{
|
{
|
||||||
let worldPosition = instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
|
let pos: vec3[f32];
|
||||||
|
const if (HasSkinning)
|
||||||
|
{
|
||||||
|
pos = vec3[f32](0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
[unroll]
|
||||||
|
for i in 0 -> 4
|
||||||
|
{
|
||||||
|
let jointIndex = input.jointIndices[i];
|
||||||
|
let jointWeight = input.jointWeights[i];
|
||||||
|
|
||||||
|
let jointMatrix = skeletalData.JointMatrices[jointIndex];
|
||||||
|
pos += (jointMatrix * vec4[f32](input.pos, 1.0)).xyz * jointWeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pos = input.pos;
|
||||||
|
|
||||||
|
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
||||||
|
|
||||||
let output: VertOut;
|
let output: VertOut;
|
||||||
output.position = viewerData.viewProjMatrix * worldPosition;
|
output.position = viewerData.viewProjMatrix * worldPosition;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue