From ebbd3c2ea6f8ebf4eab6b4883de77a6810681b8b Mon Sep 17 00:00:00 2001 From: evg-zhabotinsky Date: Sat, 7 Jun 2014 02:36:04 +0400 Subject: [PATCH] Mimic screen text fading for holograms. Performance might be affected (definitely improved but I can't notice it) --- src/main/resources/reference.conf | 6 ++++++ src/main/scala/li/cil/oc/Settings.scala | 1 + .../oc/client/renderer/tileentity/HologramRenderer.scala | 9 +++++++-- .../scala/li/cil/oc/common/tileentity/Hologram.scala | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 76939ec69..9d4d9fd10 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -66,6 +66,12 @@ opencomputers { # hologram projector when at maximum scale. Render distance is scaled # down with the actual scale of the hologram. hologramRenderDistance: 64 + + # The distance at which to start fading out the hologram (as with + # hologramRenderDistance). This is purely cosmetic, to avoid image + # disappearing instantly when moving too far away from a projector. + # It does not affect performance. Holograms are transparent anyway. + hologramFadeStartDistance: 48 } # Computer related settings, concerns server performance and security. diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index 38df2498d..a7cb84d69 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -31,6 +31,7 @@ class Settings(config: Config) { val robotLabels = config.getBoolean("client.robotLabels") val soundVolume = config.getDouble("client.soundVolume").toFloat max 0 min 2 val fontCharScale = config.getDouble("client.fontCharScale") max 0.5 min 2 + val hologramFadeStartDistance = config.getDouble("client.hologramFadeStartDistance") max 0 val hologramRenderDistance = config.getDouble("client.hologramRenderDistance") max 0 // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala index 4518ea941..fcb31626c 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala @@ -34,6 +34,11 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit RenderState.makeItBlend() GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE) + val playerDistSq = x*x + y*y + z*z + val maxDistSq = hologram.getMaxRenderDistanceSquared + val fadeDistSq = hologram.getFadeStartDistanceSquared + RenderState.setBlendAlpha(0.75f * (if (playerDistSq > fadeDistSq) math.max(0, 1 - ((playerDistSq - fadeDistSq) / (maxDistSq - fadeDistSq)).toFloat) else 1)) + GL11.glPushMatrix() GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) GL11.glScaled(1.001, 1.001, 1.001) // Avoid z-fighting with other blocks. @@ -150,7 +155,7 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit for (hz <- 0 until hologram.width) { for (hy <- 0 until hologram.height) { if (isSolid(hx, hy, hz)) { - val v: Int = (192 << 24) + hologram.colors(value(hx, hy, hz) - 1) + val v: Int = hologram.colors(value(hx, hy, hz) - 1) // South if (!isSolid(hx, hy, hz + 1)) { tmpBuf.put(c) @@ -252,7 +257,7 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit GL11.glInterleavedArrays(GL11.GL_T2F_V3F, 0, 0) GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, privateBuf) GL11.glEnableClientState(GL11.GL_COLOR_ARRAY) - GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, 0) + GL11.glColorPointer(3, GL11.GL_UNSIGNED_BYTE, 4, 0) GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, privateBuf) GL11.glDrawElements(GL11.GL_QUADS, hologram.visibleQuads * 4, GL11.GL_UNSIGNED_INT, hologram.width * hologram.width * hologram.height * 24 * 4) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala index 33f832aff..3663f6ff1 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala @@ -278,6 +278,7 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w override def shouldRenderInPass(pass: Int) = pass == 1 override def getMaxRenderDistanceSquared = scale / Settings.hologramMaxScaleByTier.max * Settings.get.hologramRenderDistance * Settings.get.hologramRenderDistance + def getFadeStartDistanceSquared = scale / Settings.hologramMaxScaleByTier.max * Settings.get.hologramFadeStartDistance * Settings.get.hologramFadeStartDistance override def getRenderBoundingBox = AxisAlignedBB.getAABBPool.getAABB(xCoord + 0.5 - 1.5 * scale, yCoord, zCoord - scale, xCoord + 0.5 + 1.5 * scale, yCoord + 0.25 + 2 * scale, zCoord + 0.5 + 1.5 * scale)