Depth Buffer Object Edge Dissolve

To apply:

Create a MeshInstance

Set the mesh to QuadMesh

Create a new ShaderMaterial

Paste the shader and tweak the settings

Shader code
shader_type spatial;
render_mode unshaded;

uniform float zNear = 1.0;
uniform float zFar = 5.0;

uniform vec4 effectColor : hint_color = vec4(1);
uniform bool flatColor = false;

void vertex() {
	POSITION = vec4(VERTEX, 1.0);
}

float _linearizeScale(vec4 view){
	float linearDepth = vec3((view.xyz / view.w)).z;
	float depthScaled =  2.0 * (zNear * zFar) / (zFar + (linearDepth * zNear));
	return depthScaled;
}

void fragment() {
	//depth sample at screen_uv coords;
	float depthSample = texture(DEPTH_TEXTURE, SCREEN_UV).x;
	
	vec3 ndc = vec3(SCREEN_UV, depthSample);
	vec4 view = (INV_PROJECTION_MATRIX * vec4(ndc, 1.0));
	float realDepth = _linearizeScale(view);
	
	if (flatColor) {
		if (realDepth > 0.0) {
			realDepth = 1.0;
		}
	}
	
	ALBEDO = vec3(realDepth) * effectColor.rgb;
	
//	debug;
//	vec4 originalColor = texture(SCREEN_TEXTURE, SCREEN_UV);
//	ALBEDO = originalColor.rgb;
}
Tags
Color, Depth buffer, edge highlight, post process
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from absentSpaghetti

Depth-Based Outline

Related shaders

3D Vertical dissolve

3D burn dissolve

Depth Modulated Pixel Outline in Screen Space

guest

0 Comments
Inline Feedbacks
View all comments