2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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:
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/CocosGUI.h"
|
|
|
|
|
2023-03-14 07:56:07 +08:00
|
|
|
#include "extensions/axmol-ext.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "../BaseTest.h"
|
|
|
|
|
|
|
|
DEFINE_TEST_SUITE(ShaderTests);
|
|
|
|
|
|
|
|
class ShaderTestDemo : public TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderMonjori : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderMonjori);
|
|
|
|
ShaderMonjori();
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderMandelbrot : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderMandelbrot);
|
|
|
|
ShaderMandelbrot();
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderJulia : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderJulia);
|
|
|
|
ShaderJulia();
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderHeart : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderHeart);
|
|
|
|
ShaderHeart();
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderFlower : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderFlower);
|
|
|
|
ShaderFlower();
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderPlasma : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderPlasma);
|
|
|
|
ShaderPlasma();
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SpriteBlur;
|
|
|
|
class ShaderBlur : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderBlur);
|
|
|
|
ShaderBlur();
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
void createSliderCtls();
|
2022-10-18 19:17:36 +08:00
|
|
|
void onRadiusChanged(ax::Ref* sender, ax::extension::Control::EventType controlEvent);
|
|
|
|
void onSampleNumChanged(ax::Ref* sender, ax::extension::Control::EventType controlEvent);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
SpriteBlur* _blurSprite;
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::extension::ControlSlider* _sliderRadiusCtl;
|
|
|
|
ax::extension::ControlSlider* _sliderNumCtrl;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderRetroEffect : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderRetroEffect);
|
|
|
|
ShaderRetroEffect();
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::Label* _label;
|
2021-12-31 12:12:40 +08:00
|
|
|
float _accum;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
class ShaderNode : public ax::Node
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderNode);
|
2021-12-31 12:12:40 +08:00
|
|
|
static ShaderNode* shaderNodeWithVertex(std::string_view vert, std::string_view frag);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual void update(float dt) override;
|
2022-10-18 19:17:36 +08:00
|
|
|
virtual void setPosition(const ax::Vec2& newPosition) override;
|
|
|
|
virtual void draw(ax::Renderer* renderer, const ax::Mat4& transform, uint32_t flags) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ShaderNode();
|
|
|
|
~ShaderNode();
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
bool initWithVertex(std::string_view vert, std::string_view frag);
|
|
|
|
void loadShaderVertex(std::string_view vert, std::string_view frag);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-09-01 10:37:57 +08:00
|
|
|
virtual bool setProgramState(ax::backend::ProgramState* programState, bool ownPS = false) override
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2023-09-01 10:37:57 +08:00
|
|
|
if (Node::setProgramState(programState, ownPS))
|
2021-12-31 12:12:40 +08:00
|
|
|
{
|
2020-10-16 16:23:14 +08:00
|
|
|
_customCommand.getPipelineDescriptor().programState = programState;
|
|
|
|
updateUniforms();
|
|
|
|
return true;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2020-10-16 16:23:14 +08:00
|
|
|
return false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateUniforms();
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::Vec2 _center;
|
|
|
|
ax::Vec2 _resolution;
|
2021-12-31 12:12:40 +08:00
|
|
|
float _time;
|
|
|
|
std::string _vertFileName;
|
|
|
|
std::string _fragFileName;
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::CustomCommand _customCommand;
|
|
|
|
|
|
|
|
ax::backend::UniformLocation _locResolution;
|
|
|
|
ax::backend::UniformLocation _locCenter;
|
|
|
|
ax::backend::UniformLocation _locMVP;
|
|
|
|
ax::backend::UniformLocation _locTime;
|
|
|
|
ax::backend::UniformLocation _locSinTime;
|
|
|
|
ax::backend::UniformLocation _locCosTime;
|
|
|
|
ax::backend::UniformLocation _locScreenSize;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderLensFlare : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderLensFlare);
|
|
|
|
ShaderLensFlare();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderGlow : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderGlow);
|
|
|
|
ShaderGlow();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderMultiTexture : public ShaderTestDemo
|
|
|
|
{
|
|
|
|
static const int rightSpriteTag = 2014;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
|
|
|
CREATE_FUNC(ShaderMultiTexture);
|
|
|
|
ShaderMultiTexture();
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::ui::Slider* createSliderCtl();
|
|
|
|
void changeTexture(ax::Ref*);
|
2019-11-23 20:27:39 +08:00
|
|
|
int _changedTextureId;
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::Sprite* _sprite;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual bool init() override;
|
|
|
|
};
|