Jump to content

Recommended Posts

Apologies for cross-posting. This is also in Coder's Corner/Shaders--but since this is actually a vopnet...

I've developed a stereo lens shader for Arnold, and have replicated its functionality in Houdini--almost.

I'm using a grid in front of my ortho camera, transforming P to NDC and driving all of my math from these values. I am using "Refracted Light" VOP in my surface shader to fire rays from an origin that I've computed in a direction that I've computed.

All is fine and well when using Ray Tracing--although I was a bit surprised to find that [0,0,0] P ray origin in this context is actually Camera Origin, not Object Origin.(even though it's a surface shader) That's fine--move grid to -0.1 in Z and Camera to zero and all is well.

When I started working with PBR, I find that I cannot change the Ray Origin using "Refracted Light." No matter what I do, the ray origin is geometry Surface P.

I can get close to the proper results for non stereo if I use a tiny, tiny grid and ortho plane size--but this will never be exact and makes me feel dirty. Furthermore, I need to dramatically alter the ray origin across the image plane for any stereo application of this shader.

So--three questions:

- How can I exert this control over ray origin in PBR? (direction works fine)

- Is there a way to detect the renderer being used from within the shader? (like I said--PBR and RT behave very differently)

- Will we ever get the capacity for creating proper lens shaders for Mantra?

I'm sure this all stems from a fundamental misunderstanding I have regarding what to do with the BSDF parameter--but not sure how to proceed. Any help is appreciated.

Cheers

-matt

Link to comment
Share on other sites

Hey Matt,

- How can I exert this control over ray origin in PBR? (direction works fine)

With pbr all of the actual ray tracing is done in the pathtracer shader. I don't think you can change the origin of the rays without editing the the pathtracer shader and likely pbr.h. I'm not too familiar with lens shaders, but I think by editing the pathtracer shader and pbr.h you'd be able to get the effect you're after without needing a grid in front of the camera, but this might be a major headache.

- Is there a way to detect the renderer being used from within the shader? (like I said--PBR and RT behave very differently)

The renderstate vex function can grab the renderer:renderengine property from the ifd to tell which renderer you're using.

http://www.sidefx.com/docs/houdini12.0/vex/functions/renderstate

Dan

Link to comment
Share on other sites

Thanks, Dan-

Just heard back from SESI this morning, confirming your post with a bit more info.

Seems doable--modify the VEX in a copy of v_pathtracer. I'm assuming that P is in camera space in this context. I'm also not sure how I would prevent P from being modified on subsequent ray hits. It's not obvious to me from looking at the VEX--is there a hit count I can query so that I modify P only on the 1st hit?

FWIW--here is the reply from SESI

What's happening in PBR is that the initial ray (fired by the camera, in mantra) hits your lens grid object, which then executes to produce a bsdf (the F output). After the surface shader for the lens grid executes, the F is passed to the PBR shader (the pathtracer) which uses F to compute a secondary ray which then hits your actual geometry. This secondary ray uses the P from the initial hit without modification, which is why you can't control the ray origin within the surface shader.

To change this, you'd need to make a new copy of the pathtracer shader that modifies P before passing it to the pbr_compute_lighting routine. One way to do this is to lay down a "Pathtracer" shader in /shop, assign this to the "PBR Shader" parameter on the mantra ROP, and then edit type properties on the shop to modify the code (change P to the modified value you were using in the surface shader).

Thanks again, Dan!

-m

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...