mirror of https://github.com/axmolengine/axmol.git
commit
2f2e2e2b46
|
@ -52,6 +52,7 @@ static std::function<Layer*()> createFunctions[] =
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||||
// 3DEffect use custom shader which is not supported on WP8/WinRT yet.
|
// 3DEffect use custom shader which is not supported on WP8/WinRT yet.
|
||||||
CL(Sprite3DEffectTest),
|
CL(Sprite3DEffectTest),
|
||||||
|
CL(Sprite3DUVAnimationTest),
|
||||||
#endif
|
#endif
|
||||||
CL(Sprite3DWithSkinTest),
|
CL(Sprite3DWithSkinTest),
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||||
|
@ -225,6 +226,103 @@ std::string Sprite3DBasicTest::subtitle() const
|
||||||
return "Tap screen to add more sprites";
|
return "Tap screen to add more sprites";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Sprite3DUVAnimationTest
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
Sprite3DUVAnimationTest::Sprite3DUVAnimationTest()
|
||||||
|
{
|
||||||
|
//the offset use to translating texture
|
||||||
|
this->cylinder_texture_offset = 0;
|
||||||
|
this->shining_duraion = 0;
|
||||||
|
Size visibleSize = Director::getInstance()->getVisibleSize();
|
||||||
|
|
||||||
|
//use custom camera
|
||||||
|
auto camera = Camera::createPerspective(60,visibleSize.width/visibleSize.height,0.1,200);
|
||||||
|
camera->setCameraFlag(CameraFlag::USER1);
|
||||||
|
|
||||||
|
//create cylinder
|
||||||
|
auto cylinder = Sprite3D::create("Sprite3DTest/cylinder.c3b");
|
||||||
|
|
||||||
|
//create and set our custom shader
|
||||||
|
auto shader =GLProgram::createWithFilenames("Sprite3DTest/cylinder.vert","Sprite3DTest/cylinder.frag");
|
||||||
|
state = GLProgramState::create(shader);
|
||||||
|
cylinder->setGLProgramState(state);
|
||||||
|
|
||||||
|
state->setUniformFloat("offset",cylinder_texture_offset);
|
||||||
|
state->setUniformFloat("duration",shining_duraion);
|
||||||
|
//pass mesh's attribute to shader
|
||||||
|
long offset = 0;
|
||||||
|
auto attributeCount = cylinder->getMesh()->getMeshVertexAttribCount();
|
||||||
|
for (auto i = 0; i < attributeCount; i++) {
|
||||||
|
auto meshattribute = cylinder->getMesh()->getMeshVertexAttribute(i);
|
||||||
|
state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
||||||
|
meshattribute.size,
|
||||||
|
meshattribute.type,
|
||||||
|
GL_FALSE,
|
||||||
|
cylinder->getMesh()->getVertexSizeInBytes(),
|
||||||
|
(GLvoid*)offset);
|
||||||
|
offset += meshattribute.attribSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//create the second texture for cylinder
|
||||||
|
auto shining_texture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/caustics.png");
|
||||||
|
Texture2D::TexParams tRepeatParams;//set texture parameters
|
||||||
|
tRepeatParams.magFilter = GL_LINEAR_MIPMAP_LINEAR;
|
||||||
|
tRepeatParams.minFilter = GL_LINEAR;
|
||||||
|
tRepeatParams.wrapS = GL_REPEAT;
|
||||||
|
tRepeatParams.wrapT = GL_REPEAT;
|
||||||
|
shining_texture->setTexParameters(tRepeatParams);
|
||||||
|
//pass the texture sampler to our custom shader
|
||||||
|
state->setUniformTexture("caustics",shining_texture);
|
||||||
|
|
||||||
|
|
||||||
|
this->addChild(cylinder);
|
||||||
|
this->setCameraMask(2);
|
||||||
|
this->addChild(camera);
|
||||||
|
|
||||||
|
//adjust cylinder's position & rotation
|
||||||
|
cylinder->setPosition3D(Vec3(0,-15,-50));
|
||||||
|
cylinder->setRotation3D(Vec3(-90,0,0));
|
||||||
|
|
||||||
|
//the callback function update cylinder's texcoord
|
||||||
|
schedule(schedule_selector(Sprite3DUVAnimationTest::cylinderUpdate));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DUVAnimationTest::title() const
|
||||||
|
{
|
||||||
|
return "The UV Animation of Sprite3D";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DUVAnimationTest::subtitle() const
|
||||||
|
{
|
||||||
|
return " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sprite3DUVAnimationTest::cylinderUpdate(float dt)
|
||||||
|
{
|
||||||
|
//callback function to update cylinder's texcoord
|
||||||
|
static bool fade_in = true;
|
||||||
|
cylinder_texture_offset += 0.3*dt;
|
||||||
|
cylinder_texture_offset = (cylinder_texture_offset >1)?0:cylinder_texture_offset;
|
||||||
|
if(fade_in)
|
||||||
|
{
|
||||||
|
shining_duraion += 0.5*dt;
|
||||||
|
if(shining_duraion>1) fade_in = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shining_duraion -= 0.5*dt;
|
||||||
|
if(shining_duraion<0) fade_in = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//pass the result to shader
|
||||||
|
state->setUniformFloat("offset",cylinder_texture_offset);
|
||||||
|
state->setUniformFloat("duration",shining_duraion);
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Sprite3DHitTest
|
// Sprite3DHitTest
|
||||||
|
@ -1445,3 +1543,5 @@ void Sprite3DMirrorTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
}
|
}
|
||||||
_mirrorSprite = sprite;
|
_mirrorSprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,19 @@ public:
|
||||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Sprite3DUVAnimationTest : public Sprite3DTestDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(Sprite3DUVAnimationTest);
|
||||||
|
Sprite3DUVAnimationTest();
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
private:
|
||||||
|
void cylinderUpdate(float dt);
|
||||||
|
float cylinder_texture_offset;
|
||||||
|
float shining_duraion;
|
||||||
|
GLProgramState * state;
|
||||||
|
};
|
||||||
class EffectSprite3D;
|
class EffectSprite3D;
|
||||||
|
|
||||||
class Effect3D : public Ref
|
class Effect3D : public Ref
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
@ -0,0 +1,16 @@
|
||||||
|
#ifdef GL_ES
|
||||||
|
varying mediump vec2 TextureCoordOut;
|
||||||
|
#else
|
||||||
|
varying vec2 TextureCoordOut;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform vec4 u_color;
|
||||||
|
uniform float offset;
|
||||||
|
uniform float duration;
|
||||||
|
uniform sampler2D caustics;
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
vec4 golden = duration*vec4(0,0.8,0.4,1.0);
|
||||||
|
//blend two texture
|
||||||
|
gl_FragColor = texture2D(CC_Texture0, vec2(TextureCoordOut.x- 2.0 * offset,TextureCoordOut.y)) * vec4(0.3,0.3,0.3,1)+texture2D(caustics,vec2(TextureCoordOut.x-offset,TextureCoordOut.y)).r*golden;
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
attribute vec4 a_position;
|
||||||
|
attribute vec2 a_texCoord;
|
||||||
|
uniform float offset;
|
||||||
|
varying vec2 TextureCoordOut;
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
gl_Position = CC_MVPMatrix * a_position;
|
||||||
|
TextureCoordOut = a_texCoord;
|
||||||
|
TextureCoordOut.y = (1.0 - TextureCoordOut.y);
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
Loading…
Reference in New Issue