Hey guys! I have thrown together a small shader to simulate a z depth pass in Toolbag 3. I have two questions, one is technical and one is artistic.
1. The shader partially works, but there seems to be an issue with the gradient from white to black, where the final ~25% seem like they have been compressed. To demonstrate:
And here is the code:
uniform float nearClip; // name "Near Clip" min 0 max 100.0 default 1.0
uniform float farClip; // name "Far Clip" min 0.001 max 500.0 default 20.0
void custom_depth(inout FragmentState s) {
float d = nearClip - (s.vertexEyeDistance / farClip);
s.albedo = vec4(d, d, d, 1);
}
#undef Albedo
I know it must be the math somehow but I can't seem to work out what would be the correct formula:( The two parameters are there to adjust for the size of the scene, though I'd like to not have this be user input. I've looked at the screenDepth variable but I will look more on that later
2. Once I have the depth pass ready, how should I treat it in Photoshop? I know this is more general but I hope you know. I have used the Lens Blur effect with the depth pass as input but I'm not a huge fan of how it looks...
Lastly, to justify this post, I am working in TB3 on my Mac and right now there seems to be an issue with DOF that I don't know how to work around. It's not the end of the world but I wanted to get my hands on some shaders anyway.
wtf.png
Thank you!
Replies
Could it be that the gradient gets gamma corrected ?
Also our lead dev here said the gradient of the zdepth in Unity is not linear and gives more precision for closer objects.
I'm not sure how it is correct for compositing software.
And yes it shoud be the lens blur filter.