Skip to content

Commit 8bceba4

Browse files
committed
fix: fog height issues
1 parent db04255 commit 8bceba4

File tree

8 files changed

+29
-24
lines changed

8 files changed

+29
-24
lines changed

editor/app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
334334
plRendererSettings tRenderSettings = {
335335
.ptDevice = ptAppData->ptDevice,
336336
.ptSwap = gptStarter->get_swapchain(),
337-
.uMaxTextureResolution = 1024 * 2,
337+
.uMaxTextureResolution = 1024,
338338
};
339339
gptRenderer->initialize(tRenderSettings);
340340

extensions/pl_renderer_ext.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,7 @@ pl_renderer_finalize_scene(plScene* ptScene)
23882388

23892389
const plBufferDesc tInstanceBufferDesc = {
23902390
.tUsage = PL_BUFFER_USAGE_STORAGE,
2391-
.szByteSize = sizeof(uint32_t) * 10000 * 2,
2391+
.szByteSize = sizeof(plShadowInstanceBufferData) * 10000,
23922392
.pcDebugName = "instance buffer"
23932393
};
23942394

@@ -2913,6 +2913,7 @@ pl_renderer_prepare_view(plView* ptView, plCamera* ptCamera)
29132913
ptScene->uDShadowIndex = 0;
29142914
ptScene->uDShadowOffset = 0;
29152915

2916+
ptView->tData.iFogActive = (int)gptData->tRuntimeOptions.bFog;
29162917
ptView->tData.fFogHeight = gptData->tRuntimeOptions.fFogHeight;
29172918
ptView->tData.fFogCutOffDistance = gptData->tRuntimeOptions.fFogCutOffDistance;
29182919
ptView->tData.fFogMaxOpacity = gptData->tRuntimeOptions.fFogMaxOpacity;
@@ -4628,8 +4629,7 @@ pl_renderer_remove_objects_from_scene(plScene* ptScene, uint32_t uObjectCount, c
46284629
{
46294630
pl_hm_remove(&ptScene->tDrawableHashmap, tObject.uData);
46304631
pl_sb_del_swap(ptScene->sbtStagedEntities, j);
4631-
j--;
4632-
uDrawableCount--;
4632+
break;
46334633
}
46344634
}
46354635
}

extensions/pl_renderer_internal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ pl__renderer_generate_shadow_maps(plRenderEncoder* ptEncoder, plCommandBuffer* p
898898
{
899899
.tBuffer = ptScene->atInstanceBuffer[uFrameIdx],
900900
.uSlot = 1,
901-
.szBufferRange = sizeof(uint32_t) * 2 * 10000
901+
.szBufferRange = sizeof(plShadowInstanceBufferData) * 10000
902902
}
903903
};
904904

@@ -1570,7 +1570,7 @@ pl__renderer_generate_cascaded_shadow_map(plRenderEncoder* ptEncoder, plCommandB
15701570
{
15711571
.tBuffer = ptScene->atInstanceBuffer[uFrameIdx],
15721572
.uSlot = 1,
1573-
.szBufferRange = sizeof(uint32_t) * 2 * 10000
1573+
.szBufferRange = sizeof(plShadowInstanceBufferData) * 10000
15741574
}
15751575
};
15761576

