Merge pull request #1984 from kevlahnota/newmaster2

update Shaders
This commit is contained in:
Anthony Calosa
2022-11-29 16:47:06 +08:00
committed by GitHub
8 changed files with 40 additions and 43 deletions

View File

@@ -6,10 +6,11 @@ varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform float u_grayness;
uniform float u_bias;
void main() {
vec4 c = v_color * texture2D(u_texture, v_texCoords);
float grey = dot( c.rgb, vec3(0.22, 0.707, 0.071) );
vec3 blendedColor = mix(c.rgb, vec3(grey), u_grayness);
gl_FragColor = vec4(blendedColor.rgb, c.a);
gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), vec4(blendedColor.rgb, c.a), u_bias);
}

View File

@@ -6,10 +6,11 @@ varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform float u_grayness;
uniform float u_bias;
void main() {
vec4 c = v_color * texture2D(u_texture, v_texCoords);
float grey = dot( c.rgb, vec3(0.22, 0.707, 0.071) );
vec3 blendedColor = mix(c.rgb, vec3(grey), u_grayness);
gl_FragColor = vec4(blendedColor.rgb, c.a);
gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), vec4(blendedColor.rgb, c.a), u_bias);
}

View File

@@ -6,10 +6,11 @@ varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform float u_grayness;
uniform float u_bias;
void main() {
vec4 c = v_color * texture2D(u_texture, v_texCoords);
float grey = dot( c.rgb, vec3(0.22, 0.707, 0.071) );
vec3 blendedColor = mix(c.rgb, vec3(grey), u_grayness);
gl_FragColor = vec4(blendedColor.rgb, c.a);
gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), vec4(blendedColor.rgb, c.a), u_bias);
}

View File

