Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
58208f2
WGSL: Derive WgslShaderGenerator and similar classes from VkShaderGen…
scotbrew May 16, 2025
fabd07f
Updating .gitignore -- ignore .DSStore
scotbrew May 16, 2025
38867fd
For GLSL (WGSL flavor), use texture2D+sampler types instead of sample…
scotbrew May 22, 2025
770fcaa
Cleanup debug output.
scotbrew May 22, 2025
03eacd4
Fixing MSLShaderGenerator after refactoring mx_environment_prefilter.…
scotbrew May 22, 2025
2fae1f6
Testing: Add "genglsl_wgsl" to the list of code generators to use.
scotbrew May 22, 2025
17666a4
Merge branch 'AcademySoftwareFoundation:main' into brews/feature/wgsl
scotbrew May 22, 2025
131d322
WGSL: Refactor shader code and CompountNode shader gen
scotbrew May 23, 2025
8249985
Reverting changes to mx_microfacet
scotbrew May 23, 2025
c1a6c29
Code cleanup for WGSL. Removing unused items.
scotbrew May 23, 2025
e16dc86
Cleaning up unused variables.
scotbrew May 24, 2025
75cddf1
Add wgsl to github tests (main.yml)
scotbrew May 24, 2025
3216a40
Revising WGSL validator test to use vulkan1.3 glsl
scotbrew May 24, 2025
84c011b
WGSL: Tweaking Github tests
scotbrew May 24, 2025
c50abbb
Removing unused wgsl.glsl file.
scotbrew May 24, 2025
7592972
Streamlining out unneeded WGSL overrides.
scotbrew May 24, 2025
2885f70
Align introduced virtual function to align with naming conventions.
scotbrew May 24, 2025
a99de01
Removing unnecessary override.
scotbrew May 24, 2025
1eaa79d
Replace constructed string with static for virtual func.
scotbrew May 24, 2025
c32a2e4
Creating T_ENV_RADIANCE_TEXTURE and T_ENV_RADIANCE_SAMPLER
scotbrew May 25, 2025
06ee2ed
Adding docs and missing externs for added strings
scotbrew May 25, 2025
5622026
Merge branch 'main' into brews/feature/wgsl
scotbrew May 27, 2025
44e5a48
Add full list of WGSL Keywords and Reserved Words
scotbrew May 29, 2025
9a7c5c8
Merge branch 'main' into brews/feature/wgsl
jstone-lucasfilm Jun 4, 2025
a4a26c4
Merge branch 'main' into brews/feature/wgsl
jstone-lucasfilm Jun 6, 2025
d94732f
Remove extra newline
jstone-lucasfilm Jun 6, 2025
9971db0
Remove extra newline
jstone-lucasfilm Jun 6, 2025
e7bbffb
Minor coding style update
jstone-lucasfilm Jun 6, 2025
aac3bfc
Fix issue introduced with emitFunctionDefinitionParameter refactor
scotbrew Jun 8, 2025
cc5f77d
Merge branch 'main' into brews/feature/wgsl
scotbrew Jun 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ jobs:
python Scripts/mxdoc.py --docType html ../libraries/bxdf/standard_surface.mtlx
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target glsl
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target vulkan
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target wgsl
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target osl
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target mdl
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target msl
Expand All @@ -224,6 +225,7 @@ jobs:
python python/Scripts/generateshader.py resources/Materials/Examples --target glsl --validator C:/vcpkg/installed/x64-windows-release/tools/glslang/glslangValidator.exe
python python/Scripts/generateshader.py resources/Materials/Examples/StandardSurface --target essl --validator C:/vcpkg/installed/x64-windows-release/tools/glslang/glslangValidator.exe
python python/Scripts/generateshader.py resources/Materials/Examples/StandardSurface --target vulkan --validator C:/vcpkg/installed/x64-windows-release/tools/glslang/glslangValidator.exe
python python/Scripts/generateshader.py resources/Materials/Examples/StandardSurface --target wgsl --validator "C:/vcpkg/installed/x64-windows-release/tools/glslang/glslangValidator.exe --target-env vulkan1.3 --quiet"

