Skip to content

Commit

Permalink
Update OSL shaders for metal closure changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
est77 committed Mar 29, 2020
1 parent 0156e17 commit 5e9631b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ shader as_metal_surface
Tn,
NormalReflectance,
EdgeTint,
1.0,
microfacet_roughness(Roughness, RoughnessDepthScale),
Anisotropic);
}
44 changes: 22 additions & 22 deletions sandbox/tests/test scenes/osl/_shaders/as_metal_surface.oso
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OpenShadingLanguage 1.00
# Compiled by oslc 1.10.3
# Compiled by oslc 1.10.9
# options: -I/home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include
shader as_metal_surface %meta{string,help,"Metal surface shader"}
param vector Normal 0 0 0 %read{11,11} %write{0,0} %initexpr
Expand All @@ -12,12 +12,12 @@ param float RoughnessDepthScale 1 %meta{float,min,1} %read{3,7} %write{2147483
param float Anisotropic 0 %meta{string,help,"Anisotropy"} %meta{float,min,-1} %meta{float,max,1} %read{11,11} %write{2147483647,-1}
oparam closure color BRDF %read{2147483647,-1} %write{12,12}
global normal N %read{0,0} %write{2147483647,-1}
local float ___351_out %read{10,10} %write{2,9}
local int ___352_ray_depth %read{6,8} %write{5,5}
local float ___364_out %read{10,10} %write{2,9}
local int ___365_ray_depth %read{6,8} %write{5,5}
temp closure color $tmp1 %read{12,12} %write{11,11}
const float $const1 1 %read{3,11} %write{2147483647,-1}
temp float $tmp2 %read{11,11} %write{10,10}
const string $const1 "microfacet_roughness" %read{1,1} %write{2147483647,-1}
const float $const2 1 %read{3,3} %write{2147483647,-1}
const string $const2 "microfacet_roughness" %read{1,1} %write{2147483647,-1}
temp int $tmp3 %read{4,4} %write{3,3}
temp int $tmp4 %read{2147483647,-1} %write{5,5}
const string $const3 "path:ray_depth" %read{5,5} %write{2147483647,-1}
Expand All @@ -29,32 +29,32 @@ code Normal
# vector Normal = N,
assign Normal N %filename{"as_metal_surface.osl"} %line{36} %argrw{"wr"}
code ___main___
# as_metal_surface.osl:77
# as_metal_surface.osl:78
# microfacet_roughness(Roughness, RoughnessDepthScale),
functioncall $const1 11 %filename{"as_metal_surface.osl"} %line{77} %argrw{"r"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:35
functioncall $const2 11 %filename{"as_metal_surface.osl"} %line{78} %argrw{"r"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:45
# float out = roughness;
assign ___351_out Roughness %filename{"/home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h"} %line{35} %argrw{"wr"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:37
assign ___364_out Roughness %filename{"/home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h"} %line{45} %argrw{"wr"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:47
# if (depth_scale > 1.0)
gt $tmp3 RoughnessDepthScale $const2 %line{37} %argrw{"wrr"}
gt $tmp3 RoughnessDepthScale $const1 %line{47} %argrw{"wrr"}
if $tmp3 10 10 %argrw{"r"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:40
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:50
# getattribute("path:ray_depth", ray_depth);
getattribute $tmp4 $const3 ___352_ray_depth %line{40} %argrw{"wrw"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:42
getattribute $tmp4 $const3 ___365_ray_depth %line{50} %argrw{"wrw"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:52
# if (ray_depth)
if ___352_ray_depth 10 10 %line{42} %argrw{"r"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:44
if ___365_ray_depth 10 10 %line{52} %argrw{"r"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:54
# out = roughness * depth_scale * ray_depth;
mul $tmp5 Roughness RoughnessDepthScale %line{44} %argrw{"wrr"}
assign $tmp6 ___352_ray_depth %argrw{"wr"}
mul ___351_out $tmp5 $tmp6 %argrw{"wrr"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:47
mul $tmp5 Roughness RoughnessDepthScale %line{54} %argrw{"wrr"}
assign $tmp6 ___365_ray_depth %argrw{"wr"}
mul ___364_out $tmp5 $tmp6 %argrw{"wrr"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/include/appleseed/material/as_material_helpers.h:57
# return out;
assign $tmp2 ___351_out %line{47} %argrw{"wr"}
assign $tmp2 ___364_out %line{57} %argrw{"wr"}
# as_metal_surface.osl:72
# BRDF = Reflectance * as_metal(
closure $tmp1 $const4 Normal Tn NormalReflectance EdgeTint $tmp2 Anisotropic %filename{"as_metal_surface.osl"} %line{72} %argrw{"wrrrrrrr"}
closure $tmp1 $const4 Normal Tn NormalReflectance EdgeTint $const1 $tmp2 Anisotropic %filename{"as_metal_surface.osl"} %line{72} %argrw{"wrrrrrrrr"}
mul BRDF $tmp1 Reflectance %argrw{"wrr"}
end
1 change: 1 addition & 0 deletions src/appleseed.shaders/as_osl_extensions.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ closure color as_metal(
vector T,
color normal_reflectance,
color edge_tint,
float edge_tint_weight,
float roughness,
float anisotropic
// keyword arguments:
Expand Down
10 changes: 10 additions & 0 deletions src/appleseed.shaders/src/appleseed/as_metal.osl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ shader as_metal
string help = "Reflectance at grazing incidence.",
int as_max_param_id = 2
]],
float in_edge_reflectance_weight = 0.0
[[
string as_maya_attribute_name = "edgeReflectanceWeight",
string as_maya_attribute_short_name = "f90w",
string label = "Edge Reflectance Weight",
string page = "Fresnel",
string help = "Edge reflectance weight.",
int as_max_param_id = 26
]],
int in_distribution = 0
[[
string as_maya_attribute_name = "distribution",
Expand Down Expand Up @@ -401,6 +410,7 @@ shader as_metal
tangent,
in_face_reflectance,
in_edge_reflectance,
in_edge_reflectance_weight,
in_roughness,
in_anisotropy_amount,
"energy_compensation", in_energy_compensation);
Expand Down
1 change: 1 addition & 0 deletions src/appleseed.shaders/src/appleseed/as_sbs_pbrmaterial.osl
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ shader as_sbs_pbrmaterial
tangent,
in_baseColor,
color(1.0), // edge tint
0.0, // edge tint weight
max(0.01, in_roughness),
in_anisotropyLevel,
"energy_compensation", 0.0);
Expand Down
17 changes: 16 additions & 1 deletion src/appleseed.shaders/src/appleseed/as_standard_surface.osl
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,23 @@ shader as_standard_surface
int as_maya_attribute_hidden = 1,
int as_blender_input_socket = 0,
int gafferNoduleLayoutVisible = 0,
int divider = 1,
int as_max_param_id = 27
]],
float in_edge_tint_weight = 0.0
[[
string as_maya_attribute_name = "edgeTintWeight",
string as_maya_attribute_short_name = "f90w",
string label = "Edge Tint Weight",
string page = "Specular",
string help = "Edge tint weight.",
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 as_max_param_id = 71
]],
float in_anisotropy_amount = 0.0
[[
string as_maya_attribute_name = "anisotropyAmount",
Expand Down Expand Up @@ -792,6 +806,7 @@ shader as_standard_surface
tangent,
in_face_tint,
in_edge_tint,
in_edge_tint_weight,
in_specular_roughness,
in_anisotropy_amount);
}
Expand Down
1 change: 1 addition & 0 deletions src/appleseed.shaders/src/max/as_max_metal_material.osl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ shader as_max_metal_material
Tn,
NormalReflectance,
EdgeTint,
1.0, // edge tint weight
microfacet_roughness(Roughness, RoughnessDepthScale),
Anisotropic,
"energy_compensation", 1.0);
Expand Down
4 changes: 3 additions & 1 deletion src/appleseed/renderer/kernel/shading/closures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ namespace
OSL::Vec3 T;
OSL::Color3 normal_reflectance;
OSL::Color3 edge_tint;
float edge_tint_weight;
float roughness;
float anisotropy;
float energy_compensation;
Expand Down Expand Up @@ -917,6 +918,7 @@ namespace
CLOSURE_VECTOR_PARAM(Params, T),
CLOSURE_COLOR_PARAM(Params, normal_reflectance),
CLOSURE_COLOR_PARAM(Params, edge_tint),
CLOSURE_FLOAT_PARAM(Params, edge_tint_weight),
CLOSURE_FLOAT_PARAM(Params, roughness),
CLOSURE_FLOAT_PARAM(Params, anisotropy),
CLOSURE_FLOAT_KEYPARAM(Params, energy_compensation, "energy_compensation"),
Expand Down Expand Up @@ -948,7 +950,7 @@ namespace

values->m_normal_reflectance.set(Color3f(p->normal_reflectance), g_std_lighting_conditions, Spectrum::Reflectance);
values->m_edge_tint.set(Color3f(p->edge_tint), g_std_lighting_conditions, Spectrum::Reflectance);
values->m_edge_tint_weight = 1.0f;
values->m_edge_tint_weight = saturate(p->edge_tint_weight);
values->m_reflectance_multiplier = 1.0f;
values->m_roughness = std::max(p->roughness, 0.0f);
values->m_anisotropy = clamp(p->anisotropy, -1.0f, 1.0f);
Expand Down

0 comments on commit 5e9631b

Please sign in to comment.