Skip to content

Commit

Permalink
Merge branch 'adsk_contrib/dev' into adsk_contrib/shaderx (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardkwok authored Feb 8, 2019
1 parent 2db0bee commit fe8ff70
Show file tree
Hide file tree
Showing 131 changed files with 3,043 additions and 1,024 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

### Added
- Added support for 'nodedef' attributes on MaterialX\:\:Node, integrating this usage into GraphElement\:\:addNodeInstance.
- Added the MaterialX\:\:GeomPropDef class for geometric input declarations.
- Added the Document\:\:getGeomAttrValue method.
- Added the ValueElement\:\:getResolvedValue method.
- Added support for GCC 8 and Clang 7.

### Changed
- Added callbacks Observer\:\:onCopyContent and Observer\:\:onClearContent, and removed callback Observer::onInitialize.
- Moved the standard document library to the 'documents/Libraries/stdlib' folder.

## [1.36.1] - 2018-12-18

Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ The Python bindings for MaterialX are based on [PyBind11](https://github.com/pyb

The MaterialX repository consists of the following folders:

documents - The MaterialX specification, developer guide, and example files.
source - A cross-platform C++ library for MaterialX with Python bindings.
The MaterialXCore module supports the core MaterialX elements
and graph traversal, while the MaterialXFormat module supports
XML serialization.
python - Support modules for MaterialX Python.
- [documents](documents) - The MaterialX specification, developer guide, example and test suite files.
- [source](source) - Cross-platform C++ libraries for MaterialX with Python bindings.
- [python](python) - Support modules for MaterialX Python.

### Usage

Use of this code is subject to the terms of the Autodesk license agreement provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form.

### Additional Resources

- The [Developer Guide](http://www.materialx.org/docs/api/index.html) contains more detailed documentation and code examples in C++ and Python.
- The [Developer Guide](http://www.materialx.org/docs/api/index.html) contains more detailed documentation and code examples in C++ and Python.
5 changes: 5 additions & 0 deletions documents/DeveloperGuide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Developer Information

- [MainPage.md](MainPage.md) : Main developer information
- [CodeExamples.md](CodeExamples.md) : Code examples
- [ShaderGeneration.md](ShaderGeneration.md) : Shader generation documentation.
486 changes: 486 additions & 0 deletions documents/DeveloperGuide/ShaderGeneration.md

Large diffs are not rendered by default.

Binary file added documents/Images/shaderx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions documents/Libraries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Library Structure

The following is the layout of the definitions and implementations provided as part of the core libraries.

## Standard Library
- [stdlib](stdlib)
- [stdlib_defs.mtlx](stdlib/stdlib_defs.mtlx) : Single node nodedef definitions file.
- [stdlib_ng.mtlx](stdlib/stdlib_ng.mtlx) : Node graph definitions file.
- [genglsl](stdlib/genglsl): GLSL language support
- lib : Shader utility files.
- [stdlib_genglsl_impl.mtlx](stdlib/genglsl/stdlib_genglsl_impl.mtlx) : Mapping from definitions to implementations
- [stdlib_genglsl_cm_impl.mtlx](stdlib/genglsl/stdlib_genglsl_cm_impl.mtlx) : Minimal set of "default" color management implementations.
- GLSL implementation files
- [ogsfx](stdlib/genglsl/ogsfx): OGSFX support
- [stdlib_genglsl_ogsfx_impl.mtlx](stdlib/genglsl/ogsfx/stdlib_genglsl_ogsfx_impl.mtlx) : Mapping from definitions to implementations
- OGSFX implementation files
- [genosl](stdlib/genosl): OSL language support
- lib: Shader utility files.
- [stdlib_genosl_impl.mtlx](stdlib/genosl/stdlib_genosl_impl.mtlx) : Mapping from definitions to implementations
- [stdlib_genosl_cm_impl.mtlx](stdlib/genosl/stdlib_genosl_cm_impl.mtlx) : Minimal set of "default" color management implementations
- OSL implementation files.
- [osl](stdlib/genosl): OSL reference implementation
- OSL implementation files.

## PBR library
- [pbrlib](pbrlib)
- [pbrlib_defs.mtlx](pbrlib/pbrlib_defs.mtlx) : Single node definitions file.
- [pbrlib_ng.mtlx](pbrlib/pbrlib_ng.mtlx) : Node graph definitions file.
- [genglsl](pbrlib/genglsl) : GLSL language support
- lib : Shader utility files.
- [pbrlib_genglsl_impl.mtlx](pbrlib/genglsl/pbrlib_genglsl_impl.mtlx) : Mapping from definitions to implementations
- GLSL implementation files.
- [ogsfx](pbrlib/genglsl/ogsfx) : OGSFX support
- OGSFX implementation files.
- [genosl](pbrlib/genosl) : OSL language support
- lib : Utilities
- [pbrlib_genosl_impl.mtlx](pbrlib/genosl/pbrlib_genosl_impl.mtlx) : Mapping from definitions to implementations
- OSL implementation files.

Note that there is no reference implementation for the PBR library.
23 changes: 21 additions & 2 deletions documents/Libraries/pbrlib/genglsl/lib/mx_bsdfs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,27 @@ float mx_microfacet_ggx_NDF(vec3 X, vec3 Y, vec3 H, float NdotH, float alphaX, f
{
float XdotH = dot(X, H);
float YdotH = dot(Y, H);
float denom = XdotH * XdotH / (alphaX * alphaX) + YdotH * YdotH / (alphaY * alphaY) + NdotH * NdotH;
return denom > 0.0 ? 1.0 / (M_PI * alphaX * alphaY * denom * denom) : 0.0;
float denom = mx_square(XdotH / alphaX) + mx_square(YdotH / alphaY) + mx_square(NdotH);
return 1.0 / (M_PI * alphaX * alphaY * mx_square(denom));
}

// https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf
// Appendix B.1 Equation 3
float mx_microfacet_ggx_PDF(vec3 X, vec3 Y, vec3 H, float NdotH, float LdotH, float alphaX, float alphaY)
{
return mx_microfacet_ggx_NDF(X, Y, H, NdotH, alphaX, alphaY) * NdotH / (4.0 * LdotH);
}

// https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf
// Appendix B.2 Equation 15
vec3 mx_microfacet_ggx_IS(vec2 Xi, vec3 X, vec3 Y, vec3 N, float alphaX, float alphaY)
{
float phi = 2.0 * M_PI * Xi.x;
float tanTheta = sqrt(Xi.y / (1.0 - Xi.y));
vec3 H = vec3(X * (tanTheta * alphaX * cos(phi)) +
Y * (tanTheta * alphaY * sin(phi)) +
N);
return normalize(H);
}

// https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf (Equation 34)
Expand Down
1 change: 1 addition & 0 deletions documents/Libraries/pbrlib/genglsl/lib/mx_defines.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define M_PI 3.1415926535897932384626433832795
#define M_PI_INV 1.0/3.1415926535897932384626433832795
#define M_GOLDEN_RATIO 1.6180339887498948482045868343656
#define M_FLOAT_EPS 0.000001
83 changes: 83 additions & 0 deletions documents/Libraries/pbrlib/genglsl/lib/mx_environment_fis.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "pbrlib/genglsl/lib/mx_bsdfs.glsl"

vec2 mx_latlong_projection(vec3 dir)
{
float latitude = -asin(dir.y) * M_PI_INV + 0.5;
latitude = clamp(latitude, 0.01, 0.99);
float longitude = atan(dir.x, -dir.z) * M_PI_INV * 0.5 + 0.5;
return vec2(longitude, latitude);
}

// https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch20.html
// Section 20.4 Equation 13
float mx_latlong_compute_lod(vec3 dir, float pdf, float maxMipLevel, int envSamples)
{
const float MIP_LEVEL_OFFSET = 1.5;
float effectiveMaxMipLevel = maxMipLevel - MIP_LEVEL_OFFSET;
float distortion = sqrt(1.0 - mx_square(dir.y));
return max(effectiveMaxMipLevel - 0.5 * log2(envSamples * pdf * distortion), 0.0);
}

vec3 mx_latlong_map_lookup(vec3 dir, mat4 transform, float lod, sampler2D sampler)
{
vec3 envDir = normalize((transform * vec4(dir,0.0)).xyz);
vec2 uv = mx_latlong_projection(envDir);
return textureLod(sampler, uv, lod).rgb;
}

// Only GGX is supported for now and the distribution argument is ignored
vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, roughnessinfo roughness, int distribution)
{
vec3 Y = normalize(cross(N, X));
X = cross(Y, N);

// Compute shared dot products.
float NdotV = clamp(dot(N, V), 1e-8, 1.0);

// Integrate outgoing radiance using filtered importance sampling.
// http://cgg.mff.cuni.cz/~jaroslav/papers/2008-egsr-fis/2008-egsr-fis-final-embedded.pdf
vec3 radiance = vec3(0.0);
for (int i = 0; i < u_envSamples; i++)
{
vec2 Xi = mx_spherical_fibonacci(i, u_envSamples);

// Compute the half vector and incoming light direction.
vec3 H = mx_microfacet_ggx_IS(Xi, X, Y, N, roughness.alphaX, roughness.alphaY);
vec3 L = -reflect(V, H);

// Compute dot products for this sample.
float NdotH = clamp(dot(N, H), 1e-8, 1.0);
float NdotL = clamp(dot(N, L), 1e-8, 1.0);
float VdotH = clamp(dot(V, H), 1e-8, 1.0);
float LdotH = VdotH;

// Sample the environment light from the given direction.
float pdf = mx_microfacet_ggx_PDF(X, Y, H, NdotH, LdotH, roughness.alphaX, roughness.alphaY);
float lod = mx_latlong_compute_lod(L, pdf, u_envRadianceMips - 1, u_envSamples);
vec3 sampleColor = mx_latlong_map_lookup(L, u_envMatrix, lod, u_envRadiance);

// Compute the geometric term.
float G = mx_microfacet_ggx_smith_G(NdotL, NdotV, roughness.alpha);

// Fresnel is applied outside the lighting integral for now.
// TODO: Move Fresnel term into the lighting integral.
float F = 1.0;

// Add the radiance contribution of this sample.
// From https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf
// incidentLight = sampleColor * NdotL
// microfacetSpecular = D * G * F / (4 * NdotL * NdotV)
// pdf = D * NdotH / (4 * VdotH)
// radiance = incidentLight * microfacetSpecular / pdf
radiance += sampleColor * G * F * VdotH / (NdotV * NdotH);
}

// Normalize and return the final radiance.
radiance /= float(u_envSamples);
return radiance;
}

vec3 mx_environment_irradiance(vec3 N)
{
return mx_latlong_map_lookup(N, u_envMatrix, 0.0, u_envIrradiance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ vec3 mx_latlong_map_lookup(vec3 dir, mat4 transform, float lodBias, sampler2D sa
return vec3(0.0);
}

vec3 mx_environment_specular(vec3 normal, vec3 view, float roughness)
vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, roughnessinfo roughness, int distribution)
{
vec3 dir = reflect(-view, normal);
return mx_latlong_map_lookup(dir, u_envMatrix, roughness, u_envSpecular);
vec3 dir = reflect(-V, N);
return mx_latlong_map_lookup(dir, u_envMatrix, roughness.alpha, u_envRadiance);
}

vec3 mx_environment_irradiance(vec3 normal)
vec3 mx_environment_irradiance(vec3 N)
{
vec3 result = mx_latlong_map_lookup(normal, u_envMatrix, u_envIrradiance);
return result;
return mx_latlong_map_lookup(N, u_envMatrix, u_envIrradiance);
}
12 changes: 12 additions & 0 deletions documents/Libraries/pbrlib/genglsl/lib/mx_math.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ bool mx_is_tiny(vec3 v)
{
return all(lessThan(abs(v), vec3(M_FLOAT_EPS)));
}

// https://www.graphics.rwth-aachen.de/publication/2/jgt.pdf
float mx_golden_ratio_sequence(int i)
{
return fract((float(i) + 1.0) * M_GOLDEN_RATIO);
}

// https://people.irisa.fr/Ricardo.Marques/articles/2013/SF_CGF.pdf
vec2 mx_spherical_fibonacci(int i, int numSamples)
{
return vec2((float(i) + 0.5) / float(numSamples), mx_golden_ratio_sequence(i));
}
18 changes: 9 additions & 9 deletions documents/Libraries/pbrlib/genglsl/mx_conductorbrdf.glsl
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#include "pbrlib/genglsl/lib/mx_bsdfs.glsl"
#include "pbrlib/genglsl/lib/mx_refractionindex.glsl"

void mx_conductorbrdf_reflection(vec3 L, vec3 V, float weight, vec3 reflectivity, vec3 edgecolor, roughnessinfo roughness, vec3 normal, vec3 tangent, int distribution, out BSDF result)
void mx_conductorbrdf_reflection(vec3 L, vec3 V, float weight, vec3 reflectivity, vec3 edgecolor, roughnessinfo roughness, vec3 N, vec3 X, int distribution, out BSDF result)
{
if (weight < M_FLOAT_EPS)
{
result = BSDF(0.0);
return;
}

float NdotL = dot(normal,L);
float NdotV = dot(normal,V);
float NdotL = dot(N,L);
float NdotV = dot(N,V);
if (NdotL <= 0.0 || NdotV <= 0.0)
{
result = BSDF(0.0);
return;
}

vec3 bitangent = normalize(cross(normal, tangent));
vec3 Y = normalize(cross(N, X));

vec3 H = normalize(L + V);
float NdotH = dot(normal, H);
float NdotH = dot(N, H);

float D = mx_microfacet_ggx_NDF(tangent, bitangent, H, NdotH, roughness.alphaX, roughness.alphaY);
float D = mx_microfacet_ggx_NDF(X, Y, H, NdotH, roughness.alphaX, roughness.alphaY);
float G = mx_microfacet_ggx_smith_G(NdotL, NdotV, roughness.alpha);

vec3 ior_n, ior_k;
Expand All @@ -36,7 +36,7 @@ void mx_conductorbrdf_reflection(vec3 L, vec3 V, float weight, vec3 reflectivity
result = F * D * G / (4 * NdotV);
}

void mx_conductorbrdf_indirect(vec3 V, float weight, vec3 reflectivity, vec3 edgecolor, roughnessinfo roughness, vec3 normal, vec3 tangent, int distribution, out vec3 result)
void mx_conductorbrdf_indirect(vec3 V, float weight, vec3 reflectivity, vec3 edgecolor, roughnessinfo roughness, vec3 N, vec3 X, int distribution, out vec3 result)
{
if (weight < M_FLOAT_EPS)
{
Expand All @@ -47,8 +47,8 @@ void mx_conductorbrdf_indirect(vec3 V, float weight, vec3 reflectivity, vec3 edg
vec3 ior_n, ior_k;
mx_artistic_to_complex_ior(reflectivity, edgecolor, ior_n, ior_k);

vec3 Li = mx_environment_specular(normal, V, roughness.alpha);
vec3 F = mx_fresnel_conductor(dot(normal, V), ior_n, ior_k);
vec3 Li = mx_environment_radiance(N, V, X, roughness, distribution);
vec3 F = mx_fresnel_conductor(dot(N, V), ior_n, ior_k);
F *= weight;
result = Li * F;
}
22 changes: 11 additions & 11 deletions documents/Libraries/pbrlib/genglsl/mx_dielectricbrdf.glsl
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#include "pbrlib/genglsl/lib/mx_bsdfs.glsl"

void mx_dielectricbrdf_reflection(vec3 L, vec3 V, float weight, vec3 tint, float ior, roughnessinfo roughness, vec3 normal, vec3 tangent, int distribution, BSDF base, out BSDF result)
void mx_dielectricbrdf_reflection(vec3 L, vec3 V, float weight, vec3 tint, float ior, roughnessinfo roughness, vec3 N, vec3 X, int distribution, BSDF base, out BSDF result)
{
if (weight < M_FLOAT_EPS)
{
result = base;
return;
}

float NdotL = dot(normal,L);
float NdotV = dot(normal,V);
float NdotL = dot(N,L);
float NdotV = dot(N,V);
if (NdotL <= 0.0 || NdotV <= 0.0)
{
result = base;
return;
}

vec3 bitangent = normalize(cross(normal, tangent));
vec3 Y = normalize(cross(N, X));

vec3 H = normalize(L + V);
float NdotH = dot(normal, H);
float NdotH = dot(N, H);

float D = mx_microfacet_ggx_NDF(tangent, bitangent, H, NdotH, roughness.alphaX, roughness.alphaY);
float D = mx_microfacet_ggx_NDF(X, Y, H, NdotH, roughness.alphaX, roughness.alphaY);
float G = mx_microfacet_ggx_smith_G(NdotL, NdotV, roughness.alpha);

float VdotH = dot(V, H);
Expand All @@ -33,7 +33,7 @@ void mx_dielectricbrdf_reflection(vec3 L, vec3 V, float weight, vec3 tint, float
+ base * (1.0 - F); // Base layer reflection attenuated by top fresnel
}

void mx_dielectricbrdf_transmission(vec3 V, float weight, vec3 tint, float ior, roughnessinfo roughness, vec3 normal, vec3 tangent, int distribution, BSDF base, out BSDF result)
void mx_dielectricbrdf_transmission(vec3 V, float weight, vec3 tint, float ior, roughnessinfo roughness, vec3 N, vec3 X, int distribution, BSDF base, out BSDF result)
{
if (weight < M_FLOAT_EPS)
{
Expand All @@ -46,24 +46,24 @@ void mx_dielectricbrdf_transmission(vec3 V, float weight, vec3 tint, float ior,
// inverse of top layer reflectance.

// Abs here to allow transparency through backfaces
float NdotV = abs(dot(normal,V));
float NdotV = abs(dot(N,V));
float F = mx_fresnel_schlick(NdotV, ior);
F *= weight;

result = base * (1.0 - F); // Base layer transmission attenuated by top fresnel
}

void mx_dielectricbrdf_indirect(vec3 V, float weight, vec3 tint, float ior, roughnessinfo roughness, vec3 normal, vec3 tangent, int distribution, BSDF base, out BSDF result)
void mx_dielectricbrdf_indirect(vec3 V, float weight, vec3 tint, float ior, roughnessinfo roughness, vec3 N, vec3 X, int distribution, BSDF base, out BSDF result)
{
if (weight < M_FLOAT_EPS)
{
result = base;
return;
}

vec3 Li = mx_environment_specular(normal, V, roughness.alpha);
vec3 Li = mx_environment_radiance(N, V, X, roughness, distribution);

float NdotV = dot(normal,V);
float NdotV = dot(N,V);
float F = mx_fresnel_schlick_roughness(NdotV, ior, roughness.alpha);
F *= weight;

Expand Down
Loading

0 comments on commit fe8ff70

Please sign in to comment.