What is wrong with the dividing depth fade for my material?


Here’s my code:


I want my material to fade to white when it intersects with another material.
But on the code above, my entire material is white…
If I remove the divide node, it works, but I want the fade to be larger.
What is wrong with dividing depth?


I’m not sure what’s wrong with the material you posted, but you can implement your own DepthFade if you want. It’s just

	// Scales Opacity by a Linear fade based on SceneDepth, from 0 at PixelDepth to 1 at FadeDistance
	// Result = Opacity * saturate((SceneDepth - PixelDepth) / max(FadeDistance, DELTA))

saturate is HLSL for clamp(x, 0, 1). SceneDepth and PixelDepth you have access to through nodes. Fade Distance you supply, and opacity is whatever you were going to plug into the material Opacity pin.