Skip to content

Commit

Permalink
Add new shaders, Maya matte support, fixes
Browse files Browse the repository at this point in the history
- Added raySwitch surface shader, for closures. We have one for textures.
- Added blendNormals node to blend **tangent space normal maps** via
  reoriented normal mapping.
- Added surface luminance node via NPR rays, color space aware.
- Added support for matte opacity in the Maya shaders, but restricted only
  to matte opacity mode 0 ("Black Hole"). For the rest, piping the output
  to the as_matte shader via shader passthrough provides equivalent
  functionality.
- Added minor performance optimizations to the Maya nodes, mostly related
  to opacity tests and *shadow* and *transparency* rays.
- Added **reorientNormal** checkbox to *as_bump* node to give the user the
  option to ensure the resulting normals of tangent space normal mapping
  are in the same hemisphere as the surface normal N.
- Added orientation check to *as_fresnel*, to ensure the normal is forward
  facing.
- Added access to appleseed exclusive global primvars dNdu, dNdv, and
  others.
- Added access to *vertex_color*, currently a placeholder attribute.
- Chromaticity coordinates can be negative, so ensure the UI metadata
  reflects this in *as_luminance* node.
- Added the *glass random walk* profile to *as_subsurface*.
- Added flip/switch XY/RG components of the texture sections of the
  triplanar node, required to blend correctly tangent space normal maps.
- Add integer remainder and remove random function.
- Replace mod/fmod by remainder when using large (signed) hash IDs.
- Remove labels from help URL tokens.
- Minor fixes and cleanups.
  • Loading branch information