@@ -2319,6 +2319,7 @@ pl__renderer_get_bindless_texture_index(plScene* ptScene, plTextureHandle tTextu
23192319
uint64_t ulValue = pl_hm_get_free_index(&ptScene->tTextureIndexHashmap);
23202320
if(ulValue == PL_DS_HASH_INVALID)
23212321
{
2322+
PL_ASSERT(ptScene->uTextureIndexCount < PL_MAX_BINDLESS_TEXTURES);
23222323
ulValue = ptScene->uTextureIndexCount++;
23232324

23242325
// TODO: handle when greater than 4096
@@ -3751,6 +3752,7 @@ pl__renderer_set_drawable_shaders(plScene* ptScene)
37513752
.ulDepthMode = PL_COMPARE_MODE_GREATER_OR_EQUAL,
37523753
.ulCullMode = PL_CULL_MODE_NONE,
37533754
.ulWireframe = 0,
3755+
.ulDepthClampEnabled = 1,
37543756
.ulStencilMode = PL_COMPARE_MODE_ALWAYS,
37553757
.ulStencilRef = 0xff,
37563758
.ulStencilMask = 0xff,

shaders/fog.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vec4
33
fog(vec4 color, vec3 view)
44
{
55
float height = tViewInfo.tData.fFogHeight;
6-
float fHeightFalloff = tViewInfo.tData.fFogHeightFalloff;
6+
float fHeightFalloff = -tViewInfo.tData.fFogHeightFalloff;
77

88
float iblLuminance = 1.0;
99
float fogStart = tViewInfo.tData.fFogStart;

shaders/pl_shader_interop_renderer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ PL_BEGIN_STRUCT(plGpuViewData)
218218

219219
int iTransmissionFrameBufferIndex;
220220
int _iUnused0;
221-
int _iUnused1;
221+
int iFogActive;
222222
float fFogHeight;
223223
// ~~~~~~~~~~~~~~~~16 bytes~~~~~~~~~~~~~~~~
224224

@@ -347,10 +347,7 @@ PL_BEGIN_STRUCT(plGpuDynShadow)
347347
int iMaterialIndex;
348348
// ~~~~~~~~~~~~~~~~16 bytes~~~~~~~~~~~~~~~~
349349

350-
mat4 tInverseWorld;
351-
// ~~~~~~~~~~~~~~~~64 bytes~~~~~~~~~~~~~~~~
352-
353-
// ~~~~~~~~~~~~~~~~80 bytes~~~~~~~~~~~~~~~~
350+
// ~~~~~~~~~~~~~~~~16 bytes~~~~~~~~~~~~~~~~
354351
PL_END_STRUCT(plGpuDynShadow)
355352

356353
//-----------------------------------------------------------------------------

shaders/shaders.pls

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@
479479
"tGraphicsState": {
480480
"ulDepthWriteEnabled": true,
481481
"ulDepthMode": "PL_COMPARE_MODE_GREATER_OR_EQUAL",
482-
"ulCullMode": "PL_CULL_MODE_CULL_BACK",
482+
"ulCullMode": "PL_CULL_MODE_NONE",
483483
"ulWireframe": false,
484484
"ulDepthClampEnabled": true,
485485
"ulStencilTestEnabled": false,
@@ -498,15 +498,7 @@
498498
}
499499
],
500500
"atBlendStates": [
501-
{
502-
"bBlendEnabled": true,
503-
"tSrcColorFactor": "PL_BLEND_FACTOR_SRC_ALPHA",
504-
"tDstColorFactor": "PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA",
505-
"tColorOp": "PL_BLEND_OP_ADD",
506-
"tSrcAlphaFactor": "PL_BLEND_FACTOR_SRC_ALPHA",
507-
"tDstAlphaFactor": "PL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA",
508-
"tAlphaOp": "PL_BLEND_OP_ADD"
509-
}
501+
{ "bBlendEnabled": false }
510502
],
511503
"atVertexConstants": [
512504
{ "tType": "PL_DATA_TYPE_INT" },

shaders/shadow.vert

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ void main()
107107
gl_ViewportIndex = uViewportIndex;
108108

109109
// if(tCameraInfo.atCameraProjs[tObjectInfo.tData.iIndex + uViewportIndex][3][3] == 1.0) // orthographic
110-
// gl_Position.z = 1.0 - gl_Position.z;
110+
// {
111+
// // gl_Position.z = 1.0 - gl_Position.z;
112+
// if(gl_Position.z > 1.0)
113+
// {
114+
// gl_Position.z = 0.0;
115+
// }
116+
// }
111117

112118
tShaderIn.tUV[0] = inTexCoord0;
113119
tShaderIn.tUV[1] = inTexCoord1;

shaders/skybox.frag

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "pl_shader_interop_renderer.h"
55
#include "bg_scene.inc"
66
#include "bg_view.inc"
7+
#include "math.glsl"
8+
#include "fog.glsl"
79

810
//-----------------------------------------------------------------------------
911
// [SECTION] bind group 2
@@ -34,5 +36,11 @@ main()
3436
{
3537
vec3 tVectorOut = normalize(tShaderIn.tWorldPosition);
3638
outColor = vec4(texture(samplerCube(samplerCubeMap, tSamplerLinearRepeat), tVectorOut).rgb, 1.0);
37-
outColor.rgb = outColor.rgb * (1.0 - tViewInfo.tData.fFogMaxOpacity) + tViewInfo.tData.fFogMaxOpacity * tViewInfo.tData.tFogColor;
39+
40+
if(bool(tViewInfo.tData.iFogActive))
41+
{
42+
tVectorOut.y *= -1.0;
43+
outColor = fog(outColor, tVectorOut * tViewInfo.tData.fFogCutOffDistance * 0.75);
44+
}
45+
// outColor.rgb = outColor.rgb * (1.0 - tViewInfo.tData.fFogMaxOpacity) + tViewInfo.tData.fFogMaxOpacity * tViewInfo.tData.tFogColor;
3846
}

0 commit comments

Comments
 (0)