forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'adsk_contrib/dev' into adsk_contrib/shaderx (#264)
- Loading branch information
1 parent
2db0bee
commit fe8ff70
Showing
131 changed files
with
3,043 additions
and
1,024 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
83
documents/Libraries/pbrlib/genglsl/lib/mx_environment_fis.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.