Skip to content

Commit

Permalink
Removed deprecated node "viewdirection" (#1105)
Browse files Browse the repository at this point in the history
* Remove deprecated node "fresnel"

* Remove a unit test file.

* Removed deprecated node "viewdirection"

* Added custom viewdir node, required by MaterialXView environment shader.

* Fix regression with loading shader source from file in MaterialXView.

* Removed unit test
  • Loading branch information
niklasharrysson authored and bernardkwok committed Feb 10, 2021
1 parent 734b134 commit e6367bf
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 131 deletions.
3 changes: 0 additions & 3 deletions libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@
<!-- <time> -->
<implementation name="IM_time_float_genglsl" nodedef="ND_time_float" function="mx_time_float" target="genglsl"/>

<!-- <viewdirection> -->
<implementation name="IM_viewdirection_vector3_genglsl" nodedef="ND_viewdirection_vector3" target="genglsl"/>

<!-- ======================================================================== -->
<!-- Math nodes -->
<!-- ======================================================================== -->
Expand Down
3 changes: 0 additions & 3 deletions libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@
<!-- <time> -->
<implementation name="IM_time_float_genmdl" nodedef="ND_time_float" sourcecode="mx::stdlib::mx_time_float()" target="genmdl" />

<!-- <viewdirection> -->
<implementation name="IM_viewdirection_vector3_genmdl" nodedef="ND_viewdirection_vector3" sourcecode="mx::stdlib::mx_viewdirection_vector3()" target="genmdl"/>

<!-- ======================================================================== -->
<!-- Math nodes -->
<!-- ======================================================================== -->
Expand Down
1 change: 0 additions & 1 deletion libraries/stdlib/genosl/mx_viewdirection_vector3.inline

This file was deleted.

2 changes: 0 additions & 2 deletions libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@
<!-- <time> -->
<implementation name="IM_time_float_genosl" nodedef="ND_time_float" file="stdlib/genosl/mx_time_float.osl" function="mx_time_float" target="genosl"/>

<!-- <viewdirection> -->
<implementation name="IM_viewdirection_vector3_genosl" nodedef="ND_viewdirection_vector3" file="stdlib/genosl/mx_viewdirection_vector3.inline" target="genosl"/>

<!-- ======================================================================== -->
<!-- Math nodes -->
Expand Down
10 changes: 0 additions & 10 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<geompropdef name="Tworld" type="vector3" geomprop="tangent" space="world" index="0"/>
<geompropdef name="Bworld" type="vector3" geomprop="bitangent" space="world" index="0"/>
<geompropdef name="UV0" type="vector2" geomprop="texcoord" index="0"/>
<geompropdef name="Vworld" type="vector3" geomprop="viewdirection" space="world"/>

<!-- ======================================================================== -->
<!-- Materials -->
Expand Down Expand Up @@ -1125,15 +1124,6 @@
<output name="out" type="float" default="0.041666667"/>
</nodedef>

<!--
Node: <viewdirection>
The current scene view direction, as defined by the shading environment.
-->
<nodedef name="ND_viewdirection_vector3" node="viewdirection" nodegroup="application">
<parameter name="space" type="string" value="world" enum="model,object,world"/>
<output name="out" type="vector3" default="0.0, 0.0, 1.0"/>
</nodedef>


<!-- ======================================================================== -->
<!-- Math nodes -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?xml version="1.0"?>
<materialx version="1.37">

<!-- Custom node: <viewdir> -->
<!-- Required by environment shader graph below -->
<nodedef name="ND_viewdir_vector3" node="viewdir">
<output name="out" type="vector3" default="0.0, 0.0, 1.0"/>
</nodedef>
<implementation name="IM_viewdir_vector3_genglsl" nodedef="ND_viewdir_vector3" target="genglsl"/>

<nodegraph name="environmentDraw">

<!-- Get view direction -->
<viewdirection name="viewDir" type="vector3">
<parameter name="space" type="string" value="world" />
</viewdirection>
<viewdir name="viewDir" type="vector3" />

<!-- Compute longitude coordinate -->
<atan2 name="angleXZ" type="float">
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions source/MaterialXGenGlsl/GlslShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <MaterialXGenGlsl/Nodes/GeomPropValueNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/FrameNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/TimeNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/SurfaceNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/SurfaceShaderNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/LightNodeGlsl.h>
Expand Down Expand Up @@ -203,8 +202,6 @@ GlslShaderGenerator::GlslShaderGenerator() :
registerImplementation("IM_frame_float_" + GlslShaderGenerator::TARGET, FrameNodeGlsl::create);
// <!-- <time> -->
registerImplementation("IM_time_float_" + GlslShaderGenerator::TARGET, TimeNodeGlsl::create);
// <!-- <viewdirection> -->
registerImplementation("IM_viewdirection_vector3_" + GlslShaderGenerator::TARGET, ViewDirectionNodeGlsl::create);

// <!-- <surface> -->
registerImplementation("IM_surface_" + GlslShaderGenerator::TARGET, SurfaceNodeGlsl::create);
Expand Down
54 changes: 0 additions & 54 deletions source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp

This file was deleted.

27 changes: 0 additions & 27 deletions source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.h

This file was deleted.

16 changes: 0 additions & 16 deletions source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -1282,22 +1282,6 @@ export float mx_time_float(
return ::state::animation_time();
}

export float3 mx_viewdirection_vector3(
uniform mx_coordinatespace_type mxp_space = mx_coordinatespace_type(mx_coordinatespace_type_world)
[[
anno::description("Enumeration {model,object,world}."),
anno::unused()
]]
)
[[
anno::description("Node Group: application")
]]
{
// Not implemented: mx_viewdirection_vector3
float3 defaultValue = float3(0.0, 0.0, 1.0);
return defaultValue;
}

export material mx_add_surfaceshader(
material mxp_in1,
material mxp_in2 [[ anno::unused() ]]
Expand Down
7 changes: 6 additions & 1 deletion source/MaterialXView/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ bool Material::loadSource(const mx::FilePath& vertexShaderFile, const mx::FilePa
return false;
}

// TODO:
// Here we set new source code on the _glProgram without rebuilding
// the _hwShader instance. So the _hwShader is not in sync with the
// _glProgram after this operation.
_glProgram = mx::GlslProgram::create();
_glProgram->setStages(_hwShader);
_glProgram->addStage(mx::Stage::VERTEX, vertexShader);
_glProgram->addStage(mx::Stage::PIXEL, pixelShader);
_glProgram->build();

updateUniformsList();
Expand Down
51 changes: 50 additions & 1 deletion source/MaterialXView/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,52 @@ void applyModifiers(mx::DocumentPtr doc, const DocumentModifiers& modifiers)
}
}

