Graphics: Move skinning to a separate module
This commit is contained in:
@@ -6,6 +6,8 @@ import LightData from Engine.LightData;
|
||||
import SkeletalData from Engine.SkeletalData;
|
||||
import ViewerData from Engine.ViewerData;
|
||||
|
||||
import SkinLinearPosition, SkinLinearPositionNormal from Engine.SkinningLinear;
|
||||
|
||||
// Pass-specific options
|
||||
option DepthPass: bool = false;
|
||||
|
||||
@@ -33,13 +35,16 @@ option VertexPositionLoc: i32;
|
||||
option VertexTangentLoc: i32 = -1;
|
||||
option VertexUvLoc: i32 = -1;
|
||||
|
||||
option VertexJointIndicesLoc: i32 = -1;
|
||||
option VertexJointWeightsLoc: i32 = -1;
|
||||
|
||||
const HasNormal = (VertexNormalLoc >= 0);
|
||||
const HasVertexColor = (VertexColorLoc >= 0);
|
||||
const HasColor = (HasVertexColor || Billboard);
|
||||
const HasTangent = (VertexTangentLoc >= 0);
|
||||
const HasUV = (VertexUvLoc >= 0);
|
||||
const HasNormalMapping = HasNormalTexture && HasNormal && HasTangent && !DepthPass;
|
||||
|
||||
const HasSkinning = (VertexJointIndicesLoc >= 0 && VertexJointWeightsLoc >= 0);
|
||||
|
||||
[layout(std140)]
|
||||
struct MaterialSettings
|
||||
@@ -272,6 +277,12 @@ struct VertIn
|
||||
[cond(HasTangent), location(VertexTangentLoc)]
|
||||
tangent: vec3[f32],
|
||||
|
||||
[cond(HasSkinning), location(VertexJointIndicesLoc)]
|
||||
jointIndices: vec4[i32],
|
||||
|
||||
[cond(HasSkinning), location(VertexJointWeightsLoc)]
|
||||
jointWeights: vec4[f32],
|
||||
|
||||
[cond(Billboard), location(BillboardCenterLocation)]
|
||||
billboardCenter: vec3[f32],
|
||||
|
||||
@@ -316,7 +327,38 @@ fn billboardMain(input: VertIn) -> VertToFrag
|
||||
[entry(vert), cond(!Billboard)]
|
||||
fn main(input: VertIn) -> VertToFrag
|
||||
{
|
||||
let worldPosition = instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
|
||||
let pos: vec3[f32];
|
||||
const if (HasNormal) let normal: vec3[f32];
|
||||
|
||||
const if (HasSkinning)
|
||||
{
|
||||
let jointMatrices = array[mat4[f32]](
|
||||
skeletalData.jointMatrices[input.jointIndices[0]],
|
||||
skeletalData.jointMatrices[input.jointIndices[1]],
|
||||
skeletalData.jointMatrices[input.jointIndices[2]],
|
||||
skeletalData.jointMatrices[input.jointIndices[3]]
|
||||
);
|
||||
|
||||
const if (HasNormal)
|
||||
{
|
||||
let skinningOutput = SkinLinearPositionNormal(jointMatrices, input.jointWeights, input.pos, input.normal);
|
||||
pos = skinningOutput.position;
|
||||
normal = skinningOutput.normal;
|
||||
}
|
||||
else
|
||||
{
|
||||
let skinningOutput = SkinLinearPosition(jointMatrices, input.jointWeights, input.pos);
|
||||
pos = skinningOutput.position;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = input.pos;
|
||||
const if (HasNormal)
|
||||
normal = input.normal;
|
||||
}
|
||||
|
||||
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
||||
|
||||
let output: VertToFrag;
|
||||
output.worldPos = worldPosition.xyz;
|
||||
@@ -328,7 +370,7 @@ fn main(input: VertIn) -> VertToFrag
|
||||
output.color = input.color;
|
||||
|
||||
const if (HasNormal)
|
||||
output.normal = rotationMatrix * input.normal;
|
||||
output.normal = rotationMatrix * normal;
|
||||
|
||||
const if (HasUV)
|
||||
output.uv = input.uv;
|
||||
|
||||
Reference in New Issue
Block a user