Improved Bloom-Effect
[Can be now used, instead of filling another HDR-ColorAttachment, you just "overfill" the "color" buffer.]
This commit is contained in:
parent
4c18127c88
commit
af90d617d3
3 changed files with 14 additions and 17 deletions
|
|
@ -23,6 +23,7 @@ namespace SM.Base.PostEffects
|
||||||
private bool _hdr;
|
private bool _hdr;
|
||||||
|
|
||||||
public int Iterations = 5;
|
public int Iterations = 5;
|
||||||
|
public float Threshold = 0.8f;
|
||||||
|
|
||||||
public float[] Weights = { 0.227027f, 0.1945946f, 0.1216216f, 0.054054f, 0.016216f };
|
public float[] Weights = { 0.227027f, 0.1945946f, 0.1216216f, 0.054054f, 0.016216f };
|
||||||
|
|
||||||
|
|
@ -34,7 +35,7 @@ namespace SM.Base.PostEffects
|
||||||
|
|
||||||
protected override void InitProcess()
|
protected override void InitProcess()
|
||||||
{
|
{
|
||||||
Pipeline.MainFramebuffer.Append("bloom", new ColorAttachment(_bloomLocation, PixelInformation.RGBA_HDR));
|
Pipeline.MainFramebuffer.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR;
|
||||||
|
|
||||||
_bloomBuffer1 = new Framebuffer(SMRenderer.CurrentWindow);
|
_bloomBuffer1 = new Framebuffer(SMRenderer.CurrentWindow);
|
||||||
_bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
|
_bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
|
||||||
|
|
@ -57,8 +58,11 @@ namespace SM.Base.PostEffects
|
||||||
{
|
{
|
||||||
(hoz ? _bloomBuffer1 : _bloomBuffer2).Activate();
|
(hoz ? _bloomBuffer1 : _bloomBuffer2).Activate();
|
||||||
|
|
||||||
_shader.Draw(first ? Pipeline.MainFramebuffer.ColorAttachments["bloom"] : (hoz ? _yBuffer : _xBuffer), collection =>
|
_shader.Draw(first ? Pipeline.MainFramebuffer.ColorAttachments["color"] : (hoz ? _yBuffer : _xBuffer), collection =>
|
||||||
{
|
{
|
||||||
|
collection["First"].SetUniform1(first);
|
||||||
|
collection["Threshold"].SetUniform1(Threshold);
|
||||||
|
|
||||||
collection["Horizontal"].SetUniform1(hoz);
|
collection["Horizontal"].SetUniform1(hoz);
|
||||||
|
|
||||||
collection["Weights"].SetUniform1(Weights);
|
collection["Weights"].SetUniform1(Weights);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
uniform sampler2D renderedTexture;
|
uniform sampler2D renderedTexture;
|
||||||
|
|
||||||
|
uniform bool First;
|
||||||
|
uniform float Threshold;
|
||||||
|
|
||||||
uniform bool Horizontal;
|
uniform bool Horizontal;
|
||||||
|
|
||||||
uniform float[32] Weights;
|
uniform float[32] Weights;
|
||||||
|
|
@ -12,13 +15,15 @@ layout(location = 0) out vec4 color;
|
||||||
vec4 GetRenderColorOffset(vec2 offset);
|
vec4 GetRenderColorOffset(vec2 offset);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
vec3 thres = vec3(First ? Threshold : 0);
|
||||||
|
|
||||||
vec2 tex_offset = 1.0 / textureSize(renderedTexture, 0);
|
vec2 tex_offset = 1.0 / textureSize(renderedTexture, 0);
|
||||||
vec3 result = GetRenderColorOffset(vec2(0)).rgb * Weights[0];
|
vec3 result = max(GetRenderColorOffset(vec2(0)).rgb - thres, 0) * Weights[0];
|
||||||
|
|
||||||
if (Horizontal) {
|
if (Horizontal) {
|
||||||
for(int i = 1; i < WeightCount; i++) {
|
for(int i = 1; i < WeightCount; i++) {
|
||||||
result += GetRenderColorOffset(vec2(tex_offset.x * i, 0)).rgb * Weights[i];
|
result += max(GetRenderColorOffset(vec2(tex_offset.x * i, 0)).rgb - thres, 0) * Weights[i];
|
||||||
result += GetRenderColorOffset(vec2(-tex_offset.x * i, 0)).rgb * Weights[i];
|
result += max(GetRenderColorOffset(vec2(-tex_offset.x * i, 0)).rgb - thres, 0) * Weights[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(int i = 1; i < WeightCount; i++) {
|
for(int i = 1; i < WeightCount; i++) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ using SM.Base.Time;
|
||||||
using SM.Utility;
|
using SM.Utility;
|
||||||
using SM2D;
|
using SM2D;
|
||||||
using SM2D.Drawing;
|
using SM2D.Drawing;
|
||||||
using SM2D.Light;
|
|
||||||
using SM2D.Object;
|
using SM2D.Object;
|
||||||
using SM2D.Pipelines;
|
using SM2D.Pipelines;
|
||||||
using SM2D.Scene;
|
using SM2D.Scene;
|
||||||
|
|
@ -46,14 +45,12 @@ namespace SM_TEST
|
||||||
window.Run();
|
window.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PointLight light;
|
|
||||||
private static DrawParticles particles;
|
private static DrawParticles particles;
|
||||||
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard.GetState()[Key.R])
|
if (Keyboard.GetState()[Key.R])
|
||||||
particles.Trigger();
|
particles.Trigger();
|
||||||
//particles.Paused = Keyboard.GetState()[Key.P];
|
//particles.Paused = Keyboard.GetState()[Key.P];
|
||||||
light.Position.Set( window.Mouse.InWorld());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WindowOnLoad(object sender, EventArgs e)
|
private static void WindowOnLoad(object sender, EventArgs e)
|
||||||
|
|
@ -68,15 +65,6 @@ namespace SM_TEST
|
||||||
text.Transform.Size.Set(2);
|
text.Transform.Size.Set(2);
|
||||||
scene.Objects.Add(text);
|
scene.Objects.Add(text);
|
||||||
|
|
||||||
light = new PointLight
|
|
||||||
{
|
|
||||||
Color = new Color4(0, 1, 1, 1),
|
|
||||||
Power = 100
|
|
||||||
};
|
|
||||||
scene.LightInformations.Lights.Add(light);
|
|
||||||
|
|
||||||
scene.LightInformations.Ambient = Color4.White;
|
|
||||||
|
|
||||||
//particles.Trigger();
|
//particles.Trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue