2022-01-21 22:38:16 +00:00
|
|
|
struct VertexInput {
|
|
|
|
@location(0)
|
2022-03-28 14:31:22 +00:00
|
|
|
position : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(1)
|
2022-03-28 14:31:22 +00:00
|
|
|
normal : vec3<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(2)
|
2022-03-28 14:31:22 +00:00
|
|
|
tangent : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(3)
|
2022-03-28 14:31:22 +00:00
|
|
|
texcoord : vec2<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(6)
|
2022-03-28 14:31:22 +00:00
|
|
|
joints : vec4<u32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(7)
|
2022-03-28 14:31:22 +00:00
|
|
|
weights : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(8)
|
2022-03-28 14:31:22 +00:00
|
|
|
instance0 : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(9)
|
2022-03-28 14:31:22 +00:00
|
|
|
instance1 : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(10)
|
2022-03-28 14:31:22 +00:00
|
|
|
instance2 : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(11)
|
2022-03-28 14:31:22 +00:00
|
|
|
instance3 : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(12)
|
2022-03-28 14:31:22 +00:00
|
|
|
instanceColor : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct VertexOutput {
|
|
|
|
@builtin(position)
|
2022-03-28 14:31:22 +00:00
|
|
|
position : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(0)
|
2022-03-28 14:31:22 +00:00
|
|
|
worldPos : vec3<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(1)
|
2022-03-28 14:31:22 +00:00
|
|
|
view : vec3<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(2)
|
2022-03-28 14:31:22 +00:00
|
|
|
texcoord : vec2<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(3)
|
2022-03-28 14:31:22 +00:00
|
|
|
texcoord2 : vec2<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(4)
|
2022-03-28 14:31:22 +00:00
|
|
|
color : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(5)
|
2022-03-28 14:31:22 +00:00
|
|
|
instanceColor : vec4<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(6)
|
2022-03-28 14:31:22 +00:00
|
|
|
normal : vec3<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(7)
|
2022-03-28 14:31:22 +00:00
|
|
|
tangent : vec3<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
@location(8)
|
2022-03-28 14:31:22 +00:00
|
|
|
bitangent : vec3<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Camera {
|
2022-03-28 14:31:22 +00:00
|
|
|
projection : mat4x4<f32>,
|
|
|
|
inverseProjection : mat4x4<f32>,
|
|
|
|
view : mat4x4<f32>,
|
|
|
|
position : vec3<f32>,
|
|
|
|
time : f32,
|
|
|
|
outputSize : vec2<f32>,
|
|
|
|
zNear : f32,
|
|
|
|
zFar : f32,
|
2022-01-21 22:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@binding(0) @group(0) var<uniform> camera : Camera;
|
|
|
|
|
|
|
|
fn getInstanceMatrix(input : VertexInput) -> mat4x4<f32> {
|
|
|
|
return mat4x4(input.instance0, input.instance1, input.instance2, input.instance3);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Joints {
|
2022-03-28 14:31:22 +00:00
|
|
|
matrices : array<mat4x4<f32>>,
|
2022-01-21 22:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@binding(1) @group(0) var<storage, read> joint : Joints;
|
|
|
|
|
|
|
|
@binding(2) @group(0) var<storage, read> inverseBind : Joints;
|
|
|
|
|
|
|
|
fn getSkinMatrix(input : VertexInput) -> mat4x4<f32> {
|
|
|
|
let joint0 = (joint.matrices[input.joints.x] * inverseBind.matrices[input.joints.x]);
|
|
|
|
let joint1 = (joint.matrices[input.joints.y] * inverseBind.matrices[input.joints.y]);
|
|
|
|
let joint2 = (joint.matrices[input.joints.z] * inverseBind.matrices[input.joints.z]);
|
|
|
|
let joint3 = (joint.matrices[input.joints.w] * inverseBind.matrices[input.joints.w]);
|
|
|
|
let skinMatrix = ((((joint0 * input.weights.x) + (joint1 * input.weights.y)) + (joint2 * input.weights.z)) + (joint3 * input.weights.w));
|
|
|
|
return skinMatrix;
|
|
|
|
}
|
|
|
|
|
2022-06-07 13:55:34 +00:00
|
|
|
@vertex
|
2022-01-21 22:38:16 +00:00
|
|
|
fn vertexMain(input : VertexInput) -> VertexOutput {
|
|
|
|
var output : VertexOutput;
|
|
|
|
let modelMatrix = getSkinMatrix(input);
|
|
|
|
output.normal = normalize(((modelMatrix * vec4(input.normal, 0.0))).xyz);
|
|
|
|
output.tangent = normalize(((modelMatrix * vec4(input.tangent.xyz, 0.0))).xyz);
|
|
|
|
output.bitangent = (cross(output.normal, output.tangent) * input.tangent.w);
|
|
|
|
output.color = vec4(1.0);
|
|
|
|
output.texcoord = input.texcoord;
|
|
|
|
output.instanceColor = input.instanceColor;
|
|
|
|
let modelPos = (modelMatrix * input.position);
|
|
|
|
output.worldPos = modelPos.xyz;
|
|
|
|
output.view = (camera.position - modelPos.xyz);
|
|
|
|
output.position = ((camera.projection * camera.view) * modelPos);
|
|
|
|
return output;
|
|
|
|
}
|