Skip to content

Commit

Permalink
better bloom effects and 3 more settings
Browse files Browse the repository at this point in the history
  • Loading branch information
EyeOfDarkness committed Jan 15, 2024
1 parent ddf42ba commit 135deb1
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
6 changes: 6 additions & 0 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ setting.al-bloom-blur-feedback.description = How much the blur brighten each ite
setting.al-bloom-flare-feedback.name = Flare Feedback
setting.al-bloom-flare-feedback.description = How much the flare brighten each iteration, only works when Flare Amount is greater than 1.

setting.al-bloom-diffuse-amount.name = Blur Diffuse Amount
setting.al-bloom-diffuse-amount.description = Amount of extra blur with increasing sizes added on top.

setting.al-bloom-diffuse-size.name = Blur Diffuse Size
setting.al-bloom-diffuse-feedback.name = Blur Diffuse Feedback

setting.al-hide-lights.name = Disable Lights
setting.al-hide-lights.description = Disables Vanilla Lights.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Advance lighting",
"author": "EoD",
"description": "Not recommended for weak devices. Only supports Vanilla/Supported-Json content. This mod replaces/add some effects, and may cause issues with mods that actively check on those effects. May conflict with vanilla bloom.",
"version": "v1.5.3.1",
"version": "v1.5.4.0",
"minGameVersion": 145,
"main": "lights.AdvanceLighting",
"hidden": true,
Expand Down
22 changes: 22 additions & 0 deletions src/lights/AdvanceLighting.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ void loadSettings(){
}
return (s / 100f) + "";
});
st.sliderPref("al-bloom-diffuse-amount", 0, 0, 15, s -> {
if(bloom != null){
bloom.blurDiffuseAmount = s;
}
return s + "";
});
st.sliderPref("al-bloom-diffuse-size", 175, 0, 300, s -> {
if(bloom != null){
bloom.blurDiffuseSize = s / 100f;
}
return (s / 100f) + "";
});
st.sliderPref("al-bloom-diffuse-feedback", 100, 100, 200, s -> {
if(bloom != null){
bloom.blurDiffuseFeedBack = s / 100f;
}
return (s / 100f) + "";
});

st.row();

Expand All @@ -282,6 +300,10 @@ public void setBloom(boolean on){

bloom.setBlurFeedBack(Core.settings.getInt("al-bloom-blur-feedback", 100) / 100f);
bloom.setFlareFeedBack(Core.settings.getInt("al-bloom-flare-feedback", 100) / 100f);

bloom.blurDiffuseAmount = Core.settings.getInt("al-bloom-diffuse-amount", 0);
bloom.blurDiffuseSize = Core.settings.getInt("al-bloom-diffuse-size", 175) / 100f;
bloom.blurDiffuseFeedBack = Core.settings.getInt("al-bloom-diffuse-feedback", 100) / 100f;
}
bloomActive = on;
}
Expand Down
90 changes: 88 additions & 2 deletions src/lights/graphics/AdditiveBloom.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import arc.graphics.g2d.*;
import arc.graphics.gl.*;
import arc.math.*;
import lights.*;
import mindustry.*;

public class AdditiveBloom{
Expand All @@ -15,8 +16,11 @@ public class AdditiveBloom{
public float blurFeedBack = 1f, flareFeedBack = 1f;
public float saturation = 12f;
public float flareDirection = 0f;
public int blurDiffuseAmount = 0;
public float blurDiffuseSize = 1.75f, blurDiffuseFeedBack = 1f;

private FrameBuffer pingPong1, pingPong2, pingPong3;
private Shader blurShader, renderShader, thresholdShader;
private Shader blurShader, renderShader, thresholdShader, diffuseShader;

private float lastIntens = 0.75f;

Expand All @@ -33,6 +37,7 @@ void init(int width, int height){
blurShader = createBlurShader();
renderShader = createRenderShader();
thresholdShader = createThresholdShader();
diffuseShader = createDiffuseShader();

setSize(width, height);
setIntensity(0.75f);
Expand Down Expand Up @@ -73,11 +78,67 @@ public void render(Texture texture){

pingPong1.begin();
blurShader.bind();
blurShader.setUniformf("u_feedBack", f);
//blurShader.setUniformf("u_feedBack", f);
blurShader.setUniformf("dir", 0f, blurSize);
pingPong2.blit(blurShader);
pingPong1.end();
}

if(blurDiffuseAmount > 0){
pingPong3.begin(Color.black);
//diffuseShader.bind();
//diffuseShader.setUniformf("u_diffuse", 1f / (blurDiffuseAmount * 2));
//diffuseShader.setUniformf("u_diffuse", 1f / (blurDiffuseAmount / (1f + (blurDiffuseSize - 1f) / 10f)));
//diffuseShader.setUniformf("u_diffuse", 1f);
pingPong1.blit(diffuseShader);
pingPong3.end();

//Blending.additive.apply();

float scl = blurSize * blurDiffuseSize;
for(int i = 0; i < blurDiffuseAmount; i++){
float fb = blurDiffuseAmount > 1 ? Mathf.lerp(blurDiffuseFeedBack, 1f, i / (blurDiffuseAmount - 1f)) : 1f;

pingPong2.begin();
blurShader.bind();
//blurShader.setUniformf("u_feedBack", 1f);
blurShader.setUniformf("u_feedBack", fb);
blurShader.setUniformf("dir", scl, 0f);
pingPong3.blit(blurShader);
/*
if(i == 0){
pingPong3.blit(blurShader);
}else{
pingPong1.blit(blurShader);
}
*/
pingPong2.end();

pingPong1.begin();
blurShader.bind();
//blurShader.setUniformf("u_feedBack", 1);
blurShader.setUniformf("dir", 0f, scl);
pingPong2.blit(blurShader);
pingPong1.end();

//scl *= blurDiffuseSize;
scl += blurSize * blurDiffuseSize;

Gl.blendEquationSeparate(Gl.max, Gl.max);
Blending.additive.apply();

pingPong3.begin();
pingPong1.blit(AdvanceLighting.screenShader);
pingPong3.end();

Gl.blendEquationSeparate(Gl.funcAdd, Gl.funcAdd);
Gl.disable(Gl.blend);
}

pingPong1.begin(Color.black);
pingPong3.blit(AdvanceLighting.screenShader);
pingPong1.end();
}

if(flarePasses > 0){
float sx = Mathf.cosDeg(flareDirection) * flareLength, sy = Mathf.sinDeg(flareDirection) * flareLength;
Expand Down Expand Up @@ -221,6 +282,31 @@ void main(){
}
""");
}
private static Shader createDiffuseShader(){
return new Shader("""
attribute vec4 a_position;
attribute vec2 a_texCoord0;
varying vec2 v_texCoords;
void main(){
v_texCoords = a_texCoord0;
gl_Position = a_position;
}
""", """
uniform sampler2D u_texture;
varying vec2 v_texCoords;
//uniform float u_diffuse;
void main(){
vec4 c = texture2D(u_texture, v_texCoords);
//c.rgb = c.rgb * u_diffuse;
vec3 tc = mix(vec3(0.0, 0.0, 0.0), c.rgb, c.a);
gl_FragColor = vec4(tc, 1.0);
}
""");
}

private static Fi local(String name){
return Vars.tree.get("shaders/" + name);
Expand Down

0 comments on commit 135deb1

Please sign in to comment.