diff --git a/TODO.md b/TODO.md index 109d5b3..57796c2 100644 --- a/TODO.md +++ b/TODO.md @@ -7,7 +7,7 @@ - [x] Fit in 32MB VRAM to run on N8, E7, E6, etc. - [ ] Fix crash in Texture::destroy on exit - [ ] Optimize to always run 20+ fps -- [ ] Fix skinning shader (cutscene heads require it) +- [x] Fix skinning shader (cutscene heads require it) - [ ] Use etc1 compression - [ ] Simplify geometry - [ ] Touch controls diff --git a/group/bld.inf b/group/bld.inf index abf4d0e..c4c8c5c 100644 --- a/group/bld.inf +++ b/group/bld.inf @@ -2,7 +2,7 @@ PRJ_PLATFORMS DEFAULT ARMV6 PRJ_MMPFILES -gnumakefile Icons_scalable_dc.mk gnumakefile shaders.mk +gnumakefile Icons_scalable_dc.mk librw.mmp re3.mmp diff --git a/group/shaders.mk b/group/shaders.mk index 7e321f2..43bec97 100644 --- a/group/shaders.mk +++ b/group/shaders.mk @@ -5,7 +5,8 @@ do_nothing : MAKMAKE: do_nothing -BLD: do_nothing +BLD: + $(MAKE) -C ../vendor/librw/src/gl/shaders/ -f Makefile all CLEAN: rm ../vendor/librw/src/gl/shaders/*.inc @@ -14,8 +15,7 @@ LIB: do_nothing CLEANLIB: do_nothing -RESOURCE: - $(MAKE) -C ../vendor/librw/src/gl/shaders/ -f Makefile all +RESOURCE: do_nothing FREEZE: do_nothing diff --git a/vendor/librw/src/gl/gl3skin.cpp b/vendor/librw/src/gl/gl3skin.cpp index 04777a2..4c7e916 100644 --- a/vendor/librw/src/gl/gl3skin.cpp +++ b/vendor/librw/src/gl/gl3skin.cpp @@ -340,11 +340,10 @@ skinClose(void *o, int32, int32) void initSkin(void) { - // TODO -// u_boneMatrices = registerUniform("u_boneMatrices", UNIFORM_MAT4, MAX_BONES); -// -// Driver::registerPlugin(PLATFORM_GL3, 0, ID_SKIN, -// skinOpen, skinClose); + u_boneMatrices = registerUniform("u_boneMatrices", UNIFORM_MAT4, MAX_BONES); + + Driver::registerPlugin(PLATFORM_GL3, 0, ID_SKIN, + skinOpen, skinClose); } ObjPipeline* diff --git a/vendor/librw/src/gl/shaders/skin.vert b/vendor/librw/src/gl/shaders/skin.vert index 2a712d1..1092d85 100644 --- a/vendor/librw/src/gl/shaders/skin.vert +++ b/vendor/librw/src/gl/shaders/skin.vert @@ -5,55 +5,23 @@ VSIN(ATTRIB_POS) vec3 in_pos; VSOUT vec4 v_color; VSOUT vec3 v_tex0_fog; -mat4 getBoneMatrix(int idx) { - if(idx == 0) return u_boneMatrices[0]; - if(idx == 1) return u_boneMatrices[1]; - if(idx == 2) return u_boneMatrices[2]; - if(idx == 3) return u_boneMatrices[3]; - if(idx == 4) return u_boneMatrices[4]; - if(idx == 5) return u_boneMatrices[5]; - if(idx == 6) return u_boneMatrices[6]; - if(idx == 7) return u_boneMatrices[7]; - if(idx == 8) return u_boneMatrices[8]; - if(idx == 9) return u_boneMatrices[9]; - if(idx == 10) return u_boneMatrices[10]; - if(idx == 11) return u_boneMatrices[11]; - if(idx == 12) return u_boneMatrices[12]; - if(idx == 13) return u_boneMatrices[13]; - if(idx == 14) return u_boneMatrices[14]; - if(idx == 15) return u_boneMatrices[15]; - if(idx == 16) return u_boneMatrices[16]; - if(idx == 17) return u_boneMatrices[17]; - if(idx == 18) return u_boneMatrices[18]; - if(idx == 19) return u_boneMatrices[19]; - if(idx == 20) return u_boneMatrices[20]; - if(idx == 21) return u_boneMatrices[21]; - if(idx == 22) return u_boneMatrices[22]; - if(idx == 23) return u_boneMatrices[23]; - return u_boneMatrices[0]; -} - void main(void) { vec3 SkinVertex = vec3(0.0, 0.0, 0.0); - vec3 SkinNormal = vec3(0.0, 0.0, 0.0); - for(int i = 0; i < 4; i++){ - SkinVertex += (getBoneMatrix(int(in_indices[i])) * vec4(in_pos, 1.0)).xyz * in_weights[i]; - SkinNormal += (mat3(getBoneMatrix(int(in_indices[i]))) * in_normal) * in_weights[i]; - } + + SkinVertex += (u_boneMatrices[int(in_indices.x)] * vec4(in_pos, 1.0)).xyz * in_weights.x; + SkinVertex += (u_boneMatrices[int(in_indices.y)] * vec4(in_pos, 1.0)).xyz * in_weights.y; + SkinVertex += (u_boneMatrices[int(in_indices.z)] * vec4(in_pos, 1.0)).xyz * in_weights.z; + SkinVertex += (u_boneMatrices[int(in_indices.w)] * vec4(in_pos, 1.0)).xyz * in_weights.w; vec4 Vertex = u_world * vec4(SkinVertex, 1.0); gl_Position = u_proj * u_view * Vertex; - vec3 Normal = mat3(u_world) * SkinNormal; - - v_tex0_fog.xy = in_tex0; v_color = in_color; v_color.rgb += u_ambLight.rgb*surfAmbient; - v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse; v_color = clamp(v_color, 0.0, 1.0); v_color *= u_matColor; - v_tex0_fog.z = DoFog(gl_Position.z); + v_tex0_fog = vec3(in_tex0.x, in_tex0.y, DoFog(gl_Position.w)); } diff --git a/vendor/librw/src/gl/shaders/skin_gl.inc b/vendor/librw/src/gl/shaders/skin_gl.inc index 9a264cb..21f13d7 100644 --- a/vendor/librw/src/gl/shaders/skin_gl.inc +++ b/vendor/librw/src/gl/shaders/skin_gl.inc @@ -6,56 +6,24 @@ const char *skin_vert_src = "VSOUT vec4 v_color;\n" "VSOUT vec3 v_tex0_fog;\n" -"mat4 getBoneMatrix(int idx) {\n" -" if(idx == 0) return u_boneMatrices[0];\n" -" if(idx == 1) return u_boneMatrices[1];\n" -" if(idx == 2) return u_boneMatrices[2];\n" -" if(idx == 3) return u_boneMatrices[3];\n" -" if(idx == 4) return u_boneMatrices[4];\n" -" if(idx == 5) return u_boneMatrices[5];\n" -" if(idx == 6) return u_boneMatrices[6];\n" -" if(idx == 7) return u_boneMatrices[7];\n" -" if(idx == 8) return u_boneMatrices[8];\n" -" if(idx == 9) return u_boneMatrices[9];\n" -" if(idx == 10) return u_boneMatrices[10];\n" -" if(idx == 11) return u_boneMatrices[11];\n" -" if(idx == 12) return u_boneMatrices[12];\n" -" if(idx == 13) return u_boneMatrices[13];\n" -" if(idx == 14) return u_boneMatrices[14];\n" -" if(idx == 15) return u_boneMatrices[15];\n" -" if(idx == 16) return u_boneMatrices[16];\n" -" if(idx == 17) return u_boneMatrices[17];\n" -" if(idx == 18) return u_boneMatrices[18];\n" -" if(idx == 19) return u_boneMatrices[19];\n" -" if(idx == 20) return u_boneMatrices[20];\n" -" if(idx == 21) return u_boneMatrices[21];\n" -" if(idx == 22) return u_boneMatrices[22];\n" -" if(idx == 23) return u_boneMatrices[23];\n" -" return u_boneMatrices[0];\n" -"}\n" - "void\n" "main(void)\n" "{\n" " vec3 SkinVertex = vec3(0.0, 0.0, 0.0);\n" -" vec3 SkinNormal = vec3(0.0, 0.0, 0.0);\n" -" for(int i = 0; i < 4; i++){\n" -" SkinVertex += (getBoneMatrix(int(in_indices[i])) * vec4(in_pos, 1.0)).xyz * in_weights[i];\n" -" SkinNormal += (mat3(getBoneMatrix(int(in_indices[i]))) * in_normal) * in_weights[i];\n" -" }\n" +" \n" +" SkinVertex += (u_boneMatrices[int(in_indices.x)] * vec4(in_pos, 1.0)).xyz * in_weights.x;\n" +" SkinVertex += (u_boneMatrices[int(in_indices.y)] * vec4(in_pos, 1.0)).xyz * in_weights.y;\n" +" SkinVertex += (u_boneMatrices[int(in_indices.z)] * vec4(in_pos, 1.0)).xyz * in_weights.z;\n" +" SkinVertex += (u_boneMatrices[int(in_indices.w)] * vec4(in_pos, 1.0)).xyz * in_weights.w;\n" " vec4 Vertex = u_world * vec4(SkinVertex, 1.0);\n" " gl_Position = u_proj * u_view * Vertex;\n" -" vec3 Normal = mat3(u_world) * SkinNormal;\n" - -" v_tex0_fog.xy = in_tex0;\n" " v_color = in_color;\n" " v_color.rgb += u_ambLight.rgb*surfAmbient;\n" -" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" " v_color = clamp(v_color, 0.0, 1.0);\n" " v_color *= u_matColor;\n" -" v_tex0_fog.z = DoFog(gl_Position.z);\n" +" v_tex0_fog = vec3(in_tex0.x, in_tex0.y, DoFog(gl_Position.w));\n" "}\n" ;