05.01.2021

+ Bloom effect
+ PixelInformation
+ Many Summaries
+ Add-methods for CVectors
+ Exposure-Field in GenericCamera for HDR.

~ ColorAttachments now can have PixelInformation
~ Transformed MeshAttributes to a own class
~ Fixed the non-applying of transformations at texts
~ Added more information to the context
~ Improved Pipeline-Process.
~ Changed how Uniform takes arrays

- Light system
This commit is contained in:
Michel Fedde 2021-01-06 17:04:15 +01:00
parent 9b917ac181
commit 4c18127c88
52 changed files with 697 additions and 373 deletions

View file

@ -0,0 +1,82 @@
using System.ComponentModel;
using OpenTK.Graphics.OpenGL4;
using SM.Base.Contexts;
using SM.Base.PostProcess;
using SM.OGL.Framebuffer;
using SM.OGL.Texture;
using SM.Utility;
namespace SM.Base.PostEffects
{
public class BloomEffect : PostProcessEffect
{
private Framebuffer _bloomBuffer1;
private Framebuffer _bloomBuffer2;
private ColorAttachment _xBuffer;
private ColorAttachment _yBuffer;
private PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM.Base.PostEffects.Shaders.bloom_blur.glsl"));
private PostProcessShader _mergeShader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM.Base.PostEffects.Shaders.bloom_merge.glsl"));
private int _bloomLocation;
private bool _hdr;
public int Iterations = 5;
public float[] Weights = { 0.227027f, 0.1945946f, 0.1216216f, 0.054054f, 0.016216f };
public BloomEffect(int bloomLocation, bool hdr = false)
{
_bloomLocation = bloomLocation;
_hdr = hdr;
}
protected override void InitProcess()
{
Pipeline.MainFramebuffer.Append("bloom", new ColorAttachment(_bloomLocation, PixelInformation.RGBA_HDR));
_bloomBuffer1 = new Framebuffer(SMRenderer.CurrentWindow);
_bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
_bloomBuffer1.Compile();
_bloomBuffer2 = new Framebuffer(SMRenderer.CurrentWindow);
_bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
_bloomBuffer2.Compile();
Pipeline.Framebuffers.Add(_bloomBuffer1);
Pipeline.Framebuffers.Add(_bloomBuffer2);
}
public override void Draw(DrawContext context)
{
Framebuffer target = Framebuffer.GetCurrentlyActive();
bool first = true, hoz = true;
int iter = Iterations * 2;
for (int i = 0; i < iter; i++)
{
(hoz ? _bloomBuffer1 : _bloomBuffer2).Activate();
_shader.Draw(first ? Pipeline.MainFramebuffer.ColorAttachments["bloom"] : (hoz ? _yBuffer : _xBuffer), collection =>
{
collection["Horizontal"].SetUniform1(hoz);
collection["Weights"].SetUniform1(Weights);
collection["WeightCount"].SetUniform1(Weights.Length);
});
hoz = !hoz;
if (first) first = false;
}
target.Activate();
_mergeShader.Draw(Pipeline.MainFramebuffer.ColorAttachments["color"], collection =>
{
collection["Bloom"].SetTexture(_yBuffer);
collection["Exposure"].SetUniform1(context.UsedCamera.Exposure);
collection["HDR"].SetUniform1(_hdr);
});
}
}
}

View file

@ -0,0 +1,30 @@
#version 330
uniform sampler2D renderedTexture;
uniform bool Horizontal;
uniform float[32] Weights;
uniform int WeightCount;
layout(location = 0) out vec4 color;
vec4 GetRenderColorOffset(vec2 offset);
void main() {
vec2 tex_offset = 1.0 / textureSize(renderedTexture, 0);
vec3 result = GetRenderColorOffset(vec2(0)).rgb * Weights[0];
if (Horizontal) {
for(int i = 1; i < WeightCount; i++) {
result += GetRenderColorOffset(vec2(tex_offset.x * i, 0)).rgb * Weights[i];
result += GetRenderColorOffset(vec2(-tex_offset.x * i, 0)).rgb * Weights[i];
}
} else {
for(int i = 1; i < WeightCount; i++) {
result += GetRenderColorOffset(vec2(0, tex_offset.x * i)).rgb * Weights[i];
result += GetRenderColorOffset(vec2(0, -tex_offset.x * i)).rgb * Weights[i];
}
}
color = vec4(result, 1);
}

View file

@ -0,0 +1,21 @@
#version 330
in vec2 vTexture;
uniform sampler2D renderedTexture;
uniform sampler2D Bloom;
uniform float Exposure;
uniform bool HDR;
layout(location = 0) out vec4 color;
void main() {
vec3 result = texture(Bloom, vTexture).rgb;
if (!HDR) {
result = vec3(1.0) - exp(-result * Exposure);
}
result += texture(renderedTexture, vTexture).rgb;
color = vec4(result, 1);
}