How is the vex function cvex_bsdf implemented?

   965   2   0
User Avatar
Member
6 posts
Joined: Oct. 2015
Offline
Hello! I'm trying to write a custom bsdf for shading, which I believe is possible as described in these two docs pages:

https://www.sidefx.com/docs/houdini/vex/pbr.html [www.sidefx.com]
https://www.sidefx.com/docs/houdini/vex/functions/cvex_bsdf.html [www.sidefx.com]



The example section on the cvex_bsdf docs page describes three separate vex functions;
a creation function
an evaluation shader
and a sample shader

I don't currently see how or where in houdini that those would be implemented. I'm sure there's some core information I'm missing.

For this post, all I'm trying to do is get the example cvex_bsdf diffuse rendering on a object in Mantra.

---
Here's what I've tried:

I've tried to set it up in a materialBuilder in the /mat context. I've placed all those scripts into snippets together and separately, but the snippet claims that the return type (cvex) is not valid. That combined with the way the cvex_bsdf function calls for "diffuse_eval" as a string leads me to believe there's something else to it.

I've tried setting it up through a cvex builder. This looks promising, but the documentation on it is too sparse.
Your text to link here... [www.sidefx.com]

The cvexBuilder makes a cvex output, but I've not seen any examples on how to use it. I'm not sure if any snippet is creating usable information, or checking what is created by the output.

I have been able to use snippets for the built-in bsdfs, such as diffuse. I've included an image of that simple setup.

I'm not seeing what other nodes may help.

---

This has all been part of a whole research endeavor that lead me to write a whole raytracer from scratch in cops. I found out a lot from that process, but I'm hoping to upgrade to using houdini's renderers which should be a whole lot more efficient. Would appreciate all your help, or if you could lead me in the right direction.
Edited by KaleWeaver - March 25, 2025 02:25:21

Attachments:
SimpleDiffuse.png (58.6 KB)

User Avatar
Member
6 posts
Joined: Oct. 2015
Offline
Still looking for any information on how to use cvex_bsdf. Here's my research so far:

Vex Source Strings:

According to the cvex_bsdf documentation page [www.sidefx.com], The cvex_bsdf() function is looking for two CVEX shaders, an evaluation and sample shader. These are accessed by the cvex_bsdf() function as "VEX source strings."

I'm not entirely sure what VEX source strings are. Searches for that terminology mostly come up blank. I assume that as long as the shaders are named, placed in a Houdini accessible folder, or connected to the "creation" node (vex snippet maybe?), it might work.

I found that there are a number of existing CVEX shaders available as .vfl and .vex files in the installation folder.

C:\Program Files\Side Effects Software\Houdini 20.5.516\houdini\vex\CVex

For example, there's already existing diffuse_eval and diffuse_sample files. I don't know how to create one of these for myself, but It would be good information if these could be accessed from cvex_bsdf() to create a successful render.

I tried this using the material builder, simply using the example creation code from the cvex_bsdf() page. I created a new material builder, > created a bind with a blank bsdf, > connected to a snippet node, and placed in the creation code from the docs:

Fdiff = cvex_bsdf("diffuse_eval", "diffuse_sample", "label", "diffuse", "N", N);

I then connected the output to the surface_output's F(bsdf) input, and set Mantra to render PBR.

It doesn't error out on render, but there the result is black...


I've spent some time reading through the Mantra User guide, and there's some pages that show lots of functions, like the PBR lighting page, but I don't see examples on where these would be used.
https://www.sidefx.com/docs/houdini/render/pbrlighting.html [www.sidefx.com]

I was hoping there might be some available assets that may have used it, but Orbolt seem to have no available materials currently.

----

Broken links

This thread from ODFORCE clearly indicates prior activity using the cvex_bsdf() function.
https://forums.odforce.net/topic/20682-bsdf-bonanza-ggx-microfacets-disney-brdf-and-more/ [forums.odforce.net]

Sadly all the files and many images are lost to time.


EDIT: You just need to be logged in to Odforce to download the examples there. In this example, only the pbrggx asset still works, but it does have a working version of the cvex_bsdf() function! The others could work, however they have overlapping function names in current versions of Houdini which would need to be manually fixed

Specifically, this comment seems to describe a bit of how to use it.
https://forums.odforce.net/topic/20682-bsdf-bonanza-ggx-microfacets-disney-brdf-and-more/?do=findComment&comment=124447 [forums.odforce.net]

