diff --git a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs index 1665148..67431d9 100644 --- a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs +++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs @@ -4,18 +4,33 @@ using OpenTK.Graphics.OpenGL4; using SM.Base.PostProcess; using SM.Base.Utility; using SM.OGL.Framebuffer; +using SM.OGL.Shaders; +using System.Collections.Generic; #endregion namespace SM.Base.PostEffects { + public enum HDRColorCurve + { + OnlyExposure, + Reinhard, + ACES + } + /// /// This class has some utility for render pipelines /// public static class PostProcessUtility { - private static readonly PostProcessShader _hdrExposureShader = - new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl")); + private static readonly string _finalizeHdrCode = AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl"); + + private static readonly Dictionary _hdrExposureShader = new Dictionary() + { + { 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 = new PostProcessShader( @@ -48,9 +63,9 @@ namespace SM.Base.PostEffects /// /// /// - 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["Exposure"].SetFloat(exposure); diff --git a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl index 696e186..bf754bb 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl +++ b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl @@ -1,4 +1,5 @@ #version 330 +#define TYPE //!TYPE in vec2 vTexture; @@ -29,7 +30,12 @@ vec3 exposure(vec3 scene) { void main() { 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); } \ No newline at end of file diff --git a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs index e2477b8..1ef0498 100644 --- a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs +++ b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs @@ -43,8 +43,13 @@ namespace SM.Base.PostProcess /// /// Creates the shader with the default vertex shader and custom fragment. /// - public PostProcessShader(string fragment) : this(_normalVertex, - new ShaderFile(fragment)) + public PostProcessShader(string fragment) : this(_normalVertex, new ShaderFile(fragment)) + { + } + /// + /// Creates the shader with the default vertex shader and custom fragment shader. + /// + public PostProcessShader(ShaderFile fragment) : this(_normalVertex, fragment) { } @@ -60,7 +65,7 @@ namespace SM.Base.PostProcess { } /// - /// Creates the shader with an vertex extension and custom fragment. + /// Creates the shader with an vertex shader and custom fragment. /// /// /// @@ -68,7 +73,12 @@ namespace SM.Base.PostProcess { } - private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( + /// + /// Creates the shader with an vertex shader and custom fragment. + /// + /// + /// + public PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( new ShaderFileCollection(vertex, fragment)) { fragment.GLSLExtensions.Add(_fragExtensions); diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs index 04ba92f..1c8368a 100644 --- a/tests/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -58,7 +58,7 @@ namespace SM_TEST _bloom.Draw(_postBuffer["color"], context); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - PostProcessUtility.FinalizeHDR(_postBuffer["color"], 1f); + PostProcessUtility.FinalizeHDR(_postBuffer["color"], HDRColorCurve.OnlyExposure, .1f); } } } \ No newline at end of file