Skip to content

Commit

Permalink
Added glass
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Dec 15, 2024
1 parent 1710cd7 commit 86674da
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
Binary file added client/src/main/resources/textures/blocks/glass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/main/scala/hexacraft/client/BlockSpecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ object BlockSpecs {
)
case "leaves_birch" => BlockSpec(Textures.basic("leaves_birch"))
case "tnt" => BlockSpec(Textures.basic("tnt").withTop("tnt_top").withBottom("tnt_top"))
case "glass" => BlockSpec(Textures.basic("glass"))
}
}
12 changes: 8 additions & 4 deletions client/src/main/scala/hexacraft/client/WorldRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import hexacraft.infra.gpu.OpenGL
import hexacraft.renderer.{GpuState, TextureArray, TextureSingle, VAO}
import hexacraft.shaders.*
import hexacraft.util.{NamedThreadFactory, TickableTimer}
import hexacraft.world.{BlocksInWorld, Camera, ChunkLoadingPrioritizer, CylinderSize, PosAndDir, WorldGenerator}
import hexacraft.world.block.BlockState
import hexacraft.world.*
import hexacraft.world.chunk.{Chunk, ChunkColumnHeightMap, ChunkColumnTerrain, ChunkStorage}
import hexacraft.world.coord.{BlockRelWorld, ChunkRelWorld, ColumnRelWorld}
import hexacraft.world.coord.{ChunkRelWorld, ColumnRelWorld}
import hexacraft.world.entity.{Entity, EntityModel}

import org.joml.{Vector2ic, Vector3f}
Expand Down Expand Up @@ -44,7 +43,7 @@ class WorldRenderer(
private val terrainShader = new TerrainShader()

private val solidBlockGpuState = GpuState.build(_.blend(false).cullFace(true))
private val transmissiveBlockGpuState = GpuState.build(_.blend(true).cullFace(false))
private val transmissiveBlockGpuState = GpuState.build(_.blend(true).cullFace(true))

private val terrainGpuState = GpuState.build(_.blend(false).cullFace(true))

Expand Down Expand Up @@ -301,6 +300,11 @@ class WorldRenderer(

// World content
renderBlocks(camera, sun)
// TODO: Opaque and translucent blocks are both rendered here, but they need to be separate.
// In the world combiner there is a normal field, but if there is glass in front of grass then the normal will be for the glass.
// The normal-based shading only happens for the grass.
// Instead we should render in two steps, or alternatively send both to the shader. How is this usually done?

// renderTerrain(camera, sun)
renderEntities(camera, sun)

Expand Down
15 changes: 10 additions & 5 deletions client/src/main/scala/hexacraft/client/render/BlockVboData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ object BlockVboData {
if neigh != null then {
val bs = neigh.getBlock(c2)

val shouldRenderSide = if bs.blockType == Block.Water then {
b != bs && s < 2 && b.blockType != Block.Water
} else {
b != bs && (s == 0 || !bs.blockType.isSolid)
}
val here = b.blockType
val there = bs.blockType

val shouldRenderSide =
if here == there then false
else if there.isTransmissive then true
else if s == 0 && here.blockHeight(b.metadata) < 1.0 then true
else false

// TODO: sort translucent faces and the rendering glitches might be fixed

if shouldRenderSide then {
brightness(c.value) = neigh.lighting.getBrightness(c2)
Expand Down
7 changes: 7 additions & 0 deletions game/src/main/scala/hexacraft/world/block/blocks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object Block {
val BirchLog = register(new Block(9, "log_birch", "Birch log"))
val BirchLeaves = register(new Block(10, "leaves_birch", "Birch leaves"))
val Tnt = register(new Block(11, "tnt", "TNT"))
val Glass = register(new BlockGlass(12, "glass", "Glass"))
}

class Block(val id: Byte, val name: String, val displayName: String) {
Expand Down Expand Up @@ -72,3 +73,9 @@ class BlockAir extends Block(0, "air", "Air") {
trait EmittingLight extends Block {
override def lightEmitted: Byte = 14
}

class BlockGlass(_id: Byte, _name: String, _displayName: String) extends Block(_id, _name, _displayName) {
override def isCovering(metadata: Byte, side: Int): Boolean = false

override def isTransmissive: Boolean = true
}

0 comments on commit 86674da

Please sign in to comment.