-
Notifications
You must be signed in to change notification settings - Fork 9
Lighting & Shaders Improvements #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8b488d3
Try to store highest tile per x
raphydaphy eee60af
Merge branch 'master' of https://github.com/RockBottomGame/RockBottom…
raphydaphy 421d539
Calculate heightmap before updating new tiles
raphydaphy 9eeeb74
Handle empty columns
raphydaphy f4f0a97
make the world look a lot nicer
raphydaphy 526cfbb
Cave Mushrooms emit actual light
raphydaphy 6fd9270
Merge branch 'master' of https://github.com/RockBottomGame/RockBottom…
raphydaphy 6644caa
Pass scale & camera position to shaders
raphydaphy 9bb4c83
whoops I broke the clouds
raphydaphy ab68c20
Fix the sky
raphydaphy eb4aab1
Merge branch 'master' of https://github.com/RockBottomGame/RockBottom…
raphydaphy ef3932f
Merge branch 'master' of https://github.com/RockBottomGame/RockBottom…
raphydaphy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
|
||
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
@@ -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(); | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -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++) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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(); | ||
|
|
||
|
|
@@ -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(); | ||
|
|
@@ -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) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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); | ||
|
|
@@ -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) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?