37 lines
842 B
WebGPU Shading Language
37 lines
842 B
WebGPU Shading Language
struct Params {
|
|
divisor: f32,
|
|
}
|
|
|
|
struct Vertex {
|
|
@location(0) screen: vec2f,
|
|
}
|
|
|
|
struct Varying {
|
|
@location(0) tex: vec2f,
|
|
@builtin(position) v: vec4f,
|
|
}
|
|
|
|
@group(0) @binding(0) var smp: sampler;
|
|
@group(0) @binding(1) var tex: texture_2d<f32>;
|
|
@group(0) @binding(2) var<uniform> params: Params;
|
|
|
|
@vertex
|
|
fn on_vertex(in: Vertex) -> Varying {
|
|
let uv = in.screen;
|
|
let xy = vec2(2. * uv.x - 1., 1. - 2. * uv.y);
|
|
return Varying(uv, vec4(xy, 0., 1.));
|
|
}
|
|
|
|
@fragment
|
|
fn on_fragment(in: Varying) -> @location(0) vec4f {
|
|
let pixel = textureSample(tex, smp, in.tex) / params.divisor;
|
|
return vec4(rational_tone_map(pixel.xyz), 1.0);
|
|
}
|
|
|
|
fn rational_tone_map(hdr: vec3<f32>) -> vec3<f32> {
|
|
let luminosity = dot(hdr, vec3(0.2126, 0.7152, 0.0722));
|
|
let color = hdr / luminosity;
|
|
let luma = luminosity / (luminosity + 1.0);
|
|
return luma * color;
|
|
}
|