Frosted Glass Effect with Blur Post-Process: RenderTarget and Blur Pipeline Issues
Hi BabylonJS Community
,
I’m working on a frosted glass effect where I need to blur specific objects behind a transparent material. The implementation involves using a RenderTargetTexture and applying two BlurPostProcess instances (horizontal and vertical) to create the blurred texture. However, the pipeline is not producing the expected results, and both the horizontalBlur.outputTexture and verticalBlur.outputTexture remain undefined.
Steps Taken:
1. Created a RenderTargetTexture:
- Added specific meshes to the
renderList. - Configured
refreshRatetoBABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYFRAME.
const renderTarget = new BABYLON.RenderTargetTexture("renderTarget", { width: 512, height: 512 }, scene);
renderTarget.clearColor = new BABYLON.Color4(0, 0, 0, 0);
renderTarget.refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYFRAME; renderTarget.renderList.push( scene.getMeshByName("quadro"), scene.getMeshByName("scenario"), scene.getMeshByName("logo-gambero"), scene.getMeshByName("logo-scritta") );
2. Created Horizontal and Vertical Blur Post-Processes:
- Set
inputTexturefor the horizontal blur to theRenderTargetTexture. - Set
inputTexturefor the vertical blur to thehorizontalBlur.outputTexture.
const horizontalBlur = new BABYLON.BlurPostProcess( "horizontalBlur", new BABYLON.Vector2(1.0, 0.0), 40.0, 1.0, null, BABYLON.Constants.TEXTURE_BILINEAR_SAMPLINGMODE, engine );
horizontalBlur.width = 512;
horizontalBlur.height = 512;
const verticalBlur = new BABYLON.BlurPostProcess( "verticalBlur", new BABYLON.Vector2(0.0, 1.0), 40.0, 1.0, null, BABYLON.Constants.TEXTURE_BILINEAR_SAMPLINGMODE, engine ); verticalBlur.width = 512;
verticalBlur.height = 512;
horizontalBlur.inputTexture = renderTarget;
verticalBlur.inputTexture = horizontalBlur.outputTexture;
3. Attached Blur Processes to a Temporary Camera:
- Created a
FreeCameraand attached the blur processes to ensure they render.
const tempCamera = new BABYLON.FreeCamera("tempCamera", new BABYLON.Vector3(0, 0, 0), scene);
tempCamera.attachPostProcess(horizontalBlur);
tempCamera.attachPostProcess(verticalBlur);
4. Used Debug Logs to Verify Pipeline:
- Checked the
RenderTargetTexture,renderList, and the blur pipeline output.
Debug Logs:
RenderTarget Initialization: Render target initialized: Object { _wrapU: 1, _wrapV: 1, wrapR: 1, ... }
Render List: Render target render list: Array(4) [ {…}, {…}, {…}, {…} ] Mesh "quadro": Found Mesh "scenario": Found Mesh "logo-gambero": Found Mesh "logo-scritta": Found
Blur Post-Process Outputs: Horizontal blur output texture: undefined Vertical blur output texture: undefined
What I’ve Tried:
- Ensured all meshes in the
renderListare valid, visible, and not culled:renderTarget.renderList.forEach((mesh) => { mesh.isVisible = true; mesh.alwaysSelectAsActiveMesh = true; }); - Debugged
RenderTargetTextureupdates:renderTarget.onAfterRenderObservable.add(() => { console.log("RenderTarget updated successfully"); }); - Visualized the
renderTargeton a debug plane:const debugPlane = BABYLON.MeshBuilder.CreatePlane("debugPlane", { size: 5 }, scene); const debugMaterial = new BABYLON.StandardMaterial("debugMaterial", scene); debugMaterial.diffuseTexture = renderTarget; // Use render target texture debugPlane.material = debugMaterial; debugPlane.position = new BABYLON.Vector3(0, 5, 0);
Problem:
Despite these steps, the blur pipeline is not working as expected, and the textures remain undefined. What could be causing the horizontalBlur.outputTexture and verticalBlur.outputTexture to fail?
Any help would be greatly appreciated!
Summary
This text will be hidden