Skip to content

Commit

Permalink
Very basic ambient occlusion
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Sep 30, 2024
1 parent 0230f76 commit 0625296
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/src/main/resources/shaders/block/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ void main() {

position = fragIn.position;
normal = fragIn.normal;
color.rgb *= fragIn.brightness * 0.8 + 0.2;
color.rgb *= sqrt(fragIn.brightness) * 0.8 + 0.2;
}
2 changes: 1 addition & 1 deletion client/src/main/resources/shaders/block/vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ void main() {

fragIn.mult = mult;
fragInFlat.texIndex = texIndex;
fragIn.brightness = brightness;
fragIn.brightness = brightness * brightness;
}
16 changes: 11 additions & 5 deletions client/src/main/scala/hexacraft/client/render/BlockVboData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,15 @@ object BlockVboData {
}
case _ =>
cornerIdx match {
case 0 => b += Offset(0, 1, 0)
case 1 => b += Offset(0, 1, 0)
case 2 => b += Offset(0, -1, 0)
case 3 => b += Offset(0, -1, 0)
case 0 => b += Offset(0, 1, 0); b += Offset(0, 1, 0)
case 1 => b += Offset(0, 1, 0); b += Offset(0, 1, 0)
case 2 => b += Offset(0, -1, 0); b += Offset(0, -1, 0)
case 3 => b += Offset(0, -1, 0); b += Offset(0, -1, 0)
}
}

// TODO: calculate ambient occlusion based on the neighbors, and make sure it's independent of `side`

var brSum = 0f
var brCount = 0
var bIdx = 0
Expand All @@ -320,7 +322,11 @@ object BlockVboData {
}
bIdx += 1
}
if brCount == 0 then brightness(neighborBlockCoords) else brSum / brCount
if brCount == 0 then brightness(neighborBlockCoords)
else {
val ambientOcclusionFactor = (brCount - 1).toFloat / (bLen - 1) * 0.2f + 0.8f // TODO: temporary
brSum / brCount * ambientOcclusionFactor
}
}

private def oppositeSide(s: Int): Int = {
Expand Down

0 comments on commit 0625296

Please sign in to comment.