forked from nonsensical-dev/zenyx-engine
42 lines
No EOL
1.1 KiB
WebGPU Shading Language
42 lines
No EOL
1.1 KiB
WebGPU Shading Language
struct CameraUniform {
|
|
view: mat4x4<f32>,
|
|
proj: mat4x4<f32>,
|
|
};
|
|
|
|
struct ModelUniform {
|
|
model: mat4x4<f32>,
|
|
};
|
|
|
|
@group(0) @binding(0)
|
|
var<uniform> camera: CameraUniform;
|
|
|
|
@group(1) @binding(0)
|
|
var<uniform> model: ModelUniform;
|
|
|
|
struct VertexInput {
|
|
@location(0) position: vec3<f32>,
|
|
@location(1) normal: vec3<f32>,
|
|
};
|
|
|
|
struct VertexOutput {
|
|
@builtin(position) clip_position: vec4<f32>,
|
|
@location(0) normal: vec3<f32>,
|
|
};
|
|
|
|
@vertex
|
|
fn vs_main(input: VertexInput) -> VertexOutput {
|
|
var output: VertexOutput;
|
|
let model_pos = model.model * vec4<f32>(input.position, 1.0);
|
|
output.clip_position = camera.proj * camera.view * model_pos;
|
|
output.normal = input.normal;
|
|
return output;
|
|
}
|
|
|
|
@fragment
|
|
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
|
|
let ambient: f32 = 0.2;
|
|
let light_dir = normalize(vec3<f32>(0.5, 1.0, 0.5));
|
|
let diffuse = clamp(dot(normalize(input.normal), light_dir), 0.0, 1.0);
|
|
let brightness = ambient + (1.0 - ambient) * diffuse;
|
|
return vec4<f32>(0.7 * brightness, 0.7 * brightness, 0.9 * brightness, 1.0);
|
|
} |