Skip to content

osltoy: auto-detect output variable -- doesn't need to be Cout if there's only one #2021

@lgritz

Description

@lgritz

Right now, osltoy assumes that the shader being toyed with has a color output variable called "Cout", and that's the one to display.

There are two ways to make this more flexible (either one, or maybe both, have merit):

  1. Allow the UI to let the user designate the output to be viewing, not always Cout.
  2. Automatically scan (via OSLQuery) the output variables of the compiled shader, and if there is not a "Cout", just use the first output color variable that is found.

Some breadcrumbs to help find the right spots to change:

  • OSLToyRenderer::OSLToyRenderer() is where it sets up the shading system, and immediately designates "Cout" as the "renderer_outputs" list attribute, hard coded.
  • You can override the renderer_outputs attribute on a per-shader-group basis, using the form of ShadingSystem::attribute() that takes a ShaderGroup* as the first argument.
  • OSLToyMainWindow::build_shader_group() is where it sets up the shader group. It doesn't set up any per-group attributes, but it could once the group is made. (It does get some attributes to find out about the group.)
  • You could use OSLQuery (the constructor that takes a group) to find out about the group's parameters, and find which ones are output colors, then designate those as renderer outputs for the group. Do that after the group is made (after ShaderGroupEnd), but before you do any getattribute calls on the group, because some of those attribute queries might cause the group to be optimized and JITed, but it's important to designate the outputs before it's optimized (because if there's an output that doesn't appear to be used, it will be optimized away).
  • Finally, in OSLToyRenderer::render_image(), you can see "Cout" is used again to know which output buffer to save and display. That obviously needs to be the name of the one you detected or requested, if not Cout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dev DaysASWF Dev Days suitable projectdevdays25enhancementImprovement of existing/working features.feature requestgood first issueGood one-day project for beginners without much knowledge of the code basehelp wantedA task that is desired, but needs somebody to commit the effort to implement it.osltoyosltoy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions