Skip to content

Commit c29f43d

Browse files
fix: gbuffer debug shaders
1 parent c9f7622 commit c29f43d

6 files changed

Lines changed: 151 additions & 70 deletions

File tree

extensions/pl_renderer_ext.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,10 @@ pl_renderer_create_scene(const plSceneDesc* ptInit)
746746
// create lighting shader
747747
int aiLightingConstantData[] = {iSceneWideRenderingFlags, ptScene->tDebugOptions.tShaderDebugMode};
748748

749-
ptScene->tDirectionalLightingShader = gptShaderVariant->get_shader("deferred_lighting_directional", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
749+
if(ptScene->tDebugOptions.tShaderDebugMode)
750+
ptScene->tDirectionalLightingShader = gptShaderVariant->get_shader("deferred_lighting_debug", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
751+
else
752+
ptScene->tDirectionalLightingShader = gptShaderVariant->get_shader("deferred_lighting_directional", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
750753
ptScene->tSpotLightingShader = gptShaderVariant->get_shader("deferred_lighting_spot", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
751754
ptScene->tPointLightingShader = gptShaderVariant->get_shader("deferred_lighting_point", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
752755
ptScene->tProbeLightingShader = gptShaderVariant->get_shader("deferred_lighting", NULL, NULL, NULL, &gptData->tDeferredLightingRenderPassLayout);
@@ -2020,7 +2023,12 @@ pl_renderer_editor_reload_scene_shaders(plScene* ptScene)
20202023
if(ptScene->tShadowOptions.tFlags & PL_RENDERER_SHADOW_FLAGS_PCF) iSceneWideRenderingFlags |= PL_RENDERING_FLAG_PCF_SHADOWS;
20212024

20222025
int aiLightingConstantData[] = {iSceneWideRenderingFlags, ptScene->tDebugOptions.tShaderDebugMode};
2023-
ptScene->tDirectionalLightingShader = gptShaderVariant->get_shader("deferred_lighting_directional", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
2026+
2027+
if(ptScene->tDebugOptions.tShaderDebugMode)
2028+
ptScene->tDirectionalLightingShader = gptShaderVariant->get_shader("deferred_lighting_debug", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
2029+
else
2030+
ptScene->tDirectionalLightingShader = gptShaderVariant->get_shader("deferred_lighting_directional", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
2031+
20242032
ptScene->tSpotLightingShader = gptShaderVariant->get_shader("deferred_lighting_spot", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
20252033
ptScene->tPointLightingShader = gptShaderVariant->get_shader("deferred_lighting_point", NULL, NULL, aiLightingConstantData, &gptData->tDeferredLightingRenderPassLayout);
20262034
ptScene->tProbeLightingShader = gptShaderVariant->get_shader("deferred_lighting", NULL, NULL, NULL, &gptData->tDeferredLightingRenderPassLayout);

extensions/pl_starter_ext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pl_starter_initialize(plStarterInit tInit)
157157
"../dependencies/pilotlight/shaders/"
158158
},
159159
.pcCacheOutputDirectory = "/shader-temp/",
160-
.eFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
160+
.eFlags = PL_SHADER_FLAGS_AUTO_OUTPUT | PL_SHADER_FLAGS_ALWAYS_COMPILE | PL_SHADER_FLAGS_INCLUDE_DEBUG
161161
};
162162
gptShader->initialize(&tDefaultShaderOptions);
163163
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#version 450
2+
#extension GL_ARB_separate_shader_objects : enable
3+
#extension GL_EXT_nonuniform_qualifier : enable
4+
5+
#include "pl_shader_interop_renderer.h"
6+
#include "pl_bg_scene.inc"
7+
#include "pl_bg_view.inc"
8+
#include "pl_math.glsl"
9+
#include "pl_brdf.glsl"
10+
11+
//-----------------------------------------------------------------------------
12+
// [SECTION] specialication constants
13+
//-----------------------------------------------------------------------------
14+
15+
layout(constant_id = 0) const int iRenderingFlags = 0;
16+
layout(constant_id = 1) const int tShaderDebugMode = 0;
17+
18+
//-----------------------------------------------------------------------------
19+
// [SECTION] bind group 2
20+
//-----------------------------------------------------------------------------
21+
22+
layout(input_attachment_index = 1, set = 2, binding = 0) uniform subpassInput tAlbedoSampler;
23+
layout(input_attachment_index = 2, set = 2, binding = 1) uniform subpassInput tNormalTexture;
24+
layout(input_attachment_index = 3, set = 2, binding = 2) uniform subpassInput tAOMetalRoughnessTexture;
25+
layout(input_attachment_index = 0, set = 2, binding = 3) uniform subpassInput tDepthSampler;
26+
27+
//-----------------------------------------------------------------------------
28+
// [SECTION] dynamic bind group
29+
//-----------------------------------------------------------------------------
30+
31+
layout(set = 3, binding = 0) uniform PL_DYNAMIC_DATA
32+
{
33+
plGpuDynDeferredLighting tData;
34+
} tObjectInfo;
35+
36+
//-----------------------------------------------------------------------------
37+
// [SECTION] input & output
38+
//-----------------------------------------------------------------------------
39+
40+
layout(location = 0) out vec4 outColor;
41+
42+
// layout(location = 0) in vec2 tUV;
43+
44+
const int iMaterialFlags = 0;
45+
#include "pl_lighting.glsl"
46+
#include "pl_material_info.glsl"
47+
#include "pl_fog.glsl"
48+
49+
void main()
50+
{
51+
vec4 AORoughnessMetalnessData = subpassLoad(tAOMetalRoughnessTexture);
52+
float depth = subpassLoad(tDepthSampler).r;
53+
vec2 tEncodedN = subpassLoad(tNormalTexture).xy;
54+
vec4 tBaseColor = subpassLoad(tAlbedoSampler);
55+
float fBaseColorAlpha = tBaseColor.a;
56+
57+
// vec3 n = Decode(tEncodedN);
58+
59+
outColor.a = fBaseColorAlpha;
60+
outColor = tBaseColor;
61+
}

shaders/pl_deferred_lighting_directional.frag

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ void main()
6666
tViewPosition.w = 1.0;
6767
vec4 tWorldPosition = tViewInfo2.data[tObjectInfo.tData.uGlobalIndex].tCameraViewInv * tViewPosition;
6868

69-
70-
7169
MaterialInfo materialInfo;
7270

7371
// The default index of refraction of 1.5 yields a dielectric normal incidence reflectance of 0.04.
@@ -229,62 +227,7 @@ void main()
229227
// Layer blending
230228

231229
outColor.a = fBaseColorAlpha;
232-
233-
if(tShaderDebugMode == PL_SHADER_DEBUG_MODE_NONE)
234-
{
235-
236-
outColor.rgb = color.rgb;
237-
}
238-
else
239-
{
240-
241-
outColor = vec4(1.0);
242-
{
243-
float frequency = 0.02;
244-
float gray = 0.9;
245-
246-
vec2 v1 = step(0.5, fract(frequency * gl_FragCoord.xy));
247-
vec2 v2 = step(0.5, vec2(1.0) - fract(frequency * gl_FragCoord.xy));
248-
outColor.rgb *= gray + v1.x * v1.y + v2.x * v2.y;
249-
}
250-
251-
if(tShaderDebugMode == PL_SHADER_DEBUG_BASE_COLOR)
252-
{
253-
outColor.rgb = materialInfo.baseColor;
254-
outColor.a = fBaseColorAlpha;
255-
}
256-
257-
if(tShaderDebugMode == PL_SHADER_DEBUG_SHADING_NORMAL)
258-
{
259-
outColor = vec4((n + 1.0) / 2.0, fBaseColorAlpha);
260-
}
261-
262-
if(tShaderDebugMode == PL_SHADER_DEBUG_METALLIC)
263-
{
264-
outColor.rgb = vec3(materialInfo.metallic);
265-
}
266-
267-
if(tShaderDebugMode == PL_SHADER_DEBUG_ROUGHNESS)
268-
{
269-
outColor.rgb = vec3(materialInfo.perceptualRoughness);
270-
}
271-
272-
if(tShaderDebugMode == PL_SHADER_DEBUG_ALPHA)
273-
{
274-
outColor.rgb = vec3(fBaseColorAlpha);
275-
}
276-
277-
if(tShaderDebugMode == PL_SHADER_DEBUG_OCCLUSION)
278-
{
279-
outColor.rgb = vec3(ao);
280-
}
281-
282-
if(tShaderDebugMode > PL_SHADER_DEBUG_SHADING_NORMAL)
283-
{
284-
outColor.rgb = vec3(n);
285-
}
286-
}
287-
230+
outColor.rgb = color.rgb;
288231

289232
// if(gl_FragCoord.x < 1800.0)
290233
// {

shaders/pl_gbuffer_fill_debug.frag

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ void main()
113113

114114
// fill g-buffer
115115
outAlbedo = tBaseColor;
116-
{
117-
NormalInfo tNormalInfo = pl_get_normal_info();
118-
outNormal = Encode(tNormalInfo.n);
119-
}
116+
NormalInfo tNormalInfo = pl_get_normal_info();
117+
outNormal = vec2(0);
118+
outFinal = vec4(0);
120119
outAOMetalnessRoughness = vec4(ao, materialInfo.metallic, materialInfo.perceptualRoughness, 1.0);
121120

122121

@@ -134,6 +133,36 @@ void main()
134133
}
135134
}
136135

136+
if(tShaderDebugMode == PL_SHADER_DEBUG_BASE_COLOR)
137+
{
138+
outAlbedo = tBaseColor;
139+
}
140+
141+
if(tShaderDebugMode == PL_SHADER_DEBUG_SHADING_NORMAL)
142+
{
143+
outAlbedo.rgb = vec3((1.0 + tNormalInfo.n) / 2.0);
144+
}
145+
146+
if(tShaderDebugMode == PL_SHADER_DEBUG_METALLIC)
147+
{
148+
outAlbedo.rgb = vec3(materialInfo.metallic);
149+
}
150+
151+
if(tShaderDebugMode == PL_SHADER_DEBUG_ROUGHNESS)
152+
{
153+
outAlbedo.rgb = vec3(materialInfo.perceptualRoughness);
154+
}
155+
156+
if(tShaderDebugMode == PL_SHADER_DEBUG_ALPHA)
157+
{
158+
outAlbedo.rgb = vec3(tBaseColor.a);
159+
}
160+
161+
if(tShaderDebugMode == PL_SHADER_DEBUG_OCCLUSION)
162+
{
163+
outAlbedo.rgb = vec3(ao);
164+
}
165+
137166
if(tShaderDebugMode == PL_SHADER_DEBUG_UV0)
138167
{
139168
if(bool(iMeshVariantFlags & PL_MESH_FORMAT_FLAG_HAS_TEXCOORD_0))
@@ -142,28 +171,24 @@ void main()
142171

143172
if(tShaderDebugMode == PL_SHADER_DEBUG_GEOMETRY_NORMAL)
144173
{
145-
NormalInfo tNormalInfo = pl_get_normal_info();
146174
outAlbedo.rgb = vec3((1.0 + tNormalInfo.ng) / 2.0);
147175
}
148176

149177
if(tShaderDebugMode == PL_SHADER_DEBUG_GEOMETRY_TANGENT)
150178
{
151-
NormalInfo tNormalInfo = pl_get_normal_info();
152179
outAlbedo.rgb = vec3((1.0 + tNormalInfo.t) / 2.0);
153180
}
154181

155182
if(tShaderDebugMode == PL_SHADER_DEBUG_GEOMETRY_BITANGENT)
156183
{
157-
NormalInfo tNormalInfo = pl_get_normal_info();
158184
outAlbedo.rgb = vec3((1.0 + tNormalInfo.b) / 2.0);
159185
}
160186

161187
if(tShaderDebugMode == PL_SHADER_DEBUG_TEXTURE_NORMAL)
162188
{
163189
if(bool(iTextureMappingFlags & PL_HAS_NORMAL_MAP))
164190
{
165-
NormalInfo tNormalInfo = pl_get_normal_info();
166-
outAlbedo.rgb = tNormalInfo.ntex;
191+
outAlbedo.rgb = (tNormalInfo.ntex + 1.0) / 2.0;
167192
}
168193
}
169194
}

shaders/shaders.pls

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
{ "eType": "PL_DATA_TYPE_INT" },
357357
{ "eType": "PL_DATA_TYPE_INT" },
358358
{ "eType": "PL_DATA_TYPE_INT" },
359+
{ "eType": "PL_DATA_TYPE_INT" },
359360
],
360361
"atBindGroupLayouts": [
361362
{ "pcName": "scene" },
@@ -671,6 +672,49 @@
671672

672673
]
673674
},
675+
{
676+
"pcName": "deferred_lighting_debug",
677+
"tVertexShader": { "file": "pl_full_screen.vert"},
678+
"tFragmentShader": { "file": "pl_deferred_lighting_debug.frag"},
679+
"tGraphicsState": {
680+
"bDepthWriteEnabled": false,
681+
"eDepthMode": "PL_COMPARE_MODE_ALWAYS",
682+
"eCullMode": "PL_CULL_MODE_NONE",
683+
"bWireframe": false,
684+
"eDepthClampEnabled": false,
685+
"bStencilTestEnabled": false,
686+
"eStencilMode": "PL_COMPARE_MODE_ALWAYS",
687+
"uStencilRef": 255,
688+
"eStencilMask": 255,
689+
"eStencilOpFail": "PL_STENCIL_OP_KEEP",
690+
"eStencilOpDepthFail": "PL_STENCIL_OP_KEEP",
691+
"eStencilOpPass": "PL_STENCIL_OP_KEEP"
692+
},
693+
"atBlendStates": [
694+
{
695+
"bBlendEnabled": true,
696+
"eSrcColorFactor": "PL_BLEND_FACTOR_SRC_ALPHA",
697+
"eDstColorFactor": "PL_BLEND_FACTOR_ONE",
698+
"eColorOp": "PL_BLEND_OP_ADD",
699+
"eSrcAlphaFactor": "PL_BLEND_FACTOR_SRC_ALPHA",
700+
"eDstAlphaFactor": "PL_BLEND_FACTOR_ONE",
701+
"eAlphaOp": "PL_BLEND_OP_ADD"
702+
},
703+
{ "bBlendEnabled": false, "uColorWriteMask": 0 },
704+
{ "bBlendEnabled": false, "uColorWriteMask": 0 },
705+
{ "bBlendEnabled": false, "uColorWriteMask": 0 }
706+
],
707+
"atFragmentConstants": [
708+
{ "eType": "PL_DATA_TYPE_INT" },
709+
{ "eType": "PL_DATA_TYPE_INT" }
710+
],
711+
"atBindGroupLayouts": [
712+
{ "pcName": "scene" },
713+
{ "pcName": "view" },
714+
{ "pcName": "deferred lighting 1" }
715+
716+
]
717+
},
674718
{
675719
"pcName": "deferred_lighting_directional",
676720
"tVertexShader": { "file": "pl_full_screen.vert"},

0 commit comments

Comments
 (0)