skeletal fixes

This commit is contained in:
Moritz Zwerger 2023-10-26 18:32:25 +02:00
parent 1d02603637
commit 12d9157172
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 54 additions and 36 deletions

View File

@ -20,7 +20,6 @@ import de.bixilon.minosoft.data.registries.identified.Identified
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
import de.bixilon.minosoft.gui.rendering.entities.factory.RegisteredEntityModelFactory
import de.bixilon.minosoft.gui.rendering.entities.feature.SkeletalFeature
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader
import de.bixilon.minosoft.gui.rendering.models.loader.SkeletalLoader.Companion.sModel
@ -34,6 +33,11 @@ open class PlayerRenderer<E : PlayerEntity>(renderer: EntitiesRenderer, entity:
override fun update(millis: Long) {
updateSkeletalModel()
super.update(millis)
}
private fun updateSkeletalModel() {
if (registered) return
val update = updateProperties()
@ -42,7 +46,7 @@ open class PlayerRenderer<E : PlayerEntity>(renderer: EntitiesRenderer, entity:
val instance = model?.createInstance(renderer.context) ?: return
this.registered = true
this.features += SkeletalFeature(this, instance)
// this.features += SkeletalFeature(this, instance)
}
private fun updateProperties(): Boolean {
@ -88,9 +92,10 @@ open class PlayerRenderer<E : PlayerEntity>(renderer: EntitiesRenderer, entity:
override fun create(renderer: EntitiesRenderer, entity: PlayerEntity) = PlayerRenderer(renderer, entity)
override fun register(loader: ModelLoader) {
val override = mapOf(SKIN to loader.context.textures.debugTexture) // no texture
val override = mapOf(SKIN to loader.context.textures.debugTexture) // disable textures, they all dynamic
loader.skeletal.register(WIDE, override = override)
loader.skeletal.register(SLIM, override = override)
// TODO: load with custom mesh, load custom shader
}
}
}

View File

@ -28,11 +28,9 @@
}
},
"transforms": {
"head": {},
"right_arm": {},
"left_arm": {},
"right_leg": {},
"left_leg": {}
"head": {
"pivot": [0, 24, 0]
}
},
"textures": {
"minecraft:skin": {

View File

@ -11,16 +11,15 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
float decodeNormal(uint data) {
float decodeNormalPart(uint data) {
return (data / 15.0f) * 2.0f - 1.0f;
}
vec3 decodeNormal(float normal) {
uint combined = floatBitsToUint(normal);
uint x = combined & 0x0Fu;
uint y = combined >> 8u & 0x0Fu;
uint z = combined >> 4u & 0x0Fu;
return vec3(decodeNormal(x), decodeNormal(y), decodeNormal(z));
vec3 decodeNormal(uint normal) {
uint x = normal & 0x0Fu;
uint y = normal >> 8u & 0x0Fu;
uint z = normal >> 4u & 0x0Fu;
return vec3(decodeNormalPart(x), decodeNormalPart(y), decodeNormalPart(z));
}
vec3 transformNormal(vec3 normal, mat4 transform) {
@ -29,6 +28,7 @@ vec3 transformNormal(vec3 normal, mat4 transform) {
}
float getShade(vec3 normal) {
// TODO: interpolate between 3 sides
if (normal.y < -0.5f) return 0.5f;
if (normal.y > 0.5f) return 1.0f;
if (normal.x < -0.5f || normal.x > 0.5f) return 0.6f;

View File

@ -0,0 +1,30 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
uniform mat4 uViewProjectionMatrix;
#include "minosoft:skeletal/buffer"
#include "minosoft:skeletal/shade"
uniform uint uLight;
#include "minosoft:light"
void run_skeletal(uint inTransformNormal, vec3 inPosition) {
mat4 transform = uSkeletalTransforms[(inTransformNormal >> 12u) & 0x7Fu];
vec4 position = transform * vec4(inPosition, 1.0f);
gl_Position = uViewProjectionMatrix * position;
vec3 normal = transformNormal(decodeNormal(inTransformNormal & 0xFFFu), transform);
finTintColor = getLight(uLight & 0xFFu) * vec4(vec3(getShade(normal)), 1.0f);
finFragmentPosition = position.xyz;
}

View File

@ -18,13 +18,14 @@ out vec4 foutColor;
#include "minosoft:animation/header_fragment"
#define FOG// for animation/main_fragment
#define TRANSPARENT
#include "minosoft:texture"
#include "minosoft:alpha"
#include "minosoft:fog"
#define FOG// for animation/main_fragment
#define TRANSPARENT
#include "minosoft:animation/main_fragment"

View File

@ -19,31 +19,15 @@ layout (location = 2) in float vinTransformNormal; // transform (0x7F000), norma
layout (location = 3) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000), animation index (0x00000FFF)
#include "minosoft:animation/header_vertex"
uniform mat4 uViewProjectionMatrix;
#include "minosoft:skeletal/buffer"
uniform uint uLight;
#include "minosoft:skeletal/vertex"
#include "minosoft:animation/buffer"
#include "minosoft:light"
#include "minosoft:animation/main_vertex"
#include "minosoft:skeletal/shade"
void main() {
uint transformNormal = floatBitsToInt(vinTransform);
mat4 transform = uSkeletalTransforms[(transformNormal >> 12u) & 0x7F];
vec4 position = transform * vec4(vinPosition, 1.0f);
gl_Position = uViewProjectionMatrix * position;
vec3 normal = transformNormal(decodeNormal(vinNormal & 0xFFF), transform);
finTintColor = getLight(uLight & 0xFFu) * vec4(vec3(getShade(normal)), 1.0f);
finFragmentPosition = position.xyz;
run_skeletal(floatBitsToUint(vinTransformNormal), vinPosition);
run_animation();
}