histogram to display UV values

This commit is contained in:
minjaesong
2019-02-04 05:23:07 +09:00
parent 3f108a6ea9
commit a73a865d29
2 changed files with 14 additions and 85 deletions

View File

@@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
import net.torvald.terrarum.*
import net.torvald.terrarum.Terrarum.mouseTileX
import net.torvald.terrarum.Terrarum.mouseTileY
@@ -264,16 +263,18 @@ class BasicDebugInfoWindow : UICanvas() {
}
val histogramW = 256
val histogramH = 200
val histogramH = 256
private fun drawHistogram(batch: SpriteBatch, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
val uiColour = Color(0x000000_80.toInt())
val barR = Color(0xFF0000_FF.toInt())
val barG = Color(0x00FF00_FF.toInt())
val barB = Color(0x0000FF_FF.toInt())
val barColour = arrayOf(barR, barG, barB)
val barA = Color.WHITE
val barColour = arrayOf(barR, barG, barB, barA)
val w = histogramW.toFloat()
val h = histogramH.toFloat()
val halfh = h / 2f
val range = histogram.range
val histogramMax = histogram.screen_tiles.toFloat()
@@ -285,7 +286,7 @@ class BasicDebugInfoWindow : UICanvas() {
Terrarum.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
blendScreen(batch)
for (c in 0..2) {
for (c in 0..3) {
for (i in 0..255) {
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
if (i == 255) {
@@ -295,12 +296,12 @@ class BasicDebugInfoWindow : UICanvas() {
}
val bar_x = x + (w / w.minus(1f)) * i.toFloat()
val bar_h = FastMath.ceil(h / histogramMax * histogram_value.toFloat()).toFloat()
val bar_y = y + (h / histogramMax) - bar_h + h
val bar_h = halfh * (histogram_value.toFloat() / histogramMax).sqrt()
val bar_y = if (c == 3) y + halfh else y + h
val bar_w = 1f
batch.color = barColour[c]
batch.fillRect(bar_x, bar_y, bar_w, bar_h)
batch.fillRect(bar_x, bar_y, bar_w, -bar_h)
}
}
blendNormal(batch)

View File

@@ -639,9 +639,6 @@ object LightmapRenderer {
}
}
const val DRAW_FOR_RGB = 0xFFF0
const val DRAW_FOR_ALPHA = 0x000F
var lightBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888)
private val colourNull = Color(0)
@@ -728,14 +725,6 @@ object LightmapRenderer {
data.a * (1f - darken.a * lightScalingMagic))
}
private fun scaleSqrt2(data: Color): Color {
return Color(
data.r * 1.41421356f,
data.g * 1.41421356f,
data.b * 1.41421356f,
data.a * 1.41421356f)
}
/**
* Add each channel's RGB value.
*
@@ -809,71 +798,6 @@ object LightmapRenderer {
return this
}
/*inline fun RGB10.rawR() = this.ushr(20) and 1023
inline fun RGB10.rawG() = this.ushr(10) and 1023
inline fun RGB10.rawB() = this and 1023
/** 0.0 - 1.0 for 0-1023 (0.0 - 0.25 for 0-255) */
inline fun RGB10.r(): Float = this.rawR() / CHANNEL_MAX_FLOAT
inline fun RGB10.g(): Float = this.rawG() / CHANNEL_MAX_FLOAT
inline fun RGB10.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT*/
/*inline fun constructRGBFromInt(r: Int, g: Int, b: Int): RGB10 {
//if (r !in 0..CHANNEL_MAX) throw IllegalArgumentException("Red: out of range ($r)")
//if (g !in 0..CHANNEL_MAX) throw IllegalArgumentException("Green: out of range ($g)")
//if (b !in 0..CHANNEL_MAX) throw IllegalArgumentException("Blue: out of range ($b)")
return r.shl(20) or
g.shl(10) or
b
}*/
/*inline fun constructRGBFromFloat(r: Float, g: Float, b: Float): RGB10 {
//if (r < 0 || r > CHANNEL_MAX_DECIMAL) throw IllegalArgumentException("Red: out of range ($r)")
//if (g < 0 || g > CHANNEL_MAX_DECIMAL) throw IllegalArgumentException("Green: out of range ($g)")
//if (b < 0 || b > CHANNEL_MAX_DECIMAL) throw IllegalArgumentException("Blue: out of range ($b)")
return (r * CHANNEL_MAX).round().shl(20) or
(g * CHANNEL_MAX).round().shl(10) or
(b * CHANNEL_MAX).round()
}*/
fun Int.clampZero() = if (this < 0) 0 else this
fun Float.clampZero() = if (this < 0) 0f else this
fun Int.clampChannel() = if (this < 0) 0 else if (this > CHANNEL_MAX) CHANNEL_MAX else this
fun Float.clampOne() = if (this < 0) 0f else if (this > 1) 1f else this
fun Float.clampChannel() = if (this > CHANNEL_MAX_DECIMAL) CHANNEL_MAX_DECIMAL else this
fun getHighestRGB(x: Int, y: Int): Float? {
val value = getLightInternal(x, y)
if (value == null)
return null
else
return FastMath.max(value.r, value.g, value.b)
}
fun getHighestRGBA(x: Int, y: Int): Float? {
val value = getLightInternal(x, y)
if (value == null)
return null
else
return FastMath.max(value.r, value.g, value.b, value.a)
}
/*private fun purgeLightmap() {
for (y in 0..LIGHTMAP_HEIGHT - 1) {
for (x in 0..LIGHTMAP_WIDTH - 1) {
lightmap.setcolourNull
lightmap.fillRectangle(0, 0, lightmap.width, lightmap.height)
}
}
*/
infix fun Float.powerOf(f: Float) = FastMath.pow(this, f)
private fun Float.sqr() = this * this
private fun Float.sqrt() = FastMath.sqrt(this)
private fun Float.inv() = 1f / this
fun Float.floor() = FastMath.floor(this)
fun Double.floorInt() = Math.floor(this).toInt()
@@ -1007,6 +931,7 @@ object LightmapRenderer {
val reds = IntArray(MUL) // reds[intensity] ← counts
val greens = IntArray(MUL) // do.
val blues = IntArray(MUL) // do.
val uvs = IntArray(MUL)
val render_width = for_x_end - for_x_start
val render_height = for_y_end - for_y_start
// excluiding overscans; only reckon echo lights
@@ -1018,18 +943,20 @@ object LightmapRenderer {
reds[minOf(CHANNEL_MAX, colour.r.times(MUL).floorInt())] += 1
greens[minOf(CHANNEL_MAX, colour.g.times(MUL).floorInt())] += 1
blues[minOf(CHANNEL_MAX, colour.b.times(MUL).floorInt())] += 1
uvs[minOf(CHANNEL_MAX, colour.a.times(MUL).floorInt())] += 1
}
catch (e: ArrayIndexOutOfBoundsException) { }
}
}
return Histogram(reds, greens, blues)
return Histogram(reds, greens, blues, uvs)
}
class Histogram(val reds: IntArray, val greens: IntArray, val blues: IntArray) {
class Histogram(val reds: IntArray, val greens: IntArray, val blues: IntArray, val uvs: IntArray) {
val RED = 0
val GREEN = 1
val BLUE = 2
val UV = 3
val screen_tiles: Int = (for_x_end - for_x_start + 2) * (for_y_end - for_y_start + 2)
@@ -1063,6 +990,7 @@ object LightmapRenderer {
RED -> reds
GREEN -> greens
BLUE -> blues
UV -> uvs
else -> throw IllegalArgumentException()
}
}