Skip to content

Commit cb92730

Browse files
committed
Added receiveLights
1 parent 98aca92 commit cb92730

6 files changed

Lines changed: 39 additions & 18 deletions

File tree

engine/core/component/MeshComponent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace Supernova{
9898
AABB verticesAABB = AABB::ZERO; // is not influenced by instances
9999
AABB worldAABB; // initially NULL
100100

101+
bool receiveLights = true;
101102
bool castShadows = true;
102103
bool receiveShadows = true;
103104
bool shadowsBillboard = true;

engine/core/object/Mesh.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ unsigned int Mesh::getNumSubmeshes() const{
234234
return mesh.numSubmeshes;
235235
}
236236

237+
void Mesh::setReceiveLights(bool receiveLights){
238+
MeshComponent& mesh = getComponent<MeshComponent>();
239+
240+
if (mesh.receiveLights != receiveLights){
241+
mesh.receiveLights = receiveLights;
242+
243+
mesh.needReload = true;
244+
}
245+
}
246+
247+
bool Mesh::isReceiveLights() const{
248+
MeshComponent& mesh = getComponent<MeshComponent>();
249+
250+
return mesh.receiveLights;
251+
}
252+
237253
void Mesh::setCastShadows(bool castShadows){
238254
MeshComponent& mesh = getComponent<MeshComponent>();
239255

engine/core/object/Mesh.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ namespace Supernova{
6666

6767
unsigned int getNumSubmeshes() const;
6868

69+
void setReceiveLights(bool receiveLights);
70+
bool isReceiveLights() const;
71+
6972
void setCastShadows(bool castShadows);
7073
bool isCastShadows() const;
7174

engine/core/script/binding/ObjectClassesLua.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ void LuaBinding::registerObjectClasses(lua_State *L){
339339
.addFunction("getVerticesAABB", &Mesh::getVerticesAABB)
340340
.addFunction("getWorldAABB", &Mesh::getWorldAABB)
341341
.addFunction("getNumSubmeshes", &Mesh::getNumSubmeshes)
342+
.addProperty("receiveLights", &Mesh::isReceiveLights, &Mesh::setReceiveLights)
342343
.addProperty("castShadows", &Mesh::isCastShadows, &Mesh::setCastShadows)
343344
.addProperty("receiveShadows", &Mesh::isReceiveShadows, &Mesh::setReceiveShadows)
344345
.addProperty("shadowsBillboard", &Mesh::isShadowsBillboard, &Mesh::setShadowsBillboard)

engine/core/subsystem/RenderSystem.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ bool RenderSystem::checkPBRFrabebufferUpdate(Material& material){
355355
material.emissiveTexture.isFramebufferOutdated() );
356356
}
357357

358-
bool RenderSystem::checkPBRTextures(Material& material){
358+
bool RenderSystem::checkPBRTextures(Material& material, bool receiveLights){
359359
bool hasBaseColor = !material.baseColorTexture.empty();
360360

361361
bool hasOtherPBRTextures = false;
362-
if (hasLights) {
362+
if (hasLights && receiveLights) {
363363
hasOtherPBRTextures = !material.metallicRoughnessTexture.empty() ||
364364
!material.normalTexture.empty() ||
365365
!material.occlusionTexture.empty() ||
@@ -369,7 +369,7 @@ bool RenderSystem::checkPBRTextures(Material& material){
369369
return hasBaseColor || hasOtherPBRTextures;
370370
}
371371

372-
bool RenderSystem::loadPBRTextures(Material& material, ShaderData& shaderData, ObjectRender& render){
372+
bool RenderSystem::loadPBRTextures(Material& material, ShaderData& shaderData, ObjectRender& render, bool receiveLights){
373373
TextureRender* textureRender = NULL;
374374
std::pair<int, int> slotTex(-1, -1);
375375

@@ -384,7 +384,7 @@ bool RenderSystem::loadPBRTextures(Material& material, ShaderData& shaderData, O
384384
render.addTexture(slotTex, ShaderStageType::FRAGMENT, &emptyWhite);
385385
}
386386

387-
if (hasLights){
387+
if (hasLights && receiveLights){
388388
textureRender = material.metallicRoughnessTexture.getRender(&emptyWhite);
389389
slotTex = shaderData.getTextureIndex(TextureShaderType::METALLICROUGHNESS);
390390
if (textureRender){
@@ -433,10 +433,10 @@ bool RenderSystem::loadPBRTextures(Material& material, ShaderData& shaderData, O
433433
return true;
434434
}
435435

436-
void RenderSystem::loadShadowTextures(ShaderData& shaderData, ObjectRender& render, bool receiveShadows){
436+
void RenderSystem::loadShadowTextures(ShaderData& shaderData, ObjectRender& render, bool receiveLights, bool receiveShadows){
437437
std::pair<int, int> slotTex(-1, -1);
438438

439-
if (hasLights && hasShadows && receiveShadows){
439+
if (hasLights && receiveLights && hasShadows && receiveShadows){
440440
size_t num2DShadows = 0;
441441
size_t numCubeShadows = 0;
442442
auto lights = scene->getComponentArray<LightComponent>();
@@ -636,7 +636,7 @@ bool RenderSystem::loadMesh(Entity entity, MeshComponent& mesh, uint8_t pipeline
636636

637637
render.beginLoad(mesh.submeshes[i].primitiveType);
638638

639-
bool hasPBRTextures = checkPBRTextures(mesh.submeshes[i].material);
639+
bool hasPBRTextures = checkPBRTextures(mesh.submeshes[i].material, mesh.receiveLights);
640640

641641
for (auto const& buf : buffers){
642642
if (buf.second->isRenderAttributes()) {
@@ -708,7 +708,7 @@ bool RenderSystem::loadMesh(Entity entity, MeshComponent& mesh, uint8_t pipeline
708708
if (terrain && !terrain->blendMap.empty()){
709709
p_hasTexture1 = true;
710710
}
711-
if (hasLights){
711+
if (hasLights && mesh.receiveLights){
712712
p_punctual = true;
713713

714714
p_hasNormal = true;
@@ -753,7 +753,7 @@ bool RenderSystem::loadMesh(Entity entity, MeshComponent& mesh, uint8_t pipeline
753753
if (hasFog){
754754
mesh.submeshes[i].slotFSFog = shaderData.getUniformBlockIndex(UniformBlockType::FS_FOG);
755755
}
756-
if (hasLights){
756+
if (hasLights && mesh.receiveLights){
757757
mesh.submeshes[i].slotFSLighting = shaderData.getUniformBlockIndex(UniformBlockType::FS_LIGHTING);
758758
if (hasShadows && mesh.receiveShadows){
759759
mesh.submeshes[i].slotVSShadows = shaderData.getUniformBlockIndex(UniformBlockType::VS_SHADOWS);
@@ -770,10 +770,10 @@ bool RenderSystem::loadMesh(Entity entity, MeshComponent& mesh, uint8_t pipeline
770770
mesh.submeshes[i].slotVSMorphTarget = shaderData.getUniformBlockIndex(UniformBlockType::VS_MORPHTARGET);
771771
}
772772

773-
if (!loadPBRTextures(mesh.submeshes[i].material, shaderData, mesh.submeshes[i].render)){
773+
if (!loadPBRTextures(mesh.submeshes[i].material, shaderData, mesh.submeshes[i].render, mesh.receiveLights)){
774774
return false;
775775
}
776-
loadShadowTextures(shaderData, mesh.submeshes[i].render, mesh.receiveShadows);
776+
loadShadowTextures(shaderData, mesh.submeshes[i].render, mesh.receiveLights, mesh.receiveShadows);
777777

778778
if (terrain){
779779
mesh.submeshes[i].slotVSTerrain = shaderData.getUniformBlockIndex(UniformBlockType::TERRAIN_VS_PARAMS);
@@ -1023,7 +1023,7 @@ bool RenderSystem::drawMesh(MeshComponent& mesh, Transform& transform, CameraCom
10231023

10241024
if (mesh.submeshes[i].needUpdateTexture || needUpdateFramebuffer){
10251025
ShaderData& shaderData = mesh.submeshes[i].shader.get()->shaderData;
1026-
if (loadPBRTextures(mesh.submeshes[i].material, shaderData, mesh.submeshes[i].render)){
1026+
if (loadPBRTextures(mesh.submeshes[i].material, shaderData, mesh.submeshes[i].render, mesh.receiveLights)){
10271027
mesh.submeshes[i].needUpdateTexture = false;
10281028
}
10291029
}
@@ -1037,7 +1037,7 @@ bool RenderSystem::drawMesh(MeshComponent& mesh, Transform& transform, CameraCom
10371037
render.applyUniformBlock(mesh.submeshes[i].slotFSFog, sizeof(float) * 8, &fs_fog);
10381038
}
10391039

1040-
if (hasLights){
1040+
if (hasLights && mesh.receiveLights){
10411041
render.applyUniformBlock(mesh.submeshes[i].slotFSLighting, sizeof(float) * (16 * MAX_LIGHTS + 8), &fs_lighting);
10421042
if (hasShadows && mesh.receiveShadows){
10431043
render.applyUniformBlock(mesh.submeshes[i].slotVSShadows, sizeof(float) * (16 * MAX_SHADOWSMAP), &vs_shadows);
@@ -1061,7 +1061,7 @@ bool RenderSystem::drawMesh(MeshComponent& mesh, Transform& transform, CameraCom
10611061
}
10621062
}
10631063

1064-
if (hasLights){
1064+
if (hasLights && mesh.receiveLights){
10651065
render.applyUniformBlock(mesh.submeshes[i].slotFSParams, sizeof(float) * 12, &mesh.submeshes[i].material);
10661066
}else{
10671067
render.applyUniformBlock(mesh.submeshes[i].slotFSParams, sizeof(float) * 4, &mesh.submeshes[i].material);
@@ -2841,7 +2841,7 @@ void RenderSystem::update(double dt){
28412841
if (mesh.submeshes[i].textureShadow){
28422842
mesh.submeshes[i].needUpdateDepthTexture = true;
28432843
}
2844-
if (checkPBRTextures(mesh.submeshes[s].material)){
2844+
if (checkPBRTextures(mesh.submeshes[s].material, mesh.receiveLights)){
28452845
if (!(mesh.submeshes[s].shaderProperties & (1 << 1)) && !(mesh.submeshes[s].shaderProperties & (1 << 2))){ // not 'Uv1' and not 'Uv2'
28462846
mesh.needReload = true;
28472847
}

engine/core/subsystem/RenderSystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ namespace Supernova{
116116
void configureLightShadowNearFar(LightComponent& light, const CameraComponent& camera);
117117
Matrix4 getDirLightProjection(const Matrix4& viewMatrix, const Matrix4& sceneCameraInv);
118118
bool checkPBRFrabebufferUpdate(Material& material);
119-
bool checkPBRTextures(Material& material);
120-
bool loadPBRTextures(Material& material, ShaderData& shaderData, ObjectRender& render);
121-
void loadShadowTextures(ShaderData& shaderData, ObjectRender& render, bool receiveShadow);
119+
bool checkPBRTextures(Material& material, bool receiveLights);
120+
bool loadPBRTextures(Material& material, ShaderData& shaderData, ObjectRender& render, bool receiveLights);
121+
void loadShadowTextures(ShaderData& shaderData, ObjectRender& render, bool receiveLights, bool receiveShadow);
122122
bool loadDepthTexture(Material& material, ShaderData& shaderData, ObjectRender& render);
123123
bool loadTerrainTextures(TerrainComponent& terrain, ObjectRender& render, ShaderData& shaderData);
124124
Rect getScissorRect(UILayoutComponent& layout, ImageComponent& img, Transform& transform, CameraComponent& camera);

0 commit comments

Comments
 (0)