Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMG Optimization Task #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified res/model/archer/archer.c3b
Binary file not shown.
Binary file modified res/model/dragon/dragon.c3b
Binary file not shown.
Binary file modified res/model/knight/knight.c3b
Binary file not shown.
Binary file modified res/model/mage/mage.c3b
Binary file not shown.
Binary file modified res/model/rat/rat.c3b
Binary file not shown.
Binary file modified res/model/slime/slime.c3b
Binary file not shown.
93 changes: 46 additions & 47 deletions res/shader3D/SkinnedOutline.vert
Original file line number Diff line number Diff line change
@@ -1,73 +1,72 @@
attribute vec3 a_position;
attribute vec3 a_normal;
attribute vec4 a_blendWeight;
attribute lowp vec4 a_blendWeight;
attribute vec4 a_blendIndex;

attribute vec2 a_texCoord;
uniform float OutlineWidth;

const int SKINNING_JOINT_COUNT = 60;
const int SKINNING_JOINT_COUNT = 8;
// Uniforms
uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];

// Varyings
varying vec2 TextureCoordOut;

vec4 SkinnedVec3(vec4 vec)
{
float blendWeight = a_blendWeight[0];
struct SSkinningTransform {
vec4 row_one;
vec4 row_two;
vec4 row_three;
};

SSkinningTransform GenerateSkinningTransform() {
SSkinningTransform skinning_transform;
lowp float blendWeight = a_blendWeight[0];

int matrixIndex = int (a_blendIndex[0]) * 3;
vec4 matrixPalette1 = u_matrixPalette[matrixIndex] * blendWeight;
vec4 matrixPalette2 = u_matrixPalette[matrixIndex + 1] * blendWeight;
vec4 matrixPalette3 = u_matrixPalette[matrixIndex + 2] * blendWeight;


skinning_transform.row_one = u_matrixPalette[matrixIndex] * blendWeight;
skinning_transform.row_two = u_matrixPalette[matrixIndex + 1] * blendWeight;
skinning_transform.row_three = u_matrixPalette[matrixIndex + 2] * blendWeight;

blendWeight = a_blendWeight[1];
if (blendWeight > 0.0)
{
if (blendWeight > 0.0) {
matrixIndex = int(a_blendIndex[1]) * 3;
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
skinning_transform.row_one += u_matrixPalette[matrixIndex] * blendWeight;
skinning_transform.row_two += u_matrixPalette[matrixIndex + 1] * blendWeight;
skinning_transform.row_three += u_matrixPalette[matrixIndex + 2] * blendWeight;
blendWeight = a_blendWeight[2];

if (blendWeight > 0.0) {
matrixIndex = int(a_blendIndex[2]) * 3;
skinning_transform.row_one += u_matrixPalette[matrixIndex] * blendWeight;
skinning_transform.row_two += u_matrixPalette[matrixIndex + 1] * blendWeight;
skinning_transform.row_three += u_matrixPalette[matrixIndex + 2] * blendWeight;
blendWeight = a_blendWeight[3];

if (blendWeight > 0.0) {
matrixIndex = int(a_blendIndex[3]) * 3;
skinning_transform.row_one += u_matrixPalette[matrixIndex] * blendWeight;
skinning_transform.row_two += u_matrixPalette[matrixIndex + 1] * blendWeight;
skinning_transform.row_three += u_matrixPalette[matrixIndex + 2] * blendWeight;
}
}
}


blendWeight = a_blendWeight[2];
if (blendWeight > 0.0)
{
matrixIndex = int(a_blendIndex[2]) * 3;
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
}


blendWeight = a_blendWeight[3];
if (blendWeight > 0.0)
{
matrixIndex = int(a_blendIndex[3]) * 3;
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
}

return skinning_transform;
}

vec4 _skinnedPosition;
vec4 postion = vec;
_skinnedPosition.x = dot(postion, matrixPalette1);
_skinnedPosition.y = dot(postion, matrixPalette2);
_skinnedPosition.z = dot(postion, matrixPalette3);
_skinnedPosition.w = postion.w;

return _skinnedPosition;
vec3 SkinnedVector(vec3 input_vector, SSkinningTransform skinning_transform) {
vec3 skinned_vector;
skinned_vector.x = dot(vec4(input_vector, 1.0), skinning_transform.row_one);
skinned_vector.y = dot(vec4(input_vector, 1.0), skinning_transform.row_two);
skinned_vector.z = dot(vec4(input_vector, 1.0), skinning_transform.row_three);
return skinned_vector;
}

void main()
{
vec4 pos = CC_MVPMatrix * SkinnedVec3(vec4(a_position,1.0));

vec4 normalproj = CC_MVPMatrix * vec4(SkinnedVec3(vec4(a_normal,0.0)).xyz, 0);
SSkinningTransform skinning_transform = GenerateSkinningTransform();
vec4 pos = CC_MVPMatrix * vec4(SkinnedVector(a_position, skinning_transform), 1.0);
vec4 normalproj = CC_MVPMatrix * vec4(SkinnedVector(a_normal, skinning_transform), 0.0);
normalproj = normalize(normalproj);
pos.xy += normalproj.xy * (OutlineWidth * (pos.z * 0.5 + 0.5));

Expand Down
2 changes: 1 addition & 1 deletion src/GameMaster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require "Archer"
--require "Boss"

local gloableZOrder = 1
local monsterCount = {dragon=1,slime=7,piglet=2,rat = 0} --rat count must be 0.
local monsterCount = {dragon=1,slime=8,piglet=0,rat = 0} --rat count must be 0.
local EXIST_MIN_MONSTER = 4
local scheduleid
local stage = 0
Expand Down
3 changes: 2 additions & 1 deletion src/actors/Archer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ function Archer:init3D()
self:initPuff()
self._sprite3d = cc.EffectSprite3D:create(file)
self._sprite3d:setScale(1.6)
self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
--self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could remove this line

self:addChild(self._sprite3d)
self._sprite3d:setRotation3D({x = 90, y = 0, z = 0})
self._sprite3d:setRotation(-90)
self._sprite3d:setOpacity(255)
self:setDefaultEqt()
end

Expand Down
3 changes: 2 additions & 1 deletion src/actors/Dragon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ function Dragon:init3D()
self:initShadow()
self._sprite3d = cc.EffectSprite3D:create(file)
self._sprite3d:setScale(10)
self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
--self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could remove this commented line as well

self:addChild(self._sprite3d)
self._sprite3d:setRotation3D({x = 90, y = 0, z = 0})
self._sprite3d:setRotation(-90)
self._sprite3d:setOpacity(255)
end

-- init Dragon animations=============================
Expand Down
3 changes: 2 additions & 1 deletion src/actors/Knight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ function Knight:init3D()
self:initPuff()
self._sprite3d = cc.EffectSprite3D:create(file)
self._sprite3d:setScale(25)
self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
--self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this commented line

self:addChild(self._sprite3d)
self._sprite3d:setRotation3D({x = 90, y = 0, z = 0})
self._sprite3d:setRotation(-90)
self._sprite3d:setOpacity(255)
self:setDefaultEqt()
end

Expand Down
3 changes: 2 additions & 1 deletion src/actors/Mage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ function Mage:init3D()
self:initPuff()
self._sprite3d = cc.EffectSprite3D:create(file)
self._sprite3d:setScale(1.9)
self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
--self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented line

self:addChild(self._sprite3d)
self._sprite3d:setRotation3D({x = 90, y = 0, z = 0})
self._sprite3d:setRotation(-90)
self._sprite3d:setOpacity(255)
self:setDefaultEqt()
end

Expand Down
3 changes: 2 additions & 1 deletion src/actors/Piglet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ function Piglet:init3D()
self._sprite3d = cc.EffectSprite3D:create(file)
self._sprite3d:setTexture("model/piglet/zhu0928.jpg")
self._sprite3d:setScale(1.3)
self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
--self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented line

self:addChild(self._sprite3d)
self._sprite3d:setRotation3D({x = 90, y = 0, z = 0})
self._sprite3d:setRotation(-90)
self._sprite3d:setOpacity(255)
end

-- init Piglet animations=============================
Expand Down
3 changes: 2 additions & 1 deletion src/actors/Rat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ function Rat:init3D()
self:initShadow()
self._sprite3d = cc.EffectSprite3D:create(file)
self._sprite3d:setScale(20)
self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
--self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented line

self:addChild(self._sprite3d)
self._sprite3d:setRotation3D({x = 90, y = 0, z = 0})
self._sprite3d:setRotation(-90)
self._sprite3d:setOpacity(255)
end

-- init Rat animations=============================
Expand Down
3 changes: 2 additions & 1 deletion src/actors/Slime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ function Slime:init3D()
self._sprite3d = cc.EffectSprite3D:create(file)
self._sprite3d:setTexture("model/slime/baozi.jpg")
self._sprite3d:setScale(17)
self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
--self._sprite3d:addEffect(cc.V3(0,0,0),CelLine, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented line

self:addChild(self._sprite3d)
self._sprite3d:setRotation3D({x = 90, y = 0, z = 0})
self._sprite3d:setRotation(-90)
self._sprite3d:setOpacity(255)
end
--
function Slime:walkMode()
Expand Down