Graphics: Add gamma correction
This commit is contained in:
committed by
Jérôme Leclercq
parent
041be74b9d
commit
d40b8af68d
@@ -0,0 +1,36 @@
|
||||
[nzsl_version("1.0")]
|
||||
module Math.Color;
|
||||
|
||||
// from https://en.wikipedia.org/wiki/SRGB
|
||||
|
||||
option ApproximatesRGB: bool = false;
|
||||
|
||||
[export]
|
||||
fn LinearTosRGB(color: vec3[f32]) -> vec3[f32]
|
||||
{
|
||||
const if (!ApproximatesRGB)
|
||||
{
|
||||
return select(
|
||||
color > (0.0031308).rrr,
|
||||
1.055 * pow(color, (1.0 / 2.4).rrr) - (0.055).rrr,
|
||||
12.92 * color
|
||||
);
|
||||
}
|
||||
else
|
||||
return pow(color, (1.0 / 2.2).rrr);
|
||||
}
|
||||
|
||||
[export]
|
||||
fn sRGBToLinear(color: vec3[f32]) -> vec3[f32]
|
||||
{
|
||||
const if (!ApproximatesRGB)
|
||||
{
|
||||
return select(
|
||||
color > (0.04045).rrr,
|
||||
pow((color + (0.055).rrr) / 1.055, (2.4).rrr),
|
||||
color / 12.92
|
||||
);
|
||||
}
|
||||
else
|
||||
return pow(color, (2.2).rrr);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
[nzsl_version("1.0")]
|
||||
module PostProcess.GammaCorrection;
|
||||
|
||||
import VertOut, VertexShader from Engine.FullscreenVertex;
|
||||
import LinearTosRGB from Math.Color;
|
||||
|
||||
external
|
||||
{
|
||||
[binding(0)] colorTexture: sampler2D[f32]
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
fn main(input: VertOut) -> FragOut
|
||||
{
|
||||
let color = colorTexture.Sample(input.uv);
|
||||
color.rgb = LinearTosRGB(color.rgb);
|
||||
|
||||
let output: FragOut;
|
||||
output.color = color;
|
||||
return output;
|
||||
}
|
||||
Reference in New Issue
Block a user