The use of " simply call them via" and "$f" in the code make me think it's inline code somehow.

I did try to use a python shell to create shop nodes like recommended, but that errors out.


I believe some of their implementation would be in the SHOP context, instead of materials. I've occasionally seen SHOP referred to as a legacy context so I'm not sure if there's a different way to go about it now. It's difficult to find good information on what is expected in current versions.



There's also this forum post, where a pair of fur styling cvex shaders are described in what sounds very similar, here the CVEX shaders would live inside the SHOP network.
https://www.sidefx.com/forum/topic/25909/ [www.sidefx.com]

The "fur object hda" described there doesn't exist in the same form today, so that can't be investigated.

----
Hope to learn how this works.
Edited by KaleWeaver - June 8, 2025 03:38:24
User Avatar
Member
6 posts
Joined: Oct. 2015
Offline
Part three:

I have now been able to get the example from the cvex_bsdf() documentation page [www.sidefx.com] to successfully render. I did this by hijacking an existing old .otl material asset [forums.odforce.net] that had a working example. This is great progress.

If you're interested, I've attached a .hdalc to this post with a working sample of the diffuse example from the docs.
You install it into your scene with File > Import > Houdini Digital Asset...Open your Windows > Asset Managerto see the installed .hda under the Current Hip File tree.
On any of the three assets, right click > Type Properties > Codeto see and edit the code.
Inside a mat/material builder network, you can create a diffuse_example_creation node that has an output of f.
If it renders black, make the the component_label has the string diffusewritten in it. I'm not entirely sure the .hda itself set that as the default.

I'm currently stuck on one problem. The .hdalc has three assets:
Vop/diffuse_example_creation - a VOPs VEX Builder Script asset.
Shop/diffuse_example_eval - Unknown asset type.
Shop/diffuse_example_sample - Unknown asset type.

What type of asset are the Shop/diffuse_example_eval assets, and how to I create a new one? I currently can only create new assets of this type by copying these existing ones from the Asset Manager. I have no idea how to make these from a blank scene.

---

Here's some information that might help investigate, but I'm lost in where they work.

There's documentation pages on Working with Files and Assets as Text. [www.sidefx.com] and Manipulating Asset Internals. [www.sidefx.com]
These pages indicate there are ways to pop open and modify .hda files using commands like hotland vccto compile and open hdas. There's this comment on oddforce [forums.odforce.net] that describes using vccto "compile .vfl files" but there's not quite enough information [www.sidefx.com] for me to piece together how to use these tools. It seems like something with command line or the python shell or hscript textport but it doesn't specify.

When the mystery assets are modified, they will say "compiled successfully." in the Edit Operator type properties window.

I see that the assets are in the Shop/ category. In older versions of houdini, there was a shop type operator. [forums.odforce.net] The current New Asset window no longer has that option, and the docs [www.sidefx.com] describe SHOP as completely depreciated.

---

Outside of those two mystery assets, there's also a component of the cvex_bsdf() function I don't quite understand.
On the docs [www.sidefx.com] and odforce [forums.odforce.net] pages, the cvex_bdsf() functions are clean and simple:
F = cvex_bsdf("diffuse_eval", "diffuse_sample", "label", "diffuse", "N", N);
$f = cvex_bsdf("ggx_eval","ggx_sample","label", $label, [...] )

The working example is more complex:
$f = cvex_bsdf(
                   "oplib:/Shop/diffuse_example_eval?Shop/diffuse_example_eval",
                   "oplib:/Shop/diffuse_example_sample?Shop/diffuse_example_sample",
                   "label", $label,(continues from here)

There's a page on oplib and opdef, [www.sidefx.com] but I don't get exactly how it works. I found the only way to get the cvex_bsdf to find the eval and sample functions is to copy their names exactly using the oplib format.

---

One thing to look out for, the Mantra renderer doesn't error out if it doesn't understand the bsdf function, it will instead use the last working version. That can be really rough as you can't be sure your modifications are doing as you expect. If you want to confirm your attempts work, I recommend multiplying the pdf by 10 in the diffuse_example_eval.
Edited by KaleWeaver - June 8, 2025 03:48:31

Attachments:
Diffuse_example_v01.hdalc (14.5 KB)

  • Quick Links