代码拉取完成,页面将自动刷新
#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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。