- name: Shader Validation Tests (MacOS)
if: matrix.test_shaders == 'ON' && runner.os == 'macOS'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
dist
.DS_Store
2 changes: 2 additions & 0 deletions javascript/MaterialXTest/browser/shaderGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ describe('Generate Shaders', function ()
generators.push(mx.OslShaderGenerator.create());
if (typeof mx.VkShaderGenerator != 'undefined')
generators.push(mx.VkShaderGenerator.create());
if (typeof mx.WgslShaderGenerator != 'undefined')
generators.push(mx.WgslShaderGenerator.create());
if (typeof mx.MdlShaderGenerator != 'undefined')
generators.push(mx.MdlShaderGenerator.create());

Expand Down
8 changes: 8 additions & 0 deletions libraries/pbrlib/genglsl/lib/mx_environment_fis.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distributio
vec3 Lw = tangentToWorld * L;
float pdf = mx_ggx_NDF(H, alpha) * G1V / (4.0 * NdotV);
float lod = mx_latlong_compute_lod(Lw, pdf, float($envRadianceMips - 1), envRadianceSamples);
#ifdef HW_SEPARATE_SAMPLERS
vec3 sampleColor = mx_latlong_map_lookup(Lw, $envMatrix, lod, $envRadiance_texture, $envRadiance_sampler);
#else
vec3 sampleColor = mx_latlong_map_lookup(Lw, $envMatrix, lod, $envRadiance);
#endif

// Compute the Fresnel term.
vec3 F = mx_compute_fresnel(VdotH, fd);
Expand Down Expand Up @@ -64,6 +68,10 @@ vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distributio

vec3 mx_environment_irradiance(vec3 N)
{
#ifdef HW_SEPARATE_SAMPLERS
vec3 Li = mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance_texture, $envIrradiance_sampler);
Comment thread
scotbrew marked this conversation as resolved.
Comment thread
scotbrew marked this conversation as resolved.
#else
vec3 Li = mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance);
#endif
return Li * $envLightIntensity;
}
8 changes: 8 additions & 0 deletions libraries/pbrlib/genglsl/lib/mx_environment_prefilter.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distributio
float G = mx_ggx_smith_G2(NdotV, NdotV, avgAlpha);
vec3 FG = fd.refraction ? vec3(1.0) - (F * G) : F * G;

#ifdef HW_SEPARATE_SAMPLERS
vec3 Li = mx_latlong_map_lookup(L, $envMatrix, mx_latlong_alpha_to_lod(avgAlpha), $envRadiance_texture, $envRadiance_sampler);
#else
vec3 Li = mx_latlong_map_lookup(L, $envMatrix, mx_latlong_alpha_to_lod(avgAlpha), $envRadiance);
#endif
return Li * FG * $envLightIntensity;
}

vec3 mx_environment_irradiance(vec3 N)
{
#ifdef HW_SEPARATE_SAMPLERS
vec3 Li = mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance_texture, $envIrradiance_sampler);
#else
vec3 Li = mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance);
#endif
return Li * $envLightIntensity;
}
8 changes: 8 additions & 0 deletions libraries/pbrlib/genglsl/lib/mx_generate_prefilter_env.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ vec3 mx_generate_prefilter_env()
float NdotV = 1.0;

