Ai
1 Star 1 Fork 2

小康6650/Cocos2dGraphicEffect

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ShadowScene.h 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
小康6650 提交于 2019-02-17 22:53 +08:00 . finish Shadow.
#ifndef __SHADOW_SCENE_H__
#define __SHADOW_SCENE_H__
#include "cocos2d.h"
//深度纹理帧缓存附件,可以将深度信息渲染到纹理
class RenderBufferDepthTexture :public cocos2d::experimental::RenderTargetBase
{
public:
static RenderBufferDepthTexture* create(unsigned int size);
bool init(unsigned int size);
//这里修改了游戏引擎,这个函数是我增加的,用于帧缓存渲染到特殊纹理,
//原本的帧缓存只可以渲染到Texture 2d,不可渲染到其他纹理,
virtual void onApplyFBO(GLenum target) override;
GLuint getShadowTextureName() const { return _tex; }
protected:
RenderBufferDepthTexture();
virtual ~RenderBufferDepthTexture();
private:
GLuint _tex;
};
//将摄像机放在点光源处,生成点光源视角下场景的深度信息
class ShadowCamera :public cocos2d::Camera
{
public:
static ShadowCamera *create(cocos2d::Camera *viewCamera, cocos2d::CameraFlag shadowFlag);
virtual bool init(cocos2d::Camera *viewCamera, cocos2d::CameraFlag shadowFlag);
void setPorjectionMatrix(cocos2d::Mat4 &projection);
GLuint GetShadowTexture();
protected:
ShadowCamera();
virtual ~ShadowCamera();
RenderBufferDepthTexture *_rt;
};
class ShadowSprite : public cocos2d::Sprite3D
{
public:
//重写Create函数
static ShadowSprite* create();
static ShadowSprite* create(const std::string &modelPath);
static ShadowSprite* create(const std::string &modelPath, const std::string &texturePath);
static cocos2d::Material *getShadowMaterial(cocos2d::Sprite3DMaterial::MaterialType type);
virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;
void setShadowCamera(ShadowCamera *camera, bool applyChildren = true);
bool initWithFile(const std::string &path);
protected:
static cocos2d::Sprite3DMaterial *_shadowDiffuseMaterial;
static cocos2d::Sprite3DMaterial *_shadowDiffuseNoTexMaterial;
ShadowSprite();
virtual ~ShadowSprite();
ShadowCamera *_shadowCamera;
};
class ShadowScene : public cocos2d::Scene
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuBackCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(ShadowScene);
private:
bool _isLeftButtonDown;
bool _isCrtlKeyDown;
cocos2d::EventListenerMouse *_mouseListen;
cocos2d::EventListenerKeyboard *_keyListen;
cocos2d::Vec2 _mouseLatestPosition;
float _angle = 0.f;
float _aspect = 1000.f;
float _cameraRadius = 2000.f;
};
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Kyle12/Cocos2dGraphicEffect.git
git@gitee.com:Kyle12/Cocos2dGraphicEffect.git
Kyle12
Cocos2dGraphicEffect
Cocos2dGraphicEffect
master

搜索帮助