Transition to Framebuffer#blit

This commit is contained in:
Anuken
2020-06-10 21:07:21 -04:00
parent 6648a9ff1a
commit 2a9008f042
12 changed files with 25 additions and 28 deletions

Binary file not shown.

View File

@@ -3,15 +3,12 @@ precision mediump float;
precision mediump int; precision mediump int;
#endif #endif
#define steprad 0.13
uniform sampler2D u_texture; uniform sampler2D u_texture;
uniform vec4 u_ambient; uniform vec4 u_ambient;
varying vec4 v_color;
varying vec2 v_texCoord; varying vec2 v_texCoord;
void main(){ void main(){
vec4 color = texture2D(u_texture, v_texCoord.xy); vec4 color = texture2D(u_texture, v_texCoord);
gl_FragColor = clamp(vec4(mix(u_ambient.rgb, color.rgb, color.a), u_ambient.a - color.a), 0.0, 1.0); gl_FragColor = clamp(vec4(mix(u_ambient.rgb, color.rgb, color.a), u_ambient.a - color.a), 0.0, 1.0);
} }

View File

@@ -0,0 +1,9 @@
attribute vec4 a_position;
attribute vec2 a_texCoord0;
varying vec2 v_texCoord;
void main(){
v_texCoord = a_texCoord0;
gl_Position = a_position;
}

View File