// Compute derived properties.
#ifdef HW_SEPARATE_SAMPLERS
vec2 uv = gl_FragCoord.xy * pow(2.0, $envPrefilterMip) / vec2(textureSize(sampler2D($envRadiance_texture, $envRadiance_sampler), 0));
#else
vec2 uv = gl_FragCoord.xy * pow(2.0, $envPrefilterMip) / vec2(textureSize($envRadiance, 0));
#endif
vec3 worldN = mx_latlong_map_projection_inverse(uv);
mat3 tangentToWorld = mx_orthonormal_basis(worldN);
float alpha = mx_latlong_lod_to_alpha(float($envPrefilterMip));
Expand Down Expand Up @@ -55,7 +59,11 @@ vec3 mx_generate_prefilter_env()
vec3 Lw = tangentToWorld * L;
float pdf = mx_ggx_NDF(H, vec2(alpha)) * G1V / (4.0 * NdotV);
float lod = mx_latlong_compute_lod(Lw, pdf, float($envRadianceMips - 1), envRadianceSamples);
#ifdef HW_SEPARATE_SAMPLERS
vec3 sampleColor = mx_latlong_map_lookup(Lw, $envMatrix, lod, $envRadiance_texture, $envRadiance_sampler);
#else
vec3 sampleColor = mx_latlong_map_lookup(Lw, $envMatrix, lod, $envRadiance);
#endif

// Add the radiance contribution of this sample.
radiance += G * sampleColor;
Expand Down
9 changes: 9 additions & 0 deletions libraries/pbrlib/genglsl/lib/mx_microfacet_specular.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,21 @@ vec2 mx_latlong_projection(vec3 dir)
return vec2(longitude, latitude);
}

#ifdef HW_SEPARATE_SAMPLERS
vec3 mx_latlong_map_lookup(vec3 dir, mat4 transform, float lod, texture2D env_texture, sampler env_sampler)
{
vec3 envDir = normalize((transform * vec4(dir,0.0)).xyz);
vec2 uv = mx_latlong_projection(envDir);
return textureLod(sampler2D(env_texture, env_sampler), uv, lod).rgb;
}
#else
vec3 mx_latlong_map_lookup(vec3 dir, mat4 transform, float lod, sampler2D envSampler)
{
vec3 envDir = normalize((transform * vec4(dir,0.0)).xyz);
vec2 uv = mx_latlong_projection(envDir);
return textureLod(envSampler, uv, lod).rgb;
}
#endif

// Return the mip level with the appropriate coverage for a filtered importance sample.
// https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch20.html
Expand Down
22 changes: 22 additions & 0 deletions libraries/stdlib/genglsl/mx_hextiledimage.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
// Techniques (JCGT), vol. 11, no. 2, 77-94, 2022
// http://jcgt.org/published/0011/03/05/
void mx_hextiledimage_color3(
#ifdef HW_SEPARATE_SAMPLERS
texture2D tex_texture,
sampler tex_sampler,
#else
sampler2D tex_sampler,
#endif
vec3 default_value,
vec2 tex_coord,
vec2 tiling,
Expand All @@ -25,9 +30,15 @@ void mx_hextiledimage_color3(

HextileData tile_data = mx_hextile_coord(coord, rotation, rotation_range, scale, scale_range, offset, offset_range);

#ifdef HW_SEPARATE_SAMPLERS
vec3 c1 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord1, tile_data.ddx1, tile_data.ddy1).rgb;
vec3 c2 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord2, tile_data.ddx2, tile_data.ddy2).rgb;
vec3 c3 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord3, tile_data.ddx3, tile_data.ddy3).rgb;
#else
vec3 c1 = textureGrad(tex_sampler, tile_data.coord1, tile_data.ddx1, tile_data.ddy1).rgb;
vec3 c2 = textureGrad(tex_sampler, tile_data.coord2, tile_data.ddx2, tile_data.ddy2).rgb;
vec3 c3 = textureGrad(tex_sampler, tile_data.coord3, tile_data.ddx3, tile_data.ddy3).rgb;
#endif

// luminance as weights
vec3 cw = vec3(dot(c1, lumacoeffs), dot(c2, lumacoeffs), dot(c3, lumacoeffs));
Expand All @@ -51,7 +62,12 @@ void mx_hextiledimage_color3(
}

