Skip to content

Commit 5feb7a1

Browse files
committed
style: modify grid shader
1 parent 96aaf62 commit 5feb7a1

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

editor/app.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ Index of this file:
7777
#include "pl_vfs_ext.h"
7878
#include "pl_compress_ext.h"
7979

80+
// shaders
81+
#include "pl_shader_interop_renderer.h" // PL_MESH_FORMAT_FLAG_XXXX
82+
8083
//-----------------------------------------------------------------------------
8184
// [SECTION] global apis
8285
//-----------------------------------------------------------------------------

editor/editor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Index of this file:
7373
#include "pl_bvh_ext.h"
7474
#include "pl_shader_variant_ext.h"
7575

76+
// shaders
77+
#include "pl_shader_interop_renderer.h" // PL_MESH_FORMAT_FLAG_XXXX
78+
7679
// dear imgui
7780
#include "pl_dear_imgui_ext.h"
7881
#include "imgui.h"

extensions/pl_model_loader_ext.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Index of this file:
3232
#include "pl_renderer_ext.h"
3333
#include "pl_vfs_ext.h"
3434

35+
// shaders
36+
#include "pl_shader_interop_renderer.h" // PL_MESH_FORMAT_FLAG_XXXX
37+
3538
#ifdef PL_UNITY_BUILD
3639
#include "pl_unity_ext.inc"
3740
#else

extensions/pl_renderer_ext.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pl_renderer_initialize(plRendererSettings tSettings)
267267
gptData->tRuntimeOptions.fGridCellSize = 0.025f;
268268
gptData->tRuntimeOptions.fGridMinPixelsBetweenCells = 2.0f;
269269
gptData->tRuntimeOptions.tGridColorThin = (plVec4){0.5f, 0.5f, 0.5f, 1.0f};
270-
gptData->tRuntimeOptions.tGridColorThick = (plVec4){1.0f, 1.0f, 1.0f, 1.0f};
270+
gptData->tRuntimeOptions.tGridColorThick = (plVec4){0.75f, 0.75f, 0.75f, 1.0f};
271271

272272
gptResource->initialize((plResourceManagerInit){.ptDevice = gptData->ptDevice, .uMaxTextureResolution = tSettings.uMaxTextureResolution});
273273

@@ -2796,6 +2796,8 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
27962796

