Ptex Shader Progress



  • I've managed to stumble my way through to a working (debug) prototype of a Ptex Shader. It "works" but I've been developing it with a very specific purpose in mind: converting the Moana dataset Ptex files to UDIMs. As a result, and due in large part to my inexperience with C++ and the SDK, this prototype is missing pretty much all of the features it would require to be a production ready shader 😁 I'm not doing proper error checking and it's quite possible I've written a memory leak or two in here 🤷

    Most telling: the plug-in is crashing when I switch the build to release. Debug is working, but I am unfortunately clueless when it comes to debugging 🙁

    isMountainA.jpg
    isLavaRocks1.jpg

    This Ptex shader doesn't work under several conditions that would need to be addressed if I were working on this for other people to use in production:

    • Doesn't work if the mesh has been subdivided (no correction for the change to polygon indices and coordinates)
    • Similarly doesn't work as an input for sub-polygon displacement
    • Only reads .ptex files whose filenames match objects that the shader is being evaluated on
    • Only works on Windows
    • Only works with a Debug build
    • Not designed as a general purpose shader, specifically built to work with the Moana dataset

    With all of those caveats out of the way, I've uploaded the source to Google Drive in the hopes that folks will point out the idiotic things I've done so that I can improve and also so that someone more capable might pick this up and carry it through to a real shader 😁

    P.S. For anyone working on Windows that doesn't yet know: I highly recommend picking up vcpkg. If I'd had to build Ptex from scratch I don't think I'd even have gotten this far.



  • @wuzelwazel you don’t have to build the ptex library at all. You can just directly include the ptex source files.

    Edit...

    Just checked my ptex plugin, you would also have to set the preprocessor definition PTEX_STATIC and also include zlib. So I guess not so simple :). Nice to hear that vcpkg does this all for you.

    Great work on your plugin btw.



  • This post is deleted!


  • Not sure if you have seen this or not. But I wrote a Moana importer a year or two back.

    https://www.plugins4d.com/moana-island-viewer

    I haven't released the ptex loader for it yet. But seeing someone else work on it makes me want to jump back into it as well.



  • @kbar I have seen your importer! I even tried to contact you through your website's form to share the python script that I'd been working on to convert the dataset in the hopes it would be helpful. I'd solved correction of the transform matrices and had placement of instances, archives and curves working really well.

    My goal was a bit different though, I wanted to convert the Ptex textures into UDIMs, build the materials, build Redshift proxies from the various assets and then instance them into the scene. There were only 2 things that held me back at the time:

    1. OpenImageIO couldn't read many of the Ptex files properly.

    2. The enormous size of some of the JSON files made accessing them with the built-in Python json module incredibly difficult as it would attempt to load the entire file into memory.

    What I'm trying to do now is solve #1 by circumventing OIIO all together. Although after posting this shader I realized that it would be much more efficient to create a command plugin I could call from Python that would:

    -Read the associated Ptex files
    -Setup the UDIM UVs on the objects
    -Write the Ptex sub-images directly into a bitmap following the UDIM layout

    That wouldn't be helpful in a general Ptex workflow, but would get me what I need much more efficiently (no need to bake textures in a separate pass).

    As for #2 I did find the ijson module, which would allow me to iterate through the larger json files without loading them entirely into memory.



  • @wuzelwazel So sorry for not replying back to you. I just had a look for it now (February last year), wow almost a year has gone by. Glad to see your still working on it. I will see if I can find some time soon to have another look as well.

    As far as the UDIM work goes I did something similar many years back. I extracted every texture for every triangle and wrote them to a new texture map. And as each triangle texture is extracted to the texture map I use its location for the newly created UVs. I used this for an OpenGL preview as well as rendering. Note that this is not baking at all. Since I am using actual ptex pixel image size directly for each triangle extracted to the texture. So the UV coordinates are based on the actual pixel size in the ptex images. As soon as one texture was full I created another with a new selection set for the triangles and its own material, which could be considered UDIM if I just went out of the 0-1 range, but there was not any need to for my test.

    I had planned on doing this again and converting the OBJ files to C4D files in the process, to make them smaller and faster to load. Which is what you are doing with Redshift proxies I believe?

    I will reply to your email as well so you have my contact details.

    Cheers,
    Kent



  • @kbar said in Ptex Shader Progress:

    I had planned on doing this again and converting the OBJ files to C4D files in the process, to make them smaller and faster to load. Which is what you are doing with Redshift proxies I believe?

    Yes, the Redshift Proxies work as a sort of reference so the main c4d file would be quite small. In addition the display of each proxy can be simplified to either reduce or eliminate the viewport being bogged down with drawing faces. Of course, when everything is just a bounding box the scene doesn't look like much before rendering!

    The other benefit of the proxy is specific to Redshift in that the mesh will not need to be processed before the BVH is constructed and rendering can begin.



  • Hi @wuzelwazel, thanks a lot for sharing your progresses on the Ptex Shader and for sharing your code.

    I've moved the thread to the more appropriate "General Programming & Plugin Discussions" hoping other developers could contribute to the discussion.

    Cheers, Riccardo