void mx_hextiledimage_color4(
#ifdef HW_SEPARATE_SAMPLERS
texture2D tex_texture,
sampler tex_sampler,
#else
sampler2D tex_sampler,
#endif
vec4 default_value,
vec2 tex_coord,
vec2 tiling,
Expand All @@ -71,9 +87,15 @@ void mx_hextiledimage_color4(

HextileData tile_data = mx_hextile_coord(coord, rotation, rotation_range, scale, scale_range, offset, offset_range);

#ifdef HW_SEPARATE_SAMPLERS
vec4 c1 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord1, tile_data.ddx1, tile_data.ddy1);
vec4 c2 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord2, tile_data.ddx2, tile_data.ddy2);
vec4 c3 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord3, tile_data.ddx3, tile_data.ddy3);
#else
vec4 c1 = textureGrad(tex_sampler, tile_data.coord1, tile_data.ddx1, tile_data.ddy1);
vec4 c2 = textureGrad(tex_sampler, tile_data.coord2, tile_data.ddx2, tile_data.ddy2);
vec4 c3 = textureGrad(tex_sampler, tile_data.coord3, tile_data.ddx3, tile_data.ddy3);
#endif

// luminance as weights
vec3 cw = vec3(dot(c1.rgb, lumacoeffs), dot(c2.rgb, lumacoeffs), dot(c3.rgb, lumacoeffs));
Expand Down
12 changes: 12 additions & 0 deletions libraries/stdlib/genglsl/mx_hextilednormalmap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
// Techniques (JCGT), vol. 11, no. 2, 77-94, 2022
// http://jcgt.org/published/0011/03/05/
void mx_hextilednormalmap_vector3(
#ifdef HW_SEPARATE_SAMPLERS
texture2D tex_texture,
sampler tex_sampler,
#else
sampler2D tex_sampler,
#endif
vec3 default_value,
vec2 tex_coord,
vec2 tiling,
Expand All @@ -29,9 +34,16 @@ void mx_hextilednormalmap_vector3(

HextileData tile_data = mx_hextile_coord(coord, rotation, rotation_range, scale, scale_range, offset, offset_range);

#ifdef HW_SEPARATE_SAMPLERS
vec3 nm1 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord1, tile_data.ddx1, tile_data.ddy1).xyz;
Comment thread
scotbrew marked this conversation as resolved.
vec3 nm2 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord2, tile_data.ddx2, tile_data.ddy2).xyz;
vec3 nm3 = textureGrad(sampler2D(tex_texture, tex_sampler), tile_data.coord3, tile_data.ddx3, tile_data.ddy3).xyz;
#else
vec3 nm1 = textureGrad(tex_sampler, tile_data.coord1, tile_data.ddx1, tile_data.ddy1).xyz;
vec3 nm2 = textureGrad(tex_sampler, tile_data.coord2, tile_data.ddx2, tile_data.ddy2).xyz;
vec3 nm3 = textureGrad(tex_sampler, tile_data.coord3, tile_data.ddx3, tile_data.ddy3).xyz;
#endif

nm1.y = flip_g ? 1.0 - nm1.y : nm1.y;
nm2.y = flip_g ? 1.0 - nm2.y : nm2.y;
nm3.y = flip_g ? 1.0 - nm3.y : nm3.y;
Expand Down
8 changes: 8 additions & 0 deletions libraries/stdlib/genglsl/mx_image_color3.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "lib/$fileTransformUv"

#ifdef HW_SEPARATE_SAMPLERS
void mx_image_color3(texture2D tex_texture, sampler tex_sampler, int layer, vec3 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec3 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(sampler2D(tex_texture, tex_sampler), uv).rgb;
Comment thread
jstone-lucasfilm marked this conversation as resolved.
}
#else
void mx_image_color3(sampler2D tex_sampler, int layer, vec3 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec3 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(tex_sampler, uv).rgb;
}
#endif
8 changes: 8 additions & 0 deletions libraries/stdlib/genglsl/mx_image_color4.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "lib/$fileTransformUv"

#ifdef HW_SEPARATE_SAMPLERS
void mx_image_color4(texture2D tex_texture, sampler tex_sampler, int layer, vec4 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec4 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(sampler2D(tex_texture, tex_sampler), uv);
}
#else
void mx_image_color4(sampler2D tex_sampler, int layer, vec4 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec4 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(tex_sampler, uv);
}
#endif
8 changes: 8 additions & 0 deletions libraries/stdlib/genglsl/mx_image_float.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "lib/$fileTransformUv"

#ifdef HW_SEPARATE_SAMPLERS
void mx_image_float(texture2D tex_texture, sampler tex_sampler, int layer, float defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out float result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(sampler2D(tex_texture, tex_sampler), uv).r;
}
#else
void mx_image_float(sampler2D tex_sampler, int layer, float defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out float result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(tex_sampler, uv).r;
}
#endif
8 changes: 8 additions & 0 deletions libraries/stdlib/genglsl/mx_image_vector2.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "lib/$fileTransformUv"

#ifdef HW_SEPARATE_SAMPLERS
void mx_image_vector2(texture2D tex_texture, sampler tex_sampler, int layer, vec2 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec2 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(sampler2D(tex_texture, tex_sampler), uv).rg;
}
#else
void mx_image_vector2(sampler2D tex_sampler, int layer, vec2 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec2 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(tex_sampler, uv).rg;
}
#endif
8 changes: 8 additions & 0 deletions libraries/stdlib/genglsl/mx_image_vector3.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "lib/$fileTransformUv"

#ifdef HW_SEPARATE_SAMPLERS
void mx_image_vector3(texture2D tex_texture, sampler tex_sampler, int layer, vec3 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec3 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(sampler2D(tex_texture, tex_sampler), uv).rgb;
}
#else
void mx_image_vector3(sampler2D tex_sampler, int layer, vec3 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec3 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(tex_sampler, uv).rgb;
}
#endif
8 changes: 8 additions & 0 deletions libraries/stdlib/genglsl/mx_image_vector4.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "lib/$fileTransformUv"

#ifdef HW_SEPARATE_SAMPLERS
void mx_image_vector4(texture2D tex_texture, sampler tex_sampler, int layer, vec4 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec4 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(sampler2D(tex_texture, tex_sampler), uv);
}
#else
void mx_image_vector4(sampler2D tex_sampler, int layer, vec4 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec4 result)
{
vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
result = texture(tex_sampler, uv);
}
#endif
6 changes: 4 additions & 2 deletions python/Scripts/generateshader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main():
parser = argparse.ArgumentParser(description='Generate shader code for each renderable element in a MaterialX document or folder.')
parser.add_argument('--path', dest='paths', action='append', nargs='+', help='An additional absolute search path location (e.g. "/projects/MaterialX")')
parser.add_argument('--library', dest='libraries', action='append', nargs='+', help='An additional relative path to a custom data library folder (e.g. "libraries/custom")')
parser.add_argument('--target', dest='target', default='glsl', help='Target shader generator to use (e.g. "glsl, osl, mdl, essl, vulkan"). Default is glsl.')
parser.add_argument('--target', dest='target', default='glsl', help='Target shader generator to use (e.g. "glsl, osl, mdl, essl, vulkan, wgsl"). Default is glsl.')
parser.add_argument('--outputPath', dest='outputPath', help='File path to output shaders to. If not specified, is the location of the input document is used.')
parser.add_argument('--validator', dest='validator', nargs='?', const=' ', type=str, help='Name of executable to perform source code validation.')
parser.add_argument('--validatorArgs', dest='validatorArgs', nargs='?', const=' ', type=str, help='Optional arguments for code validator.')
Expand Down Expand Up @@ -98,6 +98,8 @@ def main():
shadergen = mx_gen_glsl.EsslShaderGenerator.create()
elif gentarget == 'vulkan':
shadergen = mx_gen_glsl.VkShaderGenerator.create()
elif gentarget == 'wgsl':
shadergen = mx_gen_glsl.WgslShaderGenerator.create()
elif gentarget == 'msl':
shadergen = mx_gen_msl.MslShaderGenerator.create()
else:
Expand Down Expand Up @@ -153,7 +155,7 @@ def main():
if shader:
# Use extension of .vert and .frag as it's type is
# recognized by glslangValidator
if gentarget in ['glsl', 'essl', 'vulkan', 'msl']:
if gentarget in ['glsl', 'essl', 'vulkan', 'msl', 'wgsl']:
pixelSource = shader.getSourceCode(mx_gen_shader.PIXEL_STAGE)
filename = pathPrefix + "/" + shader.getName() + "." + gentarget + ".frag"
print('--- Wrote pixel shader to: ' + filename)
Expand Down
6 changes: 4 additions & 2 deletions source/JsMaterialX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(GENGLSL ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenGlsl/)
set(GENMSL ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenMsl/)
set(GENVK ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenVk/)
set(GENMDL ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenMdl/)
set(GENWGSL ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenWgsl/)

