Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void link() {
}

@Override
public void bind() {
public IShaderProgram bind() {
if (boundProgram != this.id) {
boundProgram = this.id;
boundProgramRef = this;
Expand All @@ -92,6 +92,7 @@ public void bind() {
GL20.glEnableVertexAttribArray(i);
}
}
return this;
}

@Override
Expand All @@ -116,35 +117,40 @@ public void pointVertexAttribute(String name, int size) {
}

@Override
public void setUniform(String name, Matrix4f matrix) {
public IShaderProgram setUniform(String name, Matrix4f matrix) {
int location = this.getUniformLocation(name);
MemoryStack stack = MemoryStack.stackPush();
GL20.glUniformMatrix4fv(location, false, matrix.get(stack.mallocFloat(4 * 4)));
stack.pop();
return this;
}

@Override
public void setUniform(String name, int value) {
public IShaderProgram setUniform(String name, int value) {
GL20.glUniform1i(this.getUniformLocation(name), value);
return this;
}

@Override
public void setUniform(String name, float f) {
public IShaderProgram setUniform(String name, float f) {
GL20.glUniform1f(this.getUniformLocation(name), f);
return this;
}

@Override
public void setUniform(String name, float x, float y) {
public IShaderProgram setUniform(String name, float x, float y) {
GL20.glUniform2f(this.getUniformLocation(name), x, y);
return this;
}

@Override
public void setUniform(String name, float x, float y, float z) {
public IShaderProgram setUniform(String name, float x, float y, float z) {
GL20.glUniform3f(this.getUniformLocation(name), x, y, z);
return this;
}

@Override
public void unbind() {
public IShaderProgram unbind() {
if (boundProgram == this.id) {
for (int i : this.attributeLocations.values()) {
GL20.glDisableVertexAttribArray(i);
Expand All @@ -156,6 +162,7 @@ public void unbind() {
boundProgram = -1;
boundProgramRef = null;
}
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void draw(float x, float y) {

@Override
public void draw(float x, float y, float scale) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the scale necessary to have in this method at this point then?

this.draw(x, y, this.renderWidth * scale, this.renderHeight * scale);
this.draw(x, y, this.renderWidth, this.renderHeight);
}

@Override
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/de/ellpeck/rockbottom/init/RockBottom.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ protected void updateTickless() {
this.renderer.cameraY = 0D;
}
SoundHandler.setListenerPos(this.renderer.cameraX, this.renderer.cameraY);
this.worldRenderer.calcCameraValues(this.renderer);

this.render();

Expand All @@ -554,15 +553,11 @@ protected void render() {
}

this.renderer.setDefaultProgram(this.assetManager.getShaderProgram(IShaderProgram.GUI_SHADER));

float scale = this.renderer.getGuiScale();
this.renderer.setScale(scale, scale);
this.assetManager.getShaderProgram(IShaderProgram.GUI_SHADER).bind().setUniform("scale", this.renderer.getGuiScale());

this.guiManager.render(this, this.assetManager, this.renderer, this.player);
this.toaster.render(this, this.assetManager, this.renderer);

this.renderer.setScale(1F, 1F);

if (this.renderer.isDebug()) {
DebugRenderer.render(this, this.assetManager, this.getPlayerWorld(), this.player, this.renderer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void update(IGameInstance game) {
}
}

public void render(IGameInstance game, IAssetManager manager, IRenderer g, IWorld world, float transX, float transY) {
public void render(IGameInstance game, IAssetManager manager, IRenderer g, IWorld world) {
this.particles.forEach(particle -> {
ResourceName program = particle.getRenderShader(game, manager, g);
g.setProgram(program == null ? null : manager.getShaderProgram(program));
Expand All @@ -40,7 +40,7 @@ public void render(IGameInstance game, IAssetManager manager, IRenderer g, IWorl
double y = particle.getY();

int light = world.getCombinedVisualLight(Util.floor(x), Util.floor(y));
particle.render(game, manager, g, (float) x - transX, (float) -y - transY + 1F, RockBottomAPI.getApiHandler().getColorByLight(light, TileLayer.MAIN));
particle.render(game, manager, g, (float) x, (float) -y + 1F, RockBottomAPI.getApiHandler().getColorByLight(light, TileLayer.MAIN));
});
}

Expand Down
80 changes: 42 additions & 38 deletions src/main/java/de/ellpeck/rockbottom/render/WorldRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public WorldRenderer() {
this.addClouds(Util.RANDOM.nextInt(5) + 3, true);
}

public void calcCameraValues(IRenderer g) {
public void calcCameraValues(IAssetManager m, IRenderer g) {
double width = g.getWidthInWorld();
double height = g.getHeightInWorld();

Expand All @@ -101,19 +101,32 @@ public void calcCameraValues(IRenderer g) {
this.maxY = Util.ceil(-this.transY + 1) - offset;
}

private IShaderProgram setCameraValues(IAssetManager manager, ResourceName shader, float transX, float transY, float scale) {
IShaderProgram program = manager.getShaderProgram(shader);
program.bind();
program.setUniform("camera", transX, transY, scale);
return program;
}

public void render(IGameInstance game, IAssetManager manager, ParticleManager particles, IRenderer g, AbstractWorld world, EntityPlayer player, InteractionManager input) {
float scale = g.getWorldScale();
calcCameraValues(manager, g);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this dot


this.setCameraValues(manager, IShaderProgram.BREAK_SHADER, this.transX, this.transY, g.getWorldScale()).unbind();
this.setCameraValues(manager, IShaderProgram.WORLD_SHADER, 0, 0, g.getWorldScale());

this.renderSky(game, manager, g, world, player, g.getWidthInWorld(), g.getHeightInWorld());

g.flush();
this.setCameraValues(manager, IShaderProgram.WORLD_SHADER, this.transX, this.transY, g.getWorldScale());

List<Entity> entities = new ArrayList<>();
List<EntityPlayer> players = new ArrayList<>();

for (int gridY = this.minChunkY; gridY <= this.maxChunkY; gridY++) {
for (int gridX = this.minChunkX; gridX <= this.maxChunkX; gridX++) {
if (world.isChunkLoaded(gridX, gridY)) {
IChunk chunk = world.getChunkFromGridCoords(gridX, gridY);
this.renderChunk(game, manager, g, input, world, chunk, scale, chunk.getLoadedLayers(), false);
this.renderChunk(game, manager, g, input, world, chunk, chunk.getLoadedLayers(), false);

for (Entity entity : chunk.getAllEntities()) {
entities.add(entity);
Expand All @@ -127,8 +140,6 @@ public void render(IGameInstance game, IAssetManager manager, ParticleManager pa
}
g.setProgram(null);

g.setScale(scale, scale);

entities.stream().sorted(Comparator.comparingInt(Entity::getRenderPriority)).forEach(entity -> {
if (entity.shouldRender()) {
IEntityRenderer renderer = entity.getRenderer();
Expand Down Expand Up @@ -165,41 +176,39 @@ public void render(IGameInstance game, IAssetManager manager, ParticleManager pa
}
}

renderer.render(game, manager, g, world, entity, (float) x - this.transX, (float) -y - this.transY + 1F, color);
renderer.render(game, manager, g, world, entity, (float) x, (float) -y + 1F, color);

if (g.isBoundBoxDebug()) {
g.addFilledRect((float) x - this.transX - 0.1F, (float) -y - this.transY + 0.9F, 0.2F, 0.2F, Colors.GREEN);
g.addFilledRect((float) x - 0.1F, (float) -y + 0.9F, 0.2F, 0.2F, Colors.GREEN);

BoundBox box = entity.currentBounds;
g.addEmptyRect((float) box.getMinX() - this.transX, (float) -box.getMaxY() - this.transY + 1F, (float) box.getWidth(), (float) box.getHeight(), 0.1F, Colors.RED);
g.addEmptyRect((float) box.getMinX(), (float) -box.getMaxY() + 1F, (float) box.getWidth(), (float) box.getHeight(), 0.1F, Colors.RED);

BoundBox boxMotion = box.copy().add(entity.motionX, entity.motionY);
g.addEmptyRect((float) boxMotion.getMinX() - this.transX, (float) -boxMotion.getMaxY() - this.transY + 1F, (float) boxMotion.getWidth(), (float) boxMotion.getHeight(), 0.05F, Colors.YELLOW);
g.addEmptyRect((float) boxMotion.getMinX(), (float) -boxMotion.getMaxY() + 1F, (float) boxMotion.getWidth(), (float) boxMotion.getHeight(), 0.05F, Colors.YELLOW);
}
}
}
}
});
g.setProgram(null);

particles.render(game, manager, g, world, this.transX, this.transY);
particles.render(game, manager, g, world);
g.setProgram(null);

RockBottomAPI.getEventHandler().fireEvent(new WorldRenderEvent(game, manager, g, world, player, this.transX, this.transY));
RockBottomAPI.getEventHandler().fireEvent(new WorldRenderEvent(game, manager, g, world, player));

players.forEach(entity -> {
if (entity.shouldRender() && !entity.isLocalPlayer()) {
manager.getFont().drawCenteredString((float) entity.getLerpedX() - this.transX, (float) -entity.getLerpedY() - this.transY - 0.75F, entity.getChatColorFormat() + entity.getName(), 0.015F, false);
manager.getFont().drawCenteredString((float) entity.getLerpedX(), (float) -entity.getLerpedY() - 0.75F, entity.getChatColorFormat() + entity.getName(), 0.015F, false);
}
});

g.setScale(1F, 1F);

for (int gridY = this.minChunkY; gridY <= this.maxChunkY; gridY++) {
for (int gridX = this.minChunkX; gridX <= this.maxChunkX; gridX++) {
if (world.isChunkLoaded(gridX, gridY)) {
IChunk chunk = world.getChunkFromGridCoords(gridX, gridY);
this.renderChunk(game, manager, g, input, world, chunk, scale, chunk.getLoadedLayers(), true);
this.renderChunk(game, manager, g, input, world, chunk, chunk.getLoadedLayers(), true);
}
}
}
Expand All @@ -210,7 +219,6 @@ public void render(IGameInstance game, IAssetManager manager, ParticleManager pa
boolean biomeDebug = g.isBiomeDebug();

if (chunkDebug || heightDebug || biomeDebug) {
g.setScale(scale, scale);

for (int gridX = this.minChunkX; gridX <= this.maxChunkX; gridX++) {
for (int gridY = this.minChunkY; gridY <= this.maxChunkY; gridY++) {
Expand All @@ -219,7 +227,7 @@ public void render(IGameInstance game, IAssetManager manager, ParticleManager pa
int worldY = Util.toWorldPos(gridY);

if (chunkDebug) {
g.addEmptyRect(worldX - this.transX, -worldY - this.transY + 1F - Constants.CHUNK_SIZE, Constants.CHUNK_SIZE, Constants.CHUNK_SIZE, 0.1F, Colors.GREEN);
g.addEmptyRect(worldX, -worldY + 1F - Constants.CHUNK_SIZE, Constants.CHUNK_SIZE, Constants.CHUNK_SIZE, 0.1F, Colors.GREEN);
}

if (heightDebug || biomeDebug) {
Expand All @@ -228,31 +236,33 @@ public void render(IGameInstance game, IAssetManager manager, ParticleManager pa
if (heightDebug) {
for (TileLayer layer : TileLayer.getLayersByRenderPrio()) {
this.random.setSeed(layer.getName().hashCode());
g.addFilledRect(worldX - this.transX + x, -worldY - this.transY + 1F - chunk.getHeightInner(layer, x), 1F, 0.1F, Colors.random(this.random));
g.addFilledRect(worldX + x, -worldY + 1F - chunk.getHeightInner(layer, x), 1F, 0.1F, Colors.random(this.random));
}
int highest = world.getHighestTile(worldX + x, world.getChunkHeight(TileLayer.MAIN, worldX, worldY), false);
if (highest >= chunk.getY() && highest <= chunk.getY() + Constants.CHUNK_SIZE) {
g.addFilledRect(worldX + x, -highest + 1.1F, 1F, 0.1F, Colors.YELLOW);
}
}

if (biomeDebug) {
for (int y = 0; y < Constants.CHUNK_SIZE; y++) {
if (!world.isClient()) {
this.random.setSeed(chunk.getExpectedBiomeLevel(worldX + x, worldY + y).getName().hashCode());
g.addFilledRect(worldX - this.transX + x + 0.35F, -worldY - this.transY - y + 0.35F, 0.3F, 0.3F, Colors.random(this.random));
g.addFilledRect(worldX + x + 0.35F, -worldY - y + 0.35F, 0.3F, 0.3F, Colors.random(this.random));
}
this.random.setSeed(chunk.getBiomeInner(x, y).getName().hashCode());
g.addEmptyRect(worldX - this.transX + x + 0.25F, -worldY - this.transY - y + 0.25F, 0.5F, 0.5F, 0.1F, Colors.random(this.random));
g.addEmptyRect(worldX + x + 0.25F, -worldY - y + 0.25F, 0.5F, 0.5F, 0.1F, Colors.random(this.random));
}
}
}
}
}
}
}

g.setScale(1F, 1F);
}
}

private void renderChunk(IGameInstance game, IAssetManager manager, IRenderer g, InteractionManager input, IWorld world, IChunk chunk, float scale, List<TileLayer> layers, boolean foreground) {
private void renderChunk(IGameInstance game, IAssetManager manager, IRenderer g, InteractionManager input, IWorld world, IChunk chunk, List<TileLayer> layers, boolean foreground) {
int chunkX = chunk.getX();
int chunkY = chunk.getY();

Expand Down Expand Up @@ -286,13 +296,13 @@ private void renderChunk(IGameInstance game, IAssetManager manager, IRenderer g,
}
}

this.renderLayer(game, manager, g, input, world, chunk, layer, x, y, scale, color, foreground);
this.renderLayer(game, manager, g, input, world, chunk, layer, x, y, color, foreground);
}
}
}
}

private void renderLayer(IGameInstance game, IAssetManager manager, IRenderer g, InteractionManager input, IWorld world, IChunk chunk, TileLayer layer, int x, int y, float scale, int[] color, boolean foreground) {
private void renderLayer(IGameInstance game, IAssetManager manager, IRenderer g, InteractionManager input, IWorld world, IChunk chunk, TileLayer layer, int x, int y, int[] color, boolean foreground) {
if (layer.isVisible(game, game.getPlayer(), chunk, x, y, foreground)) {
TileState state = chunk.getState(layer, x, y);
Tile tile = state.getTile();
Expand All @@ -301,15 +311,15 @@ private void renderLayer(IGameInstance game, IAssetManager manager, IRenderer g,

if (renderer != null) {
if (foreground) {
this.renderTile(game, manager, g, input, world, layer, state, tile, renderer, x, y, scale, color, forcesForeground, true);
this.renderTile(game, manager, g, input, world, layer, state, tile, renderer, x, y, color, forcesForeground, true);
} else if (!forcesForeground) {
this.renderTile(game, manager, g, input, world, layer, state, tile, renderer, x, y, scale, color, true, false);
this.renderTile(game, manager, g, input, world, layer, state, tile, renderer, x, y, color, true, false);
}
}
}
}

private void renderTile(IGameInstance game, IAssetManager manager, IRenderer g, InteractionManager input, IWorld world, TileLayer layer, TileState state, Tile tile, ITileRenderer renderer, int x, int y, float scale, int[] color, boolean renderNormal, boolean renderForeground) {
private void renderTile(IGameInstance game, IAssetManager manager, IRenderer g, InteractionManager input, IWorld world, TileLayer layer, TileState state, Tile tile, ITileRenderer renderer, int x, int y, int[] color, boolean renderNormal, boolean renderForeground) {
boolean isBreakTile = input.breakingLayer == layer && input.breakProgress > 0 && x == input.breakTileX && y == input.breakTileY;

if (isBreakTile) {
Expand All @@ -321,11 +331,11 @@ private void renderTile(IGameInstance game, IAssetManager manager, IRenderer g,
}

if (renderNormal) {
renderer.render(game, manager, g, world, tile, state, x, y, layer, (x - this.transX) * scale, (-y - this.transY) * scale, scale, color);
renderer.render(game, manager, g, world, tile, state, x, y, layer, x, -y, 1, color);
}

if (renderForeground) {
renderer.renderInForeground(game, manager, g, world, tile, state, x, y, layer, (x - this.transX) * scale, (-y - this.transY) * scale, scale, color);
renderer.renderInForeground(game, manager, g, world, tile, state, x, y, layer, x, -y, 1, color);
}

if (isBreakTile) {
Expand All @@ -345,11 +355,7 @@ private void renderSky(IGameInstance game, IAssetManager manager, IRenderer g, A
int skyColor = SKY_COLORS[skyLight];
g.backgroundColor(skyColor);

float scale = g.getWorldScale();
g.setScale(scale, scale);

int time = world.getCurrentTime();
float worldScale = game.getSettings().renderScale;

float starAlpha = 1F - Math.min(1F, skylightMod + 0.5F);
if (starAlpha <= 0F) {
Expand All @@ -372,8 +378,8 @@ private void renderSky(IGameInstance game, IAssetManager manager, IRenderer g, A
}
}

double radiusX = 10D / worldScale;
double radiusY = 7D / worldScale;
double radiusX = 10D;
double radiusY = 7D;

double sunAngle = (time / (double) Constants.TIME_PER_DAY) * 360D + 180D;
double sunRads = Math.toRadians(sunAngle);
Expand All @@ -391,8 +397,6 @@ private void renderSky(IGameInstance game, IAssetManager manager, IRenderer g, A
for (Cloud cloud : this.clouds) {
cloud.render(manager, width, height, skylightMod, yOff);
}

g.setScale(1F, 1F);
}

public void update(IWorld world, IParticleManager manager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TileCaveMushroomRenderer extends TileMetaRenderer<TileCaveMushroom>
@Override
public void render(IGameInstance game, IAssetManager manager, IRenderer g, IWorld world, TileCaveMushroom tile, TileState state, int x, int y, TileLayer layer, float renderX, float renderY, float scale, int[] light) {
for (int i = 0; i < light.length; i++) {
light[i] = Math.max(light[i], Colors.multiply(Colors.WHITE, 0.2F));
//light[i] = Math.max(light[i], Colors.multiply(Colors.WHITE, 0.2F));
}
this.getTexture(manager, tile, state.get(tile.metaProp)).getPositionalVariation(x, y).draw(renderX, renderY, scale, scale, light);
}
Expand Down
Loading