Skip to content

Commit

Permalink
Improve shader generation for viewdirection
Browse files Browse the repository at this point in the history
This changelist improves shader generation logic for the new viewdirection node, allowing it to work correctly in derived hardware languages such as ESSL.
  • Loading branch information
jstone-lucasfilm committed Jan 4, 2024
1 parent 39d6d5b commit 8ab122f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ void ViewDirectionNodeGlsl::createVariables(const ShaderNode&, GenContext&, Shad

void ViewDirectionNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
const ShaderGenerator& shadergen = context.getShaderGenerator();
const GlslShaderGenerator& shadergen = static_cast<const GlslShaderGenerator&>(context.getShaderGenerator());

DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
{
VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
const string prefix = vertexData.getInstance() + ".";
const string prefix = shadergen.getVertexDataPrefix(vertexData);
ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
if (!position->isEmitted())
{
Expand All @@ -43,7 +43,7 @@ void ViewDirectionNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext&
DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
{
VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
const string prefix = vertexData.getInstance() + ".";
const string prefix = shadergen.getVertexDataPrefix(vertexData);
ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
shadergen.emitLineBegin(stage);
shadergen.emitOutput(node.getOutput(), true, false, context, stage);
Expand Down
6 changes: 3 additions & 3 deletions source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ void ViewDirectionNodeMsl::createVariables(const ShaderNode&, GenContext&, Shade

void ViewDirectionNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
const ShaderGenerator& shadergen = context.getShaderGenerator();
const MslShaderGenerator& shadergen = static_cast<const MslShaderGenerator&>(context.getShaderGenerator());

DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
{
VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
const string prefix = vertexData.getInstance() + ".";
const string prefix = shadergen.getVertexDataPrefix(vertexData);
ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
if (!position->isEmitted())
{
Expand All @@ -43,7 +43,7 @@ void ViewDirectionNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext&
DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
{
VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
const string prefix = vertexData.getInstance() + ".";
const string prefix = shadergen.getVertexDataPrefix(vertexData);
ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
shadergen.emitLineBegin(stage);
shadergen.emitOutput(node.getOutput(), true, false, context, stage);
Expand Down

0 comments on commit 8ab122f

Please sign in to comment.