-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3990 from Autodesk/gamaj/MAYA-133932/import_expor…
…t_open_pbr MAYA-133932 - Implement OpenPBR import/export
- Loading branch information
Showing
35 changed files
with
3,244 additions
and
361 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
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
39 changes: 39 additions & 0 deletions
39
lib/mayaUsd/render/MaterialXGenOgsXml/Nodes/MayaClosureSourceCodeNode.cpp
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,39 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "MayaClosureSourceCodeNode.h" | ||
|
||
#include <MaterialXGenShader/HwShaderGenerator.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
ShaderNodeImplPtr MayaClosureSourceCodeNode::create() | ||
{ | ||
return std::make_shared<MayaClosureSourceCodeNode>(); | ||
} | ||
|
||
void MayaClosureSourceCodeNode::emitFunctionDefinition( | ||
const ShaderNode& node, | ||
GenContext& context, | ||
ShaderStage& stage) const | ||
{ | ||
// Pre-inject backported OpenPBR lighting code: | ||
if (_name == "IM_dielectric_tf_bsdf_genglsl" | ||
|| _name == "IM_generalized_schlick_tf_82_bsdf_genglsl") { | ||
static const auto allIncludes | ||
= std::array<FilePath, 2> { "pbrlib/genglsl/lib/mx39_microfacet_specular.glsl", | ||
"pbrlib/genglsl/ogsxml/mx39_lighting_maya_all.glsl" }; | ||
for (auto const& toInclude : allIncludes) { | ||
// Update source code to inject our mx39 lighting functions: | ||
FilePath libraryPrefix = context.getOptions().libraryPrefix; | ||
FilePath fullFilename = libraryPrefix.isEmpty() ? toInclude : libraryPrefix / toInclude; | ||
FilePath resolvedFilename = context.resolveSourceFile(fullFilename, FilePath()); | ||
stage.addInclude(fullFilename, resolvedFilename, context); | ||
} | ||
} | ||
return ClosureSourceCodeNode::emitFunctionDefinition(node, context, stage); | ||
} | ||
|
||
MATERIALX_NAMESPACE_END |
25 changes: 25 additions & 0 deletions
25
lib/mayaUsd/render/MaterialXGenOgsXml/Nodes/MayaClosureSourceCodeNode.h
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,25 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#ifndef MAYA_MATERIALX_CLOSURESOURCECODENODE_H | ||
#define MAYA_MATERIALX_CLOSURESOURCECODENODE_H | ||
|
||
#include <MaterialXGenShader/Nodes/ClosureSourceCodeNode.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
/// Source code node that supports the backported OpenPBR Surface node from MaterialX 1.39 | ||
class MayaClosureSourceCodeNode : public ClosureSourceCodeNode | ||
{ | ||
public: | ||
static ShaderNodeImplPtr create(); | ||
|
||
void emitFunctionDefinition(const ShaderNode& node, GenContext& context, ShaderStage& stage) | ||
const override; | ||
}; | ||
|
||
MATERIALX_NAMESPACE_END | ||
|
||
#endif |
112 changes: 112 additions & 0 deletions
112
lib/mayaUsd/render/MaterialXGenOgsXml/libraries/mx39_lighting_maya_all.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,112 @@ | ||
#ifdef MAYA_MX39_USING_ENVIRONMENT_FIS | ||
|
||
vec3 mx39_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distribution, Mx39FresnelData fd) | ||
{ | ||
if (mayaGetSpecularEnvironmentNumLOD() == 0) { | ||
return vec3(0); | ||
} | ||
|
||
// Generate tangent frame. | ||
X = normalize(X - dot(X, N) * N); | ||
vec3 Y = cross(N, X); | ||
mat3 tangentToWorld = mat3(X, Y, N); | ||
|
||
// Transform the view vector to tangent space. | ||
V = vec3(dot(V, X), dot(V, Y), dot(V, N)); | ||
|
||
// Compute derived properties. | ||
float NdotV = clamp(V.z, M_FLOAT_EPS, 1.0); | ||
float avgAlpha = mx_average_alpha(alpha); | ||
float G1V = mx_ggx_smith_G1(NdotV, avgAlpha); | ||
|
||
// 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 < MX_NUM_FIS_SAMPLES; i++) | ||
{ | ||
vec2 Xi = mx_spherical_fibonacci(i, MX_NUM_FIS_SAMPLES); | ||
|
||
// Compute the half vector and incoming light direction. | ||
vec3 H = mx_ggx_importance_sample_VNDF(Xi, V, alpha); | ||
vec3 L = fd.refraction ? mx_refraction_solid_sphere(-V, H, fd.ior.x) : -reflect(V, H); | ||
|
||
// Compute dot products for this sample. | ||
float NdotL = clamp(L.z, M_FLOAT_EPS, 1.0); | ||
float VdotH = clamp(dot(V, H), M_FLOAT_EPS, 1.0); | ||
|
||
// Sample the environment light from the given direction. | ||
vec3 Lw = tangentToWorld * L; | ||
float pdf = mx_ggx_NDF(H, alpha) * G1V / (4.0 * NdotV); | ||
float lod = mx_latlong_compute_lod_adsk(Lw, pdf, float(mayaGetSpecularEnvironmentNumLOD() - 1), MX_NUM_FIS_SAMPLES); | ||
vec3 sampleColor = mayaSampleSpecularEnvironmentAtLOD(Lw, lod); | ||
|
||
// Compute the Fresnel term. | ||
vec3 F = mx39_compute_fresnel(VdotH, fd); | ||
|
||
// Compute the geometric term. | ||
float G = mx_ggx_smith_G2(NdotL, NdotV, avgAlpha); | ||
|
||
// Compute the combined FG term, which is inverted for refraction. | ||
vec3 FG = fd.refraction ? vec3(1.0) - (F * G) : F * G; | ||
|
||
// Add the radiance contribution of this sample. | ||
// From https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf | ||
// incidentLight = sampleColor * NdotL | ||
// microfacetSpecular = D * F * G / (4 * NdotL * NdotV) | ||
// pdf = D * G1V / (4 * NdotV); | ||
// radiance = incidentLight * microfacetSpecular / pdf | ||
radiance += sampleColor * FG; | ||
} | ||
|
||
// Apply the global component of the geometric term and normalize. | ||
radiance /= G1V * float(MX_NUM_FIS_SAMPLES); | ||
|
||
// Return the final radiance. | ||
return radiance; | ||
} | ||
|
||
#endif | ||
|
||
#ifdef MAYA_MX39_USING_ENVIRONMENT_PREFILTER_V1 | ||
|
||
vec3 mx39_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distribution, Mx39FresnelData fd) | ||
{ | ||
N = mx_forward_facing_normal(N, V); | ||
vec3 L = fd.refraction ? mx_refraction_solid_sphere(-V, N, fd.ior.x) : -reflect(V, N); | ||
float NdotV = clamp(dot(N, V), M_FLOAT_EPS, 1.0); | ||
float avgAlpha = mx_average_alpha(alpha); | ||
vec3 F = mx39_compute_fresnel(NdotV, fd); | ||
float G = mx_ggx_smith_G2(NdotV, NdotV, avgAlpha); | ||
vec3 FG = fd.refraction ? vec3(1.0) - (F * G) : F * G; | ||
vec3 Li = mix(g_specularI, g_diffuseI, avgAlpha); | ||
return Li * FG; | ||
} | ||
|
||
#endif | ||
|
||
#ifdef MAYA_MX39_USING_ENVIRONMENT_PREFILTER_V2 | ||
|
||
vec3 mx39_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distribution, Mx39FresnelData fd) | ||
{ | ||
N = mx_forward_facing_normal(N, V); | ||
vec3 L = fd.refraction ? mx_refraction_solid_sphere(-V, N, fd.ior.x) : -reflect(V, N); | ||
float NdotV = clamp(dot(N, V), M_FLOAT_EPS, 1.0); | ||
float avgAlpha = mx_average_alpha(alpha); | ||
vec3 F = mx39_compute_fresnel(NdotV, fd); | ||
float G = mx_ggx_smith_G2(NdotV, NdotV, avgAlpha); | ||
vec3 FG = fd.refraction ? vec3(1.0) - (F * G) : F * G; | ||
float phongExp = mayaRoughnessToPhongExp(sqrt(avgAlpha)); | ||
vec3 Li = mayaGetSpecularEnvironment(N, V, phongExp); | ||
return Li * FG; | ||
} | ||
|
||
#endif | ||
|
||
#ifdef MAYA_MX39_USING_ENVIRONMENT_NONE | ||
|
||
vec3 mx39_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distribution, Mx39FresnelData fd) | ||
{ | ||
return vec3(0.0); | ||
} | ||
|
||
#endif |
Oops, something went wrong.