@@ -693,6 +693,7 @@ public class Graphics {
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", 1f);
shaderGrayscale.setUniformf("u_bias", 1f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
@@ -714,6 +715,7 @@ public class Graphics {
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", 1f);
shaderGrayscale.setUniformf("u_bias", 0.8f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
@@ -733,6 +735,7 @@ public class Graphics {
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", 1f);
shaderGrayscale.setUniformf("u_bias", 0.8f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
@@ -753,6 +756,7 @@ public class Graphics {
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", 1f);
shaderGrayscale.setUniformf("u_bias", 0.8f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
@@ -764,12 +768,13 @@ public class Graphics {
}
}
}
public void drawGrayTransitionImage(FImage image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) {
public void drawGrayTransitionImage(FImage image, float x, float y, float w, float h, float percentage) {
if (image == null)
return;
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", percentage);
shaderGrayscale.setUniformf("u_bias", 0.5f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
@@ -778,17 +783,12 @@ 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 drawGrayTransitionImage(Texture image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) {
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", percentage);
shaderGrayscale.setUniformf("u_bias", withDarkOverlay ? 0.4f : 1f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
@@ -797,17 +797,12 @@ 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 drawGrayTransitionImage(TextureRegion image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) {
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", percentage);
shaderGrayscale.setUniformf("u_bias", withDarkOverlay ? 0.4f : 1f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
@@ -816,12 +811,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 drawChromatic(TextureRegion image, float x, float y, float w, float h, Float time) {
if (image == null)
@@ -848,10 +837,9 @@ public class Graphics {
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);
shaderRipple.setUniformf("u_bias", 0.5f);
batch.setShader(shaderRipple);
batch.begin();
//draw

View File

@@ -50,31 +50,31 @@ public class Shaders {
"#define PRECISION\n" +
"#endif\n" +
"\n" +
"varying vec2 v_texCoords;\n" +
"uniform sampler2D u_texture;\n" +
"varying vec2 v_texCoords;\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" +
"\tvec2 center = vec2(0.0);\n" +
"\tvec2 coord = uv;\n" +
"\tvec2 centered_coord = (2.0 * uv) - 1.0;\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" +
"\tfloat shutter = 0.9;\n" +
"\tfloat texelDistance = distance(center, centered_coord) * u_time;\n" +
"\tfloat dist = (1.41 * 1.41 * shutter) - texelDistance;\n" +
"\n" +
"\tfloat ripples = 1.0 - sin((texelDistance * 32.0) - (2.0 * u_time));\n" +
"\tcoord -= normalize(centered_coord - center) * clamp(ripples, 0.0, 1.0)*(0.050 * u_time);\n" +
" \n" +
" vec2 offset = normalize(dv)* sinFactor * discardFactor;\n" +
" uv = offset + uv;\n" +
"\t\n" +
"\tvec4 texColor;\n" +
"\tvec4 color;\n" +
"\tif (u_yflip > 0)\n" +
"\t\ttexColor = texture2D(u_texture, vec2(uv.x, 1.-uv.y));\n" +
"\t\tcolor = texture2D(u_texture, vec2(coord.x, 1.-coord.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" +
"\t\tcolor = texture2D(u_texture, coord);\n" +
"\tgl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), vec4(color.rgba * dist), u_bias);\n" +
"}";
public static final String fragChromaticAbberation="#ifdef GL_ES\n" +
"#define PRECISION mediump\n" +

View File

@@ -175,6 +175,8 @@ public class RewardScene extends UIScene {
done(true);
else if (type == Type.Loot && !shown) {
shown = true;
float delay = 0.09f;
generated.shuffle();
for (Actor actor : new Array.ArrayIterator<>(generated)) {
if (!(actor instanceof RewardActor)) {
continue;
@@ -186,7 +188,8 @@ public class RewardScene extends UIScene {
public void run() {
reward.flip();
}
}, 0.09f);
}, delay);
delay += 0.15f;
}
}
} else {

View File

@@ -617,6 +617,7 @@ public boolean toolTipIsVisible()
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", 1f);
shaderGrayscale.setUniformf("u_bias", 0.7f);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray

View File

@@ -845,6 +845,8 @@ public class MatchScreen extends FScreen {
} else if (percentage > 1) {
percentage = 1;
}
if (MatchController.instance.getGameView().isMatchOver())
percentage=1;
if (Forge.isMobileAdventureMode) {
if (percentage < 1)
g.drawNightDay(currentBG, x, y, w, h, time);
@@ -860,10 +862,10 @@ public class MatchScreen extends FScreen {
} else {
g.setAlphaComposite(percentage);
if (!daynightTransition) {
if (image instanceof FSkinTexture)//for loading bg images
if (image instanceof FSkinTexture && !GuiBase.isAndroid()) //for loading bg images, currently android version cant load this ripple shader
g.drawRipple(image, x, y, w, h, 1 - (percentage * 1), false);
else
g.drawGrayTransitionImage(image, x, y, w, h, darkoverlay, 1 - (percentage * 1));
g.drawGrayTransitionImage(image, x, y, w, h, 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));
}
@@ -945,7 +947,7 @@ public class MatchScreen extends FScreen {
bgFullWidth = w;
bgHeight = scaledbgHeight;
}
if (bgAnimation != null && !isGameFast && !MatchController.instance.getGameView().isMatchOver()) {
if (bgAnimation != null && !isGameFast) {
bgAnimation.drawBackground(g, matchBG, x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, !Forge.isMobileAdventureMode, true);
} else {
g.drawImage(matchBG, x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, !Forge.isMobileAdventureMode);
@@ -969,7 +971,7 @@ public class MatchScreen extends FScreen {
bgFullWidth = w;
bgHeight = scaledbgHeight;
}
if (bgAnimation != null && !isGameFast && !MatchController.instance.getGameView().isMatchOver()) {
if (bgAnimation != null && !isGameFast) {
bgAnimation.drawBackground(g, FSkinTexture.valueOf(imageName), x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, true, false);
} else {
g.drawImage(FSkinTexture.valueOf(imageName), x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, true);