Allowed PostProcessUtility.FinalizeHDR to select a color curve.

This commit is contained in:
Nineto Nine 2021-09-27 17:48:17 +02:00
parent 17cbebcf6a
commit 443877019b
4 changed files with 41 additions and 10 deletions

View file

@ -4,18 +4,33 @@ using OpenTK.Graphics.OpenGL4;
using SM.Base.PostProcess; using SM.Base.PostProcess;
using SM.Base.Utility; using SM.Base.Utility;
using SM.OGL.Framebuffer; using SM.OGL.Framebuffer;
using SM.OGL.Shaders;
using System.Collections.Generic;
#endregion #endregion
namespace SM.Base.PostEffects namespace SM.Base.PostEffects
{ {
public enum HDRColorCurve
{
OnlyExposure,
Reinhard,
ACES
}
/// <summary> /// <summary>
/// This class has some utility for render pipelines /// This class has some utility for render pipelines
/// </summary> /// </summary>
public static class PostProcessUtility public static class PostProcessUtility
{ {
private static readonly PostProcessShader _hdrExposureShader = private static readonly string _finalizeHdrCode = AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl");
new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl"));
private static readonly Dictionary<HDRColorCurve, PostProcessShader> _hdrExposureShader = new Dictionary<HDRColorCurve, PostProcessShader>()
{
{ HDRColorCurve.OnlyExposure, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { StringOverrides = { { "TYPE", "0" } } }) },
{ HDRColorCurve.Reinhard, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { StringOverrides = { { "TYPE", "1" } } }) },
{ HDRColorCurve.ACES, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { StringOverrides = { { "TYPE", "2" } } }) },
};
private static readonly PostProcessShader _gammaShader = private static readonly PostProcessShader _gammaShader =
new PostProcessShader( new PostProcessShader(
@ -48,9 +63,9 @@ namespace SM.Base.PostEffects
/// </summary> /// </summary>
/// <param name="attachment"></param> /// <param name="attachment"></param>
/// <param name="exposure"></param> /// <param name="exposure"></param>
public static void FinalizeHDR(ColorAttachment attachment, float exposure) public static void FinalizeHDR(ColorAttachment attachment, HDRColorCurve colorCurve = HDRColorCurve.ACES, float exposure = 1)
{ {
_hdrExposureShader.Draw(u => _hdrExposureShader[colorCurve].Draw(u =>
{ {
u["Gamma"].SetFloat(Gamma); u["Gamma"].SetFloat(Gamma);
u["Exposure"].SetFloat(exposure); u["Exposure"].SetFloat(exposure);

View file

@ -1,4 +1,5 @@
#version 330 #version 330
#define TYPE //!TYPE
in vec2 vTexture; in vec2 vTexture;
@ -29,7 +30,12 @@ vec3 exposure(vec3 scene) {
void main() { void main() {
vec3 scene = texture2D(Scene, vTexture).rgb; vec3 scene = texture2D(Scene, vTexture).rgb;
vec3 result = reinhardTone(scene); vec3 result = exposure(scene);
#if (TYPE == 1)
result = reinhardTone(result);
#elif (TYPE == 2)
result = ACES(result);
#endif
color = vec4(pow(result, vec3(1 / Gamma)), 1); color = vec4(pow(result, vec3(1 / Gamma)), 1);
} }

View file

@ -43,8 +43,13 @@ namespace SM.Base.PostProcess
/// <summary> /// <summary>
/// Creates the shader with the default vertex shader and custom fragment. /// Creates the shader with the default vertex shader and custom fragment.
/// </summary> /// </summary>
public PostProcessShader(string fragment) : this(_normalVertex, public PostProcessShader(string fragment) : this(_normalVertex, new ShaderFile(fragment))
new ShaderFile(fragment)) {
}
/// <summary>
/// Creates the shader with the default vertex shader and custom fragment shader.
/// </summary>
public PostProcessShader(ShaderFile fragment) : this(_normalVertex, fragment)
{ {
} }
@ -60,7 +65,7 @@ namespace SM.Base.PostProcess
{ {
} }
/// <summary> /// <summary>
/// Creates the shader with an vertex extension and custom fragment. /// Creates the shader with an vertex shader and custom fragment.
/// </summary> /// </summary>
/// <param name="vertex"></param> /// <param name="vertex"></param>
/// <param name="fragment"></param> /// <param name="fragment"></param>
@ -68,7 +73,12 @@ namespace SM.Base.PostProcess
{ {
} }
private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( /// <summary>
/// Creates the shader with an vertex shader and custom fragment.
/// </summary>
/// <param name="vertex"></param>
/// <param name="fragment"></param>
public PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base(
new ShaderFileCollection(vertex, fragment)) new ShaderFileCollection(vertex, fragment))
{ {
fragment.GLSLExtensions.Add(_fragExtensions); fragment.GLSLExtensions.Add(_fragExtensions);

View file

@ -58,7 +58,7 @@ namespace SM_TEST
_bloom.Draw(_postBuffer["color"], context); _bloom.Draw(_postBuffer["color"], context);
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
PostProcessUtility.FinalizeHDR(_postBuffer["color"], 1f); PostProcessUtility.FinalizeHDR(_postBuffer["color"], HDRColorCurve.OnlyExposure, .1f);
} }
} }
} }