Help Modifying a shader to work on Love 11.2

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
kicknbritt
Citizen
Posts: 96
Joined: Sat May 30, 2015 2:15 am
Location: Chicago, IL/Anchorage,AK

Help Modifying a shader to work on Love 11.2

Post 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.
Attachments
Proper Rendering.PNG
Proper Rendering.PNG (141.48 KiB) Viewed 3312 times
love3d-demos-master.zip
The project folder
(599.47 KiB) Downloaded 137 times
The mesh rendering glitch
The mesh rendering glitch
Mesh Glitch.png (12.16 KiB) Viewed 3314 times
"I AM THE ARBITER!!!" *Pulls out Energy sword and kills everything*
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help Modifying a shader to work on Love 11.2

Post 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.
User avatar
kicknbritt
Citizen
Posts: 96
Joined: Sat May 30, 2015 2:15 am
Location: Chicago, IL/Anchorage,AK

Re: Help Modifying a shader to work on Love 11.2

Post 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
"I AM THE ARBITER!!!" *Pulls out Energy sword and kills everything*
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 51 guests