2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-03-26 13:45:03 +08:00
|
|
|
#pragma once
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2014-05-16 07:45:46 +08:00
|
|
|
#include "ui/CocosGUI.h"
|
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/cocos-ext.h"
|
2013-06-08 08:21:11 +08:00
|
|
|
#include "../BaseTest.h"
|
2012-07-19 17:22:36 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
DEFINE_TEST_SUITE(ShaderTests);
|
|
|
|
|
|
|
|
class ShaderTestDemo : public TestCase
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderMonjori : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderMonjori);
|
2012-03-21 17:27:13 +08:00
|
|
|
ShaderMonjori();
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderMandelbrot : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderMandelbrot);
|
2012-04-19 14:35:52 +08:00
|
|
|
ShaderMandelbrot();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderJulia : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderJulia);
|
2012-04-19 14:35:52 +08:00
|
|
|
ShaderJulia();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderHeart : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderHeart);
|
2012-04-19 14:35:52 +08:00
|
|
|
ShaderHeart();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderFlower : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderFlower);
|
2012-04-19 14:35:52 +08:00
|
|
|
ShaderFlower();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderPlasma : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderPlasma);
|
2012-04-19 14:35:52 +08:00
|
|
|
ShaderPlasma();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
2012-04-17 18:31:31 +08:00
|
|
|
class SpriteBlur;
|
|
|
|
class ShaderBlur : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderBlur);
|
2012-04-17 18:31:31 +08:00
|
|
|
ShaderBlur();
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2014-06-12 09:49:48 +08:00
|
|
|
void createSliderCtls();
|
2015-04-09 08:37:30 +08:00
|
|
|
void onRadiusChanged(cocos2d::Ref* sender, cocos2d::extension::Control::EventType controlEvent);
|
|
|
|
void onSampleNumChanged(cocos2d::Ref* sender, cocos2d::extension::Control::EventType controlEvent);
|
2014-06-12 09:49:48 +08:00
|
|
|
|
2012-04-17 18:31:31 +08:00
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
SpriteBlur* _blurSprite;
|
2015-04-09 12:23:47 +08:00
|
|
|
cocos2d::extension::ControlSlider* _sliderRadiusCtl;
|
|
|
|
cocos2d::extension::ControlSlider* _sliderNumCtrl;
|
2012-04-17 18:31:31 +08:00
|
|
|
};
|
|
|
|
|
2012-04-18 13:58:24 +08:00
|
|
|
class ShaderRetroEffect : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderRetroEffect);
|
2012-04-18 13:58:24 +08:00
|
|
|
ShaderRetroEffect();
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2017-09-08 14:10:40 +08:00
|
|
|
virtual bool init() override;
|
|
|
|
virtual void update(float dt) override;
|
2012-04-18 13:58:24 +08:00
|
|
|
protected:
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Label* _label;
|
2013-06-15 14:03:30 +08:00
|
|
|
float _accum;
|
2012-04-18 13:58:24 +08:00
|
|
|
};
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
class ShaderNode : public cocos2d::Node
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderNode);
|
2014-05-13 10:12:56 +08:00
|
|
|
static ShaderNode* shaderNodeWithVertex(const std::string &vert, const std::string &frag);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual void update(float dt) override;
|
2015-04-09 08:37:30 +08:00
|
|
|
virtual void setPosition(const cocos2d::Vec2 &newPosition) override;
|
|
|
|
virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override;
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-12-25 16:38:43 +08:00
|
|
|
protected:
|
2014-05-13 10:12:56 +08:00
|
|
|
ShaderNode();
|
|
|
|
~ShaderNode();
|
|
|
|
|
|
|
|
bool initWithVertex(const std::string &vert, const std::string &frag);
|
|
|
|
void loadShaderVertex(const std::string &vert, const std::string &frag);
|
|
|
|
|
2019-07-03 10:43:10 +08:00
|
|
|
virtual void setProgramState(cocos2d::backend::ProgramState *programState) override
|
2019-03-26 13:45:03 +08:00
|
|
|
{
|
|
|
|
if (programState != _programState)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(_programState);
|
|
|
|
_programState = programState;
|
|
|
|
CC_SAFE_RETAIN(_programState);
|
|
|
|
}
|
|
|
|
_customCommand.getPipelineDescriptor().programState = programState;
|
|
|
|
updateUniforms();
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateUniforms();
|
|
|
|
|
|
|
|
cocos2d::Vec2 _center;
|
|
|
|
cocos2d::Vec2 _resolution;
|
|
|
|
float _time;
|
|
|
|
std::string _vertFileName;
|
|
|
|
std::string _fragFileName;
|
|
|
|
cocos2d::CustomCommand _customCommand;
|
|
|
|
|
|
|
|
cocos2d::backend::UniformLocation _locResolution;
|
|
|
|
cocos2d::backend::UniformLocation _locCenter;
|
|
|
|
cocos2d::backend::UniformLocation _locMVP;
|
|
|
|
cocos2d::backend::UniformLocation _locTime;
|
|
|
|
cocos2d::backend::UniformLocation _locSinTime;
|
|
|
|
cocos2d::backend::UniformLocation _locCosTime;
|
2019-09-04 09:58:40 +08:00
|
|
|
cocos2d::backend::UniformLocation _locScreenSize;
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
2014-05-10 11:34:15 +08:00
|
|
|
class ShaderLensFlare : public ShaderTestDemo
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderLensFlare);
|
2014-05-10 11:34:15 +08:00
|
|
|
ShaderLensFlare();
|
2014-05-10 02:48:11 +08:00
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2014-05-10 02:48:11 +08:00
|
|
|
};
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
class ShaderGlow : public ShaderTestDemo
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderGlow);
|
2014-05-14 03:55:34 +08:00
|
|
|
ShaderGlow();
|
2014-05-10 02:48:11 +08:00
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2014-05-10 02:48:11 +08:00
|
|
|
};
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
class ShaderMultiTexture : public ShaderTestDemo
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
2014-06-09 10:58:28 +08:00
|
|
|
static const int rightSpriteTag = 2014;
|
2014-05-10 02:48:11 +08:00
|
|
|
public:
|
2015-04-03 14:31:03 +08:00
|
|
|
CREATE_FUNC(ShaderMultiTexture);
|
2014-05-14 03:55:34 +08:00
|
|
|
ShaderMultiTexture();
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::ui::Slider* createSliderCtl();
|
|
|
|
void changeTexture(cocos2d::Ref*);
|
2014-06-09 10:58:28 +08:00
|
|
|
int _changedTextureId;
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Sprite* _sprite;
|
2014-05-14 03:55:34 +08:00
|
|
|
|
2014-05-10 02:48:11 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2014-05-10 02:48:11 +08:00
|
|
|
};
|
|
|
|
|