Skip to content

Commit 8452e8a

Browse files
committed
не робит нихуя
1 parent 70757c6 commit 8452e8a

File tree

10 files changed

+185
-84
lines changed

10 files changed

+185
-84
lines changed

res/data/builder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
durmiendo/98
1+
durmiendo/192

res/shaders/normal.frag

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,49 @@
22

33
uniform sampler2D u_normal;
44
uniform sampler2D u_texture;
5+
//uniform sampler2D u_textures;
56
uniform vec2 u_texsize;
67
uniform vec2 u_offset;
78
uniform vec2 u_lightPos;
89
uniform vec4 u_lightColor;
910

1011
varying vec2 v_texCoords;
12+
varying lowp vec4 v_color;
13+
varying lowp vec4 v_mix_color;
14+
15+
//void main(){
16+
// gl_FragColor = v_color * mix(c, vec4(v_mix_color.rgb, c.a), v_mix_color.a);
17+
// gl_FragColor.r = 1.;
18+
//}
19+
1120

1221
void main() {
1322
vec2 T = v_texCoords.xy;
14-
// vec2 coords = (T * u_texsize) + u_offset;
15-
// vec3 normal = vec3(texture2D(u_normal, T).r*2.-1.,(texture2D(u_normal, T).b*2.-1.),texture2D(u_normal, T).g);
16-
//
17-
//
18-
// vec3 lightPos = vec3(u_lightPos.x, u_lightPos.y, 24.);
19-
// vec3 surfacePos = vec3(coords.x, coords.y, 8.);
20-
//
21-
//
22-
// vec3 N = normalize(normal);
23-
// vec3 LightDir = lightPos.xyz-surfacePos.xyz;
24-
// float D = length(LightDir)/1024.;
25-
// vec3 L = normalize(LightDir);
26-
//
27-
// vec3 Diffuse = (u_lightColor.rgb * u_lightColor.a) * max(dot(N, L), 0.0);
28-
// vec3 Ambient = vec3(0.22, 0.22, 0.3);
29-
// float Attenuation = 1.0 / (.4 + 3.*D + 20.*D*D);
30-
//
31-
// vec3 Intensity = Ambient + Diffuse * Attenuation;
32-
// vec3 FinalColor = texture2D(u_normal, T).rgb * Intensity;
33-
// gl_FragColor = vec4(FinalColor, texture2D(u_texture, T).a);
34-
// gl_FragColor = texture2D(u_normal, T);
35-
gl_FragColor = vec4(1.0);
23+
vec2 coords = (T * u_texsize) + u_offset;
24+
vec3 normal = vec3(texture2D(u_normal, T).r*2.-1.,(texture2D(u_normal, T).b*2.-1.),texture2D(u_normal, T).g);
25+
26+
27+
vec3 lightPos = vec3(u_lightPos.x, u_lightPos.y, 24.);
28+
vec3 surfacePos = vec3(coords.x, coords.y, 8.);
29+
30+
31+
vec3 N = normalize(normal);
32+
vec3 LightDir = lightPos.xyz-surfacePos.xyz;
33+
float D = length(LightDir)/1024.;
34+
vec3 L = normalize(LightDir);
35+
36+
vec3 Diffuse = (u_lightColor.rgb * u_lightColor.a) * max(dot(N, L), 0.0);
37+
vec3 Ambient = vec3(0.22, 0.22, 0.3);
38+
float Attenuation = 1.0 / (.4 + 3.*D + 20.*D*D);
39+
40+
vec3 Intensity = Ambient + Diffuse * Attenuation;
41+
42+
vec4 c = texture2D(u_texture, v_texCoords);
43+
44+
vec4 rc = v_color * mix(c, vec4(v_mix_color.rgb, c.a), v_mix_color.a);
45+
46+
vec3 FinalColor = rc.rgb * Intensity;
47+
gl_FragColor = texture2D(u_normal, T);
48+
// gl_FragColor = vec4(texture2D(u_normal, T).rgb, rc.a);
3649
}
50+
//

