Home Technical Talk

Maya depth shader controlled by ramp?

polycount sponsor
Offline / Send Message
malcolm polycount sponsor
Anyone know how to do this, I'd like my luminance depth pass controlled by a ramp so I can control exactly where I want the gradients to appear, I'd like more than one gradient so the near and far are both out of focus.

Replies

  • willy-wilson
    Options
    Offline / Send Message
    willy-wilson polycounter lvl 8
    http://www.kostas.se/shader

    all the way at the bottom. might do what you'd like.
  • malcolm
    Options
    Offline / Send Message
    malcolm polycount sponsor
    I think that one's real time I'm looking for a way to do it in mental ray so the antialiasing matches up.
  • ceebee
    Options
    Offline / Send Message
    ceebee polycounter lvl 14
    I believe what you're looking for has to do with facing ratio based nodes in Maya. Here's a site which might help: http://www.stevenchan.us/facing_ratio_shader_node_in_maya
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    malcolm> I actually made some course lecture material for doing this :)

    Use a "samplerInfo" node's "Point Camera" to evaluate the distance to the rendered pixel. Then it's just a matter of scaling your range of interest to 0-1 to pass on to RGB coloring of a shader. You can create some interactive objects with distance tools all set up to get a more intuitive way of tweaking your range.

    I'm not sure if I can share the course material I made but here's a screenshot of my shader is set up in Maya for this kind of shading. There's some interactive controllers in form of locators to set the measuring range.

    zdepth.jpg

    What do you mean by multiple gradients?
    Either way you should be able to set it up similar to the way i described. Should just be a matter of math.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    You mean like black in the very background, going to white where you have focus, then from where you have focus going to black again when it's right near the camera?

    It should just be a matter of tweaking a similar network as the one I showed above.
  • chronic
    Options
    Offline / Send Message
    chronic polycounter lvl 10
    really, you should do a proper un-clamped floating point depth pass that encodes distance from camera and then to any remapping or DOF effects in comp with the proper nodes to set focal point and focus range. one of the mental ray render passes offers a preset that will do this.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    chronic wrote: »
    really, you should do a proper un-clamped floating point depth pass that encodes distance from camera and then to any remapping or DOF effects in comp with the proper nodes to set focal point and focus range. one of the mental ray render passes offers a preset that will do this.

    While we're on the subject does anyone have any advice on how to do a proper DOF-effect on a still image given that you can output the right Z-Depth info?

    Only thing I've ever tried is the photoshop Lens Blur with depth info in alpha channel. But I'm thinking that there might be some better software for this?

    I wanted to step up to the challenge of making a maya template scene with interactive near/far planes and a falloff value to set up this kind of render. I created a shader for this where you go by a ramp. Was a fun exercise. Every time I do small projects like this it reminds me why I love working with Maya. :)

    Tried the output with Photoshop, works fairly well the Lens Blur filter.

    Let me know if you're interested, I can share it.

    zdepth1.jpg
    zdepth2.jpg
    zdepth3.jpg
  • Warheart
    Options
    Offline / Send Message
    Warheart polycounter lvl 17
    There is a filter for applying DOF in post from a pass like this in After Effects which I have used in the past and works pretty well.

    I don't see why you want it to go from black in the foreground through white in the center and back to black in the distance though... The filter should deal with this. Normally you just render depth information from white to black or black to white. It's possible to get finer precision doing it with two ramps I suppose but if you render to 32bit images then one ramp should give you enough precision and it means you can play with the distance of the focal point in post instead of re-rendering the pass.

    Also for most "natural" looking results (if I'm not mistaken) the depth falloff should be exponential into the distance (as it normally is in a game engine's depth buffer). If you think about it in photographic terms you normally only get tight focus with subjects that are close and the further away the subject is the wider the band of focus. If you have tight focus on a distant subject it looks odd (not that you'd never want to use this effect but it's not what your brain expects).

    Tight focus on a far away subject makes it look like a scale model. Google for "tilt-shift" photography for examples of this effect.

    p.s. kodde: Love your viewcube modification :D

    p.p.s This is the shader I have used to do it in MR before: http://homepage.mac.com/bauer/portfolio_shaders/zDepthDOF/zDepthDOF.html
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Warheart> I'm not sure if your question was aimed at malcolm or me, but the reason for me making a black-white-white-black shader was that malcolm initially requested this. Making it plain black-white/white-black is even easier.

    Never considered the exponential issue you are describing. Isn't this covered by the way a camera works by default? Should I alter my equations in some manner to cover this?

    The CompantionCube ViewCube is awesome! :D
    It's just changing a existing image. Not possible in 2011 if I'm not mistaking.
  • Warheart
    Options
    Offline / Send Message
    Warheart polycounter lvl 17
    kodde: Yea I was more wondering why malcolm was looking to do it that way in the first place. If the filter in your compositing package expects to use blur strength based on how much black there is then that makes sense I suppose (I didn't see a package/filter mentioned) but my (however limited) experience is that if a filter is set up to do this then it will let you blur within a defined greyscale range (single greyscale value as the focus point and then falling off from there).

    Yea that's a really nice shader/rig you have set up for doing it actually. Always nice to have objects that you can see in the scene to set distances rather than tweaking and re-rendering. I think the only change I would make would be to have just a near and far clip plane and then have the v-ramp fill between them and have it set to white at the bottom and black at the top and interpolation set to "Exponential Down" (assuming it renders the bottom of the ramp as the closest pixels)

    (Setting this sort of thing up gets more complex if you want to make it support transparent materials (especially if they can be refractive :P))

    Then to render set the mental ray framebuffer to 32bit (e.g. the "Depth (Float) 1x32Bit" preset in 2011) and render to an image format which supports 32bit channels which can also be read by your compositing package.

    (p.s. damn.. If only I wasn't using 2011 I may actually have re-enabled the viewcube for once :P)
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Warheart> Why do you figure changing the ramp in that manner? My screenshots might not show how it works but you don't ever touch anything in the ramp, the only things you change are the cameras placement/rotation through regular camera controls (rest of rig follows), you move the near/far planes in translateZ and you select the Controller object which has a falloff distance attribute which in turn moves both the near/far falloff planes away from their parent near/far planes. In other words, the falloff for both near/far is always same distance. Does it work otherwise with real-life camera lenses?

    The math behind the shader calculates the entire range and sets the ramp positions accordingly so there shouldn't(probably somehow) be any room for errors. Maybe you don't get good enough precision?

    Never tried rendering to 32-bit. I should get around to trying it.

    I never use the viewcube otherwise. Now I just keep it for the visuals, never click it :P I don't like the animated camera movement you get.
  • malcolm
    Options
    Offline / Send Message
    malcolm polycount sponsor
    Warheart, yes I'd like to apply lens blur in photoshop post and for something like tilt shift I'd like the gradient to go from white to black to white again so just the center of the depth blur is in focus. As far as I know photoshop lens blur does not support this, I tried a bunch last night and could not fully control blurry near and far using a black to white gradient, am I missing something?
  • Warheart
    Options
    Offline / Send Message
    Warheart polycounter lvl 17
    Ah, sorry, I don't think I explained what I meant properly. I wasn't saying I'd change that ramp in your shader. I was explaining how I would set up that shader/rig. So my setup would be a rig to render a white to black gradient with exponential falloff between a near and far plane (no falloff planes and no solid white section of the gradient in the center).

    The reason I would set it up that way is so that you are rendering purely depth information. This can be interpreted by the compositing package (After effects, Photoshop etc.) so that you can just manipulate the filter settings to give you the focus point and blur depth that you want instead of having to re-render a new gradient every time you want to alter the DOF.

    Rendering depth in a single gradient pass like this is especially useful if you need to animate a focus pull in post. Another trick you can use this method for is that you can colour correct the depth pass and screen/overlay/multiply it to use it for atmospheric fading/fog effects.
  • Warheart
    Options
    Offline / Send Message
    Warheart polycounter lvl 17
    malcolm: yea it is possible to do in Photoshop. I just had a look into a process for you. The Lens Blur filter is pretty similar to the one in AE. Just the setup is really weird.

    Before you run the Lens Blur filter on your image make sure you add the depth pass to your beauty render as a new channel. (use "duplicate channel" from your depth image and duplicate it into the image to be blurred). Then run the Lens Blur filter and in the [Depth Map > Source] dropdown box pick the new channel you just added. From there it's just a matter of tweaking settings. "Blur focal distance" refers to what value on the depth map is considered the focus plane. So if you set the Blur focal distance to 128 then mid grey on your depth map will be in focus and the further away from that value the more blurry your image will get.

    That's the main trickyness out of the way :). The help on the other settings should be easy enough to follow to get you the result you're looking for.
  • ceebee
    Options
    Offline / Send Message
    ceebee polycounter lvl 14
    Why not just use a bokeh lens shader if you want to do rack focus things?
  • malcolm
    Options
    Offline / Send Message
    malcolm polycount sponsor
    Warheart, yeah I figured that out before, you can actually click on the image in the lens blur filter and it will try to figure out what part you want in focus, still couldn't get the look I'm after though.

    ceebee, I'm looking for a way to do this in post it's much faster than setting up a custom depth of field for every shot as well rendering bokeh in mental ray is not that fast for tuning it.
  • malcolm
    Options
    Offline / Send Message
    malcolm polycount sponsor
    kodde I can't figure out your shader graph I'm not good with the tech art. I tried plugging point camera z into v coord of ramp then ramp out colour to value z and then out value into surface shader, no luck I got a tiling ramp could not figure out how to remap the range from 0-1.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Malcolm> Here you go. A camera+shader you can import to any scene and use for white->black zdepth pass. If you want the one above with falloff as well I can upload it also.

    Or maybe you want to learn how to create it yourself?


    EDIT:
    The above link was broken, so I removed the linking. Check below for newer link.
  • malcolm
    Options
    Offline / Send Message
    malcolm polycount sponsor
    Shit sorry, I figured it out right after I posted. I just hacked the existing luminense depth shader and got a custom ramp working in it. I bit hard to control though your ramp controlled by planes looks much easier to tune.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Adding the locators is one hell of a nice idea. I've been using a similar shader at work but it was always a pain tweaking the near and far values.

    Cheers Kodde
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    malcolm wrote: »
    Shit sorry, I figured it out right after I posted. I just hacked the existing luminense depth shader and got a custom ramp working in it. I bit hard to control though your ramp controlled by planes looks much easier to tune.

    No worries.
    r_fletch_r wrote: »
    Adding the locators is one hell of a nice idea. I've been using a similar shader at work but it was always a pain tweaking the near and far values.

    Cheers Kodde

    Glad you like it.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    I got a request for the example scene I posted pics of above, also my prior link is broken since I've changed hosts since then.

    Here's the link for the example scene.

    To change the near/far limits just move the bigger planes. To change the falloff you have to select the camera shaped controller and change it's Falloff attribute. Sadly I did not find an easy solution for making falloff planes interactive in the sense of just moving them around. They'd have to update on both side regardless of which you chose to move around. The whole setup follows the camera so just navigate around with it as normal.

    So far I've only been able to render this with Maya software. For some reason my... *cough* complex shader setup *cough* with Mental Ray makes Maya crash. :/

    Although if all you want is a Z-Depth pass then I don't see why Maya Software wouldn't suffice. Still bugs me though.
  • malcolm
    Options
    Offline / Send Message
    malcolm polycount sponsor
    The link is broken, and the depth pass needs to come out of the same renderer you intend to use it in. Otherwise the antialiasing will be different if you render the depth in Maya software and the diffuse in mental ray.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    What?
    The link works fine for me, the one in post #23. The prior one in #19 is still broken. I can remove it.

    You are probably right concerning anti-aliasing. I think you can get it quite close, but you will probably always have discrepancies between different renderers.
  • malcolm
    Options
    Offline / Send Message
    malcolm polycount sponsor
    Link works now.
Sign In or Register to comment.