mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-10-03 03:31:28 +03:00
Misc fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#define HIGHP
|
#define HIGHP
|
||||||
|
|
||||||
uniform sampler2D u_texture;
|
uniform highp sampler2DArray u_texture;
|
||||||
|
|
||||||
uniform vec2 u_texsize;
|
uniform vec2 u_texsize;
|
||||||
uniform vec2 u_uv;
|
uniform vec2 u_uv;
|
||||||
@@ -10,22 +10,23 @@ uniform float u_time;
|
|||||||
uniform float u_alpha;
|
uniform float u_alpha;
|
||||||
|
|
||||||
varying vec4 v_color;
|
varying vec4 v_color;
|
||||||
varying vec2 v_texCoords;
|
varying vec3 v_texCoords;
|
||||||
|
|
||||||
|
|
||||||
bool id(vec2 coords, vec4 base){
|
bool id(vec2 coords, vec4 base, float depth){
|
||||||
vec4 target = texture2D(u_texture, coords);
|
vec4 target = texture2D(u_texture, vec3(coords, depth));
|
||||||
return target.a < 0.1 || (coords.x < u_uv.x || coords.y < u_uv.y || coords.x > u_uv2.x || coords.y > u_uv2.y);
|
return target.a < 0.1 || (coords.x < u_uv.x || coords.y < u_uv.y || coords.x > u_uv2.x || coords.y > u_uv2.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cont(vec2 T, vec2 v){
|
bool cont(vec3 coords, vec2 v){
|
||||||
const float step = 3.5;
|
const float step = 3.5;
|
||||||
vec4 base = texture2D(u_texture, T);
|
vec4 base = texture(u_texture, coords);
|
||||||
|
vec2 T = coords.xy;
|
||||||
return base.a > 0.1 &&
|
return base.a > 0.1 &&
|
||||||
(id(T + vec2(0, step) * v, base) || id(T + vec2(0, -step) * v, base) ||
|
(id(T + vec2(0, step) * v, base, coords.z) || id(T + vec2(0, -step) * v, base, coords.z) ||
|
||||||
id(T + vec2(step, 0) * v, base) || id(T + vec2(-step, 0) * v, base) ||
|
id(T + vec2(step, 0) * v, base, coords.z) || id(T + vec2(-step, 0) * v, base, coords.z) ||
|
||||||
id(T + vec2(step, step) * v, base) || id(T + vec2(step, -step) * v, base) ||
|
id(T + vec2(step, step) * v, base, coords.z) || id(T + vec2(step, -step) * v, base, coords.z) ||
|
||||||
id(T + vec2(-step, -step) * v, base) || id(T + vec2(-step, step) * v, base));
|
id(T + vec2(-step, -step) * v, base, coords.z) || id(T + vec2(-step, step) * v, base, coords.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 blend(vec4 dst, vec4 src){
|
vec4 blend(vec4 dst, vec4 src){
|
||||||
@@ -34,18 +35,16 @@ vec4 blend(vec4 dst, vec4 src){
|
|||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
|
|
||||||
vec2 t = v_texCoords.xy;
|
|
||||||
|
|
||||||
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
||||||
vec2 coords = (v_texCoords-u_uv) / v;
|
vec2 coords = (v_texCoords.xy-u_uv) / v;
|
||||||
float value = coords.x + coords.y;
|
float value = coords.x + coords.y;
|
||||||
|
|
||||||
vec4 color = texture2D(u_texture, t);
|
vec4 color = texture(u_texture, v_texCoords);
|
||||||
|
|
||||||
vec2 center = ((u_uv + u_uv2)/2.0 - u_uv) /v;
|
vec2 center = ((u_uv + u_uv2)/2.0 - u_uv) /v;
|
||||||
float dst = (abs(center.x - coords.x) + abs(center.y - coords.y))/2.0;
|
float dst = (abs(center.x - coords.x) + abs(center.y - coords.y))/2.0;
|
||||||
|
|
||||||
if((mod(u_time / 1.5 + value, 20.0) < 15.0 && cont(t, v))){
|
if((mod(u_time / 1.5 + value, 20.0) < 15.0 && cont(v_texCoords, v))){
|
||||||
gl_FragColor = blend(color, v_color) * vec4(vec3(1.0), u_alpha);
|
gl_FragColor = blend(color, v_color) * vec4(vec3(1.0), u_alpha);
|
||||||
}else if(dst > (1.0-u_progress) * (center.x)){
|
}else if(dst > (1.0-u_progress) * (center.x)){
|
||||||
gl_FragColor = color * vec4(vec3(1.0), u_alpha);
|
gl_FragColor = color * vec4(vec3(1.0), u_alpha);
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
uniform mat4 u_projTrans;
|
||||||
|
|
||||||
|
attribute vec4 a_position;
|
||||||
|
attribute vec3 a_texCoord0;
|
||||||
|
attribute vec4 a_color;
|
||||||
|
|
||||||
|
varying vec4 v_color;
|
||||||
|
varying vec3 v_texCoords;
|
||||||
|
|
||||||
|
uniform vec2 u_viewportInverse;
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
gl_Position = u_projTrans * a_position;
|
||||||
|
v_texCoords = a_texCoord0;
|
||||||
|
v_color = a_color;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
uniform sampler2D u_texture;
|
uniform highp sampler2DArray u_texture;
|
||||||
|
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
uniform float u_progress;
|
uniform float u_progress;
|
||||||
@@ -8,13 +8,13 @@ uniform vec2 u_uv2;
|
|||||||
uniform vec2 u_texsize;
|
uniform vec2 u_texsize;
|
||||||
|
|
||||||
varying vec4 v_color;
|
varying vec4 v_color;
|
||||||
varying vec2 v_texCoords;
|
varying vec3 v_texCoords;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
vec2 coords = (v_texCoords - u_uv) / (u_uv2 - u_uv);
|
vec2 coords = (v_texCoords.xy - u_uv) / (u_uv2 - u_uv);
|
||||||
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
||||||
|
|
||||||
vec4 c = texture2D(u_texture, v_texCoords);
|
vec4 c = texture(u_texture, v_texCoords);
|
||||||
float alpha = c.a;
|
float alpha = c.a;
|
||||||
|
|
||||||
c.a *= u_progress;
|
c.a *= u_progress;
|
||||||
|
|||||||
@@ -57,13 +57,18 @@ public class EditorRenderer implements Disposable{
|
|||||||
attribute vec4 a_position;
|
attribute vec4 a_position;
|
||||||
attribute vec4 a_color;
|
attribute vec4 a_color;
|
||||||
attribute vec2 a_texCoord0;
|
attribute vec2 a_texCoord0;
|
||||||
|
attribute float a_depth;
|
||||||
|
|
||||||
uniform mat4 u_projTrans;
|
uniform mat4 u_projTrans;
|
||||||
varying vec4 v_color;
|
varying vec4 v_color;
|
||||||
varying vec2 v_texCoords;
|
varying vec2 v_texCoords;
|
||||||
|
varying float v_depth;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
v_color = a_color;
|
v_color = a_color;
|
||||||
v_color.a = v_color.a * (255.0/254.0);
|
v_color.a = v_color.a * (255.0/254.0);
|
||||||
v_texCoords = a_texCoord0;
|
v_texCoords = a_texCoord0;
|
||||||
|
v_depth = a_depth;
|
||||||
gl_Position = u_projTrans * a_position;
|
gl_Position = u_projTrans * a_position;
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
@@ -71,10 +76,11 @@ public class EditorRenderer implements Disposable{
|
|||||||
"""
|
"""
|
||||||
varying lowp vec4 v_color;
|
varying lowp vec4 v_color;
|
||||||
varying vec2 v_texCoords;
|
varying vec2 v_texCoords;
|
||||||
uniform sampler2D u_texture;
|
varying float v_depth;
|
||||||
|
uniform highp sampler2DArray u_texture;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
gl_FragColor = v_color * texture2D(u_texture, v_texCoords);
|
gl_FragColor = v_color * texture2D(u_texture, vec3(v_texCoords, v_depth));
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,22 +4,21 @@ import arc.graphics.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.graphics.gl.*;
|
import arc.graphics.gl.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.struct.*;
|
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
|
||||||
public class EditorSpriteCache implements Disposable{
|
public class EditorSpriteCache implements Disposable{
|
||||||
//packed xy + color + packed uv
|
//packed xy + color + packed uv + depth
|
||||||
static final int vertexSize = 1 + 1 + 1;
|
static final int vertexSize = 1 + 1 + 1 + 1;
|
||||||
|
|
||||||
private @Nullable Mesh mesh;
|
private @Nullable Mesh mesh;
|
||||||
private final Seq<Texture> textures = new Seq<>(8);
|
private int count;
|
||||||
private final IntSeq counts = new IntSeq(8);
|
|
||||||
private final float packX, packY, packW, packH;
|
private final float packX, packY, packW, packH;
|
||||||
|
|
||||||
private float[] tmpVertices;
|
private float[] tmpVertices;
|
||||||
|
|
||||||
/** Index in tmpVertices of current vertex data. */
|
/** Index in tmpVertices of current vertex data. */
|
||||||
private int index;
|
private int index;
|
||||||
|
private Texture texture;
|
||||||
|
|
||||||
/** @param tmpVertices Temporary buffer to hold vertices while building up sprites. Should be large enough to hold all sprite data this cache will contain. */
|
/** @param tmpVertices Temporary buffer to hold vertices while building up sprites. Should be large enough to hold all sprite data this cache will contain. */
|
||||||
public EditorSpriteCache(float[] tmpVertices, float packX, float packY, float packW, float packH){
|
public EditorSpriteCache(float[] tmpVertices, float packX, float packY, float packW, float packH){
|
||||||
@@ -48,7 +47,8 @@ public class EditorSpriteCache implements Disposable{
|
|||||||
mesh = new Mesh(true, index / vertexSize, 0,
|
mesh = new Mesh(true, index / vertexSize, 0,
|
||||||
VertexAttribute.packedPosition,
|
VertexAttribute.packedPosition,
|
||||||
VertexAttribute.color,
|
VertexAttribute.color,
|
||||||
VertexAttribute.packedTexCoords
|
VertexAttribute.packedTexCoords,
|
||||||
|
VertexAttribute.depthCoords
|
||||||
);
|
);
|
||||||
mesh.indices = indices;
|
mesh.indices = indices;
|
||||||
mesh.setVertices(tmpVertices, 0, index);
|
mesh.setVertices(tmpVertices, 0, index);
|
||||||
@@ -115,32 +115,31 @@ public class EditorSpriteCache implements Disposable{
|
|||||||
int idx = index;
|
int idx = index;
|
||||||
float[] verts = tmpVertices;
|
float[] verts = tmpVertices;
|
||||||
Texture texture = region.texture;
|
Texture texture = region.texture;
|
||||||
|
float depth = texture.getDepth();
|
||||||
|
|
||||||
verts[idx + 0] = pack(x1, y1);
|
verts[idx + 0] = pack(x1, y1);
|
||||||
verts[idx + 1] = colorPacked;
|
verts[idx + 1] = colorPacked;
|
||||||
verts[idx + 2] = Pack.packUv(u, v);
|
verts[idx + 2] = Pack.packUv(u, v);
|
||||||
|
verts[idx + 3] = depth;
|
||||||
|
|
||||||
verts[idx + 3] = pack(x2, y2);
|
verts[idx + 4] = pack(x2, y2);
|
||||||
verts[idx + 4] = colorPacked;
|
verts[idx + 5] = colorPacked;
|
||||||
verts[idx + 5] = Pack.packUv(u, v2);
|
verts[idx + 6] = Pack.packUv(u, v2);
|
||||||
|
verts[idx + 7] = depth;
|
||||||
|
|
||||||
verts[idx + 6] = pack(x3, y3);
|
verts[idx + 8] = pack(x3, y3);
|
||||||
verts[idx + 7] = colorPacked;
|
verts[idx + 9] = colorPacked;
|
||||||
verts[idx + 8] = Pack.packUv(u2, v2);
|
verts[idx + 10] = Pack.packUv(u2, v2);
|
||||||
|
verts[idx + 11] = depth;
|
||||||
|
|
||||||
verts[idx + 9] = pack(x4, y4);
|
verts[idx + 12] = pack(x4, y4);
|
||||||
verts[idx + 10] = colorPacked;
|
verts[idx + 13] = colorPacked;
|
||||||
verts[idx + 11] = Pack.packUv(u2, v);
|
verts[idx + 14] = Pack.packUv(u2, v);
|
||||||
|
verts[idx + 15] = depth;
|
||||||
int lastIndex = textures.size - 1;
|
|
||||||
if(lastIndex < 0 || textures.get(lastIndex) != texture){
|
|
||||||
textures.add(texture);
|
|
||||||
counts.add(6);
|
|
||||||
}else{
|
|
||||||
counts.incr(lastIndex, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
count += 6;
|
||||||
index += vertexSize * 4;
|
index += vertexSize * 4;
|
||||||
|
this.texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float pack(float x, float y){
|
private float pack(float x, float y){
|
||||||
@@ -151,15 +150,8 @@ public class EditorSpriteCache implements Disposable{
|
|||||||
public void render(Shader shader){
|
public void render(Shader shader){
|
||||||
if(mesh == null) throw new IllegalStateException("Cache is empty, call build() first.");
|
if(mesh == null) throw new IllegalStateException("Cache is empty, call build() first.");
|
||||||
|
|
||||||
int offset = 0;
|
texture.bind();
|
||||||
|
mesh.render(shader, Gl.triangles, 0, count);
|
||||||
for(int i = 0; i < textures.size; i++){
|
|
||||||
int count = counts.items[i];
|
|
||||||
textures.get(i).bind();
|
|
||||||
|
|
||||||
mesh.render(shader, Gl.triangles, offset, count);
|
|
||||||
offset += count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -525,20 +525,22 @@ public class FloorRenderer{
|
|||||||
@Override
|
@Override
|
||||||
protected void draw(Texture texture, float[] spriteVertices, int offset, int count){
|
protected void draw(Texture texture, float[] spriteVertices, int offset, int count){
|
||||||
//TODO broken
|
//TODO broken
|
||||||
if(spriteVertices.length != 20){
|
if(spriteVertices.length != 24){
|
||||||
throw new IllegalArgumentException("cached vertices must be in non-mixcolor format (20 per sprite, 5 per vertex)");
|
throw new IllegalArgumentException("cached vertices must be in non-mixcolor format (24 per sprite, 6 per vertex: x y color u v depth)");
|
||||||
}
|
}
|
||||||
|
|
||||||
float[] verts = vertices;
|
float[] verts = vertices;
|
||||||
float[] src = spriteVertices;
|
float[] src = spriteVertices;
|
||||||
int idx = vidx;
|
int idx = vidx;
|
||||||
int sidx = offset;
|
int sidx = offset;
|
||||||
|
float depth = texture.getDepth();
|
||||||
|
|
||||||
//convert 5-float format to internal packed 3-float format
|
//convert 5-float format to internal packed 3-float format
|
||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
verts[idx++] = pack(src[sidx++], src[sidx++]);
|
verts[idx++] = pack(src[sidx++], src[sidx++]);
|
||||||
verts[idx++] = src[sidx++];
|
verts[idx++] = src[sidx++];
|
||||||
verts[idx++] = Pack.packUv(src[sidx++], src[sidx++]);
|
verts[idx++] = Pack.packUv(src[sidx++], src[sidx++]);
|
||||||
|
verts[idx++] = depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
vidx += spriteSize;
|
vidx += spriteSize;
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ public class Shaders{
|
|||||||
public TextureRegion region;
|
public TextureRegion region;
|
||||||
|
|
||||||
public UnitBuildShader(){
|
public UnitBuildShader(){
|
||||||
super("unitbuild", "default");
|
super("unitbuild", "default_batch");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -243,7 +243,7 @@ public class Shaders{
|
|||||||
public float time;
|
public float time;
|
||||||
|
|
||||||
public BlockBuildShader(){
|
public BlockBuildShader(){
|
||||||
super("blockbuild", "default");
|
super("blockbuild", "default_batch");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -477,6 +477,7 @@ public class Shaders{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class LoadShader extends Shader{
|
public static class LoadShader extends Shader{
|
||||||
|
|
||||||
public LoadShader(String frag, String vert){
|
public LoadShader(String frag, String vert){
|
||||||
super(getShaderFi(vert + ".vert"), getShaderFi(frag + ".frag"));
|
super(getShaderFi(vert + ".vert"), getShaderFi(frag + ".frag"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ public class ColoredFloor extends Floor{
|
|||||||
/** If the alpha value of the color is set to this value, colors are interpolated across corners. This is essentially linear filtering for the whole "image". */
|
/** If the alpha value of the color is set to this value, colors are interpolated across corners. This is essentially linear filtering for the whole "image". */
|
||||||
public static final int flagSmoothBlend = 2;
|
public static final int flagSmoothBlend = 2;
|
||||||
|
|
||||||
//4x (pos2 color uv2)
|
//4x (pos2 color uv2 depth)
|
||||||
private static final float[] verts = new float[4 * 5];
|
private static final float[] verts = new float[4 * 6];
|
||||||
|
|
||||||
public Color defaultColor = Color.white;
|
public Color defaultColor = Color.white;
|
||||||
protected int defaultColorRgba;
|
protected int defaultColorRgba;
|
||||||
@@ -85,30 +85,35 @@ public class ColoredFloor extends Floor{
|
|||||||
var region = autotileRegions[TileBitmask.values[bits]];
|
var region = autotileRegions[TileBitmask.values[bits]];
|
||||||
float s = Vars.tilesize/2f;
|
float s = Vars.tilesize/2f;
|
||||||
float x = tile.worldx(), y = tile.worldy();
|
float x = tile.worldx(), y = tile.worldy();
|
||||||
|
float depth = region.getDepth();
|
||||||
|
|
||||||
verts[0] = x - s;
|
verts[0] = x - s;
|
||||||
verts[1] = y - s;
|
verts[1] = y - s;
|
||||||
verts[2] = sample(this, tile.x, tile.y, tile.x - 1, tile.y - 1, tile.x, tile.y - 1, tile.x - 1, tile.y);
|
verts[2] = sample(this, tile.x, tile.y, tile.x - 1, tile.y - 1, tile.x, tile.y - 1, tile.x - 1, tile.y);
|
||||||
verts[3] = region.u;
|
verts[3] = region.u;
|
||||||
verts[4] = region.v2;
|
verts[4] = region.v2;
|
||||||
|
verts[5] = depth;
|
||||||
|
|
||||||
verts[5] = x + s;
|
verts[6] = x + s;
|
||||||
verts[6] = y - s;
|
verts[7] = y - s;
|
||||||
verts[7] = sample(this, tile.x, tile.y, tile.x, tile.y - 1, tile.x + 1, tile.y - 1, tile.x + 1, tile.y);
|
verts[8] = sample(this, tile.x, tile.y, tile.x, tile.y - 1, tile.x + 1, tile.y - 1, tile.x + 1, tile.y);
|
||||||
verts[8] = region.u2;
|
verts[9] = region.u2;
|
||||||
verts[9] = region.v2;
|
verts[10] = region.v2;
|
||||||
|
verts[11] = depth;
|
||||||
|
|
||||||
verts[10] = x + s;
|
verts[12] = x + s;
|
||||||
verts[11] = y + s;
|
verts[13] = y + s;
|
||||||
verts[12] = sample(this, tile.x, tile.y, tile.x + 1, tile.y + 1, tile.x, tile.y + 1, tile.x + 1, tile.y);
|
verts[14] = sample(this, tile.x, tile.y, tile.x + 1, tile.y + 1, tile.x, tile.y + 1, tile.x + 1, tile.y);
|
||||||
verts[13] = region.u2;
|
verts[15] = region.u2;
|
||||||
verts[14] = region.v;
|
verts[16] = region.v;
|
||||||
|
verts[17] = depth;
|
||||||
|
|
||||||
verts[15] = x - s;
|
verts[18] = x - s;
|
||||||
verts[16] = y + s;
|
verts[19] = y + s;
|
||||||
verts[17] = sample(this, tile.x, tile.y, tile.x - 1, tile.y + 1, tile.x, tile.y + 1, tile.x - 1, tile.y);
|
verts[20] = sample(this, tile.x, tile.y, tile.x - 1, tile.y + 1, tile.x, tile.y + 1, tile.x - 1, tile.y);
|
||||||
verts[18] = region.u;
|
verts[21] = region.u;
|
||||||
verts[19] = region.v;
|
verts[22] = region.v;
|
||||||
|
verts[23] = depth;
|
||||||
|
|
||||||
Draw.vert(region.texture, verts, 0, verts.length);
|
Draw.vert(region.texture, verts, 0, verts.length);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
+1
-1
@@ -26,4 +26,4 @@ org.gradle.caching=true
|
|||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
android.enableR8.fullMode=false
|
android.enableR8.fullMode=false
|
||||||
archash=1d92c52fcc
|
archash=fcc3251f16
|
||||||
|
|||||||
Reference in New Issue
Block a user