-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Metal Shader Generation and Rendering Support (#1258)
- Adds Metal Support to MaterialXShaderGen Backend - Adds Metal Support to MaterialX Rendering code for testing generated shaders - Adds Metal Support to MaterialXView Rendering Support (switchable between Metal and OpenGL, default is Metal)
- Loading branch information
Showing
162 changed files
with
14,759 additions
and
1,876 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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<materialx version="1.37"> | ||
|
||
<!-- <point_light> --> | ||
<implementation name="IM_point_light_genmsl" nodedef="ND_point_light" file="mx_point_light.metal" function="mx_point_light" target="genmsl"/> | ||
|
||
<!-- <directional_light> --> | ||
<implementation name="IM_directional_light_genmsl" nodedef="ND_directional_light" file="mx_directional_light.metal" function="mx_directional_light" target="genmsl"/> | ||
|
||
<!-- <spot_light> --> | ||
<implementation name="IM_spot_light_genmsl" nodedef="ND_spot_light" file="mx_spot_light.metal" function="mx_spot_light" target="genmsl"/> | ||
|
||
</materialx> |
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 @@ | ||
void mx_directional_light(LightData light, float3 position, thread lightshader& result) | ||
{ | ||
result.direction = -light.direction; | ||
result.intensity = light.color * light.intensity; | ||
} |
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,8 @@ | ||
void mx_point_light(LightData light, float3 position, thread lightshader& result) | ||
{ | ||
result.direction = light.position - position; | ||
float distance = length(result.direction) + M_FLOAT_EPS; | ||
float attenuation = pow(distance + 1.0, light.decay_rate + M_FLOAT_EPS); | ||
result.intensity = light.color * light.intensity / attenuation; | ||
result.direction /= distance; | ||
} |
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,13 @@ | ||
void mx_spot_light(LightData light, float3 position, thread lightshader& result) | ||
{ | ||
result.direction = light.position - position; | ||
float distance = length(result.direction) + M_FLOAT_EPS; | ||
float attenuation = pow(distance + 1.0, light.decay_rate + M_FLOAT_EPS); | ||
result.intensity = light.color * light.intensity / attenuation; | ||
result.direction /= distance; | ||
float low = min(light.inner_angle, light.outer_angle); | ||
float high = light.inner_angle; | ||
float cosDir = dot(result.direction, -light.direction); | ||
float spotAttenuation = smoothstep(low, high, cosDir); | ||
result.intensity *= spotAttenuation; | ||
} |
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,74 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
|
||
<!-- <oren_nayar_diffuse_bsdf> --> | ||
<implementation name="IM_oren_nayar_diffuse_bsdf_genmsl" nodedef="ND_oren_nayar_diffuse_bsdf" file="../genglsl/mx_oren_nayar_diffuse_bsdf.glsl" function="mx_oren_nayar_diffuse_bsdf" target="genmsl" /> | ||
|
||
<!-- <burley_diffuse_bsdf> --> | ||
<implementation name="IM_burley_diffuse_bsdf_genmsl" nodedef="ND_burley_diffuse_bsdf" file="../genglsl/mx_burley_diffuse_bsdf.glsl" function="mx_burley_diffuse_bsdf" target="genmsl" /> | ||
|
||
<!-- <translucent_bsdf> --> | ||
<implementation name="IM_translucent_bsdf_genmsl" nodedef="ND_translucent_bsdf" file="../genglsl/mx_translucent_bsdf.glsl" function="mx_translucent_bsdf" target="genmsl" /> | ||
|
||
<!-- <dielectric_bsdf> --> | ||
<implementation name="IM_dielectric_bsdf_genmsl" nodedef="ND_dielectric_bsdf" file="../genglsl/mx_dielectric_bsdf.glsl" function="mx_dielectric_bsdf" target="genmsl" /> | ||
|
||
<!-- <conductor_bsdf> --> | ||
<implementation name="IM_conductor_bsdf_genmsl" nodedef="ND_conductor_bsdf" file="../genglsl/mx_conductor_bsdf.glsl" function="mx_conductor_bsdf" target="genmsl" /> | ||
|
||
<!-- <generalized_schlick_bsdf> --> | ||
<implementation name="IM_generalized_schlick_bsdf_genmsl" nodedef="ND_generalized_schlick_bsdf" file="../genglsl/mx_generalized_schlick_bsdf.glsl" function="mx_generalized_schlick_bsdf" target="genmsl" /> | ||
|
||
<!-- <subsurface_bsdf> --> | ||
<implementation name="IM_subsurface_bsdf_genmsl" nodedef="ND_subsurface_bsdf" file="../genglsl/mx_subsurface_bsdf.glsl" function="mx_subsurface_bsdf" target="genmsl" /> | ||
|
||
<!-- <sheen_bsdf> --> | ||
<implementation name="IM_sheen_bsdf_genmsl" nodedef="ND_sheen_bsdf" file="../genglsl/mx_sheen_bsdf.glsl" function="mx_sheen_bsdf" target="genmsl" /> | ||
|
||
<!-- <anisotropic_vdf> --> | ||
<implementation name="IM_anisotropic_vdf_genmsl" nodedef="ND_anisotropic_vdf" file="../genglsl/mx_anisotropic_vdf.glsl" function="mx_anisotropic_vdf" target="genmsl" /> | ||
|
||
<!-- <thin_film_bsdf> --> | ||
<implementation name="IM_thin_film_bsdf_genmsl" nodedef="ND_thin_film_bsdf" target="genmsl" /> | ||
|
||
<!-- <layer> --> | ||
<implementation name="IM_layer_bsdf_genmsl" nodedef="ND_layer_bsdf" target="genmsl" /> | ||
<implementation name="IM_layer_vdf_genmsl" nodedef="ND_layer_vdf" target="genmsl" /> | ||
|
||
<!-- <mix> --> | ||
<implementation name="IM_mix_bsdf_genmsl" nodedef="ND_mix_bsdf" target="genmsl" /> | ||
<implementation name="IM_mix_edf_genmsl" nodedef="ND_mix_edf" target="genmsl" /> | ||
|
||
<!-- <add> --> | ||
<implementation name="IM_add_bsdf_genmsl" nodedef="ND_add_bsdf" target="genmsl" /> | ||
<implementation name="IM_add_edf_genmsl" nodedef="ND_add_edf" target="genmsl" /> | ||
|
||
<!-- <multiply> --> | ||
<implementation name="IM_multiply_bsdfC_genmsl" nodedef="ND_multiply_bsdfC" target="genmsl" /> | ||
<implementation name="IM_multiply_bsdfF_genmsl" nodedef="ND_multiply_bsdfF" target="genmsl" /> | ||
<implementation name="IM_multiply_edfC_genmsl" nodedef="ND_multiply_edfC" target="genmsl" /> | ||
<implementation name="IM_multiply_edfF_genmsl" nodedef="ND_multiply_edfF" target="genmsl" /> | ||
|
||
<!-- <uniform_edf> --> | ||
<implementation name="IM_uniform_edf_genmsl" nodedef="ND_uniform_edf" file="../genglsl/mx_uniform_edf.glsl" function="mx_uniform_edf" target="genmsl" /> | ||
|
||
<!-- <surface> --> | ||
<implementation name="IM_surface_genmsl" nodedef="ND_surface" target="genmsl" /> | ||
|
||
<!-- <displacement> --> | ||
<implementation name="IM_displacement_float_genmsl" nodedef="ND_displacement_float" file="../genglsl/mx_displacement_float.glsl" function="mx_displacement_float" target="genmsl" /> | ||
<implementation name="IM_displacement_vector3_genmsl" nodedef="ND_displacement_vector3" file="../genglsl/mx_displacement_vector3.glsl" function="mx_displacement_vector3" target="genmsl" /> | ||
|
||
<!-- <light> --> | ||
<implementation name="IM_light_genmsl" nodedef="ND_light" target="genmsl" /> | ||
|
||
<!-- <roughness_anisotropy> --> | ||
<implementation name="IM_roughness_anisotropy_genmsl" nodedef="ND_roughness_anisotropy" file="../genglsl/mx_roughness_anisotropy.glsl" function="mx_roughness_anisotropy" target="genmsl" /> | ||
|
||
<!-- <roughness_dual> --> | ||
<implementation name="IM_roughness_dual_genmsl" nodedef="ND_roughness_dual" file="../genglsl/mx_roughness_dual.glsl" function="mx_roughness_dual" target="genmsl" /> | ||
|
||
<!-- <artistic_ior> --> | ||
<implementation name="IM_artistic_ior_genmsl" nodedef="ND_artistic_ior" file="../genglsl/mx_artistic_ior.glsl" function="mx_artistic_ior" target="genmsl" /> | ||
|
||
</materialx> |
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,107 @@ | ||
#define M_FLOAT_EPS 1e-8 | ||
|
||
float mx_square(float x) | ||
{ | ||
return x*x; | ||
} | ||
|
||
vec2 mx_square(vec2 x) | ||
{ | ||
return x*x; | ||
} | ||
|
||
vec3 mx_square(vec3 x) | ||
{ | ||
return x*x; | ||
} | ||
|
||
#ifdef __DECL_GL_MATH_FUNCTIONS__ | ||
|
||
float radians(float degree) { return (degree * M_PI_F / 180.0f); } | ||
|
||
float3x3 inverse(float3x3 m) | ||
{ | ||
float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0]; | ||
float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1]; | ||
float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2]; | ||
|
||
float det = determinant(m); | ||
float idet = 1.0f / det; | ||
|
||
float3x3 ret; | ||
|
||
ret[0][0] = idet * (n22 * n33 - n32 * n23); | ||
ret[1][0] = idet * (n32 * n13 - n12 * n33); | ||
ret[2][0] = idet * (n12 * n23 - n22 * n13); | ||
|
||
ret[0][1] = idet * (n31 * n23 - n21 * n33); | ||
ret[1][1] = idet * (n11 * n33 - n31 * n13); | ||
ret[2][1] = idet * (n21 * n13 - n11 * n23); | ||
|
||
ret[0][2] = idet * (n21 * n32 - n31 * n22); | ||
ret[1][2] = idet * (n31 * n12 - n11 * n32); | ||
ret[2][2] = idet * (n11 * n22 - n21 * n12); | ||
|
||
return ret; | ||
} | ||
|
||
float4x4 inverse(float4x4 m) | ||
{ | ||
float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0]; | ||
float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1]; | ||
float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2]; | ||
float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3]; | ||
|
||
float t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44; | ||
float t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44; | ||
float t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44; | ||
float t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; | ||
|
||
float det = determinant(m); | ||
float idet = 1.0f / det; | ||
|
||
float4x4 ret; | ||
|
||
ret[0][0] = t11 * idet; | ||
ret[0][1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * idet; | ||
ret[0][2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * idet; | ||
ret[0][3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * idet; | ||
|
||
ret[1][0] = t12 * idet; | ||
ret[1][1] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * idet; | ||
ret[1][2] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * idet; | ||
ret[1][3] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * idet; | ||
|
||
ret[2][0] = t13 * idet; | ||
ret[2][1] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * idet; | ||
ret[2][2] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * idet; | ||
ret[2][3] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * idet; | ||
|
||
ret[3][0] = t14 * idet; | ||
ret[3][1] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * idet; | ||
ret[3][2] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * idet; | ||
ret[3][3] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * idet; | ||
|
||
return ret; | ||
} | ||
|
||
template<class T1, class T2> | ||
T1 mod(T1 x, T2 y) | ||
{ | ||
return x - y * floor(x/y); | ||
} | ||
|
||
template <typename T> | ||
T atan(T y_over_x) { return ::atan(y_over_x); } | ||
|
||
template <typename T> | ||
T atan(T y, T x) { return ::atan2(y, x); } | ||
|
||
#define lessThan(a, b) ((a) < (b)) | ||
#define lessThanEqual(a, b) ((a) <= (b)) | ||
#define greaterThan(a, b) ((a) > (b)) | ||
#define greaterThanEqual(a, b) ((a) >= (b)) | ||
#define equal(a, b) ((a) == (b)) | ||
#define notEqual(a, b) ((a) != (b)) | ||
|
||
#endif |
Oops, something went wrong.