fkavum
May 10, 2021, 3:04pm
#1
I wrote a shader to print depthTexture on Quad using uniform sampler2D uDepthMap;
But it prints nothing.
When I add these extra codes in the initialization part.;
var depthLayer = pc.app.scene.layers.getLayerById(pc.LAYERID_DEPTH);
depthLayer.incrementCounter();
it prints pure white texture.
Here is the link of my editor: https://playcanvas.com/project/793925/overview/customshader
Below, I took a screenshot from Unity3D. I achieved to print cameraDepthTexture on a quad
by using UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture)
; helper function.
Hi @fkavum and welcome,
If that’s meant for a post process effect, then you can extend the pc.PostEffect class and request depth map access using:
this.needsDepthBuffer = true;
Check the following example:
// --------------- POST EFFECT DEFINITION --------------- //
/**
* @class
* @name BokehEffect
* @classdesc Implements the BokehEffect post processing effect.
* @description Creates new instance of the post effect.
* @augments PostEffect
* @param {GraphicsDevice} graphicsDevice - The graphics device of the application.
* @property {number} maxBlur The maximum amount of blurring. Ranges from 0 to 1.
* @property {number} aperture Bigger values create a shallower depth of field.
* @property {number} focus Controls the focus of the effect.
*/
function BokehEffect(graphicsDevice) {
pc.PostEffect.call(this, graphicsDevice);
this.needsDepthBuffer = true;
// Shader author: alteredq / http://alteredqualia.com/
// Depth-of-field shader with bokeh
// ported from GLSL shader by Martins Upitis
This file has been truncated. show original
2 Likes
this example does debug rendering of the depth as well if that’s what you’re after
http://playcanvas.github.io/#graphics/post-effects.html
3 Likes
fkavum
May 11, 2021, 11:54am
#4
@Leonidas , @mvaligursky Thanks for the quick reply! Its really helped a lot.
I finally managed to make it without using any postProcessing effect.
For anyone struggling with this situation, can fork my project (its really messy).
I made it by the help of this and the other two posts:
I haven’t tried it on WebGL 1 yet, fingers crossed.
And here is the result:
2 Likes
Nice! Thanks for sharing this info @fkavum .
1 Like