diff --git a/packages/dev/materials/src/grid/grid.fragment.fx b/packages/dev/materials/src/grid/grid.fragment.fx index 12c6eacef67..96337101e41 100644 --- a/packages/dev/materials/src/grid/grid.fragment.fx +++ b/packages/dev/materials/src/grid/grid.fragment.fx @@ -20,6 +20,8 @@ varying vec3 vNormal; #extension GL_EXT_frag_depth : enable #endif +#include + #include #include @@ -90,6 +92,8 @@ void main(void) { #define CUSTOM_FRAGMENT_MAIN_BEGIN + #include + // Scale position to the requested ratio. float gridRatio = gridControl.x; vec3 gridPos = (vPosition + gridOffset.xyz) / gridRatio; diff --git a/packages/dev/materials/src/grid/grid.vertex.fx b/packages/dev/materials/src/grid/grid.vertex.fx index d3c7eddb823..94bc39e628c 100644 --- a/packages/dev/materials/src/grid/grid.vertex.fx +++ b/packages/dev/materials/src/grid/grid.vertex.fx @@ -29,6 +29,7 @@ uniform mat4 opacityMatrix; uniform vec2 vOpacityInfos; #endif +#include #define CUSTOM_VERTEX_DEFINITIONS @@ -62,6 +63,9 @@ void main(void) { } #endif + // Clip plane + #include + #include vPosition = position; diff --git a/packages/dev/materials/src/grid/gridMaterial.ts b/packages/dev/materials/src/grid/gridMaterial.ts index 21d0ef79f8c..776d9616f85 100644 --- a/packages/dev/materials/src/grid/gridMaterial.ts +++ b/packages/dev/materials/src/grid/gridMaterial.ts @@ -25,8 +25,15 @@ import { PrepareDefinesForFrameBoundValues, PrepareDefinesForMisc, } from "core/Materials/materialHelper.functions"; +import { addClipPlaneUniforms, bindClipPlane } from "core/Materials/clipPlaneMaterialHelper"; class GridMaterialDefines extends MaterialDefines { + public CLIPPLANE = false; + public CLIPPLANE2 = false; + public CLIPPLANE3 = false; + public CLIPPLANE4 = false; + public CLIPPLANE5 = false; + public CLIPPLANE6 = false; public OPACITY = false; public ANTIALIAS = false; public TRANSPARENT = false; @@ -222,35 +229,26 @@ export class GridMaterial extends PushMaterial { PrepareAttributesForInstances(attribs, defines); + const uniforms = [ + "projection", + "mainColor", + "lineColor", + "gridControl", + "gridOffset", + "vFogInfos", + "vFogColor", + "world", + "view", + "opacityMatrix", + "vOpacityInfos", + "visibility", + "logarithmicDepthConstant", + ]; // Defines const join = defines.toString(); + addClipPlaneUniforms(uniforms); subMesh.setEffect( - scene - .getEngine() - .createEffect( - "grid", - attribs, - [ - "projection", - "mainColor", - "lineColor", - "gridControl", - "gridOffset", - "vFogInfos", - "vFogColor", - "world", - "view", - "opacityMatrix", - "vOpacityInfos", - "visibility", - "logarithmicDepthConstant", - ], - ["opacitySampler"], - join, - undefined, - this.onCompiled, - this.onError - ), + scene.getEngine().createEffect("grid", attribs, uniforms, ["opacitySampler"], join, undefined, this.onCompiled, this.onError), defines, this._materialContext ); @@ -309,6 +307,8 @@ export class GridMaterial extends PushMaterial { this._activeEffect.setMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix()); } + // Clip plane + bindClipPlane(effect, this, scene); // Log. depth if (this._useLogarithmicDepth) { BindLogDepth(defines, effect, scene);