// ViewDir implementation for GLSL
// as needed for the environment shader.
class ViewDirGlsl : public mx::GlslImplementation
{
public:
static mx::ShaderNodeImplPtr create()
{
return std::make_shared<ViewDirGlsl>();
}

void createVariables(const mx::ShaderNode&, mx::GenContext&, mx::Shader& shader) const override
{
mx::ShaderStage& vs = shader.getStage(mx::Stage::VERTEX);
mx::ShaderStage& ps = shader.getStage(mx::Stage::PIXEL);
addStageInput(mx::HW::VERTEX_INPUTS, mx::Type::VECTOR3, mx::HW::T_IN_POSITION, vs);
addStageConnector(mx::HW::VERTEX_DATA, mx::Type::VECTOR3, mx::HW::T_POSITION_WORLD, vs, ps);
addStageUniform(mx::HW::PRIVATE_UNIFORMS, mx::Type::VECTOR3, mx::HW::T_VIEW_POSITION, ps);
}

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

BEGIN_SHADER_STAGE(stage, mx::Stage::VERTEX)
mx::VariableBlock& vertexData = stage.getOutputBlock(mx::HW::VERTEX_DATA);
const mx::string prefix = vertexData.getInstance() + ".";
mx::ShaderPort* position = vertexData[mx::HW::T_POSITION_WORLD];
if (!position->isEmitted())
{
position->setEmitted();
shadergen.emitLine(prefix + position->getVariable() + " = hPositionWorld.xyz", stage);
}
END_SHADER_STAGE(stage, mx::Stage::VERTEX)

BEGIN_SHADER_STAGE(stage, mx::Stage::PIXEL)
mx::VariableBlock& vertexData = stage.getInputBlock(mx::HW::VERTEX_DATA);
const mx::string prefix = vertexData.getInstance() + ".";
mx::ShaderPort* position = vertexData[mx::HW::T_POSITION_WORLD];
shadergen.emitLineBegin(stage);
shadergen.emitOutput(node.getOutput(), true, false, context, stage);
shadergen.emitString(" = normalize(" + prefix + position->getVariable() + " - " + mx::HW::T_VIEW_POSITION + ")", stage);
shadergen.emitLineEnd(stage);
END_SHADER_STAGE(stage, mx::Stage::PIXEL)
}
};

} // anonymous namespace

//
Expand Down Expand Up @@ -224,6 +270,9 @@ Viewer::Viewer(const std::string& materialFilename,
_genContextMdl.getOptions().targetColorSpaceOverride = "lin_rec709";
_genContextMdl.getOptions().fileTextureVerticalFlip = false;
#endif

// Register the GLSL implementation for <viewdir> used by the environment shader.
_genContext.getShaderGenerator().registerImplementation("IM_viewdir_vector3_" + mx::GlslShaderGenerator::TARGET, ViewDirGlsl::create);
}

void Viewer::initialize()
Expand Down Expand Up @@ -447,7 +496,7 @@ void Viewer::loadEnvironmentLight()
{
// Create environment shader.
mx::FilePath envFilename = _searchPath.find(
mx::FilePath("resources/Materials/TestSuite/lights/envmap_shader.mtlx"));
mx::FilePath("resources/Lights/envmap_shader.mtlx"));
try
{
_envMaterial = Material::create();
Expand Down

0 comments on commit e6367bf

Please sign in to comment.