Planet background system
This commit is contained in:
@@ -43,6 +43,7 @@ public class Renderer implements ApplicationListener{
|
|||||||
public PlanetRenderer planets;
|
public PlanetRenderer planets;
|
||||||
|
|
||||||
public @Nullable Bloom bloom;
|
public @Nullable Bloom bloom;
|
||||||
|
public @Nullable FrameBuffer backgroundBuffer;
|
||||||
public FrameBuffer effectBuffer = new FrameBuffer();
|
public FrameBuffer effectBuffer = new FrameBuffer();
|
||||||
public boolean animateShields, drawWeather = true, drawStatus;
|
public boolean animateShields, drawWeather = true, drawStatus;
|
||||||
public float weatherAlpha;
|
public float weatherAlpha;
|
||||||
@@ -109,6 +110,14 @@ public class Renderer implements ApplicationListener{
|
|||||||
t.setWrap(TextureWrap.repeat);
|
t.setWrap(TextureWrap.repeat);
|
||||||
t.setFilter(TextureFilter.linear);
|
t.setFilter(TextureFilter.linear);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Events.on(WorldLoadEvent.class, e -> {
|
||||||
|
//reset background buffer on every world load, so it can be re-cached first render
|
||||||
|
if(backgroundBuffer != null){
|
||||||
|
backgroundBuffer.dispose();
|
||||||
|
backgroundBuffer = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -278,7 +287,7 @@ public class Renderer implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(bloom != null){
|
if(bloom != null){
|
||||||
bloom.resize(graphics.getWidth() / 4, graphics.getHeight() / 4);
|
bloom.resize(graphics.getWidth(), graphics.getHeight());
|
||||||
Draw.draw(Layer.bullet - 0.02f, bloom::capture);
|
Draw.draw(Layer.bullet - 0.02f, bloom::capture);
|
||||||
Draw.draw(Layer.effect + 0.02f, bloom::render);
|
Draw.draw(Layer.effect + 0.02f, bloom::render);
|
||||||
}
|
}
|
||||||
@@ -312,7 +321,8 @@ public class Renderer implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void drawBackground(){
|
protected void drawBackground(){
|
||||||
if(state.rules.backgroundTexture != null){
|
//draw background only if there is no planet background with a skybox
|
||||||
|
if(state.rules.backgroundTexture != null && (state.rules.planetBackground == null || !state.rules.planetBackground.drawSkybox)){
|
||||||
if(!assets.isLoaded(state.rules.backgroundTexture, Texture.class)){
|
if(!assets.isLoaded(state.rules.backgroundTexture, Texture.class)){
|
||||||
var file = assets.getFileHandleResolver().resolve(state.rules.backgroundTexture);
|
var file = assets.getFileHandleResolver().resolve(state.rules.backgroundTexture);
|
||||||
|
|
||||||
@@ -346,6 +356,36 @@ public class Renderer implements ApplicationListener{
|
|||||||
|
|
||||||
Draw.rect(Tmp.tr1, camera.position.x, camera.position.y, camera.width, camera.height);
|
Draw.rect(Tmp.tr1, camera.position.x, camera.position.y, camera.width, camera.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(state.rules.planetBackground != null){
|
||||||
|
int size = Math.max(graphics.getWidth(), graphics.getHeight());
|
||||||
|
|
||||||
|
boolean resized = false;
|
||||||
|
if(backgroundBuffer == null){
|
||||||
|
resized = true;
|
||||||
|
backgroundBuffer = new FrameBuffer(size, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(resized || backgroundBuffer.resize(size, size)){
|
||||||
|
backgroundBuffer.begin(Color.clear);
|
||||||
|
|
||||||
|
var params = state.rules.planetBackground;
|
||||||
|
|
||||||
|
//override some values
|
||||||
|
params.viewW = size;
|
||||||
|
params.viewH = size;
|
||||||
|
params.alwaysDrawAtmosphere = true;
|
||||||
|
params.drawUi = false;
|
||||||
|
|
||||||
|
planets.render(params);
|
||||||
|
|
||||||
|
backgroundBuffer.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
float drawSize = Math.max(camera.width, camera.height);
|
||||||
|
Draw.rect(Draw.wrap(backgroundBuffer.getTexture()), camera.position.x, camera.position.y, drawSize, -drawSize);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateLandParticles(){
|
void updateLandParticles(){
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import arc.util.*;
|
|||||||
import arc.util.serialization.*;
|
import arc.util.serialization.*;
|
||||||
import arc.util.serialization.Json.*;
|
import arc.util.serialization.Json.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
|
import mindustry.graphics.g3d.*;
|
||||||
import mindustry.io.*;
|
import mindustry.io.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.type.Weather.*;
|
import mindustry.type.Weather.*;
|
||||||
@@ -129,6 +130,8 @@ public class Rules{
|
|||||||
public float backgroundScl = 1f;
|
public float backgroundScl = 1f;
|
||||||
/** background UV offsets */
|
/** background UV offsets */
|
||||||
public float backgroundOffsetX = 0.1f, backgroundOffsetY = 0.1f;
|
public float backgroundOffsetX = 0.1f, backgroundOffsetY = 0.1f;
|
||||||
|
/** Parameters for planet rendered in the background. Cannot be changed once a map is loaded. */
|
||||||
|
public @Nullable PlanetParams planetBackground;
|
||||||
|
|
||||||
/** Copies this ruleset exactly. Not efficient at all, do not use often. */
|
/** Copies this ruleset exactly. Not efficient at all, do not use often. */
|
||||||
public Rules copy(){
|
public Rules copy(){
|
||||||
|
|||||||
@@ -26,10 +26,14 @@ public class PlanetParams{
|
|||||||
public boolean drawUi = false;
|
public boolean drawUi = false;
|
||||||
/** If true, a space skybox is drawn. */
|
/** If true, a space skybox is drawn. */
|
||||||
public boolean drawSkybox = true;
|
public boolean drawSkybox = true;
|
||||||
|
|
||||||
/** Handles drawing details. */
|
/** Handles drawing details. */
|
||||||
public @Nullable transient PlanetInterfaceRenderer renderer;
|
public @Nullable transient PlanetInterfaceRenderer renderer;
|
||||||
|
/** Viewport size. <=0 to use screen size. Do not change in rules. */
|
||||||
|
public transient int viewW = -1, viewH = -1;
|
||||||
|
/** If true, atmosphere will be drawn regardless of player options. */
|
||||||
|
public transient boolean alwaysDrawAtmosphere = false;
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
//- blur
|
//- blur
|
||||||
//- transparent background
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,12 +59,15 @@ public class PlanetRenderer implements Disposable{
|
|||||||
Gl.enable(Gl.cullFace);
|
Gl.enable(Gl.cullFace);
|
||||||
Gl.cullFace(Gl.back);
|
Gl.cullFace(Gl.back);
|
||||||
|
|
||||||
|
int w = params.viewW <= 0 ? Core.graphics.getWidth() : params.viewW;
|
||||||
|
int h = params.viewH <= 0 ? Core.graphics.getHeight() : params.viewH;
|
||||||
|
|
||||||
bloom.blending = !params.drawSkybox;
|
bloom.blending = !params.drawSkybox;
|
||||||
|
|
||||||
//lock to up vector so it doesn't get confusing
|
//lock to up vector so it doesn't get confusing
|
||||||
cam.up.set(Vec3.Y);
|
cam.up.set(Vec3.Y);
|
||||||
|
|
||||||
cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
cam.resize(w, h);
|
||||||
params.camPos.setLength((params.planet.radius + params.planet.camRadius) * camLength + (params.zoom-1f) * (params.planet.radius + params.planet.camRadius) * 2);
|
params.camPos.setLength((params.planet.radius + params.planet.camRadius) * camLength + (params.zoom-1f) * (params.planet.radius + params.planet.camRadius) * 2);
|
||||||
cam.position.set(params.planet.position).add(params.camPos);
|
cam.position.set(params.planet.position).add(params.camPos);
|
||||||
//cam.up.set(params.camUp); //TODO broken
|
//cam.up.set(params.camUp); //TODO broken
|
||||||
@@ -79,7 +82,9 @@ public class PlanetRenderer implements Disposable{
|
|||||||
|
|
||||||
Events.fire(Trigger.universeDrawBegin);
|
Events.fire(Trigger.universeDrawBegin);
|
||||||
|
|
||||||
beginBloom();
|
//begin bloom
|
||||||
|
bloom.resize(w, h);
|
||||||
|
bloom.capture();
|
||||||
|
|
||||||
if(params.drawSkybox){
|
if(params.drawSkybox){
|
||||||
//render skybox at 0,0,0
|
//render skybox at 0,0,0
|
||||||
@@ -102,7 +107,7 @@ public class PlanetRenderer implements Disposable{
|
|||||||
renderPlanet(params.solarSystem, params);
|
renderPlanet(params.solarSystem, params);
|
||||||
renderTransparent(params.solarSystem, params);
|
renderTransparent(params.solarSystem, params);
|
||||||
|
|
||||||
endBloom();
|
bloom.render();
|
||||||
|
|
||||||
Events.fire(Trigger.universeDrawEnd);
|
Events.fire(Trigger.universeDrawEnd);
|
||||||
|
|
||||||
@@ -118,16 +123,6 @@ public class PlanetRenderer implements Disposable{
|
|||||||
cam.update();
|
cam.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginBloom(){
|
|
||||||
bloom.resize(Core.graphics.getWidth() / 4, Core.graphics.getHeight() / 4);
|
|
||||||
bloom.capture();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void endBloom(){
|
|
||||||
bloom.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void renderPlanet(Planet planet, PlanetParams params){
|
public void renderPlanet(Planet planet, PlanetParams params){
|
||||||
if(!planet.visible()) return;
|
if(!planet.visible()) return;
|
||||||
|
|
||||||
@@ -152,7 +147,7 @@ public class PlanetRenderer implements Disposable{
|
|||||||
renderSectors(planet, params);
|
renderSectors(planet, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cam.frustum.containsSphere(planet.position, planet.clipRadius) && planet.parent != null && planet.hasAtmosphere && Core.settings.getBool("atmosphere")){
|
if(cam.frustum.containsSphere(planet.position, planet.clipRadius) && planet.parent != null && planet.hasAtmosphere && (params.alwaysDrawAtmosphere || Core.settings.getBool("atmosphere"))){
|
||||||
planet.drawAtmosphere(atmosphere, cam);
|
planet.drawAtmosphere(atmosphere, cam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,19 @@ public class JsonIO{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
json.setSerializer(Planet.class, new Serializer<>(){
|
||||||
|
@Override
|
||||||
|
public void write(Json json, Planet object, Class knownType){
|
||||||
|
json.writeValue(object.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Planet read(Json json, JsonValue jsonData, Class type){
|
||||||
|
Planet block = Vars.content.getByName(ContentType.planet, jsonData.asString());
|
||||||
|
return block == null ? Planets.serpulo : block;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
json.setSerializer(Weather.class, new Serializer<>(){
|
json.setSerializer(Weather.class, new Serializer<>(){
|
||||||
@Override
|
@Override
|
||||||
public void write(Json json, Weather object, Class knownType){
|
public void write(Json json, Weather object, Class knownType){
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import arc.math.*;
|
|||||||
import arc.util.noise.*;
|
import arc.util.noise.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
|
import mindustry.graphics.g3d.*;
|
||||||
import mindustry.maps.generators.*;
|
import mindustry.maps.generators.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.blocks.environment.*;
|
import mindustry.world.blocks.environment.*;
|
||||||
@@ -132,7 +133,11 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
|
|||||||
|
|
||||||
Schematics.placeLaunchLoadout(sx, sy);
|
Schematics.placeLaunchLoadout(sx, sy);
|
||||||
|
|
||||||
state.rules.backgroundTexture = "sprites/space.png";
|
state.rules.planetBackground = new PlanetParams(){{
|
||||||
|
planet = sector.planet;
|
||||||
|
zoom = 1f;
|
||||||
|
}};
|
||||||
|
//state.rules.backgroundTexture = "sprites/space.png";
|
||||||
state.rules.borderDarkness = false;
|
state.rules.borderDarkness = false;
|
||||||
state.rules.environment = Env.space;
|
state.rules.environment = Env.space;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ android.useAndroidX=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
http.socketTimeout=80000
|
http.socketTimeout=80000
|
||||||
http.connectionTimeout=80000
|
http.connectionTimeout=80000
|
||||||
archash=e2eead82168c1a143e345bc5f78e2d72078f4657
|
archash=e982971b17f48c13f3a18c344b8080b7498cccf6
|
||||||
|
|||||||
Reference in New Issue
Block a user