Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override implementations of sheen, conductor and subsurface BRDF's for Arnold OSL. #420

Merged
merged 5 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions source/MaterialXGenArnold/ArnoldShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const string ArnoldShaderGenerator::TARGET = "arnold";
ArnoldShaderGenerator::ArnoldShaderGenerator()
: OslShaderGenerator()
{
const StringSet restrictedNames = { "translucent", "empirical_bssrdf", "randomwalk_bssrdf", "volume_absorption",
"volume_emission", "volume_henyey_greenstein", "volume_matte" };
const StringSet restrictedNames = { "metal", "sheen", "bssrdf", "empirical_bssrdf", "randomwalk_bssrdf",
"volume_absorption", "volume_emission", "volume_henyey_greenstein",
"volume_matte" };

_syntax->registerRestrictedNames(restrictedNames);
}

Expand Down
2 changes: 2 additions & 0 deletions source/MaterialXGenArnold/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ add_library(MaterialXGenArnold STATIC
${materialx_header}
)

add_subdirectory(libraries)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious as to why we don't just keep these in the libraries folder (like ogsfx) vs copying over. Assume we want to keep doing it one way or the other.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It felt more modular and contained to keep everything Arnold related inside the same Arnold sub-directory. And copy the library data into its runtime place if Arnold is enabled. If we imagine support for other targets to be dropped in later, I think it makes sense to do it this way. But I'm open to other suggestions.

If we decide to handle it this way I can make the change to have the OgsFx target be handled in the same way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this way better. Let's cleanup OgsFx after. Thanks.


set_target_properties(
MaterialXGenArnold PROPERTIES
OUTPUT_NAME MaterialXGenArnold
Expand Down
2 changes: 2 additions & 0 deletions source/MaterialXGenArnold/libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "${CMAKE_INSTALL_PREFIX}/libraries" MESSAGE_NEVER)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "pbrlib/genosl/lib/mx_refraction_index.osl"