res/shaders/normal.vert

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
attribute vec4 a_position;
2+
attribute vec4 a_color;
23
attribute vec2 a_texCoord0;
3-
4+
attribute vec4 a_mix_color;
5+
uniform mat4 u_projTrans;
6+
varying vec4 v_color;
7+
varying vec4 v_mix_color;
48
varying vec2 v_texCoords;
59

610
void main(){
11+
v_color = a_color;
12+
v_color.a = v_color.a * (255.0/254.0);
13+
v_mix_color = a_mix_color;
14+
v_mix_color.a *= (255.0/254.0);
715
v_texCoords = a_texCoord0;
8-
gl_Position = a_position;
16+
gl_Position = u_projTrans * a_position;
917
}

src/org/durmiendo/sueno/core/SVars.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import arc.files.Fi;
44
import arc.graphics.Texture;
55
import arc.struct.ObjectMap;
6+
import arc.struct.ObjectSet;
67
import mindustry.Vars;
78
import mindustry.mod.Mods;
89
import org.durmiendo.sap.SuenoSettings;
@@ -24,6 +25,8 @@ public class SVars {
2425
public static InternalFileTree internalFileTree = new InternalFileTree(Sueno.class);
2526

2627
public static ObjectMap<Texture, Texture> textureToNormal = new ObjectMap<>();
28+
public static ObjectSet<Texture> noNormal = new ObjectSet<>();
29+
public static ObjectMap<Texture, String> regions = new ObjectMap<>();
2730

2831
//controllers
2932
public static CelestialBodyController celestialBodyController;

src/org/durmiendo/sueno/core/Setter.java

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
import arc.Core;
44
import arc.Events;
5-
import arc.graphics.g2d.Draw;
6-
import arc.graphics.g2d.TextureAtlas;
7-
import arc.graphics.gl.Shader;
5+
import arc.graphics.g2d.SortedSpriteBatch;
6+
import arc.graphics.g2d.TextureRegion;
87
import arc.util.Time;
98
import mindustry.Vars;
109
import mindustry.game.EventType;
1110
import mindustry.io.SaveVersion;
1211
import org.durmiendo.sueno.controllers.CelestialBodyController;
1312
import org.durmiendo.sueno.graphics.NTexture;
14-
import org.durmiendo.sueno.graphics.SBlockRenderer;
15-
import org.durmiendo.sueno.graphics.SShaders;
13+
import org.durmiendo.sueno.graphics.SBatch;
1614
import org.durmiendo.sueno.graphics.VoidStriderCollapseEffectController;
1715
import org.durmiendo.sueno.processors.SuenoInputProcessor;
1816
import org.durmiendo.sueno.settings.SettingsBuilder;
@@ -99,39 +97,59 @@ private static void loadChunks() {
9997
}
10098

10199
private static void loadRender() {
102-
try {
103-
Field f = Vars.renderer.getClass().getDeclaredField("blocks");
104-
f.setAccessible(true);
105-
f.set(Vars.renderer, new SBlockRenderer());
106-
} catch (Exception e) {
107-
SLog.err("Renderer dont load :(");
100+
// try {
101+
// Field f = Vars.renderer.getClass().getDeclaredField("blocks");
102+
// f.setAccessible(true);
103+
// f.set(Vars.renderer, new SBlockRenderer());
104+
// } catch (Exception e) {
105+
// SLog.err("Renderer dont load :(");
108106
// throw new RuntimeException(e);
109-
}
110-
111-
Events.on(EventType.ClientLoadEvent.class, e -> {
112-
SLog.loadTime(() -> {
113-
final int[] loaded = {0};
114-
Core.atlas.getRegionMap().each((s, atlasRegion) -> {
115-
TextureAtlas.AtlasRegion n = Core.atlas.find(s + "-normal");
116-
if (Core.atlas.isFound(n)) {
117-
loaded[0]++;
118-
SLog.load("normal texture, founded: " + s);
119-
n.texture = new NTexture(atlasRegion.texture, n.texture);
107+
// }
108+
109+
SLog.loadTime(() -> {
110+
final int[] loaded = {0};
111+
Core.atlas.getRegionMap().each((s, atlasRegion) -> {
112+
SVars.regions.put(atlasRegion.texture, s);
113+
TextureRegion n = Core.atlas.find(s + "-normal");
114+
if (Core.atlas.isFound(n)) {
115+
loaded[0]++;
116+
SLog.load("normal texture, founded: " + s);
117+
SVars.textureToNormal.put(atlasRegion.texture, n.texture);
118+
atlasRegion.texture = new NTexture(atlasRegion.texture, n.texture);
119+
Core.atlas.getTextures().remove(atlasRegion.texture);
120+
Core.atlas.getTextures().add(n.texture);
121+
}
122+
});
123+
SLog.info(loaded[0] + " normal textures loaded!");
124+
125+
try {
126+
Field[] from = Core.batch.getClass().getFields();
127+
SortedSpriteBatch b = new SBatch();
128+
for (Field fromField : from) {
129+
try {
130+
Field toField = b.getClass().getField(fromField.getName());
131+
fromField.setAccessible(true);
132+
toField.setAccessible(true);
133+
toField.set(b, fromField.get(Core.batch));
134+
} catch (Exception ee) {
135+
SLog.load(ee.getMessage());
120136
}
121-
});
122-
SLog.info(loaded[0] + " normal textures loaded!");
123-
Draw.shader(SShaders.normalShader, true);
124-
}, "normal texture load");
125-
});
137+
}
126138

127-
Shader[] last = new Shader[1];
128-
129-
Events.run(EventType.Trigger.drawOver, () -> {
139+
Core.batch = b;
140+
} catch (Exception e) {
141+
SLog.err("Error updating batch: " + e.getMessage());
142+
}
143+
}, "normal texture load");
144+
//
145+
// Shader[] last = new Shader[1];
146+
//
147+
// Events.run(EventType.Trigger.drawOver, () -> {
130148
// last[0] = Draw.getShader();
131149

132-
});
133-
134-
Events.run(EventType.Trigger.uiDrawBegin, () -> Draw.shader(last[0]));
150+
// });
151+
//
152+
// Events.run(EventType.Trigger.uiDrawBegin, () -> Draw.shader(last[0]));
135153

136154

137155

src/org/durmiendo/sueno/graphics/NTexture.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@
44

55
public class NTexture extends Texture {
66
public Texture normal;
7+
public Texture base;
78

89
public NTexture(Texture base, Texture normal) {
910
super();
1011
this.normal = normal;
11-
12-
load(base.getTextureData());
13-
}
14-
15-
@Override
16-
public void bind(int unit) {
17-
normal.bind(4);
18-
super.bind(unit);
19-
20-
}
21-
22-
@Override
23-
public void bind() {
24-
normal.bind(4);
25-
super.bind(glTarget);
12+
this.base = base;
2613
}
2714
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.durmiendo.sueno.graphics;
2+
3+
import arc.graphics.Gl;
4+
import arc.graphics.Mesh;
5+
import arc.graphics.g2d.SortedSpriteBatch;
6+
import arc.graphics.gl.Shader;
7+
8+
public class SBatch extends SortedSpriteBatch {
9+
10+
@Override
11+
protected void flush() {
12+
// super.flush();
13+
flushRequests();
14+
if(idx == 0) return;
15+
16+
if (lastTexture instanceof NTexture n) {
17+
Shader b = customShader;
18+
customShader = SShaders.normalShader;
19+
getShader().bind();
20+
setupMatrices();
21+
22+
// if(customShader != null && apply){
23+
customShader.apply();
24+
// }
25+
26+
Gl.depthMask(false);
27+
int spritesInBatch = idx / SPRITE_SIZE;
28+
29+
int count = spritesInBatch * 6;
30+
31+
blending.apply();
32+
33+
n.base.bind();
34+
// n.normal.bind(1);
35+
36+
Mesh mesh = this.mesh;
37+
mesh.setVertices(vertices, 0, idx);
38+
mesh.getIndicesBuffer().position(0);
39+
mesh.getIndicesBuffer().limit(count);
40+
mesh.render(getShader(), Gl.triangles, 0, count);
41+
Gl.activeTexture(Gl.texture0);
42+
customShader = b;
43+
} else {
44+
getShader().bind();
45+
setupMatrices();
46+
47+
if(customShader != null && apply){
48+
customShader.apply();
49+
}
50+
51+
Gl.depthMask(false);
52+
int spritesInBatch = idx / SPRITE_SIZE;
53+
54+
int count = spritesInBatch * 6;
55+
56+
blending.apply();
57+
58+
lastTexture.bind();
59+
60+
Mesh mesh = this.mesh;
61+
mesh.setVertices(vertices, 0, idx);
62+
mesh.getIndicesBuffer().position(0);
63+
mesh.getIndicesBuffer().limit(count);
64+
mesh.render(getShader(), Gl.triangles, 0, count);
65+
}
66+
idx = 0;
67+
}
68+
}

src/org/durmiendo/sueno/graphics/SBlockRenderer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,7 @@ void drawTree(QuadTree<Tile> tree){
411411
}
412412

413413
public void drawBlocks(){
414-
Draw.draw(Layer.block, () -> {
415-
SShaders.normalShader.bind();
416-
SShaders.normalShader.apply();
414+
// Draw.draw(Layer.block, () -> {
417415
Team pteam = player.team();
418416

419417
drawDestroyed();
@@ -489,7 +487,7 @@ public void drawBlocks(){
489487
}
490488
}
491489
}
492-
});
490+
// });
493491
}
494492

495493
public void updateShadow(Building build){

src/org/durmiendo/sueno/graphics/SShaders.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,19 @@ public void apply(){
124124
public static class NormalShader extends Shader{
125125
public NormalShader(){
126126
super(
127-
Shaders.getShaderFi("screenspace.vert"),
127+
SVars.internalFileTree.child("shaders/normal.vert"),
128128
SVars.internalFileTree.child("shaders/normal.frag")
129129
);
130130
}
131131

132+
public void apply(int n){
133+
// setUniformi("u_textures", t);
134+
setUniformi("u_normal", n);
135+
apply();
136+
}
132137
@Override
133138
public void apply(){
134-
setUniformi("u_normal", 4);
139+
setUniformi("u_normal", 1);
135140
setUniformf("u_offset",
136141
Core.camera.position.x - Core.camera.width / 2,
137142
Core.camera.position.y - Core.camera.height / 2);

src/org/durmiendo/sueno/world/blocks/storage/SCoreBlock.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.durmiendo.sueno.world.blocks.storage;
22

3-
import arc.graphics.g2d.Draw;
4-
import arc.graphics.g2d.SortedSpriteBatch;
5-
import arc.graphics.g2d.SpriteBatch;
63
import arc.math.Mathf;
74
import arc.util.Time;
85
import mindustry.world.Tile;
@@ -29,12 +26,15 @@ public SCoreBlock(String name) {
2926
public void load() {
3027
super.load();
3128
}
32-
public SpriteBatch b = new SortedSpriteBatch();
3329

3430
@Override
3531
public void drawBase(Tile tile) {
3632
super.drawBase(tile);
37-
Draw.batch(b, () -> Draw.rect("sueno-demand-normal17", tile.drawx(), tile.drawy()+12));
33+
// Draw.flush();
34+
// SShaders.normalShader.bind();
35+
// SShaders.normalShader.apply();
36+
// Draw.rect("sueno-demand-normal17", tile.drawx(), tile.drawy()+12);
37+
// Draw.flush();
3838
}
3939

4040
public class CoreBuild extends CoreBlock.CoreBuild implements Heated {

0 commit comments

Comments
 (0)