WIP shadowmapping

This commit is contained in:
Lauri Räsänen 2023-01-29 18:57:29 +02:00
parent 2fdae1a23a
commit ac67a3d4de
9 changed files with 270 additions and 122 deletions

View file

@ -1,50 +1,9 @@
#include constants.wgsl
#include globals.wgsl
#include brdf.wgsl
// Vertex shader
struct CameraUniform {
view: mat4x4<f32>,
proj: mat4x4<f32>,
position: vec4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: CameraUniform;
struct Light {
position: vec3<f32>,
color: vec4<f32>,
}
@group(2) @binding(0)
var<uniform> light: Light;
struct VertexInput {
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
@location(2) normal: vec3<f32>,
@location(3) tangent: vec3<f32>,
@location(4) bitangent: vec3<f32>,
}
struct InstanceInput {
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
@location(9) normal_matrix_0: vec3<f32>,
@location(10) normal_matrix_1: vec3<f32>,
@location(11) normal_matrix_2: vec3<f32>,
}
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
@location(1) tangent_position: vec3<f32>,
@location(2) tangent_light_position: vec3<f32>,
@location(3) tangent_view_position: vec3<f32>,
@location(4) world_position: vec3<f32>,
}
@vertex
fn vs_main(
model: VertexInput,
@ -81,25 +40,26 @@ fn vs_main(
out.tangent_view_position = tangent_matrix * camera.position.xyz;
out.world_position = world_position.xyz;
out.light_local_position = camera.proj * camera.view * world_position;
return out;
}
// Fragment shader
@group(0) @binding(0)
@group(2) @binding(0)
var t_diffuse: texture_2d<f32>;
@group(0)@binding(1)
@group(2)@binding(1)
var s_diffuse: sampler;
@group(0)@binding(2)
@group(2)@binding(2)
var t_normal: texture_2d<f32>;
@group(0) @binding(3)
@group(2) @binding(3)
var s_normal: sampler;
@group(0)@binding(4)
@group(2)@binding(4)
var t_roughness_metalness: texture_2d<f32>;
@group(0) @binding(5)
@group(2) @binding(5)
var s_roughness_metalness: sampler;
@fragment
@ -109,7 +69,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords);
let object_roughness_metalness: vec4<f32> = textureSample(
t_roughness_metalness, s_roughness_metalness, in.tex_coords);
// TODO: AO
//let light_depth = textureSampleCompareLevel(t_light_depth, s_light_depth, in.light_local_position.xy, 1.0);
let albedo = object_color.xyz;
// TODO: pass factors to shader