Composit Target and gamma correct rendering

This commit is contained in:
Simon Lübeß
2022-05-31 22:41:20 +02:00
parent 8db2ce1d05
commit e41645e12a
18 changed files with 750 additions and 30 deletions
+60
View File
@@ -0,0 +1,60 @@
using System;
using internal GlitchyEngine.Math;
namespace GlitchyEngine.Math
{
/// Represents an RGB color.
[CRepr]
public struct ColorRGB
{
/**
* A value representing the color of the red component.
* The range of this value is between 0 and 1.
*/
public float R;
/**
* A value representing the color of the green component.
* The range of this value is between 0 and 1.
*/
public float G;
/**
* A value representing the color of the blue component.
* The range of this value is between 0 and 1.
*/
public float B;
public this()
{
this = default;
}
public this(float red, float green, float blue)
{
R = red;
G = green;
B = blue;
}
public this(ColorRGBA color)
{
R = color.R;
G = color.G;
B = color.B;
}
// Converts a Color from sRGB color space to Linear color space.
public static ColorRGB SRgbToLinear(ColorRGB sRGB) => ColorRGB(Math.Pow(sRGB.R, srgbToLin), Math.Pow(sRGB.G, srgbToLin), Math.Pow(sRGB.B, srgbToLin));
// Converts a Color from linear color space to sRGB color space.
public static ColorRGB LinearToSRGB(ColorRGB linear) => ColorRGB(Math.Pow(linear.R, linToSRGB), Math.Pow(linear.G, linToSRGB), Math.Pow(linear.B, linToSRGB));
[Inline]
#unwarn
public static explicit operator Vector3(ColorRGB color) => *(Vector3*)&color;
[Inline]
#unwarn
public static explicit operator ColorRGB(Vector3 color) => *(ColorRGB*)&color;
}
}