autodesk-forks / MaterialX

MaterialX C++ and Python libraries

Home Page:http://www.materialx.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OSL Code generation for documents with <parameter>

krishnancr opened this issue · comments

I might have stumbled onto a bug with genosl. I'm using a nodegraph like

<nodegraph name="compound">
    <standard_surface name="standard_surface" type="surfaceshader">
      <input name="base_color" type="color3" nodename="add" />
      <input name="base" type="float" value="0.8" />
    </standard_surface>
    <add name="add" type="color3">
      <input name="in1" type="color3" nodename="constant" />
      <input name="in2" type="color3" nodename="constant1" />
    </add>
    <constant name="constant" type="color3">
      <parameter name="value" type="color3" value="1, 0, 0" />
    </constant>
    <constant name="constant1" type="color3">
      <parameter name="value" type="color3" value="0, 0, 1" />
    </constant>
    <output name="surfaceshader" type="surfaceshader" nodename="standard_surface" />

It was generated using an older mtlx format, which uses parameter instead of input. Importing it with 1.38 and generating OSL code for it, seems to ignore the value set on the constant node. Here's a portion of the OSL code that was generated for it. Note the values for add_in1 and add_in2 should be 1,0,0 and 0,0,1 respectively. Changing to results in generating the right code.

#include "/home/krishnan/dev/arnold/install/bin/../materialx/stdlib/osl/mx_funcs.h"
#define true 1
#define false 0
#define BSDF closure color
#define EDF closure color
#define VDF closure color
#define surfaceshader closure color
#define volumeshader closure color
#define displacementshader vector
#define lightshader closure color
struct thinfilm { float thickness; float ior; };
#define M_FLOAT_EPS 1e-8
#define M_GOLDEN_RATIO 1.6180339887498948482045868343656
#define GGX_DIRECTIONAL_ALBEDO_METHOD 0
#define GGX_DIRECTIONAL_ALBEDO_TABLE "resources/Lights/AlbedoTable.exr"
shader assign_look_FOO_add
(
    color add_in1 = color(0, 0, 0),
    color add_in2 = color(0, 0, 0),
    output color out = color(0.0)
)
{
    color add_out = mx_add(add_in1, add_in2);
    out = add_out;

Attached code generation using sample graph for vanilla OSL, Arnold OSL and GLSL (pixel shader).
Values are being passed through properly at hash: 715b581.

krishan_issue_arnold.osl.txt
krishan_issue_ps.glsl.txt
krishan_issue.osl.txt

Example snap from Viewer showing expected results. Will add an "save to arnold OSL" option for viewer as a
convenience. ("A" key. "O" = vanila osl, "S" = "glsl" currently).

image

GLSL / OSL Unit test result:
image