mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
updateLightingmap sync to native-engine for v3.4.1 (#4109)
* updateLightingmap sync to native-engine for v3.4.1
This commit is contained in:
committed by
GitHub
parent
e39502640a
commit
4e231f4232
@@ -79,6 +79,9 @@ void Model::updateUBOs(uint32_t stamp) {
|
||||
memcpy(bufferView.data() + pipeline::UBOLocal::MAT_WORLD_OFFSET, worldMatrix.m, sizeof(Mat4));
|
||||
Mat4::inverseTranspose(worldMatrix, &mat4);
|
||||
memcpy(bufferView.data() + pipeline::UBOLocal::MAT_WORLD_IT_OFFSET, mat4.m, sizeof(Mat4));
|
||||
const float lightmapUVParam[4] = {_lightmapSettings._lightmapUVParam.x, _lightmapSettings._lightmapUVParam.y,
|
||||
_lightmapSettings._lightmapUVParam.z, _lightmapSettings._lightmapUVParam.w};
|
||||
memcpy(bufferView.data() + pipeline::UBOLocal::LIGHTINGMAP_UVPARAM, lightmapUVParam, sizeof(lightmapUVParam));
|
||||
_localBuffer->update(bufferView.data(), pipeline::UBOLocal::SIZE);
|
||||
|
||||
const bool enableOcclusionQuery = pipeline::RenderPipeline::getInstance()->getOcclusionQueryEnabled();
|
||||
@@ -88,6 +91,20 @@ void Model::updateUBOs(uint32_t stamp) {
|
||||
}
|
||||
}
|
||||
|
||||
void Model::updateLightingmap(const Vec4 &lightmapUVParam, gfx::Sampler *sampler, gfx::Texture *lightmap) {
|
||||
_lightmapSettings._lightmapUVParam = lightmapUVParam;
|
||||
_lightmapSettings._sampler = sampler;
|
||||
_lightmapSettings._lightmap = lightmap;
|
||||
for (const SubModel *subModel : _subModels) {
|
||||
if (sampler && lightmap) {
|
||||
gfx::DescriptorSet *descriptorSet = subModel->getDescriptorSet();
|
||||
descriptorSet->bindSampler(pipeline::LIGHTMAPTEXTURE::BINDING, sampler);
|
||||
descriptorSet->bindTexture(pipeline::LIGHTMAPTEXTURE::BINDING, lightmap);
|
||||
descriptorSet->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Model::updateWorldBoundUBOs() {
|
||||
if (_worldBoundBuffer) {
|
||||
std::array<float, pipeline::UBOWorldBound::COUNT> worldBoundBufferView;
|
||||
|
||||
+32
-24
@@ -88,31 +88,33 @@ public:
|
||||
_instanceAttributes = attributes;
|
||||
_transformUpdated = true;
|
||||
}
|
||||
inline void setOctreeNode(OctreeNode *node) { _octreeNode = node; }
|
||||
inline void setScene(RenderScene *scene) { _scene = scene; if (scene) _transformUpdated = true; }
|
||||
inline void setOctreeNode(OctreeNode * node) { _octreeNode = node; }
|
||||
inline void setScene(RenderScene * scene) { _scene = scene; if (scene) _transformUpdated = true; }
|
||||
|
||||
inline bool getCastShadow() const { return _castShadow; }
|
||||
inline bool getEnabled() const { return _enabled; }
|
||||
inline int32_t getInstMatWorldIdx() const { return _instMatWorldIdx; }
|
||||
inline const std::vector<gfx::Attribute> &getInstanceAttributes() const { return _instanceAttributes; }
|
||||
inline InstancedAttributeBlock * getInstancedAttributeBlock() { return &_instanceAttributeBlock; }
|
||||
inline uint8_t * getInstancedBuffer() const { return std::get<0>(_instancedBuffer); }
|
||||
inline uint32_t getInstancedBufferSize() const { return std::get<1>(_instancedBuffer); }
|
||||
inline gfx::Buffer * getLocalBuffer() const { return _localBuffer; }
|
||||
inline gfx::Buffer * getWorldBoundBuffer() const { return _worldBoundBuffer; }
|
||||
inline float * getLocalData() const { return _localData; }
|
||||
inline const AABB & getModelBounds() const { return _modelBounds; }
|
||||
inline Node * getNode() const { return _node; }
|
||||
inline bool getReceiveShadow() const { return _receiveShadow; }
|
||||
inline const std::vector<SubModel *> & getSubModels() const { return _subModels; }
|
||||
inline Node * getTransform() const { return _transform; }
|
||||
inline bool getTransformUpdated() const { return _transformUpdated; }
|
||||
inline int32_t getUpdatStamp() const { return _updateStamp; }
|
||||
inline uint32_t getVisFlags() const { return _visFlags; }
|
||||
inline AABB * getWorldBounds() const { return _worldBounds; }
|
||||
inline ModelType getType() const { return _type; };
|
||||
inline OctreeNode * getOctreeNode() const { return _octreeNode; }
|
||||
inline RenderScene * getScene() const { return _scene; }
|
||||
inline bool getCastShadow() const { return _castShadow; }
|
||||
inline bool getEnabled() const { return _enabled; }
|
||||
inline int32_t getInstMatWorldIdx() const { return _instMatWorldIdx; }
|
||||
inline const std::vector<gfx::Attribute> & getInstanceAttributes() const { return _instanceAttributes; }
|
||||
inline InstancedAttributeBlock * getInstancedAttributeBlock() { return &_instanceAttributeBlock; }
|
||||
inline uint8_t * getInstancedBuffer() const { return std::get<0>(_instancedBuffer); }
|
||||
inline uint32_t getInstancedBufferSize() const { return std::get<1>(_instancedBuffer); }
|
||||
inline gfx::Buffer * getLocalBuffer() const { return _localBuffer; }
|
||||
inline gfx::Buffer * getWorldBoundBuffer() const { return _worldBoundBuffer; }
|
||||
inline float * getLocalData() const { return _localData; }
|
||||
inline const AABB & getModelBounds() const { return _modelBounds; }
|
||||
inline Node * getNode() const { return _node; }
|
||||
inline bool getReceiveShadow() const { return _receiveShadow; }
|
||||
inline const std::vector<SubModel *> & getSubModels() const { return _subModels; }
|
||||
inline Node * getTransform() const { return _transform; }
|
||||
inline bool getTransformUpdated() const { return _transformUpdated; }
|
||||
inline int32_t getUpdatStamp() const { return _updateStamp; }
|
||||
inline uint32_t getVisFlags() const { return _visFlags; }
|
||||
inline AABB * getWorldBounds() const { return _worldBounds; }
|
||||
inline ModelType getType() const { return _type; }
|
||||
inline OctreeNode * getOctreeNode() const { return _octreeNode; }
|
||||
inline RenderScene * getScene() const { return _scene; }
|
||||
|
||||
void updateLightingmap(const Vec4 &lightmapUVParam, gfx::Sampler *sampler, gfx::Texture *lightmap);
|
||||
|
||||
protected:
|
||||
ModelType _type{ModelType::DEFAULT};
|
||||
@@ -140,6 +142,12 @@ private:
|
||||
std::vector<SubModel *> _subModels;
|
||||
std::vector<gfx::Attribute> _instanceAttributes;
|
||||
static void uploadMat4AsVec4x3(const Mat4 &mat, float *v1, float *v2, float *v3);
|
||||
|
||||
struct LightmapSettings {
|
||||
Vec4 _lightmapUVParam;
|
||||
gfx::Texture *_lightmap{nullptr};
|
||||
gfx::Sampler *_sampler{nullptr};
|
||||
} _lightmapSettings{};
|
||||
};
|
||||
|
||||
} // namespace scene
|
||||
|
||||
Reference in New Issue
Block a user