-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
334 additions
and
312 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
resources/Materials/TestSuite/stdlib/texture/texcoord.mtlx
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"> | ||
<!-- | ||
Test for texture coordinates. This test makes sure that two texture coordinate nodes with various | ||
widths can coexist. | ||
--> | ||
<standard_surface name="standard_surface" type="surfaceshader" xpos="6.152174" ypos="-0.560345"> | ||
<input name="base" type="float" value="1" /> | ||
<input name="base_color" type="color3" nodename="swizzle_vector2_color3" /> | ||
<input name="specular_roughness" type="float" value="0.1" /> | ||
<input name="subsurface" type="float" value="0.4" /> | ||
<input name="subsurface_color" type="color3" nodename="swizzle_vector3_color3" /> | ||
</standard_surface> | ||
<surfacematerial name="surfacematerial" type="material" xpos="8.695652" ypos="0.000000"> | ||
<input name="surfaceshader" type="surfaceshader" nodename="standard_surface" /> | ||
</surfacematerial> | ||
<texcoord name="texcoord_vector2" type="vector2" xpos="1.666667" ypos="-1.405172" /> | ||
<texcoord name="texcoord_vector3" type="vector3" xpos="0.268116" ypos="1.068966" /> | ||
<swizzle name="swizzle_vector3_color3" type="color3" xpos="3.101449" ypos="0.698276"> | ||
<input name="in" type="vector3" nodename="texcoord_vector3" /> | ||
</swizzle> | ||
<swizzle name="swizzle_vector2_color3" type="color3" xpos="4.260870" ypos="-2.896552"> | ||
<input name="in" type="vector2" nodename="texcoord_vector2" /> | ||
</swizzle> | ||
</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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,83 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <MaterialXGenShader/Nodes/HwTexCoordNode.h> | ||
#include <MaterialXGenShader/HwShaderGenerator.h> | ||
#include <MaterialXGenShader/Shader.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
string HwTexCoordNode::INDEX = "index"; | ||
|
||
ShaderNodeImplPtr HwTexCoordNode::create() | ||
{ | ||
return std::make_shared<HwTexCoordNode>(); | ||
} | ||
|
||
void HwTexCoordNode::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const | ||
{ | ||
const ShaderOutput* output = node.getOutput(); | ||
const string index = getIndex(node); | ||
|
||
ShaderStage& vs = shader.getStage(Stage::VERTEX); | ||
ShaderStage& ps = shader.getStage(Stage::PIXEL); | ||
|
||
addStageInput(HW::VERTEX_INPUTS, output->getType(), HW::T_IN_TEXCOORD + "_" + index, vs, true); | ||
addStageConnector(HW::VERTEX_DATA, output->getType(), HW::T_TEXCOORD + "_" + index, vs, ps, true); | ||
} | ||
|
||
void HwTexCoordNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const | ||
{ | ||
const HwShaderGenerator& shadergen = static_cast<const HwShaderGenerator&>(context.getShaderGenerator()); | ||
|
||
const string index = getIndex(node); | ||
const string variable = HW::T_TEXCOORD + "_" + index; | ||
const ShaderOutput* output = node.getOutput(); | ||
|
||
DEFINE_SHADER_STAGE(stage, Stage::VERTEX) | ||
{ | ||
VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA); | ||
const string prefix = shadergen.getVertexDataPrefix(vertexData); | ||
ShaderPort* texcoord = vertexData[variable]; | ||
if (!texcoord->isEmitted()) | ||
{ | ||
shadergen.emitLine(prefix + texcoord->getVariable() + " = " + HW::T_IN_TEXCOORD + "_" + index, stage); | ||
texcoord->setEmitted(); | ||
} | ||
} | ||
|
||
DEFINE_SHADER_STAGE(stage, Stage::PIXEL) | ||
{ | ||
VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA); | ||
const string prefix = shadergen.getVertexDataPrefix(vertexData); | ||
ShaderPort* texcoord = vertexData[variable]; | ||
shadergen.emitLineBegin(stage); | ||
shadergen.emitOutput(output, true, false, context, stage); | ||
|
||
// Extract the requested number of components from the texture coordinates (which may be a | ||
// larger datatype than the requested number of texture coordinates, if several texture | ||
// coordinate nodes with different width coexist). | ||
string suffix = EMPTY_STRING; | ||
if (output->getType() == Type::VECTOR2) | ||
{ | ||
suffix = ".xy"; | ||
} | ||
else if (output->getType() == Type::VECTOR3) | ||
{ | ||
suffix = ".xyz"; | ||
} | ||
|
||
shadergen.emitString(" = " + prefix + texcoord->getVariable() + suffix, stage); | ||
shadergen.emitLineEnd(stage); | ||
} | ||
} | ||
|
||
string HwTexCoordNode::getIndex(const ShaderNode& node) const | ||
{ | ||
const ShaderInput* input = node.getInput(INDEX); | ||
return input ? input->getValue()->getValueString() : "0"; | ||
} | ||
|
||
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
Oops, something went wrong.