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
|
|
@ -9,7 +9,7 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM.Intergrations</RootNamespace>
|
||||
<AssemblyName>SM.Intergrations</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM.Utils</RootNamespace>
|
||||
<AssemblyName>SM.Utils</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ out vec2 TransformedTexture;
|
|||
|
||||
void main() {
|
||||
vTexture = aTex;
|
||||
//TransformedTexture = vec2(TextureTransform * vec3(aTex, 1));
|
||||
TransformedTexture = vec2(TextureTransform * vec3(aTex, 1));
|
||||
|
||||
gl_Position = MVP * vec4(aPos, 1);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM.Base</RootNamespace>
|
||||
<AssemblyName>SM.Base</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
|
|
@ -62,6 +62,7 @@
|
|||
<Compile Include="Shaders\SimpleShader.cs" />
|
||||
<Compile Include="Types\CVector4.cs" />
|
||||
<Compile Include="Types\CVectorBase.cs" />
|
||||
<Compile Include="Types\MinMax.cs" />
|
||||
<Compile Include="Utility\IInitializable.cs" />
|
||||
<Compile Include="Utility\MathUtils.cs" />
|
||||
<Compile Include="Utility\Ray.cs" />
|
||||
|
|
@ -168,6 +169,7 @@
|
|||
<EmbeddedResource Include="PostEffects\Shaders\bloom\upsample.frag" />
|
||||
<EmbeddedResource Include="PostEffects\Shaders\bloom\combine.frag" />
|
||||
<EmbeddedResource Include="PostEffects\Shaders\bloom\sampling.frag" />
|
||||
<EmbeddedResource Include="PostEffects\Shaders\bloom\combine.vert" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
|
|
|||
53
src/renderer/SM.Base/Types/MinMax.cs
Normal file
53
src/renderer/SM.Base/Types/MinMax.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using OpenTK;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Structure to store Min and Max-values.
|
||||
/// </summary>
|
||||
public struct MinMax
|
||||
{
|
||||
/// <summary>
|
||||
/// Default Value: 0..1
|
||||
/// </summary>
|
||||
public static readonly MinMax Default = new MinMax(0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Minimum Value
|
||||
/// </summary>
|
||||
public float Min;
|
||||
/// <summary>
|
||||
/// Maximum Value
|
||||
/// </summary>
|
||||
public float Max;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a MinMax-structure with two values.
|
||||
/// </summary>
|
||||
public MinMax(float min, float max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a value that is between <see cref="Min"/> and <see cref="Max"/> based on t [0..1]
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
public float GetPoint(float t)
|
||||
{
|
||||
return t * (Max - Min) + Min;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts to Vector2.
|
||||
/// </summary>
|
||||
/// <param name="v"></param>
|
||||
public static explicit operator Vector2(MinMax v) => new Vector2(v.Min, v.Max);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,6 +77,7 @@ namespace SM.OGL.Framebuffer
|
|||
PixelInformation = pixelInformation;
|
||||
AttachmentSize = size;
|
||||
|
||||
if (multisamples > 8) multisamples = 8;
|
||||
_multisamples = multisamples;
|
||||
Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM.OGL</RootNamespace>
|
||||
<AssemblyName>SM.OGL</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM2D</RootNamespace>
|
||||
<AssemblyName>SMRenderer2D</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue