Skip to content

Commit

Permalink
Merge pull request #1152 from luisbarrancos/placement2d
Browse files Browse the repository at this point in the history
Add placement2dTexture node
  • Loading branch information
est77 committed Dec 3, 2016
2 parents 7cbb259 + a1e8aa1 commit f207263
Show file tree
Hide file tree
Showing 2 changed files with 282 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/appleseed.shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ set (appleseed_maya2_osl_sources
src/maya/as_maya_matrixInverse.osl
src/maya/as_maya_multDoubleLinear.osl
src/maya/as_maya_multMatrix.osl
src/maya/as_maya_place2dTexture.osl
src/maya/as_maya_multiplyDivide.osl
src/maya/as_maya_plusMinusAverage.osl
src/maya/as_maya_quadShadingSwitch.osl
Expand Down
281 changes: 281 additions & 0 deletions src/appleseed.shaders/src/maya/as_maya_place2dTexture.osl
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@

//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2016 Luis Barrancos, The appleseedhq Organization
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// Ref: $MAYA_LOCATION/docs/Nodes/place2dTexture.html

#include "appleseed/math/as_math_helpers.h"
#include "appleseed/maya/as_maya_helpers.h"

shader as_maya_place2dTexture
[[
string maya_node_name = "place2dTexture",
string maya_classification = "utility/general/placement/2d"
]]
(
float in_uvCoord[2] = {0.0, 0.0}
[[
string maya_attribute_name = "uvCoord",
string maya_attribute_type = "float2",
string label = "Input UV Coords"
]],
float in_uvFilterSize[2] = {0.0, 0.0}
[[
string maya_attribute_name = "uvFilterSize",
string maya_attribute_type = "float2",
string label = "Input UV Filter Size"
]],
float in_coverage[2] = {1.0, 1.0}
[[
string maya_attribute_name = "coverage",
string maya_attribute_type = "float2",
string label = "Coverage"
]],
float in_translateFrame[2] = {0.0, 0.0}
[[
string maya_attribute_name = "translateFrame",
string maya_attribute_type = "float2",
string label = "UV Frame Translation"
]],
float in_rotateFrame = 0.0
[[
string maya_attribute_name = "rotateFrame",
string maya_attribute_type = "angle",
string label = "UV Frame Rotation"
]],
int in_mirrorU = 0
[[
string maya_attribute_name = "mirrorU",
string maya_attribute_type = "bool",
string label = "Mirror U",
string widget = "checkBox"
]],
int in_mirrorV = 0
[[
string maya_attribute_name = "mirrorV",
string maya_attribute_type = "bool",
string label = "Mirror V",
string widget = "checkBox"
]],
int in_stagger = 0
[[
string maya_attribute_name = "stagger",
string maya_attribute_type = "bool",
string label = "Stagger",
string widget = "c heckBox"
]],
int in_wrapU = 0
[[
string maya_attribute_name = "wrapU",
string maya_attribute_type = "bool",
string label = "Wrap U",
string widget = "checkBox"
]],
int in_wrapV = 0
[[
string maya_attribute_name = "wrapV",
string maya_attribute_type = "bool",
string label = "Wrap V",
string widget = "checkBox"
]],
int in_repeatUV[2] = {1, 1}
[[
string maya_attribute_name = "repeatUV",
string maya_attribute_type = "float2",
string label = "Repeat UV"
]],
float in_offset[2] = {0.0, 0.0}
[[
string maya_attribute_name = "offset",
string maya_attribute_type = "float2",
string label = "Offset"
]],
float in_rotateUV = 0.0
[[
string maya_attribute_name = "rotateUV",
string maya_attribute_type = "angle",
string label = "Rotate UV"
]],
float in_noiseUV[2] = {0.0, 0.0}
[[
string maya_attribute_name = "noiseUV",
string maya_attribute_type = "float2",
string label = "Noise UV"
]],
int in_fast = 0
[[
string maya_attribute_name = "fast",
string maya_attribute_type = "bool",
string label = "Fast",
string widget = "checkBox"
]],

output float out_outUV[2] = {0.0, 0.0}
[[
string maya_attribute_name = "outUV",
string maya_attribute_type = "float2",
string label = "Output UV",
string widget = "null"
]],
output float out_outUvFilterSize[2] = {0.0, 0.0}
[[
string maya_attribute_name = "outUvFilterSize",
string maya_attribute_type = "float2",
string label = "Output UV Filter Size",
string widget = "null"
]],
output int out_doTransform = 1
[[
string maya_attribute_name = "doTransform",
string maya_attribute_type = "bool",
string label = "Do Transform",
string widget = "null"
]]
)
{
// The user might override input UV coords for the placement node.
float st[2] =
{
isconnected(in_uvCoord[0]) ? in_uvCoord[0] : u,
isconnected(in_uvCoord[1]) ? in_uvCoord[1] : v
};

// Maya applies 2D noise 1st, xforms UV frame, then framed UV coords.
if (in_noiseUV[0] || in_noiseUV[1])
{
// TODO: add & match 2D noise

if (in_noiseUV[0])
{
;
}
if (in_noiseUV[1])
{
;
}
}

if (in_rotateFrame)
{
point rot = rotate(
point(st[0], st[1], 0.0),
radians(in_rotateFrame),
point(0.5, 0.5, 0.0),
point(0.5, 0.5, 1.0));

st[0] = rot[0];
st[1] = rot[1];
}

// Coverage of UV frame ∈ [ε,1.0]², and translation.
float coverage[2] =
{
max(EPS, in_coverage[0]),
max(EPS, in_coverage[1])
};

if (coverage[0] < 1.0 || coverage[1] < 1.0)
{
st[0] /= coverage[0];
st[1] /= coverage[1];

if (in_translateFrame[0])
{
st[0] -= in_translateFrame[0] / coverage[0];
}
if (in_translateFrame[1])
{
st[1] -= in_translateFrame[1] / coverage[1];
}
}

if (in_wrapU)
{
st[0] = mod(st[0], 1.0 / coverage[0]);
}
if (in_wrapV)
{
st[1] = mod(st[1], 1.0 / coverage[1]);
}

// Outside the covered UV frame, the downstream nodes use defaultColor.
if (st[0] < 0.0 || st[0] > 1.0 || st[1] < 0.0 || st[1] > 1.0)
{
st[0] = OUTSIDE_UVFRAME;
st[1] = OUTSIDE_UVFRAME;
}
else
{
st[0] *= in_repeatUV[0];
st[1] *= in_repeatUV[1];
st[0] += in_offset[0];
st[1] += in_offset[1];

if (in_stagger && mod(st[1], 2) >= 1)
{
st[0] += 0.5;
}

if (in_mirrorU)
{
if (mod(st[0], 2) >= 1.0)
{
st[0] += 0.5;
}
}

if (in_mirrorV)
{
if (mod(st[1], 2) >= 1.0)
{
st[1] += 0.5;
}
}

if (in_rotateUV)
{
point rot = rotate(
point(st[0], st[1], 0.0),
radians(in_rotateUV),
point(0.5, 0.5, 0.0),
point(0.5, 0.5, 1.0));

st[0] = rot[0];
st[1] = rot[1];
}
}
out_outUV[0] = st[0];
out_outUV[1] = st[1];

// Signal xforms applied on UV coords.
if (in_rotateFrame || in_translateFrame[0] || in_translateFrame[1] ||
in_offset[0] || in_offset[1] || in_rotateUV )
{
out_doTransform = 1;
}
}

0 comments on commit f207263

Please sign in to comment.