forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial nprlib with viewdirection node (AcademySoftwareFoundation#1631)
This changelist introduces an NPR (non-photorealistic rendering) data library to MaterialX, initially consisting of a single `viewdirection` node. The NPR data library is designed for the portable expression of artistic, non-physically-based materials, with common examples being cartoon shading, architectural diagrams, and edge highlighting. In future versions of MaterialX, we expect this data library to be extended with additional primitives and artist-facing graphs as they are requested by the graphics community and approved by the MaterialX TSC. For shader generation, MaterialX initially supports the NPR data library in GLSL, ESSL, MSL, and OSL, with MDL being omitted for now, based on intentional restrictions in its design philosophy.
- Loading branch information
1 parent
473d563
commit 39d6d5b
Showing
18 changed files
with
338 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
<!-- | ||
Copyright Contributors to the MaterialX Project | ||
SPDX-License-Identifier: Apache-2.0 | ||
Declarations for GLSL implementations of standard nodes included in the MaterialX specification. | ||
--> | ||
|
||
<!-- ======================================================================== --> | ||
<!-- View-dependent nodes --> | ||
<!-- ======================================================================== --> | ||
|
||
<!-- <viewdirection> --> | ||
<implementation name="IM_viewdirection_vector3_genglsl" nodedef="ND_viewdirection_vector3" target="genglsl"/> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
<!-- | ||
Copyright Contributors to the MaterialX Project | ||
SPDX-License-Identifier: Apache-2.0 | ||
Declarations for MDL implementations of standard nodes included in the MaterialX specification. | ||
--> | ||
|
||
<!-- ======================================================================== --> | ||
<!-- View-dependent nodes --> | ||
<!-- ======================================================================== --> | ||
|
||
<!-- <viewdirection> --> | ||
<implementation name="IM_viewdirection_vector3_genmdl" nodedef="ND_viewdirection_vector3" sourcecode="mx::stdlib::mx_viewdirection_vector3()" target="genmdl"/> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
<!-- | ||
Copyright Contributors to the MaterialX Project | ||
SPDX-License-Identifier: Apache-2.0 | ||
Declarations for MSL implementations of standard nodes included in the MaterialX specification. | ||
--> | ||
|
||
<!-- ======================================================================== --> | ||
<!-- View-dependent nodes --> | ||
<!-- ======================================================================== --> | ||
|
||
<!-- <viewdirection> --> | ||
<implementation name="IM_viewdirection_vector3_genmsl" nodedef="ND_viewdirection_vector3" target="genmsl"/> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
<!-- | ||
Copyright Contributors to the MaterialX Project | ||
SPDX-License-Identifier: Apache-2.0 | ||
Declarations for OSL implementations of standard nodes included in the MaterialX specification. | ||
--> | ||
|
||
<!-- ======================================================================== --> | ||
<!-- View-dependent nodes --> | ||
<!-- ======================================================================== --> | ||
|
||
<!-- <viewdirection> --> | ||
<implementation name="IM_viewdirection_vector3_genosl" nodedef="ND_viewdirection_vector3" sourcecode="transform({{space}}, I)" target="genosl" /> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
<!-- | ||
Copyright Contributors to the MaterialX Project | ||
SPDX-License-Identifier: Apache-2.0 | ||
Declarations of standard data types and nodes included in the MaterialX specification. | ||
--> | ||
|
||
<!-- ======================================================================== --> | ||
<!-- View-dependent nodes --> | ||
<!-- ======================================================================== --> | ||
|
||
<!-- | ||
Node: <viewdirection> | ||
The current scene view direction, as defined by the shading environment. | ||
--> | ||
<nodedef name="ND_viewdirection_vector3" node="viewdirection" nodegroup="npr"> | ||
<input name="space" type="string" value="world" enum="model,object,world" uniform="true" /> | ||
<output name="out" type="vector3" default="0.0, 0.0, 1.0" /> | ||
</nodedef> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38" colorspace="lin_rec709"> | ||
<nodegraph name="edge_brighten"> | ||
<viewdirection name="viewdirection_vector3" type="vector3" /> | ||
<normal name="normal_vector3" type="vector3" /> | ||
<multiply name="multiply_vector3" type="vector3"> | ||
<input name="in1" type="vector3" nodename="viewdirection_vector3" /> | ||
<input name="in2" type="float" value="-1" /> | ||
</multiply> | ||
<dotproduct name="dotproduct_vector3" type="float"> | ||
<input name="in1" type="vector3" nodename="multiply_vector3" /> | ||
<input name="in2" type="vector3" nodename="normal_vector3" /> | ||
</dotproduct> | ||
<clamp name="clamp_float" type="float"> | ||
<input name="in" type="float" nodename="dotproduct_vector3" /> | ||
</clamp> | ||
<power name="power_float" type="float"> | ||
<input name="in1" type="float" nodename="clamp_float" /> | ||
<input name="in2" type="float" value="0.2" /> | ||
</power> | ||
<mix name="mix_color3" type="color3"> | ||
<input name="fg" type="color3" value="0, 0.0986187, 0.186275" /> | ||
<input name="bg" type="color3" value="0.735294, 0.735294, 0.735294" /> | ||
<input name="mix" type="float" nodename="power_float" /> | ||
</mix> | ||
<output name="out" type="color3" nodename="mix_color3" /> | ||
</nodegraph> | ||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38" colorspace="lin_rec709"> | ||
<nodegraph name="starfield"> | ||
<viewdirection name="viewDir" type="vector3" /> | ||
<multiply name="multiply_vector3FA" type="vector3"> | ||
<input name="in1" type="vector3" nodename="viewDir" /> | ||
<input name="in2" type="float" value="260" /> | ||
</multiply> | ||
<noise3d name="noise3d_float" type="float"> | ||
<input name="position" type="vector3" nodename="multiply_vector3FA" /> | ||
</noise3d> | ||
<contrast name="contrast_float" type="float"> | ||
<input name="in" type="float" nodename="noise3d_float" /> | ||
<input name="amount" type="float" value="5" /> | ||
<input name="pivot" type="float" value="0.8" /> | ||
</contrast> | ||
<clamp name="clamp_float" type="float"> | ||
<input name="in" type="float" nodename="contrast_float" /> | ||
</clamp> | ||
<convert name="convert_float_color3" type="color3"> | ||
<input name="in" type="float" nodename="clamp_float" /> | ||
</convert> | ||
<output name="out" type="color3" nodename="convert_float_color3" /> | ||
</nodegraph> | ||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.h> | ||
|
||
#include <MaterialXGenShader/Shader.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
ShaderNodeImplPtr ViewDirectionNodeGlsl::create() | ||
{ | ||
return std::make_shared<ViewDirectionNodeGlsl>(); | ||
} | ||
|
||
void ViewDirectionNodeGlsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const | ||
{ | ||
ShaderStage& vs = shader.getStage(Stage::VERTEX); | ||
ShaderStage& ps = shader.getStage(Stage::PIXEL); | ||
|
||
addStageInput(HW::VERTEX_INPUTS, Type::VECTOR3, HW::T_IN_POSITION, vs); | ||
addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_POSITION_WORLD, vs, ps); | ||
addStageUniform(HW::PRIVATE_UNIFORMS, Type::VECTOR3, HW::T_VIEW_POSITION, ps); | ||
} | ||
|
||
void ViewDirectionNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const | ||
{ | ||
const ShaderGenerator& shadergen = context.getShaderGenerator(); | ||
|
||
DEFINE_SHADER_STAGE(stage, Stage::VERTEX) | ||
{ | ||
VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA); | ||
const string prefix = vertexData.getInstance() + "."; | ||
ShaderPort* position = vertexData[HW::T_POSITION_WORLD]; | ||
if (!position->isEmitted()) | ||
{ | ||
position->setEmitted(); | ||
shadergen.emitLine(prefix + position->getVariable() + " = hPositionWorld.xyz", stage); | ||
} | ||
} | ||
|
||
DEFINE_SHADER_STAGE(stage, Stage::PIXEL) | ||
{ | ||
VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA); | ||
const string prefix = vertexData.getInstance() + "."; | ||
ShaderPort* position = vertexData[HW::T_POSITION_WORLD]; | ||
shadergen.emitLineBegin(stage); | ||
shadergen.emitOutput(node.getOutput(), true, false, context, stage); | ||
shadergen.emitString(" = normalize(" + prefix + position->getVariable() + " - " + HW::T_VIEW_POSITION + ")", stage); | ||
shadergen.emitLineEnd(stage); | ||
} | ||
} | ||
|
||
MATERIALX_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#ifndef MATERIALX_VIEWDIRECTIONNODEGLSL_H | ||
#define MATERIALX_VIEWDIRECTIONNODEGLSL_H | ||
|
||
#include <MaterialXGenGlsl/GlslShaderGenerator.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
/// ViewDirection node implementation for GLSL | ||
class MX_GENGLSL_API ViewDirectionNodeGlsl : public GlslImplementation | ||
{ | ||
public: | ||
static ShaderNodeImplPtr create(); | ||
|
||
void createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const override; | ||
|
||
void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override; | ||
}; | ||
|
||
MATERIALX_NAMESPACE_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.h> | ||
|
||
#include <MaterialXGenShader/Shader.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
ShaderNodeImplPtr ViewDirectionNodeMsl::create() | ||
{ | ||
return std::make_shared<ViewDirectionNodeMsl>(); | ||
} | ||
|
||
void ViewDirectionNodeMsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const | ||
{ | ||
ShaderStage& vs = shader.getStage(Stage::VERTEX); | ||
ShaderStage& ps = shader.getStage(Stage::PIXEL); | ||
|
||
addStageInput(HW::VERTEX_INPUTS, Type::VECTOR3, HW::T_IN_POSITION, vs); | ||
addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_POSITION_WORLD, vs, ps); | ||
addStageUniform(HW::PRIVATE_UNIFORMS, Type::VECTOR3, HW::T_VIEW_POSITION, ps); | ||
} | ||
|
||
void ViewDirectionNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const | ||
{ | ||
const ShaderGenerator& shadergen = context.getShaderGenerator(); | ||
|
||
DEFINE_SHADER_STAGE(stage, Stage::VERTEX) | ||
{ | ||
VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA); | ||
const string prefix = vertexData.getInstance() + "."; | ||
ShaderPort* position = vertexData[HW::T_POSITION_WORLD]; | ||
if (!position->isEmitted()) | ||
{ | ||
position->setEmitted(); | ||
shadergen.emitLine(prefix + position->getVariable() + " = hPositionWorld.xyz", stage); | ||
} | ||
} | ||
|
||
DEFINE_SHADER_STAGE(stage, Stage::PIXEL) | ||
{ | ||
VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA); | ||
const string prefix = vertexData.getInstance() + "."; | ||
ShaderPort* position = vertexData[HW::T_POSITION_WORLD]; | ||
shadergen.emitLineBegin(stage); | ||
shadergen.emitOutput(node.getOutput(), true, false, context, stage); | ||
shadergen.emitString(" = normalize(" + prefix + position->getVariable() + " - " + HW::T_VIEW_POSITION + ")", stage); | ||
shadergen.emitLineEnd(stage); | ||
} | ||
} | ||
|
||
MATERIALX_NAMESPACE_END |
Oops, something went wrong.