1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
}
struct FragmentOutput {
@location(0) color: vec4<f32>,
}
struct Camera {
view_proj: mat4x4<f32>,
position: vec3<f32>,
}
@group(0) @binding(0) var<uniform> camera: Camera;
struct Lighting {
direction: vec3<f32>,
color: vec3<f32>,
intensity: f32,
}
@group(0) @binding(1) var<uniform> lighting: Lighting;
@group(1) @binding(0) var diffuse_tex_tex: texture_2d<f32>;
@group(1) @binding(1) var diffuse_tex_samp: sampler;
@group(1) @binding(2) var normal_tex_tex: texture_2d<f32>;
@group(1) @binding(3) var normal_tex_samp: sampler;
@fragment
fn fs_main(input: VertexOutput) -> FragmentOutput {
var __luma_output: FragmentOutput;
let diffuse = textureSample(diffuse_tex_tex, diffuse_tex_samp, input.uv);
let normal_sample = textureSample(normal_tex_tex, normal_tex_samp, input.uv);
let n = normalize(((normal_sample.xyz * 2.0) - vec3<f32>(1.0, 1.0, 1.0)));
let l = normalize(lighting.direction);
let ndotl = max(dot(n, l), 0.0);
let lit = (((diffuse.rgb * lighting.color) * ndotl) * lighting.intensity);
__luma_output.color = vec4<f32>(lit, diffuse.a);
return __luma_output;
}