27972797
if(ptView->bShowGrid)
27982798
{
2799+
ptView->bShowGrid = false;
2800+
27992801
plShaderHandle tGridShader = gptShaderVariant->get_shader("grid", NULL, NULL, NULL, &gptData->tRenderPassLayout);
28002802
gptGfx->bind_shader(ptSceneEncoder, tGridShader);
28012803

@@ -2807,6 +2809,7 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
28072809
ptGridDynamicData->fGridMinPixelsBetweenCells = gptData->tRuntimeOptions.fGridMinPixelsBetweenCells;
28082810
ptGridDynamicData->tGridColorThin = gptData->tRuntimeOptions.tGridColorThin;
28092811
ptGridDynamicData->tGridColorThick = gptData->tRuntimeOptions.tGridColorThick;
2812+
ptGridDynamicData->tViewDirection.xyz = ptCamera->_tForwardVec;
28102813
ptGridDynamicData->fCameraXPos = ptCamera->tPos.x;
28112814
ptGridDynamicData->fCameraZPos = ptCamera->tPos.z;
28122815
ptGridDynamicData->tCameraViewProjection = tMVP;

extensions/pl_renderer_ext.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ Index of this file:
6767
// [SECTION] includes
6868
//-----------------------------------------------------------------------------
6969

70-
#include "pl_ecs_ext.inl" // plEntity
71-
#include "pl_resource_ext.inl" // plResourceHandle
72-
#include "pl_math.h" // plVec3, plMat4
73-
#include "pl_shader_interop_renderer.h" // plLightType
70+
#include "pl_ecs_ext.inl" // plEntity
71+
#include "pl_resource_ext.inl" // plResourceHandle
72+
#include "pl_math.h" // plVec3, plMat4
7473

7574
//-----------------------------------------------------------------------------
7675
// [SECTION] forward declarations
@@ -114,13 +113,18 @@ typedef struct _plRenderEncoder plRenderEncoder; // pl_graphics_ext.h
114113
typedef union plRenderPassHandle plRenderPassHandle; // pl_graphics_ext.h
115114
typedef union plBindGroupHandle plBindGroupHandle; // pl_graphics_ext.h
116115
typedef void* plTextureId; // pl_ui.h
117-
typedef int plDrawFlags; // pl_draw_ext.h
116+
118117

119118
// external (pl_ecs_ext.h)
120119
typedef struct _plComponentLibrary plComponentLibrary;
121120
typedef struct _plCamera plCamera;
122121
typedef struct _plLightComponent plLightComponent;
123122

123+
// external
124+
typedef int plShaderDebugMode; // pl_shader_interop_renderer.h
125+
typedef int plLightType; // pl_shader_interop_renderer.h
126+
typedef int plDrawFlags; // pl_draw_ext.h
127+
124128
//-----------------------------------------------------------------------------
125129
// [SECTION] public api structs
126130
//-----------------------------------------------------------------------------
@@ -214,8 +218,6 @@ typedef struct _plRendererI
214218
// [SECTION] structs
215219
//-----------------------------------------------------------------------------
216220

217-
218-
219221
typedef struct _plSceneInit
220222
{
221223
plComponentLibrary* ptComponentLibrary;

shaders/grid.frag

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ gridColor(vec2 uv, vec2 camPos)
5252
float lod2 = lod1 * 10.0;
5353

5454
// each anti-aliased line covers up to 4 pixels
55-
dudv *= 4.0;
55+
dudv *= 2.0;
5656

5757
// set grid coordinates to the centers of anti-aliased lines for subsequent alpha calculations
5858
uv += dudv * 0.5;
@@ -64,11 +64,16 @@ gridColor(vec2 uv, vec2 camPos)
6464

6565
uv -= camPos;
6666

67+
vec3 view_dir = normalize(tObjectInfo.tData.tViewDirection.xyz);
68+
float op_gracing = 1.f - pow(1.0 - abs(dot(view_dir, vec3(0.0, 1.0, 0.0))), 16);
69+
// float op_gracing = 1.0;
70+
6771
// blend between falloff colors to handle LOD transition
6872
vec4 c = lod2a > 0.0 ? tObjectInfo.tData.tGridColorThick : lod1a > 0.0 ? mix(tObjectInfo.tData.tGridColorThick, tObjectInfo.tData.tGridColorThin, lodFade) : tObjectInfo.tData.tGridColorThin;
6973

7074
// calculate opacity falloff based on distance to grid extents
7175
float opacityFalloff = (1.0 - satf(length(uv) / tObjectInfo.tData.fGridSize));
76+
opacityFalloff *= op_gracing;
7277

7378
// blend between LOD level alphas and scale with opacity falloff
7479
c.a *= (lod2a > 0.0 ? lod2a : lod1a > 0.0 ? lod1a : (lod0a * (1.0-lodFade))) * opacityFalloff;

shaders/pl_shader_interop_renderer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ PL_BEGIN_STRUCT(plGpuDynGrid)
178178
int _iUnused2;
179179
// ~~~~~~~~~~~~~~~~16 bytes~~~~~~~~~~~~~~~~
180180

181+
vec4 tViewDirection;
182+
// ~~~~~~~~~~~~~~~~16 bytes~~~~~~~~~~~~~~~~
183+
181184
vec4 tGridColorThin;
182185
// ~~~~~~~~~~~~~~~~16 bytes~~~~~~~~~~~~~~~~
183186

0 commit comments

Comments
 (0)