void mx_conductor_brdf(float weight, color reflectivity, color edgecolor, roughnessinfo roughness, normal N, vector U, string distribution, output BSDF result)
{
vector ior_n, ior_k;
mx_artistic_to_complex_ior(reflectivity, edgecolor, ior_n, ior_k);
result = metal(distribution, N, U, ior_n, ior_k, roughness.alphaX, roughness.alphaY);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
float mx_microfacet_sheen_albedo(float cosTheta, float roughness)
{
// LUT for sheen directional albedo.
// A 2D table parameterized with 'cosTheta' (cosine of angle to normal) on x-axis and 'roughness' on y-axis.
int SHEEN_ALBEDO_TABLE_SIZE = 16;
float _sheenAlbedo[256] = {
1.6177, 0.978927, 0.618938, 0.391714, 0.245177, 0.150234, 0.0893475, 0.0511377, 0.0280191, 0.0144204, 0.00687674, 0.00295935, 0.00111049, 0.000336768, 7.07119e-05, 6.22646e-06,
1.1084, 0.813928, 0.621389, 0.479304, 0.370299, 0.284835, 0.21724, 0.163558, 0.121254, 0.0878921, 0.0619052, 0.0419894, 0.0270556, 0.0161443, 0.00848212, 0.00342323,
0.930468, 0.725652, 0.586532, 0.479542, 0.393596, 0.322736, 0.26353, 0.213565, 0.171456, 0.135718, 0.105481, 0.0800472, 0.0588117, 0.0412172, 0.0268329, 0.0152799,
0.833791, 0.671201, 0.558957, 0.471006, 0.398823, 0.337883, 0.285615, 0.240206, 0.200696, 0.16597, 0.135422, 0.10859, 0.0850611, 0.0644477, 0.0464763, 0.0308878,
0.771692, 0.633819, 0.537877, 0.461939, 0.398865, 0.344892, 0.297895, 0.256371, 0.219562, 0.186548, 0.156842, 0.130095, 0.10598, 0.0841919, 0.0645311, 0.04679,
0.727979, 0.606373, 0.52141, 0.453769, 0.397174, 0.348337, 0.305403, 0.267056, 0.232655, 0.201398, 0.17286, 0.146756, 0.122808, 0.100751, 0.0804254, 0.0616485,
0.695353, 0.585281, 0.508227, 0.44667, 0.394925, 0.350027, 0.310302, 0.274561, 0.242236, 0.212604, 0.185281, 0.16002, 0.13657, 0.114693, 0.0942543, 0.0750799,
0.669981, 0.568519, 0.497442, 0.440542, 0.392567, 0.350786, 0.313656, 0.280075, 0.249533, 0.221359, 0.195196, 0.170824, 0.148012, 0.126537, 0.106279, 0.0870713,
0.649644, 0.554855, 0.488453, 0.435237, 0.390279, 0.351028, 0.316036, 0.284274, 0.255266, 0.228387, 0.203297, 0.179796, 0.157665, 0.136695, 0.116774, 0.0977403,
0.632951, 0.543489, 0.480849, 0.430619, 0.388132, 0.350974, 0.317777, 0.287562, 0.259885, 0.234153, 0.210041, 0.187365, 0.165914, 0.145488, 0.125983, 0.10724,
0.61899, 0.533877, 0.47433, 0.426573, 0.386145, 0.35075, 0.319078, 0.290197, 0.263681, 0.238971, 0.215746, 0.193838, 0.173043, 0.153167, 0.134113, 0.115722,
0.607131, 0.52564, 0.468678, 0.423001, 0.38432, 0.35043, 0.320072, 0.292349, 0.266856, 0.243055, 0.220636, 0.199438, 0.179264, 0.159926, 0.141332, 0.123323,
0.596927, 0.518497, 0.463731, 0.419829, 0.382647, 0.350056, 0.320842, 0.294137, 0.269549, 0.246564, 0.224875, 0.204331, 0.18474, 0.165919, 0.147778, 0.130162,
0.588052, 0.512241, 0.459365, 0.416996, 0.381114, 0.349657, 0.321448, 0.295641, 0.271862, 0.24961, 0.228584, 0.208643, 0.189596, 0.171266, 0.153566, 0.136341,
0.580257, 0.506717, 0.455481, 0.41445, 0.379708, 0.34925, 0.321929, 0.296923, 0.273869, 0.252279, 0.231859, 0.212472, 0.193933, 0.176066, 0.158788, 0.141945,
0.573355, 0.5018, 0.452005, 0.412151, 0.378416, 0.348844, 0.322316, 0.298028, 0.275627, 0.254638, 0.234772, 0.215896, 0.197828, 0.180398, 0.163522, 0.147049
};

float x = cosTheta * (SHEEN_ALBEDO_TABLE_SIZE - 1);
float y = roughness * (SHEEN_ALBEDO_TABLE_SIZE - 1);
int ix = int(x);
int iy = int(y);
int ix2 = clamp(ix + 1, 0, SHEEN_ALBEDO_TABLE_SIZE - 1);
int iy2 = clamp(iy + 1, 0, SHEEN_ALBEDO_TABLE_SIZE - 1);
float fx = x - ix;
float fy = y - iy;

float v1 = mix(_sheenAlbedo[iy * SHEEN_ALBEDO_TABLE_SIZE + ix], _sheenAlbedo[iy * SHEEN_ALBEDO_TABLE_SIZE + ix2], fx);
float v2 = mix(_sheenAlbedo[iy2 * SHEEN_ALBEDO_TABLE_SIZE + ix], _sheenAlbedo[iy2 * SHEEN_ALBEDO_TABLE_SIZE + ix2], fx);
float albedo = mix(v1, v2, fy);

return clamp(albedo, 0.0, 1.0);
}

void mx_sheen_brdf(float weight, color _color, float roughness, vector _normal, BSDF base, output BSDF result)
{
// Get sheen directional albedo for attenuating base layer
// in order to be energy conserving.
float NdotV = fabs(dot(N,-I));
float alpha = clamp(roughness, M_FLOAT_EPS, 1.0);
float albedo = weight * mx_microfacet_sheen_albedo(NdotV, alpha);

result = weight * _color * sheen(_normal, roughness) + (1.0 - albedo) * base;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void mx_subsurface_brdf(float weight, color _color, vector radius, float anisotropy, vector _normal, output BSDF result)
{
result = weight * randomwalk_bssrdf(radius, _color, anisotropy);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<materialx version="1.35">
<!-- Implementation overrides for Arnold -->

<!-- <conductor_brdf> -->
<implementation name="IM_conductor_brdf_genosl_arnold" nodedef="ND_conductor_brdf" file="pbrlib/genosl/arnold/mx_conductor_brdf.osl" function="mx_conductor_brdf" language="genosl" target="arnold"/>

<!-- <subsurface_brdf> -->
<implementation name="IM_subsurface_brdf_genosl_arnold" nodedef="ND_subsurface_brdf" file="pbrlib/genosl/arnold/mx_subsurface_brdf.osl" function="mx_subsurface_brdf" language="genosl" target="arnold"/>

<!-- <sheen_brdf> -->
<implementation name="IM_sheen_brdf_genosl_arnold" nodedef="ND_sheen_brdf" file="pbrlib/genosl/arnold/mx_sheen_brdf.osl" function="mx_sheen_brdf" language="genosl" target="arnold"/>

</materialx>