diff --git a/forge-adventure/shaders/underwater.frag b/forge-adventure/shaders/underwater.frag index 974a1e8ae92..6287a862c9c 100644 --- a/forge-adventure/shaders/underwater.frag +++ b/forge-adventure/shaders/underwater.frag @@ -11,6 +11,7 @@ uniform sampler2D u_texture; uniform float u_amount; uniform float u_speed; uniform float u_time; +uniform float u_bias; void main () { vec2 uv = v_texCoords; @@ -19,5 +20,7 @@ void main () { uv.x += (sin((uv.y + (u_time * 0.07 * u_speed)) * 15.0) * 0.0029 * u_amount) + (sin((uv.y + (u_time * 0.1 * u_speed)) * 15.0) * 0.002 * u_amount); - gl_FragColor = texture2D(u_texture, uv); + vec4 texColor = texture2D(u_texture, uv); + + gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), texColor, u_bias); } \ No newline at end of file diff --git a/forge-gui-android/assets/shaders/underwater.frag b/forge-gui-android/assets/shaders/underwater.frag index 974a1e8ae92..6287a862c9c 100644 --- a/forge-gui-android/assets/shaders/underwater.frag +++ b/forge-gui-android/assets/shaders/underwater.frag @@ -11,6 +11,7 @@ uniform sampler2D u_texture; uniform float u_amount; uniform float u_speed; uniform float u_time; +uniform float u_bias; void main () { vec2 uv = v_texCoords; @@ -19,5 +20,7 @@ void main () { uv.x += (sin((uv.y + (u_time * 0.07 * u_speed)) * 15.0) * 0.0029 * u_amount) + (sin((uv.y + (u_time * 0.1 * u_speed)) * 15.0) * 0.002 * u_amount); - gl_FragColor = texture2D(u_texture, uv); + vec4 texColor = texture2D(u_texture, uv); + + gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), texColor, u_bias); } \ No newline at end of file diff --git a/forge-gui-mobile-dev/shaders/underwater.frag b/forge-gui-mobile-dev/shaders/underwater.frag index 974a1e8ae92..6287a862c9c 100644 --- a/forge-gui-mobile-dev/shaders/underwater.frag +++ b/forge-gui-mobile-dev/shaders/underwater.frag @@ -11,6 +11,7 @@ uniform sampler2D u_texture; uniform float u_amount; uniform float u_speed; uniform float u_time; +uniform float u_bias; void main () { vec2 uv = v_texCoords; @@ -19,5 +20,7 @@ void main () { uv.x += (sin((uv.y + (u_time * 0.07 * u_speed)) * 15.0) * 0.0029 * u_amount) + (sin((uv.y + (u_time * 0.1 * u_speed)) * 15.0) * 0.002 * u_amount); - gl_FragColor = texture2D(u_texture, uv); + vec4 texColor = texture2D(u_texture, uv); + + gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), texColor, u_bias); } \ No newline at end of file diff --git a/forge-gui-mobile/src/forge/Graphics.java b/forge-gui-mobile/src/forge/Graphics.java index d16c0e0f8d7..3e8aea0097a 100644 --- a/forge-gui-mobile/src/forge/Graphics.java +++ b/forge-gui-mobile/src/forge/Graphics.java @@ -43,6 +43,7 @@ public class Graphics { private final ShaderProgram shaderUnderwater = new ShaderProgram(Gdx.files.internal("shaders").child("grayscale.vert"), Gdx.files.internal("shaders").child("underwater.frag")); private final ShaderProgram shaderNightDay = new ShaderProgram(Shaders.vertexShaderDayNight, Shaders.fragmentShaderDayNight); private final ShaderProgram shaderPixelate = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragPixelateShader); + private final ShaderProgram shaderRipple = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragRipple); private final ShaderProgram shaderPixelateWarp = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragPixelateShaderWarp); private final ShaderProgram shaderChromaticAbberation = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragChromaticAbberation); @@ -841,14 +842,38 @@ public class Graphics { drawImage(image, x, y, w, h); } } - public void drawPixelated(FImage image, float x, float y, float w, float h, Float amount) { + public void drawRipple(FImage image, float x, float y, float w, float h, Float amount, boolean flipY) { + if (image == null) + return; + if (amount != null) { + batch.end(); + shaderRipple.bind(); + shaderRipple.setUniformf("u_resolution", Forge.isLandscapeMode() ? w : h , Forge.isLandscapeMode() ? h : w); + shaderRipple.setUniformf("u_time", amount); + shaderRipple.setUniformf("u_yflip", flipY ? 1f : 0f); + shaderRipple.setUniformf("u_bias", 0.7f); + batch.setShader(shaderRipple); + batch.begin(); + //draw + image.draw(this, x, y, w, h); + //reset + batch.end(); + batch.setShader(null); + batch.begin(); + } else { + drawImage(image, x, y, w, h); + } + } + public void drawPixelated(FImage image, float x, float y, float w, float h, Float amount, boolean flipY) { if (image == null) return; if (amount != null) { batch.end(); shaderPixelate.bind(); - shaderPixelate.setUniformf("u_resolution", image.getWidth(), image.getHeight()); + shaderPixelate.setUniformf("u_resolution", Forge.isLandscapeMode() ? w : h , Forge.isLandscapeMode() ? h : w); shaderPixelate.setUniformf("u_cellSize", amount); + shaderPixelate.setUniformf("u_yflip", flipY ? 1f : 0f); + shaderPixelate.setUniformf("u_bias", 0.7f); batch.setShader(shaderPixelate); batch.begin(); //draw @@ -861,14 +886,16 @@ public class Graphics { drawImage(image, x, y, w, h); } } - public void drawPixelated(TextureRegion image, float x, float y, float w, float h, Float amount) { + public void drawPixelated(TextureRegion image, float x, float y, float w, float h, Float amount, boolean flipY) { if (image == null) return; if (amount != null) { batch.end(); shaderPixelate.bind(); - shaderPixelate.setUniformf("u_resolution", image.getRegionWidth(), image.getRegionHeight()); + shaderPixelate.setUniformf("u_resolution", Forge.isLandscapeMode() ? w : h , Forge.isLandscapeMode() ? h : w); shaderPixelate.setUniformf("u_cellSize", amount); + shaderPixelate.setUniformf("u_yflip", flipY ? 1 : 0); + shaderPixelate.setUniformf("u_bias", 0.6f); batch.setShader(shaderPixelate); batch.begin(); //draw @@ -951,7 +978,7 @@ public class Graphics { batch.setShader(null); batch.begin(); } - public void drawUnderWaterImage(FImage image, float x, float y, float w, float h, float time, boolean withDarkOverlay) { + public void drawUnderWaterImage(FImage image, float x, float y, float w, float h, float time) { if (image == null) return; batch.end(); @@ -959,6 +986,7 @@ public class Graphics { shaderUnderwater.setUniformf("u_amount", 10f*time); shaderUnderwater.setUniformf("u_speed", 0.5f*time); shaderUnderwater.setUniformf("u_time", time); + shaderUnderwater.setUniformf("u_bias", 0.7f); batch.setShader(shaderUnderwater); batch.begin(); //draw @@ -967,12 +995,6 @@ public class Graphics { batch.end(); batch.setShader(null); batch.begin(); - if(withDarkOverlay){ - float oldalpha = alphaComposite; - setAlphaComposite(0.4f); - fillRect(Color.BLACK, x, y, w, h); - setAlphaComposite(oldalpha); - } } public void drawNightDay(FImage image, float x, float y, float w, float h, Float time) { if (image == null) diff --git a/forge-gui-mobile/src/forge/Shaders.java b/forge-gui-mobile/src/forge/Shaders.java index c409416cd57..b77688e3153 100644 --- a/forge-gui-mobile/src/forge/Shaders.java +++ b/forge-gui-mobile/src/forge/Shaders.java @@ -42,6 +42,40 @@ public class Shaders { " v_texCoords = a_texCoord0;\n" + " gl_Position = u_projTrans * a_position;\n" + "}"; + public static final String fragRipple="#ifdef GL_ES\n" + + "#define PRECISION mediump\n" + + "precision PRECISION float;\n" + + "precision PRECISION int;\n" + + "#else\n" + + "#define PRECISION\n" + + "#endif\n" + + "\n" + + "varying vec2 v_texCoords;\n" + + "uniform sampler2D u_texture;\n" + + "uniform float u_time;\n" + + "uniform vec2 u_resolution;\n" + + "uniform float u_yflip;\n" + + "uniform float u_bias;\n" + + "\n" + + "void main() {\n" + + "\tvec2 uv = v_texCoords;\n" + + "\n" + + " vec2 dv = vec2(0.5,0.5) - uv;\n" + + " float dis = length(dv);\n" + + " float sinFactor =0.02*(4.0*u_time) *sin(dis * 40.0 +u_time* -12.0);\n" + + " float rippleOffset=0.35;\n" + + " float discardFactor = clamp(0.2 - abs(rippleOffset - dis), 0.0, 1.0) / 0.2;\n" + + " \n" + + " vec2 offset = normalize(dv)* sinFactor * discardFactor;\n" + + " uv = offset + uv;\n" + + "\t\n" + + "\tvec4 texColor;\n" + + "\tif (u_yflip > 0)\n" + + "\t\ttexColor = texture2D(u_texture, vec2(uv.x, 1.-uv.y));\n" + + "\telse\n" + + "\t\ttexColor = texture2D(u_texture, uv);\n" + + " gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), texColor, u_bias);\n" + + "}"; public static final String fragChromaticAbberation="#ifdef GL_ES\n" + "#define PRECISION mediump\n" + "precision PRECISION float;\n" + @@ -81,12 +115,18 @@ public class Shaders { "uniform sampler2D u_texture;\n" + "uniform float u_cellSize;\n" + "uniform vec2 u_resolution;\n" + - "varying vec4 v_color;\n" + + "uniform float u_yflip;\n" + + "uniform float u_bias;\n" + "\n" + "void main() {\n" + "\tvec2 p = floor(gl_FragCoord.xy/u_cellSize) * u_cellSize;\n" + - "\tvec4 texColor = texture2D(u_texture, p/u_resolution.xy);\n" + - "\tgl_FragColor = v_color * texColor;\n" + + "\tvec2 p2 = p/u_resolution.xy;\n" + + "\tvec4 texColor;\n" + + "\tif (u_yflip > 0)\n" + + "\t texColor = texture2D(u_texture, vec2(p2.x, 1.-p2.y));\n" + + "\telse\n" + + "\t texColor = texture2D(u_texture, p2);\n" + + "\tgl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), texColor, u_bias);\n" + "}"; public static final String fragPixelateShaderWarp = "#ifdef GL_ES\n" + "precision mediump float;\n" + diff --git a/forge-gui-mobile/src/forge/screens/match/MatchScreen.java b/forge-gui-mobile/src/forge/screens/match/MatchScreen.java index 60c343330f1..b1e5dc32b05 100644 --- a/forge-gui-mobile/src/forge/screens/match/MatchScreen.java +++ b/forge-gui-mobile/src/forge/screens/match/MatchScreen.java @@ -859,10 +859,14 @@ public class MatchScreen extends FScreen { } } else { g.setAlphaComposite(percentage); - if (!daynightTransition) - g.drawGrayTransitionImage(image, x, y, w, h, darkoverlay, 1 - (percentage * 1)); - else - g.drawUnderWaterImage(image, x, y, w, h, 1 - (percentage * 1), darkoverlay); + if (!daynightTransition) { + if (image instanceof FSkinTexture)//for loading bg images + g.drawRipple(image, x, y, w, h, 1 - (percentage * 1), false); + else + g.drawGrayTransitionImage(image, x, y, w, h, darkoverlay, 1 - (percentage * 1)); + } else { //for non adventure transition.. todo generate new daynight + ripple shader for planechase images to use only single image + g.drawUnderWaterImage(image, x, y, w, h, 1 - (percentage * 1)); + } g.setAlphaComposite(oldAlpha); } }