Allowed PostProcessUtility.FinalizeHDR to select a color curve.
This commit is contained in:
parent
17cbebcf6a
commit
443877019b
4 changed files with 41 additions and 10 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class has some utility for render pipelines
|
||||
/// </summary>
|
||||
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<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 =
|
||||
new PostProcessShader(
|
||||
|
|
@ -48,9 +63,9 @@ namespace SM.Base.PostEffects
|
|||
/// </summary>
|
||||
/// <param name="attachment"></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["Exposure"].SetFloat(exposure);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -43,8 +43,13 @@ namespace SM.Base.PostProcess
|
|||
/// <summary>
|
||||
/// Creates the shader with the default vertex shader and custom fragment.
|
||||
/// </summary>
|
||||
public PostProcessShader(string fragment) : this(_normalVertex,
|
||||
new ShaderFile(fragment))
|
||||
public PostProcessShader(string fragment) : this(_normalVertex, 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>
|
||||
/// Creates the shader with an vertex extension and custom fragment.
|
||||
/// Creates the shader with an vertex shader and custom fragment.
|
||||
/// </summary>
|
||||
/// <param name="vertex"></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))
|
||||
{
|
||||
fragment.GLSLExtensions.Add(_fragExtensions);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue