Home Marmoset

Toolbag 3 Depth rendering

polycounter lvl 5
Offline / Send Message
LorasTyrell polycounter lvl 5
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:
#include '../state.frag'

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);
}

#ifdef Albedo
     #undef Albedo
#define Albedo custom_depth
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

  • Joshua Stubbles
    Options
    Offline / Send Message
    Joshua Stubbles polycounter lvl 19
    Hah, I was actually going to post about something like this, glad to see you're working on something for it. Although since it's faked with the shader, you're only going to be able to get so close, with Photoshop. A real depth pass would match the base render perfectly. Seems like there are still some limitations to this.
  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    I was about to ask for a z depth pass aswell.  The near blur is not that great.
    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.
Sign In or Register to comment.