When I was looking for the WebGL edge detection method,
I saw that Unity has a solution. Use Camera-DepthNormalTexture.shader to write the depth and normals data to the texture.
I will use the Roberts operator to calculate whether the obtained data is an edge,
but WebGL i can only get depthTexture in framebuffer,
can not get depthNormalTexture like in unity,
I tried to write a test in WebGL,
only use the depthtexture obtained in framebuffer,
but only detect edges with huge depth differences,
and Cannot detect all the edges of the solid color model.
I want to know if there are other ways to solve this kind of problem.
(solid color)WebGL test rendering pic
I set the normal data of the vertex in advance
Using the shader provided in gman's answer, get the texture of normals data in framebuffer in a new rendering. The result seems to draw edges, but the depth seems to be wrong
framebuffer = gl.createFramebuffer();
// rgb texture
gl.bindTexture(state.gl.TEXTURE_2D, texture);
// ... texImage2D texParameteri set up
// depth texture
gl.bindTexture(state.gl.TEXTURE_2D, depthTexture);
// ... texImage2D texParameteri set up
// Create a with normals data FBO
normalFramebuffer = gl.createFramebuffer();
gl.bindTexture(gl.TEXTURE_2D, normalTexture);
// ... texImage2D texParameteri set up
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
obj.render('rgbaData shader');
gl.bindFramebuffer(gl.FRAMEBUFFER, normalFramebuffer);
obj.render('normalsData shader');
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.useProgram('my edge detection shader');
gl.uniform1i(texture, 0);
gl.uniform1i(depthTexture, 1);
gl.uniform1i(normalTexture, 2);
my edge detection shader
uniform sampler2D texture;
uniform sampler2D depthTexture;
uniform sampler2D normalTexture;