mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
update Shaders
This commit is contained in:
@@ -11,6 +11,7 @@ uniform sampler2D u_texture;
|
|||||||
uniform float u_amount;
|
uniform float u_amount;
|
||||||
uniform float u_speed;
|
uniform float u_speed;
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
|
uniform float u_bias;
|
||||||
|
|
||||||
void main () {
|
void main () {
|
||||||
vec2 uv = v_texCoords;
|
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);
|
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);
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ uniform sampler2D u_texture;
|
|||||||
uniform float u_amount;
|
uniform float u_amount;
|
||||||
uniform float u_speed;
|
uniform float u_speed;
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
|
uniform float u_bias;
|
||||||
|
|
||||||
void main () {
|
void main () {
|
||||||
vec2 uv = v_texCoords;
|
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);
|
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);
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ uniform sampler2D u_texture;
|
|||||||
uniform float u_amount;
|
uniform float u_amount;
|
||||||
uniform float u_speed;
|
uniform float u_speed;
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
|
uniform float u_bias;
|
||||||
|
|
||||||
void main () {
|
void main () {
|
||||||
vec2 uv = v_texCoords;
|
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);
|
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);
|
||||||
}
|
}
|
||||||
@@ -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 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 shaderNightDay = new ShaderProgram(Shaders.vertexShaderDayNight, Shaders.fragmentShaderDayNight);
|
||||||
private final ShaderProgram shaderPixelate = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragPixelateShader);
|
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 shaderPixelateWarp = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragPixelateShaderWarp);
|
||||||
private final ShaderProgram shaderChromaticAbberation = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragChromaticAbberation);
|
private final ShaderProgram shaderChromaticAbberation = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragChromaticAbberation);
|
||||||
|
|
||||||
@@ -841,14 +842,38 @@ public class Graphics {
|
|||||||
drawImage(image, x, y, w, h);
|
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)
|
if (image == null)
|
||||||
return;
|
return;
|
||||||
if (amount != null) {
|
if (amount != null) {
|
||||||
batch.end();
|
batch.end();
|
||||||
shaderPixelate.bind();
|
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_cellSize", amount);
|
||||||
|
shaderPixelate.setUniformf("u_yflip", flipY ? 1f : 0f);
|
||||||
|
shaderPixelate.setUniformf("u_bias", 0.7f);
|
||||||
batch.setShader(shaderPixelate);
|
batch.setShader(shaderPixelate);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
//draw
|
//draw
|
||||||
@@ -861,14 +886,16 @@ public class Graphics {
|
|||||||
drawImage(image, x, y, w, h);
|
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)
|
if (image == null)
|
||||||
return;
|
return;
|
||||||
if (amount != null) {
|
if (amount != null) {
|
||||||
batch.end();
|
batch.end();
|
||||||
shaderPixelate.bind();
|
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_cellSize", amount);
|
||||||
|
shaderPixelate.setUniformf("u_yflip", flipY ? 1 : 0);
|
||||||
|
shaderPixelate.setUniformf("u_bias", 0.6f);
|
||||||
batch.setShader(shaderPixelate);
|
batch.setShader(shaderPixelate);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
//draw
|
//draw
|
||||||
@@ -951,7 +978,7 @@ public class Graphics {
|
|||||||
batch.setShader(null);
|
batch.setShader(null);
|
||||||
batch.begin();
|
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)
|
if (image == null)
|
||||||
return;
|
return;
|
||||||
batch.end();
|
batch.end();
|
||||||
@@ -959,6 +986,7 @@ public class Graphics {
|
|||||||
shaderUnderwater.setUniformf("u_amount", 10f*time);
|
shaderUnderwater.setUniformf("u_amount", 10f*time);
|
||||||
shaderUnderwater.setUniformf("u_speed", 0.5f*time);
|
shaderUnderwater.setUniformf("u_speed", 0.5f*time);
|
||||||
shaderUnderwater.setUniformf("u_time", time);
|
shaderUnderwater.setUniformf("u_time", time);
|
||||||
|
shaderUnderwater.setUniformf("u_bias", 0.7f);
|
||||||
batch.setShader(shaderUnderwater);
|
batch.setShader(shaderUnderwater);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
//draw
|
//draw
|
||||||
@@ -967,12 +995,6 @@ public class Graphics {
|
|||||||
batch.end();
|
batch.end();
|
||||||
batch.setShader(null);
|
batch.setShader(null);
|
||||||
batch.begin();
|
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) {
|
public void drawNightDay(FImage image, float x, float y, float w, float h, Float time) {
|
||||||
if (image == null)
|
if (image == null)
|
||||||
|
|||||||
@@ -42,6 +42,40 @@ public class Shaders {
|
|||||||
" v_texCoords = a_texCoord0;\n" +
|
" v_texCoords = a_texCoord0;\n" +
|
||||||
" gl_Position = u_projTrans * a_position;\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" +
|
public static final String fragChromaticAbberation="#ifdef GL_ES\n" +
|
||||||
"#define PRECISION mediump\n" +
|
"#define PRECISION mediump\n" +
|
||||||
"precision PRECISION float;\n" +
|
"precision PRECISION float;\n" +
|
||||||
@@ -81,12 +115,18 @@ public class Shaders {
|
|||||||
"uniform sampler2D u_texture;\n" +
|
"uniform sampler2D u_texture;\n" +
|
||||||
"uniform float u_cellSize;\n" +
|
"uniform float u_cellSize;\n" +
|
||||||
"uniform vec2 u_resolution;\n" +
|
"uniform vec2 u_resolution;\n" +
|
||||||
"varying vec4 v_color;\n" +
|
"uniform float u_yflip;\n" +
|
||||||
|
"uniform float u_bias;\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"void main() {\n" +
|
"void main() {\n" +
|
||||||
"\tvec2 p = floor(gl_FragCoord.xy/u_cellSize) * u_cellSize;\n" +
|
"\tvec2 p = floor(gl_FragCoord.xy/u_cellSize) * u_cellSize;\n" +
|
||||||
"\tvec4 texColor = texture2D(u_texture, p/u_resolution.xy);\n" +
|
"\tvec2 p2 = p/u_resolution.xy;\n" +
|
||||||
"\tgl_FragColor = v_color * texColor;\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" +
|
public static final String fragPixelateShaderWarp = "#ifdef GL_ES\n" +
|
||||||
"precision mediump float;\n" +
|
"precision mediump float;\n" +
|
||||||
|
|||||||
@@ -859,10 +859,14 @@ public class MatchScreen extends FScreen {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g.setAlphaComposite(percentage);
|
g.setAlphaComposite(percentage);
|
||||||
if (!daynightTransition)
|
if (!daynightTransition) {
|
||||||
g.drawGrayTransitionImage(image, x, y, w, h, darkoverlay, 1 - (percentage * 1));
|
if (image instanceof FSkinTexture)//for loading bg images
|
||||||
|
g.drawRipple(image, x, y, w, h, 1 - (percentage * 1), false);
|
||||||
else
|
else
|
||||||
g.drawUnderWaterImage(image, x, y, w, h, 1 - (percentage * 1), darkoverlay);
|
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);
|
g.setAlphaComposite(oldAlpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user