Skip to content

Commit 1c023e0

Browse files
committed
feat: add normal mapping debug flag
1 parent 570fafe commit 1c023e0

File tree

9 files changed

+24
-7
lines changed

9 files changed

+24
-7
lines changed

editor/app.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ pl__show_editor_window(plAppData* ptAppData)
876876
if(gptUI->checkbox("MultiViewport Shadows", &ptRuntimeOptions->bMultiViewportShadows)) bReloadShaders = true;
877877
if(gptUI->checkbox("Image Based Lighting", &ptRuntimeOptions->bImageBasedLighting)) bReloadShaders = true;
878878
if(gptUI->checkbox("Punctual Lighting", &ptRuntimeOptions->bPunctualLighting)) bReloadShaders = true;
879+
if(gptUI->checkbox("Normal Mapping", &ptRuntimeOptions->bNormalMapping)) bReloadShaders = true;
879880
gptUI->checkbox("Show Probes", &ptRuntimeOptions->bShowProbes);
880881
if(gptUI->checkbox("UI MSAA", &ptAppData->bMSAA))
881882
{

editor/editor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ pl__show_editor_window(plAppData* ptAppData)
10691069
if(ImGui::Checkbox("MultiViewport Shadows", &ptRuntimeOptions->bMultiViewportShadows)) bReloadShaders = true;
10701070
if(ImGui::Checkbox("Image Based Lighting", &ptRuntimeOptions->bImageBasedLighting)) bReloadShaders = true;
10711071
if(ImGui::Checkbox("Punctual Lighting", &ptRuntimeOptions->bPunctualLighting)) bReloadShaders = true;
1072+
if(ImGui::Checkbox("Normal Mapping", &ptRuntimeOptions->bNormalMapping)) bReloadShaders = true;
10721073
ImGui::Checkbox("Show Probes", &ptRuntimeOptions->bShowProbes);
10731074

10741075
if(bReloadShaders)

extensions/pl_renderer_ext.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pl_renderer_initialize(plRendererSettings tSettings)
255255
gptData->tRuntimeOptions.bShowSelectedBoundingBox = true;
256256
gptData->tRuntimeOptions.bImageBasedLighting = true;
257257
gptData->tRuntimeOptions.bPunctualLighting = true;
258+
gptData->tRuntimeOptions.bNormalMapping = true;
258259
gptData->tRuntimeOptions.fShadowConstantDepthBias = -1.25f;
259260
gptData->tRuntimeOptions.fShadowSlopeDepthBias = -10.75f;
260261
gptData->tRuntimeOptions.fExposure = 1.0f;
@@ -1692,6 +1693,8 @@ pl_renderer_outline_entities(plScene* ptScene, uint32_t uCount, plEntity* atEnti
16921693
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_PUNCTUAL;
16931694
if(gptData->tRuntimeOptions.bImageBasedLighting)
16941695
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_IBL;
1696+
if(gptData->tRuntimeOptions.bNormalMapping)
1697+
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_NORMAL_MAPS;
16951698

16961699
// reset old entities
16971700
const uint32_t uOldSelectedEntityCount = pl_sb_size(ptScene->sbtOutlinedEntities);
@@ -1778,7 +1781,8 @@ pl_renderer_outline_entities(plScene* ptScene, uint32_t uCount, plEntity* atEnti
17781781
(int)ptMesh->ulVertexStreamMask,
17791782
iTextureMappingFlags,
17801783
PL_INFO_MATERIAL_METALLICROUGHNESS,
1781-
gptData->tRuntimeOptions.tShaderDebugMode
1784+
gptData->tRuntimeOptions.tShaderDebugMode,
1785+
iObjectRenderingFlags
17821786
};
17831787

17841788
int aiVertexConstantData0[] = {
@@ -1880,6 +1884,8 @@ pl_renderer_reload_scene_shaders(plScene* ptScene)
18801884
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_PUNCTUAL;
18811885
if(gptData->tRuntimeOptions.bImageBasedLighting)
18821886
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_IBL;
1887+
if(gptData->tRuntimeOptions.bNormalMapping)
1888+
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_NORMAL_MAPS;
18831889

18841890
plLightComponent* ptLights = NULL;
18851891
const uint32_t uLightCount = gptECS->get_components(ptScene->ptComponentLibrary, gptData->tLightComponentType, (void**)&ptLights, NULL);
@@ -1967,6 +1973,8 @@ pl_renderer_finalize_scene(plScene* ptScene)
19671973
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_PUNCTUAL;
19681974
if(gptData->tRuntimeOptions.bImageBasedLighting)
19691975
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_IBL;
1976+
if(gptData->tRuntimeOptions.bNormalMapping)
1977+
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_NORMAL_MAPS;
19701978

19711979
// create lighting shader
19721980
int aiLightingConstantData[] = {iSceneWideRenderingFlags, pl_sb_capacity(ptScene->sbtLightData), pl_sb_size(ptScene->sbtProbeData), gptData->tRuntimeOptions.tShaderDebugMode};

extensions/pl_renderer_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ typedef struct _plRendererRuntimeOptions
235235
bool bShowSelectedBoundingBox;
236236
bool bMultiViewportShadows;
237237
bool bImageBasedLighting;
238+
bool bNormalMapping;
238239
bool bPunctualLighting;
239240
float fShadowConstantDepthBias;
240241
float fShadowSlopeDepthBias;

extensions/pl_renderer_internal.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,8 @@ pl__renderer_set_drawable_shaders(plScene* ptScene)
34803480
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_PUNCTUAL;
34813481
if(gptData->tRuntimeOptions.bImageBasedLighting)
34823482
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_IBL;
3483+
if(gptData->tRuntimeOptions.bNormalMapping)
3484+
iSceneWideRenderingFlags |= PL_RENDERING_FLAG_USE_NORMAL_MAPS;
34833485

34843486
const uint32_t uDrawableCount = pl_sb_size(ptScene->sbtDrawables);
34853487
const plEcsTypeKey tMeshComponentType = gptMesh->get_ecs_type_key_mesh();
@@ -3539,7 +3541,8 @@ pl__renderer_set_drawable_shaders(plScene* ptScene)
35393541
(int)ptMesh->ulVertexStreamMask,
35403542
iTextureMappingFlags,
35413543
PL_INFO_MATERIAL_METALLICROUGHNESS,
3542-
gptData->tRuntimeOptions.tShaderDebugMode
3544+
gptData->tRuntimeOptions.tShaderDebugMode,
3545+
iObjectRenderingFlags
35433546
};
35443547

35453548
int aiVertexConstantData0[] = {

shaders/forward.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pl_get_normal_info(int iUVSet)
113113
// Compute normals:
114114
NormalInfo info;
115115
info.ng = ng;
116-
if(bool(iTextureMappingFlags & PL_HAS_NORMAL_MAP))
116+
if(bool(iTextureMappingFlags & PL_HAS_NORMAL_MAP) && bool(iRenderingFlags & PL_RENDERING_FLAG_USE_NORMAL_MAPS))
117117
{
118118
plGpuMaterial material = tMaterialInfo.atMaterials[tObjectInfo.tData.iMaterialIndex];
119119
info.ntex = texture(sampler2D(at2DTextures[nonuniformEXT(material.iNormalTexIdx)], tSamplerLinearRepeat), UV).rgb * 2.0 - vec3(1.0);

shaders/gbuffer_fill.frag

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ layout(constant_id = 0) const int iMeshVariantFlags = 0;
3333
layout(constant_id = 1) const int iTextureMappingFlags = 0;
3434
layout(constant_id = 2) const int iMaterialFlags = 0;
3535
layout(constant_id = 3) const int tShaderDebugMode = 0;
36+
layout(constant_id = 4) const int iRenderingFlags = 0;
3637

3738
//-----------------------------------------------------------------------------
3839
// [SECTION] dynamic bind group
@@ -131,7 +132,7 @@ pl_get_normal_info(int iUVSet)
131132
// Compute normals:
132133
NormalInfo info;
133134
info.ng = ng;
134-
if(bool(iTextureMappingFlags & PL_HAS_NORMAL_MAP))
135+
if(bool(iTextureMappingFlags & PL_HAS_NORMAL_MAP) && bool(iRenderingFlags & PL_RENDERING_FLAG_USE_NORMAL_MAPS))
135136
{
136137
plGpuMaterial material = tMaterialInfo.atMaterials[tObjectInfo.tData.iMaterialIndex];
137138
info.ntex = texture(sampler2D(at2DTextures[nonuniformEXT(material.iNormalTexIdx)], tSamplerLinearRepeat), UV).rgb * 2.0 - vec3(1.0);

shaders/pl_shader_interop_renderer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ Index of this file:
5050
//-----------------------------------------------------------------------------
5151

5252
PL_BEGIN_ENUM(plRenderingFlags)
53-
PL_ENUM_ITEM(PL_RENDERING_FLAG_USE_PUNCTUAL, 1 << 0)
54-
PL_ENUM_ITEM(PL_RENDERING_FLAG_USE_IBL, 1 << 1)
55-
PL_ENUM_ITEM(PL_RENDERING_FLAG_SHADOWS, 1 << 2)
53+
PL_ENUM_ITEM(PL_RENDERING_FLAG_USE_PUNCTUAL, 1 << 0)
54+
PL_ENUM_ITEM(PL_RENDERING_FLAG_USE_IBL, 1 << 1)
55+
PL_ENUM_ITEM(PL_RENDERING_FLAG_SHADOWS, 1 << 2)
56+
PL_ENUM_ITEM(PL_RENDERING_FLAG_USE_NORMAL_MAPS, 1 << 3)
5657
PL_END_ENUM
5758

5859
PL_BEGIN_ENUM(plMeshFormatFlags)

shaders/shaders.pls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268
{ "tType": "PL_DATA_TYPE_INT" },
269269
{ "tType": "PL_DATA_TYPE_INT" },
270270
{ "tType": "PL_DATA_TYPE_INT" },
271+
{ "tType": "PL_DATA_TYPE_INT" },
271272
{ "tType": "PL_DATA_TYPE_INT" }
272273
],
273274
"atBindGroupLayouts": [

0 commit comments

Comments
 (0)