Skip to content

Commit b87417b

Browse files
luisbarrancosdictoon
authored andcommitted
Add new shaders, Maya matte support, fixes
- 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.
1 parent 24a8077 commit b87417b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1414
-307
lines changed

src/appleseed.shaders/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ set (src_appleseed_sources
267267
src/appleseed/as_attributes.osl
268268
src/appleseed/as_blackbody.osl
269269
src/appleseed/as_blend_color.osl
270+
src/appleseed/as_blend_normal.osl
270271
src/appleseed/as_blend_shader.osl
271272
src/appleseed/as_bump.osl
272273
src/appleseed/as_closure2surface.osl
@@ -290,10 +291,12 @@ set (src_appleseed_sources
290291
src/appleseed/as_noise3d.osl
291292
src/appleseed/as_plastic.osl
292293
src/appleseed/as_ray_switch.osl
294+
src/appleseed/as_ray_switch_surface.osl
293295
src/appleseed/as_sbs_pbrmaterial.osl
294296
src/appleseed/as_space_transform.osl
295297
src/appleseed/as_standard_surface.osl
296298
src/appleseed/as_subsurface.osl
299+
src/appleseed/as_surface_luminance.osl
297300
src/appleseed/as_switch_surface.osl
298301
src/appleseed/as_switch_texture.osl
299302
src/appleseed/as_swizzle.osl

src/appleseed.shaders/include/appleseed/math/as_math_helpers.h

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,14 @@ float fast_gain(float value, float g)
8181
//
8282
// Reference:
8383
//
84-
// Lehmer linear congruential generator (Park-Miller)
84+
// https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
8585
//
86-
// Random Number Generators: Good Ones Are Hard To Find,
87-
// Stephen K.Park and Keith W.Miller
88-
//
89-
// http://www.firstpr.com.au/dsp/rand31/p1192-park.pdf
90-
// https://en.wikipedia.org/wiki/Lehmer_random_number_generator
91-
//
92-
93-
int rand_int(int seed)
94-
{
95-
int a = 16807;
96-
int q = 127773;
97-
int r = 2836;
98-
int m = 2147483647;
99-
100-
int hi = seed / q;
101-
int lo = seed % q;
102-
int x = a * lo - r * hi;
103-
104-
return x > 0 ? x : x + m;
105-
}
106-
107-
int rand_float(int seed, output float result)
108-
{
109-
int x = rand_int(seed);
110-
result = x / 2147483647;
111-
112-
return x;
113-
}
114-
115-
float random(float x, float s, float t)
116-
{
117-
vector A = vector(s, t, 0); // s=u, t=v usually
118-
vector B = vector(4.213536, 8.34621351, 0);
119-
120-
return mod(sin(dot(A, B)) * 917853.4917593, 1.0);
121-
}
12286

123-
float random(float x)
87+
int remainder(int x, int y)
12488
{
125-
return random(x, u, v);
89+
int rem = x % y;
90+
if ((rem > 0 && y < 0) || (rem < 0 && y > 0)) rem += y;
91+
return rem;
12692
}
12793

12894
float fract(float x)

src/appleseed.shaders/src/appleseed/as_anisotropy_vector_field.osl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ shader as_anisotropy_vector_field
3030
[[
3131
string help = "Creates an anisotropy field vector from an input color.",
3232
string icon = "asAnisotropyVectorField.png",
33-
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_anisotropy_vector_field.html#label-as-anisotropy-vector-field",
33+
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_anisotropy_vector_field.html",
3434

3535
string as_node_name = "asAnisotropyVectorField",
3636
string as_category = "utility",

src/appleseed.shaders/src/appleseed/as_asc_cdl.osl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ shader as_asc_cdl
3939
[[
4040
string icon = "asAscCdl.png",
4141
string help = "Slope/Offset/Power Color Decision List utility shader according to the American Society of Cinematographers",
42-
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_asc_cdl.html#label-as-asc-cdl",
42+
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_asc_cdl.html",
4343

4444
string as_node_name = "asAscCdl",
4545
string as_category = "utility",
@@ -154,7 +154,7 @@ shader as_asc_cdl
154154

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

157-
out_outColor = (in_clamp_output)
157+
out_outColor = in_clamp_output
158158
? clamp(unclamped, color(0), color(1))
159159
: unclamped;
160160
}

src/appleseed.shaders/src/appleseed/as_attributes.osl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ shader as_attributes
3030
[[
3131
string help = "OSL and appleseed attributes.",
3232
string icon = "asAttributes.png",
33-
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_attributes.html#label-as-attributes",
33+
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_attributes.html",
3434

3535
string as_node_name = "asAttributes",
3636
string as_category = "utility",

src/appleseed.shaders/src/appleseed/as_blackbody.osl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ shader as_blackbody
3333
[[
3434
string help = "Emission shader with black-body radiation.",
3535
string icon = "asBlackbody.png",
36-
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blackbody.html#label-as-blackbody",
36+
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blackbody.html",
3737

3838
string as_node_name = "asBlackbody",
3939
string as_category = "shader",

src/appleseed.shaders/src/appleseed/as_blend_color.osl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ shader as_blend_color
3232
[[
3333
string help = "Color blend utility node.",
3434
string icon = "asBlendColor.png",
35-
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_blend_color.html#label-as-blend-color",
35+
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_blend_color.html",
3636

3737
string as_node_name = "asBlendColor",
3838
string as_category = "color",
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
2+
//
3+
// This source file is part of appleseed.
4+
// Visit https://appleseedhq.net/ for additional information and resources.
5+
//
6+
// This software is released under the MIT license.
7+
//
8+
// Copyright (c) 2019 Luis Barrancos, The appleseedhq Organization
9+
//
10+
// Permission is hereby granted, free of charge, to any person obtaining a copy
11+
// of this software and associated documentation files (the "Software"), to deal
12+
// in the Software without restriction, including without limitation the rights
13+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
// copies of the Software, and to permit persons to whom the Software is
15+
// furnished to do so, subject to the following conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be included in
18+
// all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
// THE SOFTWARE.
27+
//
28+
29+
#include "appleseed/math/as_math_helpers.h"
30+
31+
shader as_blend_normal
32+
[[
33+
string help = "Tangent space normal blend utility node.",
34+
string icon = "asBlendNormal.png",
35+
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/utilities/as_blend_normal.html",
36+
37+
string as_node_name = "asBlendNormal",
38+
string as_category = "utility",
39+
40+
string as_max_class_id = "1585865021 797245718",
41+
string as_max_plugin_type = "texture",
42+
43+
int as_maya_type_id = 0x00127a09,
44+
string as_maya_classification = "drawdb/shader:rendernode/appleseed/utility"
45+
]]
46+
(
47+
normal in_base_normal = normal(0)
48+
[[
49+
string as_maya_attribute_name = "baseNormal",
50+
string as_maya_attribute_short_name = "bnr",
51+
string label = "Base Normal",
52+
string page = "Base Normal",
53+
string help = "The base tangent space normal map.",
54+
int divider = 1
55+
]],
56+
string in_base_normal_mode = "Unsigned"
57+
[[
58+
string as_maya_attribute_name = "baseNormalMode",
59+
string as_maya_attribute_short_name = "brm",
60+
string widget = "popup",
61+
string options = "Unsigned|Signed",
62+
string label = "Normal Map Mode",
63+
string page = "Base Normal",
64+
int as_maya_attribute_connectable = 0,
65+
int as_maya_attribute_keyable = 0,
66+
int as_maya_attribute_hidden = 1,
67+
int as_blender_input_socket = 0,
68+
int gafferNoduleLayoutVisible = 0,
69+
int divider = 1
70+
]],
71+
int in_base_normal_flip_r = 0
72+
[[
73+
string as_maya_attribute_name = "baseNormalFlipR",
74+
string as_maya_attribute_short_name = "bfr",
75+
string widget = "checkBox",
76+
string label = "Flip R",
77+
string page = "Base Normal",
78+
int as_maya_attribute_connectable = 0,
79+
int as_maya_attribute_keyable = 0,
80+
int as_maya_attribute_hidden = 1,
81+
int as_blender_input_socket = 0,
82+
int gafferNoduleLayoutVisible = 0
83+
]],
84+
int in_base_normal_flip_g = 0
85+
[[
86+
string as_maya_attribute_name = "baseNormalFlipG",
87+
string as_maya_attribute_short_name = "bfg",
88+
string widget = "checkBox",
89+
string label = "Flip G",
90+
string page = "Base Normal",
91+
int as_maya_attribute_connectable = 0,
92+
int as_maya_attribute_keyable = 0,
93+
int as_maya_attribute_hidden = 1,
94+
int as_blender_input_socket = 0,
95+
int gafferNoduleLayoutVisible = 0
96+
]],
97+
int in_base_normal_swap_rg = 0
98+
[[
99+
string as_maya_attribute_name = "baseNormalSwapRG",
100+
string as_maya_attribute_short_name = "bsw",
101+
string widget = "checkBox",
102+
string label = "Swap RG",
103+
string page = "Base Normal",
104+
int as_maya_attribute_connectable = 0,
105+
int as_maya_attribute_keyable = 0,
106+
int as_maya_attribute_hidden = 1,
107+
int as_blender_input_socket = 0,
108+
int gafferNoduleLayoutVisible = 0,
109+
int divider = 1
110+
]],
111+
112+
normal in_detail_normal = normal(0)
113+
[[
114+
string as_maya_attribute_name = "detailNormal",
115+
string as_maya_attribute_short_name = "dno",
116+
string label = "Detail Normal",
117+
string page = "Detail Normal",
118+
string help = "The detail tangent space normal to blend over the base.",
119+
int divider = 1
120+
]],
121+
string in_detail_normal_mode = "Unsigned"
122+
[[
123+
string as_maya_attribute_name = "detailNormalMode",
124+
string as_maya_attribute_short_name = "dnm",
125+
string widget = "popup",
126+
string options = "Unsigned|Signed",
127+
string label = "Normal Map Mode",
128+
string page = "Detail Normal",
129+
int as_maya_attribute_connectable = 0,
130+
int as_maya_attribute_keyable = 0,
131+
int as_maya_attribute_hidden = 1,
132+
int as_blender_input_socket = 0,
133+
int gafferNoduleLayoutVisible = 0,
134+
int divider = 1
135+
]],
136+
int in_detail_normal_flip_r = 0
137+
[[
138+
string as_maya_attribute_name = "detailNormalFlipR",
139+
string as_maya_attribute_short_name = "dfr",
140+
string widget = "checkBox",
141+
string label = "Flip R",
142+
string page = "Detail Normal",
143+
int as_maya_attribute_connectable = 0,
144+
int as_maya_attribute_keyable = 0,
145+
int as_maya_attribute_hidden = 1,
146+
int as_blender_input_socket = 0,
147+
int gafferNoduleLayoutVisible = 0
148+
]],
149+
int in_detail_normal_flip_g = 0
150+
[[
151+
string as_maya_attribute_name = "detailNormalFlipG",
152+
string as_maya_attribute_short_name = "dfg",
153+
string widget = "checkBox",
154+
string label = "Flip G",
155+
string page = "Detail Normal",
156+
int as_maya_attribute_connectable = 0,
157+
int as_maya_attribute_keyable = 0,
158+
int as_maya_attribute_hidden = 1,
159+
int as_blender_input_socket = 0,
160+
int gafferNoduleLayoutVisible = 0
161+
]],
162+
int in_detail_normal_swap_rg = 0
163+
[[
164+
string as_maya_attribute_name = "detailNormalSwapRG",
165+
string as_maya_attribute_short_name = "dsw",
166+
string widget = "checkBox",
167+
string label = "Swap RG",
168+
string page = "Detail Normal",
169+
int as_maya_attribute_connectable = 0,
170+
int as_maya_attribute_keyable = 0,
171+
int as_maya_attribute_hidden = 1,
172+
int as_blender_input_socket = 0,
173+
int gafferNoduleLayoutVisible = 0,
174+
int divider = 1
175+
]],
176+
float in_detail_normal_weight = 1.0
177+
[[
178+
string as_maya_attribute_name = "detailNormalWeight",
179+
string as_maya_attribute_short_name = "dwe",
180+
float min = 0.0,
181+
float max = 1.0,
182+
string label = "Blending Weight",
183+
string page = "Blending",
184+
string help = "Detail normal blending weight.",
185+
int divider = 1
186+
]],
187+
vector Tn = vector(0)
188+
[[
189+
int lockgeom = 0,
190+
string widget = "null",
191+
int as_maya_attribute_hidden = 1,
192+
int as_blender_input_socket = 0,
193+
int gafferNoduleLayoutVisible = 0
194+
]],
195+
vector Bn = vector(0)
196+
[[
197+
int lockgeom = 0,
198+
string widget = "null",
199+
int as_maya_attribute_hidden = 1,
200+
int as_blender_input_socket = 0,
201+
int gafferNoduleLayoutVisible = 0
202+
]],
203+
204+
output normal out_normal = color(0)
205+
[[
206+
string as_maya_attribute_name = "outNormal",
207+
string as_maya_attribute_short_name = "on",
208+
string widget = "null",
209+
string label = "Output Normal",
210+
string help = "Output unsigned tangent space normal map"
211+
]]
212+
)
213+
{
214+
normal baseN = (in_base_normal_mode == "Unsigned")
215+
? in_base_normal * normal(2) - normal(1)
216+
: in_base_normal;
217+
218+
if (in_base_normal_flip_r) baseN[0] *= -1;
219+
if (in_base_normal_flip_g) baseN[1] *= -1;
220+
221+
if (in_base_normal_swap_rg)
222+
{
223+
float tmp = baseN[0];
224+
baseN[0] = baseN[1];
225+
baseN[1] = tmp;
226+
}
227+
228+
normal detailN = (in_detail_normal_mode == "Unsigned")
229+
? in_detail_normal * normal(2) - normal(1)
230+
: in_detail_normal;
231+
232+
if (in_detail_normal_flip_r) detailN[0] *= -1;
233+
if (in_detail_normal_flip_g) detailN[1] *= -1;
234+
235+
if (in_detail_normal_swap_rg)
236+
{
237+
float tmp = detailN[0];
238+
detailN[0] = detailN[1];
239+
detailN[1] = tmp;
240+
}
241+
242+
baseN = normalize(baseN);
243+
detailN = normalize(detailN);
244+
245+
baseN[2] += 1;
246+
detailN[0] *= -in_detail_normal_weight;
247+
detailN[1] *= -in_detail_normal_weight;
248+
249+
normal O = baseN * dot(baseN, detailN) / baseN[2] - detailN;
250+
251+
out_normal = normalize(O);
252+
out_normal = out_normal * normal(0.5) + normal(0.5);
253+
}

src/appleseed.shaders/src/appleseed/as_blend_shader.osl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ shader as_blend_shader
3030
[[
3131
string help = "Shader blending or mixing node.",
3232
string icon = "asBlendShader.png",
33-
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blend_shader.html#label-as-blend-shader",
33+
string URL = "https://appleseed.readthedocs.io/projects/appleseed-maya/en/latest/shaders/material/as_blend_shader.html",
3434

3535
string as_node_name = "asBlendShader",
3636
string as_category = "shader",

0 commit comments

Comments
 (0)