@@ -14,8 +14,8 @@ uniform vec2 u_texsize;
uniform float u_time; uniform float u_time;
uniform float u_dp; uniform float u_dp;
uniform vec2 u_offset; uniform vec2 u_offset;
uniform vec4 u_shieldcolor;
varying vec4 v_color;
varying vec2 v_texCoord; varying vec2 v_texCoord;
void main(){ void main(){
@@ -32,7 +32,7 @@ void main(){
(texture2D(u_texture, T + vec2(0, step) * v).a > 0.0 || texture2D(u_texture, T + vec2(0, -step) * v).a > 0.0 || (texture2D(u_texture, T + vec2(0, step) * v).a > 0.0 || texture2D(u_texture, T + vec2(0, -step) * v).a > 0.0 ||
texture2D(u_texture, T + vec2(step, 0) * v).a > 0.0 || texture2D(u_texture, T + vec2(-step, 0) * v).a > 0.0)){ texture2D(u_texture, T + vec2(step, 0) * v).a > 0.0 || texture2D(u_texture, T + vec2(-step, 0) * v).a > 0.0)){
gl_FragColor = mix(v_color, vec4(1.0), si); gl_FragColor = mix(u_shieldcolor, vec4(1.0), si);
}else{ }else{
if(color.a > 0.0){ if(color.a > 0.0){

View File

@@ -15,7 +15,6 @@ uniform vec2 u_campos;
uniform vec2 u_resolution; uniform vec2 u_resolution;
uniform float u_time; uniform float u_time;
varying vec4 v_color;
varying vec2 v_texCoord; varying vec2 v_texCoord;
void main(){ void main(){

View File

@@ -12,7 +12,6 @@ uniform vec2 u_campos;
uniform vec2 u_resolution; uniform vec2 u_resolution;
uniform float u_time; uniform float u_time;
varying vec4 v_color;
varying vec2 v_texCoord; varying vec2 v_texCoord;
void main(){ void main(){

View File

@@ -9,7 +9,6 @@ uniform vec2 u_campos;
uniform vec2 u_resolution; uniform vec2 u_resolution;
uniform float u_time; uniform float u_time;
varying vec4 v_color;
varying vec2 v_texCoord; varying vec2 v_texCoord;
const float mscl = 40.0; const float mscl = 40.0;

View File

@@ -238,11 +238,7 @@ public class Renderer implements ApplicationListener{
Draw.drawRange(Layer.shields, 1f, () -> effectBuffer.begin(Color.clear), () -> { Draw.drawRange(Layer.shields, 1f, () -> effectBuffer.begin(Color.clear), () -> {
effectBuffer.end(); effectBuffer.end();
Draw.shader(Shaders.shield); effectBuffer.blit(Shaders.shield);
Draw.color(Pal.accent);
Draw.rect(effectBuffer);
Draw.color();
Draw.shader();
}); });
} }

View File

@@ -79,9 +79,7 @@ public enum CacheLayer{
renderer.blocks.floor.endc(); renderer.blocks.floor.endc();
renderer.effectBuffer.end(); renderer.effectBuffer.end();
Draw.shader(shader); renderer.effectBuffer.blit(shader);
Draw.rect(renderer.effectBuffer);
Draw.shader();
renderer.blocks.floor.beginc(); renderer.blocks.floor.beginc();
} }

View File

@@ -195,9 +195,7 @@ public class LightRenderer{
Draw.color(); Draw.color();
Shaders.light.ambient.set(state.rules.ambientLight); Shaders.light.ambient.set(state.rules.ambientLight);
Draw.shader(Shaders.light); buffer.blit(Shaders.light);
Draw.rect(buffer);
Draw.shader();
lights.clear(); lights.clear();
} }

View File

@@ -16,7 +16,7 @@ import static mindustry.Vars.renderer;
public class Shaders{ public class Shaders{
public static BlockBuild blockbuild; public static BlockBuild blockbuild;
public static @Nullable Shield shield; public static @Nullable ShieldShader shield;
public static UnitBuild build; public static UnitBuild build;
public static FogShader fog; public static FogShader fog;
public static LightShader light; public static LightShader light;
@@ -30,7 +30,7 @@ public class Shaders{
public static void init(){ public static void init(){
blockbuild = new BlockBuild(); blockbuild = new BlockBuild();
try{ try{
shield = new Shield(); shield = new ShieldShader();
}catch(Throwable t){ }catch(Throwable t){
//don't load shield shader //don't load shield shader
shield = null; shield = null;
@@ -119,7 +119,7 @@ public class Shaders{
public Color ambient = new Color(0.01f, 0.01f, 0.04f, 0.99f); public Color ambient = new Color(0.01f, 0.01f, 0.04f, 0.99f);
public LightShader(){ public LightShader(){
super("light", "default"); super("light", "screenspace");
} }
@Override @Override
@@ -175,16 +175,18 @@ public class Shaders{
} }
} }
public static class Shield extends LoadShader{ public static class ShieldShader extends LoadShader{
public Color color = Pal.accent.cpy();
public Shield(){ public ShieldShader(){
super("shield", "default"); super("shield", "screenspace");
} }
@Override @Override
public void apply(){ public void apply(){
setUniformf("u_dp", Scl.scl(1f)); setUniformf("u_dp", Scl.scl(1f));
setUniformf("u_time", Time.time() / Scl.scl(1f)); setUniformf("u_time", Time.time() / Scl.scl(1f));
setUniformf("u_shieldcolor", color);
setUniformf("u_offset", setUniformf("u_offset",
Core.camera.position.x - Core.camera.width / 2, Core.camera.position.x - Core.camera.width / 2,
Core.camera.position.y - Core.camera.height / 2); Core.camera.position.y - Core.camera.height / 2);
@@ -196,7 +198,7 @@ public class Shaders{
public static class SurfaceShader extends LoadShader{ public static class SurfaceShader extends LoadShader{
public SurfaceShader(String frag){ public SurfaceShader(String frag){
super(frag, "default"); super(frag, "screenspace");
Core.assets.load("sprites/noise.png", Texture.class).loaded = t -> { Core.assets.load("sprites/noise.png", Texture.class).loaded = t -> {
((Texture)t).setFilter(TextureFilter.Linear); ((Texture)t).setFilter(TextureFilter.Linear);

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=53dae7fe3363a33793daa1d7036cc77f4e0e2797 archash=5d845b94754aa9667c60de503624ff2a51df6e64