Page 1 of 1

Help Modifying a shader to work on Love 11.2

Posted: Mon Nov 18, 2019 10:39 pm
by kicknbritt
Hey guys. So I have been trying to get 3d skeletal animation working for my game for the last week, with no avail.
I trying to use the same technique for skeletal animation used here https://github.com/excessive/love3d-dem ... mation.lua but when I try to render the model it ends up looking very strange and out of place. The original project was written for love 10.2, so I am wondering if it is something caused by a version change, because the project works fine on 10.2, but not 11.2.

Here is the shader code:

Code: Select all

local shader = love.graphics.newShader [[
	varying vec3 v_normal;

	#ifdef VERTEX
		attribute vec4 VertexWeight;
		attribute vec4 VertexBone;
		attribute vec3 VertexNormal;

		uniform mat4 u_model, u_viewproj;
		uniform mat4 u_pose[100];

		vec4 position(mat4 _, vec4 vertex) {
			mat4 skeleton = u_pose[int(VertexBone.x*255.0)] * VertexWeight.x +
				u_pose[int(VertexBone.y*255.0)] * VertexWeight.y +
				u_pose[int(VertexBone.z*255.0)] * VertexWeight.z +
				u_pose[int(VertexBone.w*255.0)] * VertexWeight.w;

			mat4 transform = u_model * skeleton;

			v_normal = mat3(transform) * VertexNormal;

			return u_viewproj * transform * vertex;
		}
	#endif

	#ifdef PIXEL
		uniform vec3 u_light;
		vec4 effect(vec4 color, Image tex, vec2 uv, vec2 sc) {
			float shade = max(0, dot(v_normal, u_light)) + 0.25;
			return vec4(vec3(shade) * color.rgb, 1.0);
		}
	#endif

]]

I checked all through anim9 and the .Iqm loader to find any issues and didn't see anything.
Anyone know why this is happening? Could it be caused by a change in shader code between love 10.2 and 11.2?
The project folder is included below.
Thanks.

Re: Help Modifying a shader to work on Love 11.2

Posted: Tue Nov 19, 2019 1:20 am
by pgimeno
The problem isn't the shader code, but the shader:send() calls. 11.0+ expects matrices to be in row-major order by default (see MatrixLayout), while 0.10.2 and earlier used column-major order only.

Changing these three lines in skeletal-animation.lua makes everything work normally again:

Code: Select all

        shader:send("u_model", "column", m:to_vec4s())
        shader:send("u_viewproj", "column", p:to_vec4s())
        shader:send("u_pose", "column", unpack(anim.current_pose))
Note that love3d.lua is no longer required in 11.0+, because now there's love.graphics.setDepthMode and love.graphics.setMeshCullMode which supersede the OpenGL calls it provided.

Re: Help Modifying a shader to work on Love 11.2

Posted: Tue Nov 19, 2019 3:05 am
by kicknbritt
Omg! Ty so much! And yes I am planning to integrate loves new features for 3d, I just wanted to figure out how skeletal animation works first.
Thanks dude