RenderKit / ospray

An Open, Scalable, Portable, Ray Tracing Based Rendering Engine for High-Fidelity Visualization
http://ospray.org
Apache License 2.0
1k stars 182 forks source link

Metal shader questions #372

Closed paulmelis closed 4 years ago

paulmelis commented 4 years ago

I added both the alloy and metal shaders to my app, the former is working fine, but the latter is not behaving as expected. First, a check: should I read the docs as saying that either the ior array needs to be provided, OR, eta and k arrays both (looking at pathtracer/materials/Metal.cpp that seems to be the case)?

Secondly, I'm getting status messages ospray::pathtracer::Metal: found unused parameter 'eta' (and same for k). I think I'm committing where needed and set the arrays in the right way. The roughness value is coming through.

Here's the relevant code:

        material = ospNewMaterial(current_renderer_type.c_str(), "Metal");

        const float eta_gold[] = { 0.07, 0.37, 1.5 };
        const float k_gold[] = { 3.7, 2.3, 1.7 };

        OSPData eta_data = ospNewCopiedData(1, OSP_VEC3F, eta_gold);
        ospCommit(eta_data);        
        OSPData k_data = ospNewCopiedData(1, OSP_VEC3F, k_gold);
        ospCommit(k_data);

        ospSetObject(material, "eta", eta_data);
        ospSetObject(material, "k", k_data);
        ospSetFloat(material, "roughness", settings.roughness());  
        ospCommit(material);

        ospRelease(eta_data);
        ospRelease(k_data);      
// For now, as I haven't looked into using shared data yet (and keeping it alive)
inline OSPData ospNewCopiedData(size_t numItems,
                          OSPDataType type,
                          const void *source)
{
    OSPData src = ospNewSharedData(source, type, numItems);
    OSPData dst = ospNewData(type, numItems);
    ospCopyData(src, dst);
    ospRelease(src);
    return dst;
}
jeffamstutz commented 4 years ago

Both the documentation and code agree on that only ior is an array, so k and eta are vec3f parameters respectively. You are seeing the "unused parameter" warnings because they were specified as the incorrect type (OSPData).

jeffamstutz commented 4 years ago

Thus all you need is:

material = ospNewMaterial(current_renderer_type.c_str(), "Metal");

ospSetVec3f(material, "eta", 0.07, 0.37, 1.5);
ospSetVec3f(material, "k", 3.7, 2.3, 1.7);
ospSetFloat(material, "roughness", settings.roughness());  
ospCommit(material);
paulmelis commented 4 years ago

Dang, it's easy to make these mistakes. I just submitted a pull request #373 to clearify that "unused" could actually also mean "wrong data type". That probably would have pointed me in the right direction here.