set(SOURCE_FOLDER ${PROJECT_SOURCE_DIR}/source)

Expand Down Expand Up @@ -47,6 +48,7 @@ set(GENOSL_DEPS ${GENOSL}JsOslShaderGenerator.cpp)
set(GENGLSL_DEPS ${GENGLSL}JsGlslShaderGenerator.cpp)
set(GENMSL_DEPS ${GENMSL}JsMslShaderGenerator.cpp)
set(GENVK_DEPS ${GENVK}JsVkShaderGenerator.cpp)
set(GENWGSL_DEPS ${GENWGSL}JsWgslShaderGenerator.cpp)
set(GENMDL_DEPS ${GENMDL}JsMdlShaderGenerator.cpp)

# Linker flags
Expand Down Expand Up @@ -98,8 +100,8 @@ add_executable(JsMaterialXGenShader MaterialXLib.cpp
${GENESSL_DEPS})

if (MATERIALX_BUILD_GEN_GLSL)
message("JS: Building JsMaterialXGenShader with GLSL, VK support")
target_sources(JsMaterialXGenShader PRIVATE ${GENGLSL_DEPS} ${GENVK_DEPS})
message("JS: Building JsMaterialXGenShader with GLSL, VK, WGSL support")
target_sources(JsMaterialXGenShader PRIVATE ${GENGLSL_DEPS} ${GENVK_DEPS} ${GENWGSL_DEPS})
endif()
if (MATERIALX_BUILD_GEN_OSL)
message("JS: Building JsMaterialXGenShader with OSL support")
Expand Down
27 changes: 27 additions & 0 deletions source/JsMaterialX/JsMaterialXGenWgsl/JsWgslShaderGenerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright Contributors to the MaterialX Project
// SPDX-License-Identifier: Apache-2.0
//

#include <MaterialXGenGlsl/WgslShaderGenerator.h>
#include <MaterialXGenShader/Util.h>

#include <emscripten/bind.h>

namespace ems = emscripten;
namespace mx = MaterialX;

namespace
{
// Creator wrapper to avoid having to expose the TypeSystem class in JavaScript
mx::ShaderGeneratorPtr WgslShaderGenerator_create()
{
return mx::WgslShaderGenerator::create();
}
}

EMSCRIPTEN_BINDINGS(WgslShaderGenerator)
{
ems::class_<mx::WgslShaderGenerator, ems::base<mx::GlslShaderGenerator>>("WgslShaderGenerator")
.class_function("create", &WgslShaderGenerator_create);
}
2 changes: 1 addition & 1 deletion source/MaterialXGenGlsl/Nodes/LightSamplerNodeGlsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void LightSamplerNodeGlsl::emitFunctionDefinition(const ShaderNode& node, GenCon
string ifstatement = "if ";
for (const auto& it : lightShaders->get())
{
shadergen.emitLine(ifstatement + "(light.type == " + std::to_string(it.first) + ")", stage, false);
shadergen.emitLine(ifstatement + "(light." + shadergen.getLightDataTypevarString() + " == " + std::to_string(it.first) + ")", stage, false);
shadergen.emitScopeBegin(stage);
shadergen.emitFunctionCall(*it.second, context, stage);
shadergen.emitScopeEnd(stage);
Expand Down
Loading