diff --git a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj index 580452a..aeea189 100644 --- a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj +++ b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj @@ -9,7 +9,7 @@ Properties SM.Intergrations SM.Intergrations - v4.7.2 + v4.5.2 512 true diff --git a/src/optionals/SM.Utils/SMRenderer.Utils.csproj b/src/optionals/SM.Utils/SMRenderer.Utils.csproj index 30b4822..3e2f80f 100644 --- a/src/optionals/SM.Utils/SMRenderer.Utils.csproj +++ b/src/optionals/SM.Utils/SMRenderer.Utils.csproj @@ -9,7 +9,7 @@ Properties SM.Utils SM.Utils - v4.7.2 + v4.5.2 512 true diff --git a/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert index 5875eb3..4d20506 100644 --- a/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert +++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert @@ -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); } \ No newline at end of file diff --git a/src/renderer/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs index 8c5cac7..347a082 100644 --- a/src/renderer/SM.Base/PostEffects/BloomEffect.cs +++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs @@ -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 /// public Color4 Color = Color4.White; + /// + /// An amount map specifices where the bloom effect should be visible. + /// Reads only in the "R"-channel. + /// + public TextureBase AmountMap; + /// + /// Allows you to transform the texture coordnates for + /// + public TextureTransformation AmountMapTransform = new TextureTransformation(); + /// + /// Specifices limits, how the is read. + /// Default: + /// + public MinMax AmountLimits = MinMax.Default; + /// /// This creates a more prettier bloom effect. /// @@ -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); }); } diff --git a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs index c925965..1665148 100644 --- a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs +++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs @@ -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(); } diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag index e72ba87..2c67f8b 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag @@ -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; diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert new file mode 100644 index 0000000..1a92d4c --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert @@ -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); +} \ No newline at end of file diff --git a/src/renderer/SM.Base/SM.Base.csproj b/src/renderer/SM.Base/SM.Base.csproj index dd59076..e40c61b 100644 --- a/src/renderer/SM.Base/SM.Base.csproj +++ b/src/renderer/SM.Base/SM.Base.csproj @@ -13,7 +13,7 @@ Properties SM.Base SM.Base - v4.7.1 + v4.5.2 512 true @@ -62,6 +62,7 @@ + @@ -168,6 +169,7 @@ + diff --git a/src/renderer/SM.Base/Types/MinMax.cs b/src/renderer/SM.Base/Types/MinMax.cs new file mode 100644 index 0000000..6b8f2c4 --- /dev/null +++ b/src/renderer/SM.Base/Types/MinMax.cs @@ -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 +{ + /// + /// Structure to store Min and Max-values. + /// + public struct MinMax + { + /// + /// Default Value: 0..1 + /// + public static readonly MinMax Default = new MinMax(0, 1); + + /// + /// Minimum Value + /// + public float Min; + /// + /// Maximum Value + /// + public float Max; + + /// + /// Creates a MinMax-structure with two values. + /// + public MinMax(float min, float max) + { + Min = min; + Max = max; + } + + /// + /// Get a value that is between and based on t [0..1] + /// + /// + public float GetPoint(float t) + { + return t * (Max - Min) + Min; + } + + /// + /// Converts to Vector2. + /// + /// + public static explicit operator Vector2(MinMax v) => new Vector2(v.Min, v.Max); + } +} diff --git a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs index 7ef84e4..0592e2e 100644 --- a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs +++ b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs @@ -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; diff --git a/src/renderer/SM.OGL/SM.OGL.csproj b/src/renderer/SM.OGL/SM.OGL.csproj index 432a51b..fd8ec5d 100644 --- a/src/renderer/SM.OGL/SM.OGL.csproj +++ b/src/renderer/SM.OGL/SM.OGL.csproj @@ -9,7 +9,7 @@ Properties SM.OGL SM.OGL - v4.7.1 + v4.5.2 512 true diff --git a/src/renderer/SM2D/SM2D.csproj b/src/renderer/SM2D/SM2D.csproj index 384bc93..247194f 100644 --- a/src/renderer/SM2D/SM2D.csproj +++ b/src/renderer/SM2D/SM2D.csproj @@ -8,7 +8,7 @@ Properties SM2D SMRenderer2D - v4.7.1 + v4.5.2 512 true diff --git a/tests/SM_TEST/App.config b/tests/SM_TEST/App.config index ecdcf8a..8227adb 100644 --- a/tests/SM_TEST/App.config +++ b/tests/SM_TEST/App.config @@ -1,6 +1,6 @@ - + diff --git a/tests/SM_TEST/SM_TEST.csproj b/tests/SM_TEST/SM_TEST.csproj index 479cccf..3050d81 100644 --- a/tests/SM_TEST/SM_TEST.csproj +++ b/tests/SM_TEST/SM_TEST.csproj @@ -10,7 +10,7 @@ WinExe SM_TEST SM_TEST - v4.7.2 + v4.5.2 512 true true diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs index fea1bc0..04ba92f 100644 --- a/tests/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -1,6 +1,7 @@ using OpenTK.Graphics.OpenGL4; using SM.Base.Legacy.PostProcessing; using SM.Base.PostEffects; +using SM.Base.Textures; using SM.Base.Window; using SM.Intergrations.ShaderTool; using SM.OGL.Framebuffer; @@ -10,20 +11,19 @@ namespace SM_TEST { public class TestRenderPipeline : RenderPipeline { - private BloomEffectOld _bloomObsolete; private BloomEffect _bloom; - private STPostProcessEffect _vittage; private Framebuffer _postBuffer; public override void Initialization() { - - MainFramebuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, true); + MainFramebuffer = CreateWindowFramebuffer(8, PixelInformation.RGBA_HDR, true); + _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGB_HDR, false); _bloom = new BloomEffect(true) { Radius = 20, + AmountMap = new Texture(new System.Drawing.Bitmap("bloom_amountMap.png")) }; PostProcessEffects.Add(_bloom); @@ -52,17 +52,13 @@ namespace SM_TEST context.Scene.DrawHUD(context); GL.Disable(EnableCap.DepthTest); - //_postBuffer.Activate(ClearBufferMask.ColorBufferBit); - //PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); + _postBuffer.Activate(ClearBufferMask.ColorBufferBit); + PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); - //_vittage.Draw(MainFramebuffer["color"], context); - //_bloom.Draw(MainFramebuffer["color"], context); - _bloomObsolete.Draw(MainFramebuffer["color"], context); + _bloom.Draw(_postBuffer["color"], context); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - PostProcessUtility.FinalizeHDR(MainFramebuffer["color"], 1f); - - //context.Scene.DrawDebug(context); + PostProcessUtility.FinalizeHDR(_postBuffer["color"], 1f); } } } \ No newline at end of file