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>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>SM.Intergrations</RootNamespace>
|
<RootNamespace>SM.Intergrations</RootNamespace>
|
||||||
<AssemblyName>SM.Intergrations</AssemblyName>
|
<AssemblyName>SM.Intergrations</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>SM.Utils</RootNamespace>
|
<RootNamespace>SM.Utils</RootNamespace>
|
||||||
<AssemblyName>SM.Utils</AssemblyName>
|
<AssemblyName>SM.Utils</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ out vec2 TransformedTexture;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vTexture = aTex;
|
vTexture = aTex;
|
||||||
//TransformedTexture = vec2(TextureTransform * vec3(aTex, 1));
|
TransformedTexture = vec2(TextureTransform * vec3(aTex, 1));
|
||||||
|
|
||||||
gl_Position = MVP * vec4(aPos, 1);
|
gl_Position = MVP * vec4(aPos, 1);
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
|
using SM.Base.Drawing;
|
||||||
using SM.Base.PostProcess;
|
using SM.Base.PostProcess;
|
||||||
|
using SM.Base.Types;
|
||||||
using SM.Base.Utility;
|
using SM.Base.Utility;
|
||||||
using SM.Base.Window;
|
using SM.Base.Window;
|
||||||
using SM.OGL.Framebuffer;
|
using SM.OGL.Framebuffer;
|
||||||
|
|
@ -33,6 +35,7 @@ namespace SM.Base.PostEffects
|
||||||
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.upsample.frag")
|
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.upsample.frag")
|
||||||
);
|
);
|
||||||
private static readonly PostProcessShader _combineShader = new PostProcessShader(
|
private static readonly PostProcessShader _combineShader = new PostProcessShader(
|
||||||
|
new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.vert")),
|
||||||
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.frag")
|
AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.frag")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -76,6 +79,21 @@ namespace SM.Base.PostEffects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color4 Color = Color4.White;
|
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>
|
/// <summary>
|
||||||
/// This creates a more prettier bloom effect.
|
/// This creates a more prettier bloom effect.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -193,6 +211,14 @@ namespace SM.Base.PostEffects
|
||||||
a["scene"].SetTexture(_downsampler[0]["1"]);
|
a["scene"].SetTexture(_downsampler[0]["1"]);
|
||||||
a["bloomColor"].SetColor(_bloomColor);
|
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);
|
a["HDR"].SetBool(_hdr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace SM.Base.PostEffects
|
||||||
target.Activate(FramebufferTarget.DrawFramebuffer);
|
target.Activate(FramebufferTarget.DrawFramebuffer);
|
||||||
GL.BlitFramebuffer(0, 0, (int) multisampledBuffers.Size.X, (int) multisampledBuffers.Size.Y, 0, 0,
|
GL.BlitFramebuffer(0, 0, (int) multisampledBuffers.Size.X, (int) multisampledBuffers.Size.Y, 0, 0,
|
||||||
(int) target.Size.X, (int) target.Size.Y, ClearBufferMask.ColorBufferBit,
|
(int) target.Size.X, (int) target.Size.Y, ClearBufferMask.ColorBufferBit,
|
||||||
BlitFramebufferFilter.Nearest);
|
BlitFramebufferFilter.Linear);
|
||||||
|
|
||||||
target.Activate();
|
target.Activate();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
in vec2 vTexture;
|
in vec2 vTexture;
|
||||||
|
in vec2 amountUV;
|
||||||
|
|
||||||
uniform sampler2D scene;
|
uniform sampler2D scene;
|
||||||
uniform vec4 bloomColor;
|
uniform vec4 bloomColor;
|
||||||
uniform bool HDR;
|
uniform bool HDR;
|
||||||
|
|
||||||
|
uniform bool hasAmountMap;
|
||||||
|
uniform sampler2D amountMap;
|
||||||
|
uniform vec2 amountLimit;
|
||||||
|
|
||||||
vec3 safe_color(vec3 c) {
|
vec3 safe_color(vec3 c) {
|
||||||
return clamp(c, vec3(0.0), vec3(1e20));
|
return clamp(c, vec3(0.0), vec3(1e20));
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +28,10 @@ void main() {
|
||||||
vec3 scene = safe_color(texture2D(scene, vTexture).rgb);
|
vec3 scene = safe_color(texture2D(scene, vTexture).rgb);
|
||||||
vec3 blur = upsample_filter_high() * bloomColor.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) {
|
if (HDR) {
|
||||||
color = vec4(scene + blur, 1);
|
color = vec4(scene + blur, 1);
|
||||||
return;
|
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>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>SM.Base</RootNamespace>
|
<RootNamespace>SM.Base</RootNamespace>
|
||||||
<AssemblyName>SM.Base</AssemblyName>
|
<AssemblyName>SM.Base</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<NuGetPackageImportStamp>
|
<NuGetPackageImportStamp>
|
||||||
|
|
@ -62,6 +62,7 @@
|
||||||
<Compile Include="Shaders\SimpleShader.cs" />
|
<Compile Include="Shaders\SimpleShader.cs" />
|
||||||
<Compile Include="Types\CVector4.cs" />
|
<Compile Include="Types\CVector4.cs" />
|
||||||
<Compile Include="Types\CVectorBase.cs" />
|
<Compile Include="Types\CVectorBase.cs" />
|
||||||
|
<Compile Include="Types\MinMax.cs" />
|
||||||
<Compile Include="Utility\IInitializable.cs" />
|
<Compile Include="Utility\IInitializable.cs" />
|
||||||
<Compile Include="Utility\MathUtils.cs" />
|
<Compile Include="Utility\MathUtils.cs" />
|
||||||
<Compile Include="Utility\Ray.cs" />
|
<Compile Include="Utility\Ray.cs" />
|
||||||
|
|
@ -168,6 +169,7 @@
|
||||||
<EmbeddedResource Include="PostEffects\Shaders\bloom\upsample.frag" />
|
<EmbeddedResource Include="PostEffects\Shaders\bloom\upsample.frag" />
|
||||||
<EmbeddedResource Include="PostEffects\Shaders\bloom\combine.frag" />
|
<EmbeddedResource Include="PostEffects\Shaders\bloom\combine.frag" />
|
||||||
<EmbeddedResource Include="PostEffects\Shaders\bloom\sampling.frag" />
|
<EmbeddedResource Include="PostEffects\Shaders\bloom\sampling.frag" />
|
||||||
|
<EmbeddedResource Include="PostEffects\Shaders\bloom\combine.vert" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<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;
|
PixelInformation = pixelInformation;
|
||||||
AttachmentSize = size;
|
AttachmentSize = size;
|
||||||
|
|
||||||
|
if (multisamples > 8) multisamples = 8;
|
||||||
_multisamples = multisamples;
|
_multisamples = multisamples;
|
||||||
Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;
|
Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>SM.OGL</RootNamespace>
|
<RootNamespace>SM.OGL</RootNamespace>
|
||||||
<AssemblyName>SM.OGL</AssemblyName>
|
<AssemblyName>SM.OGL</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>SM2D</RootNamespace>
|
<RootNamespace>SM2D</RootNamespace>
|
||||||
<AssemblyName>SMRenderer2D</AssemblyName>
|
<AssemblyName>SMRenderer2D</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
|
||||||
</startup>
|
</startup>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>SM_TEST</RootNamespace>
|
<RootNamespace>SM_TEST</RootNamespace>
|
||||||
<AssemblyName>SM_TEST</AssemblyName>
|
<AssemblyName>SM_TEST</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using OpenTK.Graphics.OpenGL4;
|
using OpenTK.Graphics.OpenGL4;
|
||||||
using SM.Base.Legacy.PostProcessing;
|
using SM.Base.Legacy.PostProcessing;
|
||||||
using SM.Base.PostEffects;
|
using SM.Base.PostEffects;
|
||||||
|
using SM.Base.Textures;
|
||||||
using SM.Base.Window;
|
using SM.Base.Window;
|
||||||
using SM.Intergrations.ShaderTool;
|
using SM.Intergrations.ShaderTool;
|
||||||
using SM.OGL.Framebuffer;
|
using SM.OGL.Framebuffer;
|
||||||
|
|
@ -10,20 +11,19 @@ namespace SM_TEST
|
||||||
{
|
{
|
||||||
public class TestRenderPipeline : RenderPipeline
|
public class TestRenderPipeline : RenderPipeline
|
||||||
{
|
{
|
||||||
private BloomEffectOld _bloomObsolete;
|
|
||||||
private BloomEffect _bloom;
|
private BloomEffect _bloom;
|
||||||
private STPostProcessEffect _vittage;
|
|
||||||
|
|
||||||
private Framebuffer _postBuffer;
|
private Framebuffer _postBuffer;
|
||||||
|
|
||||||
public override void Initialization()
|
public override void Initialization()
|
||||||
{
|
{
|
||||||
|
MainFramebuffer = CreateWindowFramebuffer(8, PixelInformation.RGBA_HDR, true);
|
||||||
MainFramebuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, true);
|
_postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGB_HDR, false);
|
||||||
|
|
||||||
_bloom = new BloomEffect(true)
|
_bloom = new BloomEffect(true)
|
||||||
{
|
{
|
||||||
Radius = 20,
|
Radius = 20,
|
||||||
|
AmountMap = new Texture(new System.Drawing.Bitmap("bloom_amountMap.png"))
|
||||||
};
|
};
|
||||||
PostProcessEffects.Add(_bloom);
|
PostProcessEffects.Add(_bloom);
|
||||||
|
|
||||||
|
|
@ -52,17 +52,13 @@ namespace SM_TEST
|
||||||
context.Scene.DrawHUD(context);
|
context.Scene.DrawHUD(context);
|
||||||
|
|
||||||
GL.Disable(EnableCap.DepthTest);
|
GL.Disable(EnableCap.DepthTest);
|
||||||
//_postBuffer.Activate(ClearBufferMask.ColorBufferBit);
|
_postBuffer.Activate(ClearBufferMask.ColorBufferBit);
|
||||||
//PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer);
|
PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer);
|
||||||
|
|
||||||
//_vittage.Draw(MainFramebuffer["color"], context);
|
_bloom.Draw(_postBuffer["color"], context);
|
||||||
//_bloom.Draw(MainFramebuffer["color"], context);
|
|
||||||
_bloomObsolete.Draw(MainFramebuffer["color"], context);
|
|
||||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
|
|
||||||
PostProcessUtility.FinalizeHDR(MainFramebuffer["color"], 1f);
|
PostProcessUtility.FinalizeHDR(_postBuffer["color"], 1f);
|
||||||
|
|
||||||
//context.Scene.DrawDebug(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue