Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/MaterialXRenderOsl/OslRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void OslRenderer::renderOSL(const FilePath& dirPath, const string& shaderName, c
const string INPUT_SHADER_PARAMETER_OVERRIDES("%input_shader_parameter_overrides%");
const string INPUT_SHADER_OUTPUT_STRING("%input_shader_output%");
const string BACKGROUND_COLOR_STRING("%background_color%");
const string OBJ_PATH_STRING("%obj_path%");

StringMap replacementMap;
replacementMap[OUTPUT_SHADER_TYPE_STRING] = outputShader;
Expand All @@ -128,6 +129,7 @@ void OslRenderer::renderOSL(const FilePath& dirPath, const string& shaderName, c
}
replacementMap[INPUT_SHADER_PARAMETER_OVERRIDES] = overrideString;
replacementMap[ENVIRONMENT_SHADER_PARAMETER_OVERRIDES] = envOverrideString;
replacementMap[OBJ_PATH_STRING] = _objPath;
replacementMap[INPUT_SHADER_OUTPUT_STRING] = outputName;
replacementMap[BACKGROUND_COLOR_STRING] = std::to_string(DEFAULT_SCREEN_COLOR_LIN_REC709[0]) + " " +
std::to_string(DEFAULT_SCREEN_COLOR_LIN_REC709[1]) + " " +
Expand Down Expand Up @@ -244,6 +246,7 @@ void OslRenderer::renderOSLNetwork(const FilePath& dirPath, const string& shader
const string ENVIRONMENT_SHADER_PARAMETER_OVERRIDES("%environment_shader_parameter_overrides%");
const string BACKGROUND_COLOR_STRING("%background_color%");
const string OSL_COMMANDS("%oslCmd%");
const string OBJ_PATH_STRING("%obj_path%");

StringMap replacementMap;

Expand All @@ -254,6 +257,7 @@ void OslRenderer::renderOSLNetwork(const FilePath& dirPath, const string& shader
}
replacementMap[ENVIRONMENT_SHADER_PARAMETER_OVERRIDES] = envOverrideString;
replacementMap[OSL_COMMANDS] = _oslCmdStr;
replacementMap[OBJ_PATH_STRING] = _objPath;
replacementMap[BACKGROUND_COLOR_STRING] = std::to_string(DEFAULT_SCREEN_COLOR_LIN_REC709[0]) + " " +
std::to_string(DEFAULT_SCREEN_COLOR_LIN_REC709[1]) + " " +
std::to_string(DEFAULT_SCREEN_COLOR_LIN_REC709[2]);
Expand Down
8 changes: 8 additions & 0 deletions source/MaterialXRenderOsl/OslRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ class MX_RENDEROSL_API OslRenderer : public ShaderRenderer
_envOslShaderParameterOverrides = parameterOverrides;
}

/// Set shader parameter string to be added to the scene XML file. These
/// strings will set the obj path used in the scene.
void setObjPath(const string& objPath)
{
_objPath = objPath;
}

/// Set the OSL shader output.
/// This is used during render validation if "testshade" or "testrender" is executed.
/// For testrender this value is used to replace the %shader_output% token in the
Expand Down Expand Up @@ -265,6 +272,7 @@ class MX_RENDEROSL_API OslRenderer : public ShaderRenderer
string _oslShaderName;
StringVec _oslShaderParameterOverrides;
StringVec _envOslShaderParameterOverrides;
string _objPath;
string _oslShaderOutputName;
string _oslShaderOutputType;
FilePath _oslUtilityOSOPath;
Expand Down
5 changes: 1 addition & 4 deletions source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,8 @@ bool GlslShaderRenderTester::runRenderer(const std::string& shaderName,

if (!geomHandler->hasGeometry(geomPath))
{
// For test sphere and plane geometry perform a V-flip of texture coordinates.
const std::string baseName = geomPath.getBaseName();
bool texcoordVerticalFlip = baseName == "sphere.obj" || baseName == "plane.obj";
geomHandler->clearGeometry();
geomHandler->loadGeometry(geomPath, texcoordVerticalFlip);
geomHandler->loadGeometry(geomPath);
for (mx::MeshPtr mesh : geomHandler->getMeshes())
{
addAdditionalTestStreams(mesh);
Expand Down
5 changes: 1 addition & 4 deletions source/MaterialXTest/MaterialXRenderMsl/RenderMsl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,8 @@ bool runRenderer(const std::string& shaderName,

if (!geomHandler->hasGeometry(geomPath))
{
// For test sphere and plane geometry perform a V-flip of texture coordinates.
const std::string baseName = geomPath.getBaseName();
bool texcoordVerticalFlip = baseName == "sphere.obj" || baseName == "plane.obj";
geomHandler->clearGeometry();
geomHandler->loadGeometry(geomPath, texcoordVerticalFlip);
geomHandler->loadGeometry(geomPath);
for (mx::MeshPtr mesh : geomHandler->getMeshes())
{
addAdditionalTestStreams(mesh);
Expand Down
77 changes: 12 additions & 65 deletions source/MaterialXTest/MaterialXRenderOsl/RenderOsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,6 @@

namespace mx = MaterialX;

namespace
{

//
// Define local overrides for the tangent frame in shader generation, aligning conventions
// between MaterialXRender and testrender.
//

class TangentOsl : public mx::ShaderNodeImpl
{
public:
static mx::ShaderNodeImplPtr create()
{
return std::make_shared<TangentOsl>();
}

void emitFunctionCall(const mx::ShaderNode& node, mx::GenContext& context, mx::ShaderStage& stage) const override
{
const mx::ShaderGenerator& shadergen = context.getShaderGenerator();

DEFINE_SHADER_STAGE(stage, mx::Stage::PIXEL)
{
shadergen.emitLineBegin(stage);
shadergen.emitOutput(node.getOutput(), true, false, context, stage);
shadergen.emitString(" = normalize(vector(N[2], 0, -N[0]))", stage);
shadergen.emitLineEnd(stage);
}
}
};

class BitangentOsl : public mx::ShaderNodeImpl
{
public:
static mx::ShaderNodeImplPtr create()
{
return std::make_shared<BitangentOsl>();
}

void emitFunctionCall(const mx::ShaderNode& node, mx::GenContext& context, mx::ShaderStage& stage) const override
{
const mx::ShaderGenerator& shadergen = context.getShaderGenerator();

DEFINE_SHADER_STAGE(stage, mx::Stage::PIXEL)
{
shadergen.emitLineBegin(stage);
shadergen.emitOutput(node.getOutput(), true, false, context, stage);
shadergen.emitString(" = normalize(cross(N, vector(N[2], 0, -N[0])))", stage);
shadergen.emitLineEnd(stage);
}
}
};

} // anonymous namespace

class OslShaderRenderTester : public RenderUtil::ShaderRenderTester
{
public:
Expand Down Expand Up @@ -106,9 +52,9 @@ class OslShaderRenderTester : public RenderUtil::ShaderRenderTester
void addSkipFiles() override
{
_skipFiles.insert("standard_surface_onyx_hextiled.mtlx");
_skipFiles.insert("hextiled.mtlx");
if (_useOslCmdStr)
{
_skipFiles.insert("hextiled.mtlx");
_skipFiles.insert("filename_cm_test.mtlx");
_skipFiles.insert("shader_ops.mtlx");
_skipFiles.insert("chiang_hair_surfaceshader.mtlx");
Expand Down Expand Up @@ -203,7 +149,7 @@ bool OslShaderRenderTester::runRenderer(const std::string& shaderName,
std::ostream& log,
const GenShaderUtil::TestSuiteOptions& testOptions,
RenderUtil::RenderProfileTimes& profileTimes,
const mx::FileSearchPath&,
const mx::FileSearchPath& searchPath,
const std::string& outputPath,
mx::ImageVec* imageVec)
{
Expand Down Expand Up @@ -233,10 +179,6 @@ bool OslShaderRenderTester::runRenderer(const std::string& shaderName,
contextOptions.targetColorSpaceOverride = "lin_rec709";
contextOptions.oslConnectCiWrapper = true;

// Apply local overrides for shader generation.
shadergen.registerImplementation("IM_tangent_vector3_" + mx::OslShaderGenerator::TARGET, TangentOsl::create);
shadergen.registerImplementation("IM_bitangent_vector3_" + mx::OslShaderGenerator::TARGET, BitangentOsl::create);

shader = shadergen.generate(shaderName, element, context);
}
catch (mx::Exception& e)
Expand Down Expand Up @@ -301,15 +243,22 @@ bool OslShaderRenderTester::runRenderer(const std::string& shaderName,

const mx::ShaderStage& stage = shader->getStage(mx::Stage::PIXEL);

// Bind IBL image name overrides.
// Bind IBL image name overrides - use the searchPath to generate complete
// paths this makes the resolved test template relocatable and easier to debug
mx::FilePath envmapPath = searchPath.find(mx::FilePath(testOptions.radianceIBLPath));
mx::StringVec envOverrides;
std::string envmap_filename("string envmap_filename \"");
envmap_filename += testOptions.radianceIBLPath;
envmap_filename += envmapPath.asString();
envmap_filename += "\";\n";
envOverrides.push_back(envmap_filename);

_renderer->setEnvShaderParameterOverrides(envOverrides);

// Set the OBJ path to render
mx::FilePath resourcesPath = searchPath.find(mx::FilePath("resources"));
mx::FilePath objPath = resourcesPath / "Geometry" / testOptions.renderGeometry;
_renderer->setObjPath(objPath);

const mx::VariableBlock& outputs = stage.getOutputBlock(mx::OSL::OUTPUTS);
if (outputs.size() > 0)
{
Expand All @@ -334,9 +283,7 @@ bool OslShaderRenderTester::runRenderer(const std::string& shaderName,
}

// Set scene template file. For now we only have the constant color scene file
mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();
mx::FilePath sceneTemplatePath = searchPath.find("resources/Utilities/");
sceneTemplatePath = sceneTemplatePath / sceneTemplateFile;
mx::FilePath sceneTemplatePath = resourcesPath/ "Utilities" / sceneTemplateFile;
_renderer->setOslTestRenderSceneTemplateFile(sceneTemplatePath.asString());

// Validate rendering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
connect inputShader.%input_shader_output% outputShader.%output_shader_input%;
</ShaderGroup>

<Sphere center="0, 0, 0" radius="1" />
<Model filename="%obj_path%" />
</World>
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
%oslCmd%
</ShaderGroup>

<Sphere center="0, 0, 0" radius="1" />
<Model filename="%obj_path%" />
</World>