render system, skeletal performance improvements

This commit is contained in:
Moritz Zwerger 2023-10-22 21:20:51 +02:00
parent ba9dfa1688
commit b8140dbe4e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 80 additions and 14 deletions

View File

@ -19,10 +19,25 @@ Entity rendering is a quite hard topic.
## Model designing
### Block entities
Block entity models (e.g. chests) are always `facing`=`north` by default.
### Entities
Entities are always designed without any rotation (i.e. `yaw`=`0`)
## Things to consider
- name rendering (without culling and visible through walls) (and scoreboard objective)
- hitbox rendering
- entity model itself
- player with arms, legs, ...
- has animations, ...
- different poses (sneaking, etc)
- yaw vs head yaw
- "features"
- armor (and armor trims)
- elytra
- stuck arrows (and bee stingers)
- cape
- shoulder entities (parrots)
- held item
- light (shade and lightmap)
-

View File

@ -36,7 +36,7 @@ class SkeletalManager(
}
fun upload(instance: SkeletalInstance) {
instance.transform.pack(uniformBuffer.buffer, instance.position)
instance.transform.pack(uniformBuffer.buffer, instance.position, Mat4())
uniformBuffer.upload(0 until instance.model.transformCount * Mat4.length)
}

View File

@ -61,6 +61,7 @@ class AnimationManager(val instance: SkeletalInstance) {
}
fun draw(delta: Float) {
if (playing.isEmpty()) return
lock.lock()
val iterator = playing.iterator()

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.gui.rendering.skeletal.instance
import de.bixilon.kotlinglm.mat4x4.Mat4
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.minosoft.gui.rendering.util.mat.mat4.Mat4Util.EMPTY_INSTANCE
import de.bixilon.minosoft.gui.rendering.util.mat.mat4.Mat4Util.reset
import java.nio.FloatBuffer
class TransformInstance(
@ -27,21 +27,21 @@ class TransformInstance(
fun reset() {
this.value(Mat4.EMPTY_INSTANCE)
this.value.reset()
for ((name, child) in children) {
child.reset()
}
}
fun pack(buffer: FloatBuffer, parent: Mat4) {
val value = parent * value
fun pack(buffer: FloatBuffer, parent: Mat4, temp: Mat4) {
parent.times(value, temp)
val offset = this.id * Mat4.length
for (index in 0 until Mat4.length) {
buffer.put(offset + index, value.array[index])
buffer.put(offset + index, temp.array[index])
}
for ((name, child) in children) {
child.pack(buffer, value)
child.pack(buffer, temp, temp)
}
}
}

View File

@ -72,7 +72,7 @@ interface RenderSystem {
this.depth = settings.depth
this.depthMask = settings.depthMask
this.clearColor = settings.clearColor
shader = null
// shader = null
polygonOffset(settings.polygonOffsetFactor, settings.polygonOffsetUnit)
}

View File

@ -14,7 +14,6 @@
package de.bixilon.minosoft.gui.rendering.system.opengl
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf
import de.bixilon.kutil.concurrent.lock.thread.ThreadMissmatchException
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.text.formatting.color.Colors
@ -47,6 +46,7 @@ import org.lwjgl.opengl.GL43.GL_DEBUG_OUTPUT
import org.lwjgl.opengl.GL43.glDebugMessageCallback
import java.nio.ByteBuffer
import java.nio.FloatBuffer
import java.util.*
class OpenGLRenderSystem(
private val context: RenderContext,
@ -54,7 +54,7 @@ class OpenGLRenderSystem(
private var thread: Thread? = null
override val nativeShaders: MutableSet<NativeShader> = mutableSetOf()
override val shaders: MutableSet<Shader> = mutableSetOf()
private val capabilities: MutableSet<RenderingCapabilities> = synchronizedSetOf()
private val capabilities: EnumSet<RenderingCapabilities> = EnumSet.noneOf(RenderingCapabilities::class.java)
override lateinit var vendor: OpenGLVendor
private set
override var active: Boolean = false

View File

@ -50,4 +50,12 @@ object Mat4Util {
res[2] = this[0, 2] * array[0] + this[1, 2] * array[1] + this[2, 2] * array[2] + this[3, 2]
return res
}
fun Mat4.reset() {
val array = this.array
array[0] = 1.0f; array[1] = 0.0f;array[2] = 0.0f;array[3] = 0.0f
array[4] = 0.0f; array[5] = 1.0f;array[6] = 0.0f;array[7] = 0.0f
array[8] = 0.0f; array[9] = 0.0f;array[10] = 1.0f;array[11] = 0.0f
array[12] = 0.0f; array[13] = 0.0f;array[14] = 0.0f;array[15] = 1.0f
}
}

View File

@ -0,0 +1,42 @@
{
"elements": {
"body": {
"from": [-4, 12, -2],
"to": [4, 24, 2],
"texture": "minecraft:skin",
"uv": [16, 16],
"faces": "all",
"children": {
"head": {
"offset": [0, 24, 0],
"from": [-4, 0, -4],
"to": [4, 8, 4],
"uv": [0, 0],
"transform": "head",
"faces": "all",
"children": {
"hat": {
"from": [-4, 0, -4],
"to": [4, 8, 4],
"inflate": 0.5,
"uv": [32, 0],
"faces": "all"
}
}
}
}
}
},
"transforms": {
"head": {},
"right_arm": {},
"left_arm": {},
"right_leg": {},
"left_leg": {}
},
"textures": {
"minecraft:skin": {
"resolution": [64, 64]
}
}
}