luisbarrancos authored and dictoon committed Dec 19, 2019
1 parent 24a8077 commit b87417b
Show file tree
Hide file tree
Showing 52 changed files with 1,414 additions and 307 deletions.
3 changes: 3 additions & 0 deletions src/appleseed.shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ set (src_appleseed_sources
src/appleseed/as_attributes.osl
src/appleseed/as_blackbody.osl
src/appleseed/as_blend_color.osl
src/appleseed/as_blend_normal.osl
src/appleseed/as_blend_shader.osl
src/appleseed/as_bump.osl
src/appleseed/as_closure2surface.osl
Expand All @@ -290,10 +291,12 @@ set (src_appleseed_sources
src/appleseed/as_noise3d.osl
src/appleseed/as_plastic.osl
src/appleseed/as_ray_switch.osl
src/appleseed/as_ray_switch_surface.osl
src/appleseed/as_sbs_pbrmaterial.osl
src/appleseed/as_space_transform.osl
src/appleseed/as_standard_surface.osl
src/appleseed/as_subsurface.osl
src/appleseed/as_surface_luminance.osl
src/appleseed/as_switch_surface.osl
src/appleseed/as_switch_texture.osl
src/appleseed/as_swizzle.osl
Expand Down
44 changes: 5 additions & 39 deletions src/appleseed.shaders/include/appleseed/math/as_math_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,48 +81,14 @@ float fast_gain(float value, float g)
//
// Reference:
//
// Lehmer linear congruential generator (Park-Miller)
// https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
//
// Random Number Generators: Good Ones Are Hard To Find,
// Stephen K.Park and Keith W.Miller
//
// http://www.firstpr.com.au/dsp/rand31/p1192-park.pdf
// https://en.wikipedia.org/wiki/Lehmer_random_number_generator
//

int rand_int(int seed)
{
int a = 16807;
int q = 127773;
int r = 2836;
int m = 2147483647;

int hi = seed / q;
int lo = seed % q;
int x = a * lo - r * hi;

return x > 0 ? x : x + m;
}

int rand_float(int seed, output float result)
{
int x = rand_int(seed);
result = x / 2147483647;

return x;
}

float random(float x, float s, float t)
{
vector A = vector(s, t, 0); // s=u, t=v usually
vector B = vector(4.213536, 8.34621351, 0);

return mod(sin(dot(A, B)) * 917853.4917593, 1.0);
}

float random(float x)
int remainder(int x, int y)
{
return random(x, u, v);
int rem = x % y;
if ((rem > 0 && y < 0) || (rem < 0 && y > 0)) rem += y;
return rem;
}

float fract(float x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ shader as_anisotropy_vector_field
[[
string help = "Creates an anisotropy field vector from an input color.",
string icon = "asAnisotropyVectorField.png",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_anisotropy_vector_field.html#label-as-anisotropy-vector-field",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_anisotropy_vector_field.html",

string as_node_name = "asAnisotropyVectorField",
string as_category = "utility",
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed.shaders/src/appleseed/as_asc_cdl.osl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ shader as_asc_cdl
[[
string icon = "asAscCdl.png",
string help = "Slope/Offset/Power Color Decision List utility shader according to the American Society of Cinematographers",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_asc_cdl.html#label-as-asc-cdl",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_asc_cdl.html",

string as_node_name = "asAscCdl",
string as_category = "utility",
Expand Down Expand Up @@ -154,7 +154,7 @@ shader as_asc_cdl

color unclamped = mix(luma, transformed_color, in_saturation);

out_outColor = (in_clamp_output)
out_outColor = in_clamp_output
? clamp(unclamped, color(0), color(1))
: unclamped;
}
2 changes: 1 addition & 1 deletion src/appleseed.shaders/src/appleseed/as_attributes.osl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ shader as_attributes
[[
string help = "OSL and appleseed attributes.",
string icon = "asAttributes.png",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_attributes.html#label-as-attributes",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_attributes.html",

string as_node_name = "asAttributes",
string as_category = "utility",
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed.shaders/src/appleseed/as_blackbody.osl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ shader as_blackbody
[[
string help = "Emission shader with black-body radiation.",
string icon = "asBlackbody.png",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blackbody.html#label-as-blackbody",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blackbody.html",

string as_node_name = "asBlackbody",
string as_category = "shader",
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed.shaders/src/appleseed/as_blend_color.osl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ shader as_blend_color
[[
string help = "Color blend utility node.",
string icon = "asBlendColor.png",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_blend_color.html#label-as-blend-color",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_blend_color.html",

string as_node_name = "asBlendColor",
string as_category = "color",
Expand Down
253 changes: 253 additions & 0 deletions src/appleseed.shaders/src/appleseed/as_blend_normal.osl
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@

//
// This source file is part of appleseed.
// Visit https://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2019 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.
//

#include "appleseed/math/as_math_helpers.h"

shader as_blend_normal
[[
string help = "Tangent space normal blend utility node.",
string icon = "asBlendNormal.png",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_blend_normal.html",

string as_node_name = "asBlendNormal",
string as_category = "utility",

string as_max_class_id = "1585865021 797245718",
string as_max_plugin_type = "texture",

int as_maya_type_id = 0x00127a09,
string as_maya_classification = "drawdb/shader:rendernode/appleseed/utility"
]]
(
normal in_base_normal = normal(0)
[[
string as_maya_attribute_name = "baseNormal",
string as_maya_attribute_short_name = "bnr",
string label = "Base Normal",
string page = "Base Normal",
string help = "The base tangent space normal map.",
int divider = 1
]],
string in_base_normal_mode = "Unsigned"
[[
string as_maya_attribute_name = "baseNormalMode",
string as_maya_attribute_short_name = "brm",
string widget = "popup",
string options = "Unsigned|Signed",
string label = "Normal Map Mode",
string page = "Base Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0,
int divider = 1
]],
int in_base_normal_flip_r = 0
[[
string as_maya_attribute_name = "baseNormalFlipR",
string as_maya_attribute_short_name = "bfr",
string widget = "checkBox",
string label = "Flip R",
string page = "Base Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0
]],
int in_base_normal_flip_g = 0
[[
string as_maya_attribute_name = "baseNormalFlipG",
string as_maya_attribute_short_name = "bfg",
string widget = "checkBox",
string label = "Flip G",
string page = "Base Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0
]],
int in_base_normal_swap_rg = 0
[[
string as_maya_attribute_name = "baseNormalSwapRG",
string as_maya_attribute_short_name = "bsw",
string widget = "checkBox",
string label = "Swap RG",
string page = "Base Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0,
int divider = 1
]],

normal in_detail_normal = normal(0)
[[
string as_maya_attribute_name = "detailNormal",
string as_maya_attribute_short_name = "dno",
string label = "Detail Normal",
string page = "Detail Normal",
string help = "The detail tangent space normal to blend over the base.",
int divider = 1
]],
string in_detail_normal_mode = "Unsigned"
[[
string as_maya_attribute_name = "detailNormalMode",
string as_maya_attribute_short_name = "dnm",
string widget = "popup",
string options = "Unsigned|Signed",
string label = "Normal Map Mode",
string page = "Detail Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0,
int divider = 1
]],
int in_detail_normal_flip_r = 0
[[
string as_maya_attribute_name = "detailNormalFlipR",
string as_maya_attribute_short_name = "dfr",
string widget = "checkBox",
string label = "Flip R",
string page = "Detail Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0
]],
int in_detail_normal_flip_g = 0
[[
string as_maya_attribute_name = "detailNormalFlipG",
string as_maya_attribute_short_name = "dfg",
string widget = "checkBox",
string label = "Flip G",
string page = "Detail Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0
]],
int in_detail_normal_swap_rg = 0
[[
string as_maya_attribute_name = "detailNormalSwapRG",
string as_maya_attribute_short_name = "dsw",
string widget = "checkBox",
string label = "Swap RG",
string page = "Detail Normal",
int as_maya_attribute_connectable = 0,
int as_maya_attribute_keyable = 0,
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0,
int divider = 1
]],
float in_detail_normal_weight = 1.0
[[
string as_maya_attribute_name = "detailNormalWeight",
string as_maya_attribute_short_name = "dwe",
float min = 0.0,
float max = 1.0,
string label = "Blending Weight",
string page = "Blending",
string help = "Detail normal blending weight.",
int divider = 1
]],
vector Tn = vector(0)
[[
int lockgeom = 0,
string widget = "null",
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0
]],
vector Bn = vector(0)
[[
int lockgeom = 0,
string widget = "null",
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0
]],

output normal out_normal = color(0)
[[
string as_maya_attribute_name = "outNormal",
string as_maya_attribute_short_name = "on",
string widget = "null",
string label = "Output Normal",
string help = "Output unsigned tangent space normal map"
]]
)
{
normal baseN = (in_base_normal_mode == "Unsigned")
? in_base_normal * normal(2) - normal(1)
: in_base_normal;

if (in_base_normal_flip_r) baseN[0] *= -1;
if (in_base_normal_flip_g) baseN[1] *= -1;

if (in_base_normal_swap_rg)
{
float tmp = baseN[0];
baseN[0] = baseN[1];
baseN[1] = tmp;
}

normal detailN = (in_detail_normal_mode == "Unsigned")
? in_detail_normal * normal(2) - normal(1)
: in_detail_normal;

if (in_detail_normal_flip_r) detailN[0] *= -1;
if (in_detail_normal_flip_g) detailN[1] *= -1;

if (in_detail_normal_swap_rg)
{
float tmp = detailN[0];
detailN[0] = detailN[1];
detailN[1] = tmp;
}

baseN = normalize(baseN);
detailN = normalize(detailN);

baseN[2] += 1;
detailN[0] *= -in_detail_normal_weight;
detailN[1] *= -in_detail_normal_weight;

normal O = baseN * dot(baseN, detailN) / baseN[2] - detailN;

out_normal = normalize(O);
out_normal = out_normal * normal(0.5) + normal(0.5);
}
2 changes: 1 addition & 1 deletion src/appleseed.shaders/src/appleseed/as_blend_shader.osl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ shader as_blend_shader
[[
string help = "Shader blending or mixing node.",
string icon = "asBlendShader.png",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blend_shader.html#label-as-blend-shader",
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blend_shader.html",

string as_node_name = "asBlendShader",
string as_category = "shader",
Expand Down
Loading

0 comments on commit b87417b

Please sign in to comment.