-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
130 changed files
with
16,476 additions
and
2,066 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
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,91 @@ | ||
/* | ||
Color transform functions. | ||
These funcions are modified versions of the color operators found in Open Shading Language: | ||
github.com/imageworks/OpenShadingLanguage/blob/master/src/liboslexec/opcolor.cpp | ||
It contains the subset of color operators needed to implement the MaterialX | ||
standard library. The modifications are for conversions from C++ to GLSL. | ||
Original copyright notice: | ||
------------------------------------------------------------------------ | ||
Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. | ||
All Rights Reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of Sony Pictures Imageworks nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
------------------------------------------------------------------------ | ||
*/ | ||
|
||
vec3 mx_hsvtorgb(vec3 hsv) | ||
{ | ||
// Reference for this technique: Foley & van Dam | ||
float h = hsv.x; float s = hsv.y; float v = hsv.z; | ||
if (s < 0.0001f) { | ||
return vec3 (v, v, v); | ||
} else { | ||
h = 6.0f * (h - floor(h)); // expand to [0..6) | ||
int hi = int(trunc(h)); | ||
float f = h - float(hi); | ||
float p = v * (1.0f-s); | ||
float q = v * (1.0f-s*f); | ||
float t = v * (1.0f-s*(1.0f-f)); | ||
if (hi == 0) | ||
return vec3 (v, t, p); | ||
else if (hi == 1) | ||
return vec3 (q, v, p); | ||
else if (hi == 2) | ||
return vec3 (p, v, t); | ||
else if (hi == 3) | ||
return vec3 (p, q, v); | ||
else if (hi == 4) | ||
return vec3 (t, p, v); | ||
return vec3 (v, p, q); | ||
} | ||
} | ||
|
||
|
||
vec3 mx_rgbtohsv(vec3 c) | ||
{ | ||
// See Foley & van Dam | ||
float r = c.x; float g = c.y; float b = c.z; | ||
float mincomp = min (r, min(g, b)); | ||
float maxcomp = max (r, max(g, b)); | ||
float delta = maxcomp - mincomp; // chroma | ||
float h, s, v; | ||
v = maxcomp; | ||
if (maxcomp > 0.0f) | ||
s = delta / maxcomp; | ||
else s = 0.0f; | ||
if (s <= 0.0f) | ||
h = 0.0f; | ||
else { | ||
if (r >= maxcomp) h = (g-b) / delta; | ||
else if (g >= maxcomp) h = 2.0f + (b-r) / delta; | ||
else h = 4.0f + (r-g) / delta; | ||
h *= (1.0f/6.0f); | ||
if (h < 0.0f) | ||
h += 1.0f; | ||
} | ||
return vec3(h, s, v); | ||
} |
Oops, something went wrong.