27 Sep 2021
+ Added Amount Map to the new Bloom system. ~ Moved all projects to .NetFramework 4.5.2 ~ Made sure, you can't get a higher multisampling as 8.
This commit is contained in:
parent
2c0517ca48
commit
17cbebcf6a
15 changed files with 125 additions and 21 deletions
|
|
@ -1,7 +1,9 @@
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.PostProcess;
|
||||
using SM.Base.Types;
|
||||
using SM.Base.Utility;
|
||||
using SM.Base.Window;
|
||||
using SM.OGL.Framebuffer;
|
||||
|
|
@ -33,6 +35,7 @@ namespace SM.Base.PostEffects
|
|||
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.upsample.frag")
|
||||
);
|
||||
private static readonly PostProcessShader _combineShader = new PostProcessShader(
|
||||
new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.vert")),
|
||||
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.frag")
|
||||
);
|
||||
|
||||
|
|
@ -76,6 +79,21 @@ namespace SM.Base.PostEffects
|
|||
/// </summary>
|
||||
public Color4 Color = Color4.White;
|
||||
|
||||
/// <summary>
|
||||
/// An amount map specifices where the bloom effect should be visible.
|
||||
/// <para>Reads only in the "R"-channel.</para>
|
||||
/// </summary>
|
||||
public TextureBase AmountMap;
|
||||
/// <summary>
|
||||
/// Allows you to transform the texture coordnates for <see cref="AmountMap"/>
|
||||
/// </summary>
|
||||
public TextureTransformation AmountMapTransform = new TextureTransformation();
|
||||
/// <summary>
|
||||
/// Specifices limits, how the <see cref="AmountMap"/> is read.
|
||||
/// <para>Default: <see cref="MinMax.Default"/></para>
|
||||
/// </summary>
|
||||
public MinMax AmountLimits = MinMax.Default;
|
||||
|
||||
/// <summary>
|
||||
/// This creates a more prettier bloom effect.
|
||||
/// </summary>
|
||||
|
|
@ -193,6 +211,14 @@ namespace SM.Base.PostEffects
|
|||
a["scene"].SetTexture(_downsampler[0]["1"]);
|
||||
a["bloomColor"].SetColor(_bloomColor);
|
||||
|
||||
if (AmountMap != null)
|
||||
{
|
||||
a["amountTransform"].SetMatrix3(AmountMapTransform.GetMatrix());
|
||||
a["amountMap"].SetTexture(AmountMap, a["hasAmountMap"]);
|
||||
a["amountLimit"].SetVector2((Vector2)AmountLimits);
|
||||
|
||||
}
|
||||
|
||||
a["HDR"].SetBool(_hdr);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace SM.Base.PostEffects
|
|||
target.Activate(FramebufferTarget.DrawFramebuffer);
|
||||
GL.BlitFramebuffer(0, 0, (int) multisampledBuffers.Size.X, (int) multisampledBuffers.Size.Y, 0, 0,
|
||||
(int) target.Size.X, (int) target.Size.Y, ClearBufferMask.ColorBufferBit,
|
||||
BlitFramebufferFilter.Nearest);
|
||||
BlitFramebufferFilter.Linear);
|
||||
|
||||
target.Activate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
#version 330 core
|
||||
|
||||
in vec2 vTexture;
|
||||
in vec2 amountUV;
|
||||
|
||||
uniform sampler2D scene;
|
||||
uniform vec4 bloomColor;
|
||||
uniform bool HDR;
|
||||
|
||||
uniform bool hasAmountMap;
|
||||
uniform sampler2D amountMap;
|
||||
uniform vec2 amountLimit;
|
||||
|
||||
vec3 safe_color(vec3 c) {
|
||||
return clamp(c, vec3(0.0), vec3(1e20));
|
||||
}
|
||||
|
|
@ -23,6 +28,10 @@ void main() {
|
|||
vec3 scene = safe_color(texture2D(scene, vTexture).rgb);
|
||||
vec3 blur = upsample_filter_high() * bloomColor.rgb;
|
||||
|
||||
if (hasAmountMap) {
|
||||
blur *= clamp(texture2D(amountMap, amountUV).r * (amountLimit.y - amountLimit.x) + amountLimit.x, 0, 1);
|
||||
}
|
||||
|
||||
if (HDR) {
|
||||
color = vec4(scene + blur, 1);
|
||||
return;
|
||||
|
|
|
|||
17
src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert
Normal file
17
src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#version 330
|
||||
|
||||
layout(location = 0) in vec3 aPos;
|
||||
layout(location = 1) in vec2 aTex;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat3 amountTransform;
|
||||
|
||||
out vec2 vTexture;
|
||||
out vec2 amountUV;
|
||||
|
||||
void main() {
|
||||
vTexture = aTex;
|
||||
amountUV = vec2(amountTransform * vec3(aTex, 1));
|
||||
|
||||
gl_Position = MVP * vec4(aPos, 1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue