diff --git a/CMakeLists.txt b/CMakeLists.txt index 63ae3ab53c..c5baeb1fab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -450,6 +450,10 @@ add_subdirectory(source/MaterialXFormat) # Add shader generation subdirectories add_subdirectory(source/MaterialXGenShader) if(MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_OSL OR MATERIALX_BUILD_GEN_MDL OR MATERIALX_BUILD_GEN_MSL) + if(MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_MSL) + add_subdirectory(source/MaterialXGenHw) + endif() + if (MATERIALX_BUILD_GEN_GLSL) add_definitions(-DMATERIALX_BUILD_GEN_GLSL) add_subdirectory(source/MaterialXGenGlsl) diff --git a/source/JsMaterialX/CMakeLists.txt b/source/JsMaterialX/CMakeLists.txt index aaadafda74..22fa4f201c 100644 --- a/source/JsMaterialX/CMakeLists.txt +++ b/source/JsMaterialX/CMakeLists.txt @@ -141,6 +141,7 @@ target_link_libraries(JsMaterialXGenShader PUBLIC MaterialXCore PUBLIC MaterialXFormat PUBLIC MaterialXGenShader + PUBLIC MaterialXGenHw PUBLIC MaterialXGenGlsl PRIVATE ${CMAKE_DL_LIBS}) diff --git a/source/JsMaterialX/JsMaterialXGenShader/JsHwShaderGenerator.cpp b/source/JsMaterialX/JsMaterialXGenShader/JsHwShaderGenerator.cpp index 900dcfc006..744a4dddbd 100644 --- a/source/JsMaterialX/JsMaterialXGenShader/JsHwShaderGenerator.cpp +++ b/source/JsMaterialX/JsMaterialXGenShader/JsHwShaderGenerator.cpp @@ -3,7 +3,8 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include diff --git a/source/MaterialXGenGlsl/CMakeLists.txt b/source/MaterialXGenGlsl/CMakeLists.txt index 37e3a44252..8a9e4acdeb 100644 --- a/source/MaterialXGenGlsl/CMakeLists.txt +++ b/source/MaterialXGenGlsl/CMakeLists.txt @@ -7,7 +7,7 @@ mx_add_library(MaterialXGenGlsl HEADER_FILES ${materialx_headers} MTLX_MODULES - MaterialXGenShader + MaterialXGenHw MaterialXCore EXPORT_DEFINE MATERIALX_GENGLSL_EXPORTS) diff --git a/source/MaterialXGenGlsl/EsslShaderGenerator.cpp b/source/MaterialXGenGlsl/EsslShaderGenerator.cpp index cb9939be8b..61b886bc70 100644 --- a/source/MaterialXGenGlsl/EsslShaderGenerator.cpp +++ b/source/MaterialXGenGlsl/EsslShaderGenerator.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenGlsl/GlslResourceBindingContext.cpp b/source/MaterialXGenGlsl/GlslResourceBindingContext.cpp index e0870d860e..dd3bfecd1d 100644 --- a/source/MaterialXGenGlsl/GlslResourceBindingContext.cpp +++ b/source/MaterialXGenGlsl/GlslResourceBindingContext.cpp @@ -5,6 +5,8 @@ #include +#include + MATERIALX_NAMESPACE_BEGIN // diff --git a/source/MaterialXGenGlsl/GlslResourceBindingContext.h b/source/MaterialXGenGlsl/GlslResourceBindingContext.h index f6d5548795..cbaf5e1333 100644 --- a/source/MaterialXGenGlsl/GlslResourceBindingContext.h +++ b/source/MaterialXGenGlsl/GlslResourceBindingContext.h @@ -11,7 +11,7 @@ #include -#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp index 96cf05b983..56255978fe 100644 --- a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp +++ b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp @@ -7,25 +7,27 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenGlsl/GlslShaderGenerator.h b/source/MaterialXGenGlsl/GlslShaderGenerator.h index bf082ce34e..6bc3859d20 100644 --- a/source/MaterialXGenGlsl/GlslShaderGenerator.h +++ b/source/MaterialXGenGlsl/GlslShaderGenerator.h @@ -11,7 +11,8 @@ #include -#include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenGlsl/GlslSyntax.cpp b/source/MaterialXGenGlsl/GlslSyntax.cpp index bd24e54793..939dad6ba9 100644 --- a/source/MaterialXGenGlsl/GlslSyntax.cpp +++ b/source/MaterialXGenGlsl/GlslSyntax.cpp @@ -6,7 +6,6 @@ #include #include -#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenGlsl/VkResourceBindingContext.cpp b/source/MaterialXGenGlsl/VkResourceBindingContext.cpp index 7b5ca79c77..692334f120 100644 --- a/source/MaterialXGenGlsl/VkResourceBindingContext.cpp +++ b/source/MaterialXGenGlsl/VkResourceBindingContext.cpp @@ -5,6 +5,8 @@ #include +#include + MATERIALX_NAMESPACE_BEGIN // diff --git a/source/MaterialXGenGlsl/VkResourceBindingContext.h b/source/MaterialXGenGlsl/VkResourceBindingContext.h index feb4f770a4..62c0bca16f 100644 --- a/source/MaterialXGenGlsl/VkResourceBindingContext.h +++ b/source/MaterialXGenGlsl/VkResourceBindingContext.h @@ -11,7 +11,7 @@ #include -#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenGlsl/VkShaderGenerator.cpp b/source/MaterialXGenGlsl/VkShaderGenerator.cpp index 1112ca1edc..22ff1f85c2 100644 --- a/source/MaterialXGenGlsl/VkShaderGenerator.cpp +++ b/source/MaterialXGenGlsl/VkShaderGenerator.cpp @@ -5,6 +5,7 @@ #include #include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenGlsl/WgslResourceBindingContext.cpp b/source/MaterialXGenGlsl/WgslResourceBindingContext.cpp index 7fd674590f..7b84cb420f 100644 --- a/source/MaterialXGenGlsl/WgslResourceBindingContext.cpp +++ b/source/MaterialXGenGlsl/WgslResourceBindingContext.cpp @@ -5,6 +5,8 @@ #include +#include + MATERIALX_NAMESPACE_BEGIN // diff --git a/source/MaterialXGenGlsl/WgslShaderGenerator.cpp b/source/MaterialXGenGlsl/WgslShaderGenerator.cpp index 8cff8e178a..d39a2498f4 100644 --- a/source/MaterialXGenGlsl/WgslShaderGenerator.cpp +++ b/source/MaterialXGenGlsl/WgslShaderGenerator.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenHw/CMakeLists.txt b/source/MaterialXGenHw/CMakeLists.txt new file mode 100644 index 0000000000..7a8c13a333 --- /dev/null +++ b/source/MaterialXGenHw/CMakeLists.txt @@ -0,0 +1,12 @@ +file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") +file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*") + +mx_add_library(MaterialXGenHw + SOURCE_FILES + ${materialx_source} + HEADER_FILES + ${materialx_headers} + MTLX_MODULES + MaterialXGenShader + EXPORT_DEFINE + MATERIALX_GENHW_EXPORTS) diff --git a/source/MaterialXGenHw/Export.h b/source/MaterialXGenHw/Export.h new file mode 100644 index 0000000000..cd5a8134c0 --- /dev/null +++ b/source/MaterialXGenHw/Export.h @@ -0,0 +1,22 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef MATERIALX_GENHW_EXPORT_H +#define MATERIALX_GENHW_EXPORT_H + +#include + +/// @file +/// Macros for declaring imported and exported symbols. + +#if defined(MATERIALX_GENHW_EXPORTS) + #define MX_GENHW_API MATERIALX_SYMBOL_EXPORT + #define MX_GENHW_EXTERN_TEMPLATE(...) MATERIALX_EXPORT_EXTERN_TEMPLATE(__VA_ARGS__) +#else + #define MX_GENHW_API MATERIALX_SYMBOL_IMPORT + #define MX_GENHW_EXTERN_TEMPLATE(...) MATERIALX_IMPORT_EXTERN_TEMPLATE(__VA_ARGS__) +#endif + +#endif diff --git a/source/MaterialXGenHw/HwConstants.cpp b/source/MaterialXGenHw/HwConstants.cpp new file mode 100644 index 0000000000..b3a62e4230 --- /dev/null +++ b/source/MaterialXGenHw/HwConstants.cpp @@ -0,0 +1,168 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include + +MATERIALX_NAMESPACE_BEGIN + +namespace HW +{ + +const string T_IN_POSITION = "$inPosition"; +const string T_IN_NORMAL = "$inNormal"; +const string T_IN_TANGENT = "$inTangent"; +const string T_IN_BITANGENT = "$inBitangent"; +const string T_IN_TEXCOORD = "$inTexcoord"; +const string T_IN_GEOMPROP = "$inGeomprop"; +const string T_IN_COLOR = "$inColor"; +const string T_POSITION_WORLD = "$positionWorld"; +const string T_NORMAL_WORLD = "$normalWorld"; +const string T_TANGENT_WORLD = "$tangentWorld"; +const string T_BITANGENT_WORLD = "$bitangentWorld"; +const string T_POSITION_OBJECT = "$positionObject"; +const string T_NORMAL_OBJECT = "$normalObject"; +const string T_TANGENT_OBJECT = "$tangentObject"; +const string T_BITANGENT_OBJECT = "$bitangentObject"; +const string T_TEXCOORD = "$texcoord"; +const string T_COLOR = "$color"; +const string T_WORLD_MATRIX = "$worldMatrix"; +const string T_WORLD_INVERSE_MATRIX = "$worldInverseMatrix"; +const string T_WORLD_TRANSPOSE_MATRIX = "$worldTransposeMatrix"; +const string T_WORLD_INVERSE_TRANSPOSE_MATRIX = "$worldInverseTransposeMatrix"; +const string T_VIEW_MATRIX = "$viewMatrix"; +const string T_VIEW_INVERSE_MATRIX = "$viewInverseMatrix"; +const string T_VIEW_TRANSPOSE_MATRIX = "$viewTransposeMatrix"; +const string T_VIEW_INVERSE_TRANSPOSE_MATRIX = "$viewInverseTransposeMatrix"; +const string T_PROJ_MATRIX = "$projectionMatrix"; +const string T_PROJ_INVERSE_MATRIX = "$projectionInverseMatrix"; +const string T_PROJ_TRANSPOSE_MATRIX = "$projectionTransposeMatrix"; +const string T_PROJ_INVERSE_TRANSPOSE_MATRIX = "$projectionInverseTransposeMatrix"; +const string T_WORLD_VIEW_MATRIX = "$worldViewMatrix"; +const string T_VIEW_PROJECTION_MATRIX = "$viewProjectionMatrix"; +const string T_WORLD_VIEW_PROJECTION_MATRIX = "$worldViewProjectionMatrix"; +const string T_VIEW_POSITION = "$viewPosition"; +const string T_VIEW_DIRECTION = "$viewDirection"; +const string T_FRAME = "$frame"; +const string T_TIME = "$time"; +const string T_GEOMPROP = "$geomprop"; +const string T_ALPHA_THRESHOLD = "$alphaThreshold"; +const string T_NUM_ACTIVE_LIGHT_SOURCES = "$numActiveLightSources"; +const string T_ENV_MATRIX = "$envMatrix"; +const string T_ENV_RADIANCE = "$envRadiance"; +const string T_ENV_RADIANCE_SAMPLER2D = "$envRadianceSampler2D"; +const string T_ENV_RADIANCE_MIPS = "$envRadianceMips"; +const string T_ENV_RADIANCE_SAMPLES = "$envRadianceSamples"; +const string T_ENV_IRRADIANCE = "$envIrradiance"; +const string T_ENV_IRRADIANCE_SAMPLER2D = "$envIrradianceSampler2D"; +const string T_TEX_SAMPLER_SAMPLER2D = "$texSamplerSampler2D"; +const string T_TEX_SAMPLER_SIGNATURE = "$texSamplerSignature"; +const string T_CLOSURE_DATA_CONSTRUCTOR = "$closureDataConstructor"; + +const string T_ENV_LIGHT_INTENSITY = "$envLightIntensity"; +const string T_ENV_PREFILTER_MIP = "$envPrefilterMip"; +const string T_REFRACTION_TWO_SIDED = "$refractionTwoSided"; +const string T_ALBEDO_TABLE = "$albedoTable"; +const string T_ALBEDO_TABLE_SIZE = "$albedoTableSize"; +const string T_AMB_OCC_MAP = "$ambOccMap"; +const string T_AMB_OCC_GAIN = "$ambOccGain"; +const string T_SHADOW_MAP = "$shadowMap"; +const string T_SHADOW_MATRIX = "$shadowMatrix"; +const string T_VERTEX_DATA_INSTANCE = "$vd"; +const string T_LIGHT_DATA_INSTANCE = "$lightData"; + +const string IN_POSITION = "i_position"; +const string IN_NORMAL = "i_normal"; +const string IN_TANGENT = "i_tangent"; +const string IN_BITANGENT = "i_bitangent"; +const string IN_TEXCOORD = "i_texcoord"; +const string IN_GEOMPROP = "i_geomprop"; +const string IN_COLOR = "i_color"; +const string POSITION_WORLD = "positionWorld"; +const string NORMAL_WORLD = "normalWorld"; +const string TANGENT_WORLD = "tangentWorld"; +const string BITANGENT_WORLD = "bitangentWorld"; +const string POSITION_OBJECT = "positionObject"; +const string NORMAL_OBJECT = "normalObject"; +const string TANGENT_OBJECT = "tangentObject"; +const string BITANGENT_OBJECT = "bitangentObject"; +const string TEXCOORD = "texcoord"; +const string COLOR = "color"; +const string WORLD_MATRIX = "u_worldMatrix"; +const string WORLD_INVERSE_MATRIX = "u_worldInverseMatrix"; +const string WORLD_TRANSPOSE_MATRIX = "u_worldTransposeMatrix"; +const string WORLD_INVERSE_TRANSPOSE_MATRIX = "u_worldInverseTransposeMatrix"; +const string VIEW_MATRIX = "u_viewMatrix"; +const string VIEW_INVERSE_MATRIX = "u_viewInverseMatrix"; +const string VIEW_TRANSPOSE_MATRIX = "u_viewTransposeMatrix"; +const string VIEW_INVERSE_TRANSPOSE_MATRIX = "u_viewInverseTransposeMatrix"; +const string PROJ_MATRIX = "u_projectionMatrix"; +const string PROJ_INVERSE_MATRIX = "u_projectionInverseMatrix"; +const string PROJ_TRANSPOSE_MATRIX = "u_projectionTransposeMatrix"; +const string PROJ_INVERSE_TRANSPOSE_MATRIX = "u_projectionInverseTransposeMatrix"; +const string WORLD_VIEW_MATRIX = "u_worldViewMatrix"; +const string VIEW_PROJECTION_MATRIX = "u_viewProjectionMatrix"; +const string WORLD_VIEW_PROJECTION_MATRIX = "u_worldViewProjectionMatrix"; +const string VIEW_POSITION = "u_viewPosition"; +const string VIEW_DIRECTION = "u_viewDirection"; +const string FRAME = "u_frame"; +const string TIME = "u_time"; +const string GEOMPROP = "u_geomprop"; +const string ALPHA_THRESHOLD = "u_alphaThreshold"; +const string NUM_ACTIVE_LIGHT_SOURCES = "u_numActiveLightSources"; +const string ENV_MATRIX = "u_envMatrix"; +const string ENV_RADIANCE = "u_envRadiance"; +const string ENV_RADIANCE_SPLIT = "u_envRadiance_texture, u_envRadiance_sampler"; +const string ENV_RADIANCE_SAMPLER2D = "u_envRadiance"; +const string ENV_RADIANCE_SAMPLER2D_SPLIT = "sampler2D(u_envRadiance_texture, u_envRadiance_sampler)"; +const string ENV_RADIANCE_MIPS = "u_envRadianceMips"; +const string ENV_RADIANCE_SAMPLES = "u_envRadianceSamples"; +const string ENV_IRRADIANCE = "u_envIrradiance"; +const string ENV_IRRADIANCE_SPLIT = "u_envIrradiance_texture, u_envIrradiance_sampler"; +const string ENV_IRRADIANCE_SAMPLER2D = "u_envIrradiance"; +const string ENV_IRRADIANCE_SAMPLER2D_SPLIT = "sampler2D(u_envIradiance_texture, u_envIrradiance_sampler)"; + +const string TEX_SAMPLER_SAMPLER2D = "tex_sampler"; +const string TEX_SAMPLER_SAMPLER2D_SPLIT = "sampler2D(tex_texture, tex_sampler)"; +const string TEX_SAMPLER_SIGNATURE = "sampler2D tex_sampler"; +const string TEX_SAMPLER_SIGNATURE_SPLIT = "texture2D tex_texture, sampler tex_sampler"; + +const string ENV_LIGHT_INTENSITY = "u_envLightIntensity"; +const string ENV_PREFILTER_MIP = "u_envPrefilterMip"; +const string REFRACTION_TWO_SIDED = "u_refractionTwoSided"; +const string ALBEDO_TABLE = "u_albedoTable"; +const string ALBEDO_TABLE_SIZE = "u_albedoTableSize"; +const string AMB_OCC_MAP = "u_ambOccMap"; +const string AMB_OCC_GAIN = "u_ambOccGain"; +const string SHADOW_MAP = "u_shadowMap"; +const string SHADOW_MATRIX = "u_shadowMatrix"; +const string VERTEX_DATA_INSTANCE = "vd"; +const string LIGHT_DATA_INSTANCE = "u_lightData"; +const string LIGHT_DATA_MAX_LIGHT_SOURCES = "MAX_LIGHT_SOURCES"; + +const string VERTEX_INPUTS = "VertexInputs"; +const string VERTEX_DATA = "VertexData"; +const string PRIVATE_UNIFORMS = "PrivateUniforms"; +const string PUBLIC_UNIFORMS = "PublicUniforms"; +const string LIGHT_DATA = "LightData"; +const string PIXEL_OUTPUTS = "PixelOutputs"; +const string DIR_N = "N"; +const string CLOSURE_DATA_TYPE = "ClosureData"; +const string CLOSURE_DATA_ARG = "closureData"; +const string DIR_L = "L"; +const string DIR_V = "V"; +const string WORLD_POSITION = "P"; +const string OCCLUSION = "occlusion"; +const string CLOSURE_DATA_CONSTRUCTOR = "ClosureData(closureType, L, V, N, P, occlusion)"; +const string ATTR_TRANSPARENT = "transparent"; +const string USER_DATA_CLOSURE_CONTEXT = "udcc"; +const string USER_DATA_LIGHT_SHADERS = "udls"; +const string USER_DATA_BINDING_CONTEXT = "udbinding"; + +const TypeDesc ClosureDataType = TypeDesc("ClosureData", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_NONE, 1, 0); +} // namespace HW + + +MATERIALX_NAMESPACE_END diff --git a/source/MaterialXGenHw/HwConstants.h b/source/MaterialXGenHw/HwConstants.h new file mode 100644 index 0000000000..0a01083958 --- /dev/null +++ b/source/MaterialXGenHw/HwConstants.h @@ -0,0 +1,252 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef MATERIALX_HWCONSTANTS_H +#define MATERIALX_HWCONSTANTS_H + +/// @file +/// Hardware shader generator constants + +#include + +MATERIALX_NAMESPACE_BEGIN + +/* +The HW shader generators have a number of predefined variables (inputs and uniforms) with binding rules. +When these are used by a shader the application must bind them to the expected data. The following table is +a listing of the variables with a description of what data they should be bound to. + +However, different renderers can have different requirements on naming conventions for these variables. +In order to facilitate this the generators will use token substitution for naming the variables. The +first column below shows the token names that should be used in source code before the token substitution +is done. The second row shows the real identifier names that will be used by default after substitution. +An generator can override these identifier names in order to use a custom naming convention for these. +Overriding identifier names is done by changing the entries in the identifiers map given to the function +replaceIdentifiers(), which is handling the token substitution on a shader stage. + +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + TOKEN NAME DEFAULT IDENTIFIER NAME TYPE BINDING +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +Vertex input variables : + $inPosition i_position vec3 Vertex position in object space + $inNormal i_normal vec3 Vertex normal in object space + $inTangent i_tangent vec3 Vertex tangent in object space + $inBitangent i_bitangent vec3 Vertex bitangent in object space + $inTexcoord_N i_texcoord_N vec2 Vertex texture coordinate for the N:th uv set + $inColor_N i_color_N vec4 Vertex color for the N:th color set (RGBA) + +Uniform variables : + $worldMatrix u_worldMatrix mat4 World transformation + $worldInverseMatrix u_worldInverseMatrix mat4 World transformation, inverted + $worldTransposeMatrix u_worldTransposeMatrix mat4 World transformation, transposed + $worldInverseTransposeMatrix u_worldInverseTransposeMatrix mat4 World transformation, inverted and transposed + $viewMatrix u_viewMatrix mat4 View transformation + $viewInverseMatrix u_viewInverseMatrix mat4 View transformation, inverted + $viewTransposeMatrix u_viewTransposeMatrix mat4 View transformation, transposed + $viewInverseTransposeMatrix u_viewInverseTransposeMatrix mat4 View transformation, inverted and transposed + $projectionMatrix u_projectionMatrix mat4 Projection transformation + $projectionInverseMatrix u_projectionInverseMatrix mat4 Projection transformation, inverted + $projectionTransposeMatrix u_projectionTransposeMatrix mat4 Projection transformation, transposed + $projectionInverseTransposeMatrix u_projectionInverseTransposeMatrix mat4 Projection transformation, inverted and transposed + $worldViewMatrix u_worldViewMatrix mat4 World-view transformation + $viewProjectionMatrix u_viewProjectionMatrix mat4 View-projection transformation + $worldViewProjectionMatrix u_worldViewProjectionMatrix mat4 World-view-projection transformation + $viewPosition u_viewPosition vec3 World-space position of the view (camera) + $viewDirection u_viewDirection vec3 World-space direction of the view (camera) + $frame u_frame float The current frame number as defined by the host application + $time u_time float The current time in seconds + $geomprop_ u_geomprop_ A named property of given where is the name of the variable on the geometry + $numActiveLightSources u_numActiveLightSources int The number of currently active light sources. Note that in shader this is clamped against + the maximum allowed number of lights sources. The maximum number is set by the generation + option GenOptions.hwMaxActiveLightSources. + $lightData[] u_lightData[] struct Array of struct LightData holding parameters for active light sources. + The LightData struct is built dynamically depending on requirements for + bound light shaders. + $envMatrix u_envMatrix mat4 Rotation matrix for the environment. + $envIrradiance u_envIrradiance sampler2D Sampler for the texture used for diffuse environment lighting. + $envIrradianceSampler2D u_envIrradiance sampler2D For split texture and sampler, takes form of sampler2D(tex, sampler) + $envRadiance u_envRadiance sampler2D Sampler for the texture used for specular environment lighting. + $envRadianceSampler2D u_envRadiance sampler2D For split texture and sampler, takes form of sampler2D(tex, sampler) + $envLightIntensity u_envLightIntensity float Linear multiplier for environment lighting + $envRadianceMips u_envRadianceMips int Number of mipmaps used on the specular environment texture. + $envRadianceSamples u_envRadianceSamples int Samples to use if Filtered Importance Sampling is used for specular environment lighting. + $texSamplerSampler2D tex_sampler sampler2D Texture sampler2D parameter. For split texture and sampler, calls sampler2D(tex_texture, tex_sampler). + $texSamplerSignature sampler2D tex_sampler signature For function signature declaration. + +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +*/ + +/// HW specific identifiers. +namespace HW +{ +/// Token identifiers +extern MX_GENHW_API const string T_IN_POSITION; +extern MX_GENHW_API const string T_IN_NORMAL; +extern MX_GENHW_API const string T_IN_TANGENT; +extern MX_GENHW_API const string T_IN_BITANGENT; +extern MX_GENHW_API const string T_IN_TEXCOORD; +extern MX_GENHW_API const string T_IN_GEOMPROP; +extern MX_GENHW_API const string T_IN_COLOR; +extern MX_GENHW_API const string T_POSITION_WORLD; +extern MX_GENHW_API const string T_NORMAL_WORLD; +extern MX_GENHW_API const string T_TANGENT_WORLD; +extern MX_GENHW_API const string T_BITANGENT_WORLD; +extern MX_GENHW_API const string T_POSITION_OBJECT; +extern MX_GENHW_API const string T_NORMAL_OBJECT; +extern MX_GENHW_API const string T_TANGENT_OBJECT; +extern MX_GENHW_API const string T_BITANGENT_OBJECT; +extern MX_GENHW_API const string T_TEXCOORD; +extern MX_GENHW_API const string T_COLOR; +extern MX_GENHW_API const string T_WORLD_MATRIX; +extern MX_GENHW_API const string T_WORLD_INVERSE_MATRIX; +extern MX_GENHW_API const string T_WORLD_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string T_WORLD_INVERSE_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string T_VIEW_MATRIX; +extern MX_GENHW_API const string T_VIEW_INVERSE_MATRIX; +extern MX_GENHW_API const string T_VIEW_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string T_VIEW_INVERSE_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string T_PROJ_MATRIX; +extern MX_GENHW_API const string T_PROJ_INVERSE_MATRIX; +extern MX_GENHW_API const string T_PROJ_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string T_PROJ_INVERSE_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string T_WORLD_VIEW_MATRIX; +extern MX_GENHW_API const string T_VIEW_PROJECTION_MATRIX; +extern MX_GENHW_API const string T_WORLD_VIEW_PROJECTION_MATRIX; +extern MX_GENHW_API const string T_VIEW_POSITION; +extern MX_GENHW_API const string T_VIEW_DIRECTION; +extern MX_GENHW_API const string T_FRAME; +extern MX_GENHW_API const string T_TIME; +extern MX_GENHW_API const string T_GEOMPROP; +extern MX_GENHW_API const string T_ALPHA_THRESHOLD; +extern MX_GENHW_API const string T_NUM_ACTIVE_LIGHT_SOURCES; +extern MX_GENHW_API const string T_ENV_MATRIX; +extern MX_GENHW_API const string T_ENV_RADIANCE; +extern MX_GENHW_API const string T_ENV_RADIANCE_SAMPLER2D; +extern MX_GENHW_API const string T_ENV_RADIANCE_MIPS; +extern MX_GENHW_API const string T_ENV_RADIANCE_SAMPLES; +extern MX_GENHW_API const string T_ENV_IRRADIANCE; +extern MX_GENHW_API const string T_ENV_IRRADIANCE_SAMPLER2D; +extern MX_GENHW_API const string T_ENV_LIGHT_INTENSITY; +extern MX_GENHW_API const string T_ENV_PREFILTER_MIP; +extern MX_GENHW_API const string T_REFRACTION_TWO_SIDED; +extern MX_GENHW_API const string T_ALBEDO_TABLE; +extern MX_GENHW_API const string T_ALBEDO_TABLE_SIZE; +extern MX_GENHW_API const string T_AMB_OCC_MAP; +extern MX_GENHW_API const string T_AMB_OCC_GAIN; +extern MX_GENHW_API const string T_SHADOW_MAP; +extern MX_GENHW_API const string T_SHADOW_MATRIX; +extern MX_GENHW_API const string T_VERTEX_DATA_INSTANCE; +extern MX_GENHW_API const string T_LIGHT_DATA_INSTANCE; +extern MX_GENHW_API const string T_TEX_SAMPLER_SAMPLER2D; +extern MX_GENHW_API const string T_TEX_SAMPLER_SIGNATURE; +extern MX_GENHW_API const string T_CLOSURE_DATA_CONSTRUCTOR; + +/// Default names for identifiers. +/// Replacing above tokens in final code. +extern MX_GENHW_API const string IN_POSITION; +extern MX_GENHW_API const string IN_NORMAL; +extern MX_GENHW_API const string IN_TANGENT; +extern MX_GENHW_API const string IN_BITANGENT; +extern MX_GENHW_API const string IN_TEXCOORD; +extern MX_GENHW_API const string IN_GEOMPROP; +extern MX_GENHW_API const string IN_COLOR; +extern MX_GENHW_API const string POSITION_WORLD; +extern MX_GENHW_API const string NORMAL_WORLD; +extern MX_GENHW_API const string TANGENT_WORLD; +extern MX_GENHW_API const string BITANGENT_WORLD; +extern MX_GENHW_API const string POSITION_OBJECT; +extern MX_GENHW_API const string NORMAL_OBJECT; +extern MX_GENHW_API const string TANGENT_OBJECT; +extern MX_GENHW_API const string BITANGENT_OBJECT; +extern MX_GENHW_API const string TEXCOORD; +extern MX_GENHW_API const string COLOR; +extern MX_GENHW_API const string WORLD_MATRIX; +extern MX_GENHW_API const string WORLD_INVERSE_MATRIX; +extern MX_GENHW_API const string WORLD_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string WORLD_INVERSE_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string VIEW_MATRIX; +extern MX_GENHW_API const string VIEW_INVERSE_MATRIX; +extern MX_GENHW_API const string VIEW_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string VIEW_INVERSE_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string PROJ_MATRIX; +extern MX_GENHW_API const string PROJ_INVERSE_MATRIX; +extern MX_GENHW_API const string PROJ_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string PROJ_INVERSE_TRANSPOSE_MATRIX; +extern MX_GENHW_API const string WORLD_VIEW_MATRIX; +extern MX_GENHW_API const string VIEW_PROJECTION_MATRIX; +extern MX_GENHW_API const string WORLD_VIEW_PROJECTION_MATRIX; +extern MX_GENHW_API const string VIEW_POSITION; +extern MX_GENHW_API const string VIEW_DIRECTION; +extern MX_GENHW_API const string FRAME; +extern MX_GENHW_API const string TIME; +extern MX_GENHW_API const string GEOMPROP; +extern MX_GENHW_API const string ALPHA_THRESHOLD; +extern MX_GENHW_API const string NUM_ACTIVE_LIGHT_SOURCES; +extern MX_GENHW_API const string ENV_MATRIX; +extern MX_GENHW_API const string ENV_RADIANCE; +extern MX_GENHW_API const string ENV_RADIANCE_SPLIT; +extern MX_GENHW_API const string ENV_RADIANCE_SAMPLER2D; +extern MX_GENHW_API const string ENV_RADIANCE_SAMPLER2D_SPLIT; +extern MX_GENHW_API const string ENV_RADIANCE_MIPS; +extern MX_GENHW_API const string ENV_RADIANCE_SAMPLES; +extern MX_GENHW_API const string ENV_IRRADIANCE; +extern MX_GENHW_API const string ENV_IRRADIANCE_SPLIT; +extern MX_GENHW_API const string ENV_IRRADIANCE_SAMPLER2D; +extern MX_GENHW_API const string ENV_IRRADIANCE_SAMPLER2D_SPLIT; +extern MX_GENHW_API const string ENV_LIGHT_INTENSITY; +extern MX_GENHW_API const string ENV_PREFILTER_MIP; +extern MX_GENHW_API const string REFRACTION_TWO_SIDED; +extern MX_GENHW_API const string ALBEDO_TABLE; +extern MX_GENHW_API const string ALBEDO_TABLE_SIZE; +extern MX_GENHW_API const string AMB_OCC_MAP; +extern MX_GENHW_API const string AMB_OCC_GAIN; +extern MX_GENHW_API const string SHADOW_MAP; +extern MX_GENHW_API const string SHADOW_MATRIX; +extern MX_GENHW_API const string VERTEX_DATA_INSTANCE; +extern MX_GENHW_API const string LIGHT_DATA_INSTANCE; +extern MX_GENHW_API const string LIGHT_DATA_MAX_LIGHT_SOURCES; + +/// Texture sampler parameters (for both combined and separate values) +extern MX_GENHW_API const string TEX_SAMPLER_SAMPLER2D; +extern MX_GENHW_API const string TEX_SAMPLER_SAMPLER2D_SPLIT; +extern MX_GENHW_API const string TEX_SAMPLER_SIGNATURE; +extern MX_GENHW_API const string TEX_SAMPLER_SIGNATURE_SPLIT; + +/// Variable blocks names. +extern MX_GENHW_API const string VERTEX_INPUTS; // Geometric inputs for vertex stage. +extern MX_GENHW_API const string VERTEX_DATA; // Connector block for data transfer from vertex stage to pixel stage. +extern MX_GENHW_API const string PRIVATE_UNIFORMS; // Uniform inputs set privately by application. +extern MX_GENHW_API const string PUBLIC_UNIFORMS; // Uniform inputs visible in UI and set by user. +extern MX_GENHW_API const string LIGHT_DATA; // Uniform inputs for light sources. +extern MX_GENHW_API const string PIXEL_OUTPUTS; // Outputs from the main/pixel stage. + +/// Variable names for lighting parameters. +extern MX_GENHW_API const string CLOSURE_DATA_TYPE; +extern MX_GENHW_API const string CLOSURE_DATA_ARG; +extern MX_GENHW_API const string DIR_N; +extern MX_GENHW_API const string DIR_L; +extern MX_GENHW_API const string DIR_V; +extern MX_GENHW_API const string WORLD_POSITION; +extern MX_GENHW_API const string OCCLUSION; + +/// Syntax for constructing ClosureData +extern MX_GENHW_API const string CLOSURE_DATA_CONSTRUCTOR; + +/// Attribute names. +extern MX_GENHW_API const string ATTR_TRANSPARENT; + +/// User data names. +extern MX_GENHW_API const string USER_DATA_LIGHT_SHADERS; +extern MX_GENHW_API const string USER_DATA_BINDING_CONTEXT; + +/// Type Descriptor for closure context data. +extern MX_GENHW_API const TypeDesc ClosureDataType; +} // namespace HW + +MATERIALX_NAMESPACE_END + +#endif diff --git a/source/MaterialXGenHw/HwImplementation.cpp b/source/MaterialXGenHw/HwImplementation.cpp new file mode 100644 index 0000000000..b7502ca370 --- /dev/null +++ b/source/MaterialXGenHw/HwImplementation.cpp @@ -0,0 +1,34 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include + +MATERIALX_NAMESPACE_BEGIN + +const string HwImplementation::SPACE = "space"; +const string HwImplementation::INDEX = "index"; +const string HwImplementation::GEOMPROP = "geomprop"; + +namespace +{ + +// When node inputs with these names are modified, we assume the +// associated HW shader must be recompiled. +const StringSet IMMUTABLE_INPUTS = +{ + "index", + "space", + "attrname" +}; + +} // anonymous namespace + +bool HwImplementation::isEditable(const ShaderInput& input) const +{ + return IMMUTABLE_INPUTS.count(input.getName()) == 0; +} + +MATERIALX_NAMESPACE_END diff --git a/source/MaterialXGenHw/HwImplementation.h b/source/MaterialXGenHw/HwImplementation.h new file mode 100644 index 0000000000..66c20f7c18 --- /dev/null +++ b/source/MaterialXGenHw/HwImplementation.h @@ -0,0 +1,45 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef MATERIALX_HWIMPLEMENTATION_H +#define MATERIALX_HWIMPLEMENTATION_H + +/// @file +/// Hardware shader node implementation base class + +#include + +#include + +MATERIALX_NAMESPACE_BEGIN + +/// @class HwImplementation +/// Base class for HW node implementations. +class MX_GENHW_API HwImplementation : public ShaderNodeImpl +{ + public: + bool isEditable(const ShaderInput& input) const override; + + protected: + HwImplementation() { } + + // Integer identifiers for coordinate spaces. + // The order must match the order given for the space enum string in stdlib. + enum Space + { + MODEL_SPACE = 0, + OBJECT_SPACE = 1, + WORLD_SPACE = 2 + }; + + /// Internal string constants + static const string SPACE; + static const string INDEX; + static const string GEOMPROP; +}; + +MATERIALX_NAMESPACE_END + +#endif diff --git a/source/MaterialXGenHw/HwLightShaders.h b/source/MaterialXGenHw/HwLightShaders.h new file mode 100644 index 0000000000..1c7cfef154 --- /dev/null +++ b/source/MaterialXGenHw/HwLightShaders.h @@ -0,0 +1,72 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef MATERIALX_HWLIGHTSHADERS_H +#define MATERIALX_HWLIGHTSHADERS_H + +/// @file +/// Hardware shader generator lights + +#include + +#include +#include + +MATERIALX_NAMESPACE_BEGIN + +class HwLightShaders; +/// Shared pointer to a HwLightShaders +using HwLightShadersPtr = shared_ptr; + +/// @class HwLightShaders +/// Hardware light shader user data +class MX_GENHW_API HwLightShaders : public GenUserData +{ + public: + /// Create and return a new instance. + static HwLightShadersPtr create() + { + return std::make_shared(); + } + + /// Bind a light shader to a light type id. + void bind(unsigned int type, ShaderNodePtr shader) + { + _shaders[type] = shader; + } + + /// Unbind a light shader previously bound to a light type id. + void unbind(unsigned int type) + { + _shaders.erase(type); + } + + /// Clear all light shaders previously bound. + void clear() + { + _shaders.clear(); + } + + /// Return the light shader bound to the given light type, + /// or nullptr if not light shader is bound to this type. + const ShaderNode* get(unsigned int type) const + { + auto it = _shaders.find(type); + return it != _shaders.end() ? it->second.get() : nullptr; + } + + /// Return the map of bound light shaders. + const std::unordered_map& get() const + { + return _shaders; + } + + protected: + std::unordered_map _shaders; +}; + +MATERIALX_NAMESPACE_END + +#endif diff --git a/source/MaterialXGenHw/HwResourceBindingContext.h b/source/MaterialXGenHw/HwResourceBindingContext.h new file mode 100644 index 0000000000..635448bd4e --- /dev/null +++ b/source/MaterialXGenHw/HwResourceBindingContext.h @@ -0,0 +1,49 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef MATERIALX_HWRESOURCEBINDINGCONTEXT_H +#define MATERIALX_HWRESOURCEBINDINGCONTEXT_H + +/// @file +/// Hardware resource bindings context base class + +#include + +#include +#include + +MATERIALX_NAMESPACE_BEGIN + +class VariableBlock; + +class HwResourceBindingContext; +/// Shared pointer to a HwResourceBindingContext +using HwResourceBindingContextPtr = shared_ptr; + +/// @class HwResourceBindingContext +/// Class representing a context for resource binding for hardware resources. +class MX_GENHW_API HwResourceBindingContext : public GenUserData +{ + public: + virtual ~HwResourceBindingContext() { } + + // Initialize the context before generation starts. + virtual void initialize() = 0; + + // Emit directives required for binding support + virtual void emitDirectives(GenContext& context, ShaderStage& stage) = 0; + + // Emit uniforms with binding information + virtual void emitResourceBindings(GenContext& context, const VariableBlock& uniforms, ShaderStage& stage) = 0; + + // Emit struct uniforms with binding information + virtual void emitStructuredResourceBindings(GenContext& context, const VariableBlock& uniforms, + ShaderStage& stage, const std::string& structInstanceName, + const std::string& arraySuffix = EMPTY_STRING) = 0; +}; + +MATERIALX_NAMESPACE_END + +#endif diff --git a/source/MaterialXGenShader/HwShaderGenerator.cpp b/source/MaterialXGenHw/HwShaderGenerator.cpp similarity index 63% rename from source/MaterialXGenShader/HwShaderGenerator.cpp rename to source/MaterialXGenHw/HwShaderGenerator.cpp index 5a881866ae..9e4fed0870 100644 --- a/source/MaterialXGenShader/HwShaderGenerator.cpp +++ b/source/MaterialXGenHw/HwShaderGenerator.cpp @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include +#include + #include #include @@ -12,187 +15,6 @@ MATERIALX_NAMESPACE_BEGIN -const string HwImplementation::SPACE = "space"; -const string HwImplementation::INDEX = "index"; -const string HwImplementation::GEOMPROP = "geomprop"; - -namespace -{ - -// When node inputs with these names are modified, we assume the -// associated HW shader must be recompiled. -const StringSet IMMUTABLE_INPUTS = -{ - "index", - "space", - "attrname" -}; - -} // anonymous namespace - -namespace HW -{ - -const string T_IN_POSITION = "$inPosition"; -const string T_IN_NORMAL = "$inNormal"; -const string T_IN_TANGENT = "$inTangent"; -const string T_IN_BITANGENT = "$inBitangent"; -const string T_IN_TEXCOORD = "$inTexcoord"; -const string T_IN_GEOMPROP = "$inGeomprop"; -const string T_IN_COLOR = "$inColor"; -const string T_POSITION_WORLD = "$positionWorld"; -const string T_NORMAL_WORLD = "$normalWorld"; -const string T_TANGENT_WORLD = "$tangentWorld"; -const string T_BITANGENT_WORLD = "$bitangentWorld"; -const string T_POSITION_OBJECT = "$positionObject"; -const string T_NORMAL_OBJECT = "$normalObject"; -const string T_TANGENT_OBJECT = "$tangentObject"; -const string T_BITANGENT_OBJECT = "$bitangentObject"; -const string T_TEXCOORD = "$texcoord"; -const string T_COLOR = "$color"; -const string T_WORLD_MATRIX = "$worldMatrix"; -const string T_WORLD_INVERSE_MATRIX = "$worldInverseMatrix"; -const string T_WORLD_TRANSPOSE_MATRIX = "$worldTransposeMatrix"; -const string T_WORLD_INVERSE_TRANSPOSE_MATRIX = "$worldInverseTransposeMatrix"; -const string T_VIEW_MATRIX = "$viewMatrix"; -const string T_VIEW_INVERSE_MATRIX = "$viewInverseMatrix"; -const string T_VIEW_TRANSPOSE_MATRIX = "$viewTransposeMatrix"; -const string T_VIEW_INVERSE_TRANSPOSE_MATRIX = "$viewInverseTransposeMatrix"; -const string T_PROJ_MATRIX = "$projectionMatrix"; -const string T_PROJ_INVERSE_MATRIX = "$projectionInverseMatrix"; -const string T_PROJ_TRANSPOSE_MATRIX = "$projectionTransposeMatrix"; -const string T_PROJ_INVERSE_TRANSPOSE_MATRIX = "$projectionInverseTransposeMatrix"; -const string T_WORLD_VIEW_MATRIX = "$worldViewMatrix"; -const string T_VIEW_PROJECTION_MATRIX = "$viewProjectionMatrix"; -const string T_WORLD_VIEW_PROJECTION_MATRIX = "$worldViewProjectionMatrix"; -const string T_VIEW_POSITION = "$viewPosition"; -const string T_VIEW_DIRECTION = "$viewDirection"; -const string T_FRAME = "$frame"; -const string T_TIME = "$time"; -const string T_GEOMPROP = "$geomprop"; -const string T_ALPHA_THRESHOLD = "$alphaThreshold"; -const string T_NUM_ACTIVE_LIGHT_SOURCES = "$numActiveLightSources"; -const string T_ENV_MATRIX = "$envMatrix"; -const string T_ENV_RADIANCE = "$envRadiance"; -const string T_ENV_RADIANCE_SAMPLER2D = "$envRadianceSampler2D"; -const string T_ENV_RADIANCE_MIPS = "$envRadianceMips"; -const string T_ENV_RADIANCE_SAMPLES = "$envRadianceSamples"; -const string T_ENV_IRRADIANCE = "$envIrradiance"; -const string T_ENV_IRRADIANCE_SAMPLER2D = "$envIrradianceSampler2D"; -const string T_TEX_SAMPLER_SAMPLER2D = "$texSamplerSampler2D"; -const string T_TEX_SAMPLER_SIGNATURE = "$texSamplerSignature"; -const string T_CLOSURE_DATA_CONSTRUCTOR = "$closureDataConstructor"; - -const string T_ENV_LIGHT_INTENSITY = "$envLightIntensity"; -const string T_ENV_PREFILTER_MIP = "$envPrefilterMip"; -const string T_REFRACTION_TWO_SIDED = "$refractionTwoSided"; -const string T_ALBEDO_TABLE = "$albedoTable"; -const string T_ALBEDO_TABLE_SIZE = "$albedoTableSize"; -const string T_AMB_OCC_MAP = "$ambOccMap"; -const string T_AMB_OCC_GAIN = "$ambOccGain"; -const string T_SHADOW_MAP = "$shadowMap"; -const string T_SHADOW_MATRIX = "$shadowMatrix"; -const string T_VERTEX_DATA_INSTANCE = "$vd"; -const string T_LIGHT_DATA_INSTANCE = "$lightData"; - -const string IN_POSITION = "i_position"; -const string IN_NORMAL = "i_normal"; -const string IN_TANGENT = "i_tangent"; -const string IN_BITANGENT = "i_bitangent"; -const string IN_TEXCOORD = "i_texcoord"; -const string IN_GEOMPROP = "i_geomprop"; -const string IN_COLOR = "i_color"; -const string POSITION_WORLD = "positionWorld"; -const string NORMAL_WORLD = "normalWorld"; -const string TANGENT_WORLD = "tangentWorld"; -const string BITANGENT_WORLD = "bitangentWorld"; -const string POSITION_OBJECT = "positionObject"; -const string NORMAL_OBJECT = "normalObject"; -const string TANGENT_OBJECT = "tangentObject"; -const string BITANGENT_OBJECT = "bitangentObject"; -const string TEXCOORD = "texcoord"; -const string COLOR = "color"; -const string WORLD_MATRIX = "u_worldMatrix"; -const string WORLD_INVERSE_MATRIX = "u_worldInverseMatrix"; -const string WORLD_TRANSPOSE_MATRIX = "u_worldTransposeMatrix"; -const string WORLD_INVERSE_TRANSPOSE_MATRIX = "u_worldInverseTransposeMatrix"; -const string VIEW_MATRIX = "u_viewMatrix"; -const string VIEW_INVERSE_MATRIX = "u_viewInverseMatrix"; -const string VIEW_TRANSPOSE_MATRIX = "u_viewTransposeMatrix"; -const string VIEW_INVERSE_TRANSPOSE_MATRIX = "u_viewInverseTransposeMatrix"; -const string PROJ_MATRIX = "u_projectionMatrix"; -const string PROJ_INVERSE_MATRIX = "u_projectionInverseMatrix"; -const string PROJ_TRANSPOSE_MATRIX = "u_projectionTransposeMatrix"; -const string PROJ_INVERSE_TRANSPOSE_MATRIX = "u_projectionInverseTransposeMatrix"; -const string WORLD_VIEW_MATRIX = "u_worldViewMatrix"; -const string VIEW_PROJECTION_MATRIX = "u_viewProjectionMatrix"; -const string WORLD_VIEW_PROJECTION_MATRIX = "u_worldViewProjectionMatrix"; -const string VIEW_POSITION = "u_viewPosition"; -const string VIEW_DIRECTION = "u_viewDirection"; -const string FRAME = "u_frame"; -const string TIME = "u_time"; -const string GEOMPROP = "u_geomprop"; -const string ALPHA_THRESHOLD = "u_alphaThreshold"; -const string NUM_ACTIVE_LIGHT_SOURCES = "u_numActiveLightSources"; -const string ENV_MATRIX = "u_envMatrix"; -const string ENV_RADIANCE = "u_envRadiance"; -const string ENV_RADIANCE_SPLIT = "u_envRadiance_texture, u_envRadiance_sampler"; -const string ENV_RADIANCE_SAMPLER2D = "u_envRadiance"; -const string ENV_RADIANCE_SAMPLER2D_SPLIT = "sampler2D(u_envRadiance_texture, u_envRadiance_sampler)"; -const string ENV_RADIANCE_MIPS = "u_envRadianceMips"; -const string ENV_RADIANCE_SAMPLES = "u_envRadianceSamples"; -const string ENV_IRRADIANCE = "u_envIrradiance"; -const string ENV_IRRADIANCE_SPLIT = "u_envIrradiance_texture, u_envIrradiance_sampler"; -const string ENV_IRRADIANCE_SAMPLER2D = "u_envIrradiance"; -const string ENV_IRRADIANCE_SAMPLER2D_SPLIT = "sampler2D(u_envIradiance_texture, u_envIrradiance_sampler)"; - -const string TEX_SAMPLER_SAMPLER2D = "tex_sampler"; -const string TEX_SAMPLER_SAMPLER2D_SPLIT = "sampler2D(tex_texture, tex_sampler)"; -const string TEX_SAMPLER_SIGNATURE = "sampler2D tex_sampler"; -const string TEX_SAMPLER_SIGNATURE_SPLIT = "texture2D tex_texture, sampler tex_sampler"; - -const string ENV_LIGHT_INTENSITY = "u_envLightIntensity"; -const string ENV_PREFILTER_MIP = "u_envPrefilterMip"; -const string REFRACTION_TWO_SIDED = "u_refractionTwoSided"; -const string ALBEDO_TABLE = "u_albedoTable"; -const string ALBEDO_TABLE_SIZE = "u_albedoTableSize"; -const string AMB_OCC_MAP = "u_ambOccMap"; -const string AMB_OCC_GAIN = "u_ambOccGain"; -const string SHADOW_MAP = "u_shadowMap"; -const string SHADOW_MATRIX = "u_shadowMatrix"; -const string VERTEX_DATA_INSTANCE = "vd"; -const string LIGHT_DATA_INSTANCE = "u_lightData"; -const string LIGHT_DATA_MAX_LIGHT_SOURCES = "MAX_LIGHT_SOURCES"; - -const string VERTEX_INPUTS = "VertexInputs"; -const string VERTEX_DATA = "VertexData"; -const string PRIVATE_UNIFORMS = "PrivateUniforms"; -const string PUBLIC_UNIFORMS = "PublicUniforms"; -const string LIGHT_DATA = "LightData"; -const string PIXEL_OUTPUTS = "PixelOutputs"; -const string DIR_N = "N"; -const string CLOSURE_DATA_TYPE = "ClosureData"; -const string CLOSURE_DATA_ARG = "closureData"; -const string DIR_L = "L"; -const string DIR_V = "V"; -const string WORLD_POSITION = "P"; -const string OCCLUSION = "occlusion"; -const string CLOSURE_DATA_CONSTRUCTOR = "ClosureData(closureType, L, V, N, P, occlusion)"; -const string ATTR_TRANSPARENT = "transparent"; -const string USER_DATA_CLOSURE_CONTEXT = "udcc"; -const string USER_DATA_LIGHT_SHADERS = "udls"; -const string USER_DATA_BINDING_CONTEXT = "udbinding"; - -const TypeDesc ClosureDataType = TypeDesc("ClosureData", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_NONE, 1, 0); -} // namespace HW - -namespace Stage -{ - -const string VERTEX = "vertex"; - -} // namespace Stage - // // HwShaderGenerator methods // @@ -567,9 +389,20 @@ void HwShaderGenerator::addStageLightingUniforms(GenContext& context, ShaderStag } } -bool HwImplementation::isEditable(const ShaderInput& input) const +void HwShaderGenerator::emitClosureDataArg(const ShaderNode& node, GenContext& /*context*/, ShaderStage& stage) const +{ + if (nodeNeedsClosureData(node)) + { + emitString(HW::CLOSURE_DATA_ARG + ", ", stage); + } +} + +void HwShaderGenerator::emitClosureDataParameter(const ShaderNode& node, GenContext& /*context*/, ShaderStage& stage) const { - return IMMUTABLE_INPUTS.count(input.getName()) == 0; + if (nodeNeedsClosureData(node)) + { + emitString(HW::CLOSURE_DATA_TYPE + " " + HW::CLOSURE_DATA_ARG + ", ", stage); + } } MATERIALX_NAMESPACE_END diff --git a/source/MaterialXGenHw/HwShaderGenerator.h b/source/MaterialXGenHw/HwShaderGenerator.h new file mode 100644 index 0000000000..67bb3a25fd --- /dev/null +++ b/source/MaterialXGenHw/HwShaderGenerator.h @@ -0,0 +1,89 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef MATERIALX_HWSHADERGENERATOR_H +#define MATERIALX_HWSHADERGENERATOR_H + +/// @file +/// Hardware shader generator base class + +#include + +#include + +// These headers below are not required for inclusion here +// they are included as an affordance to backwards compatibility +// during the refactor transition - The next breaking API point +// we should remove them +#include +#include +#include +#include + +MATERIALX_NAMESPACE_BEGIN + +class HwShaderGenerator; +/// Shared pointer to a HwShaderGenerator +using HwShaderGeneratorPtr = shared_ptr; + +/// @class HwShaderGenerator +/// Base class for shader generators targeting HW rendering. +class MX_GENHW_API HwShaderGenerator : public ShaderGenerator +{ + public: + /// Emit code for active light count definitions and uniforms + virtual void addStageLightingUniforms(GenContext& context, ShaderStage& stage) const; + + /// Return true if the node needs the ClosureData struct added + bool nodeNeedsClosureData(const ShaderNode& node) const override; + + void emitClosureDataArg(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override; + void emitClosureDataParameter(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override; + + /// Logic to indicate whether code to support direct lighting should be emitted. + /// By default if the graph is classified as a shader, or BSDF node then lighting is assumed to be required. + /// Derived classes can override this logic. + virtual bool requiresLighting(const ShaderGraph& graph) const; + + /// Bind a light shader to a light type id, for usage in surface shaders created + /// by the generator. The lightTypeId should be a unique identifier for the light + /// type (node definition) and the same id should be used when setting light parameters on a + /// generated surface shader. + static void bindLightShader(const NodeDef& nodeDef, unsigned int lightTypeId, GenContext& context); + + /// Unbind a light shader previously bound to the given light type id. + static void unbindLightShader(unsigned int lightTypeId, GenContext& context); + + /// Unbind all light shaders previously bound. + static void unbindLightShaders(GenContext& context); + + /// Determine the prefix of vertex data variables. + virtual string getVertexDataPrefix(const VariableBlock& vertexData) const = 0; + + // Note : the order must match the order defined in libraries/pbrlib/genglsl/lib/mx_closure_type.glsl + // TODO : investigate build time mechanism for ensuring these stay in sync. + + /// Types of closure contexts for HW. + enum ClosureContextType + { + DEFAULT, + REFLECTION, + TRANSMISSION, + INDIRECT, + EMISSION, + LIGHTING, + CLOSURE + }; + + protected: + HwShaderGenerator(TypeSystemPtr typeSystem, SyntaxPtr syntax); + + /// Create and initialize a new HW shader for shader generation. + virtual ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const; +}; + +MATERIALX_NAMESPACE_END + +#endif diff --git a/source/MaterialXGenShader/Nodes/HwBitangentNode.cpp b/source/MaterialXGenHw/Nodes/HwBitangentNode.cpp similarity index 96% rename from source/MaterialXGenShader/Nodes/HwBitangentNode.cpp rename to source/MaterialXGenHw/Nodes/HwBitangentNode.cpp index 7e4552cad9..2fb8f05293 100644 --- a/source/MaterialXGenShader/Nodes/HwBitangentNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwBitangentNode.cpp @@ -3,8 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include +#include + +#include #include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwBitangentNode.h b/source/MaterialXGenHw/Nodes/HwBitangentNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwBitangentNode.h rename to source/MaterialXGenHw/Nodes/HwBitangentNode.h index a8bfa0bf11..e121263acb 100644 --- a/source/MaterialXGenShader/Nodes/HwBitangentNode.h +++ b/source/MaterialXGenHw/Nodes/HwBitangentNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWBITANGENTNODE_H #define MATERIALX_HWBITANGENTNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Bitangent node implementation for hardware languages -class MX_GENSHADER_API HwBitangentNode : public HwImplementation +class MX_GENHW_API HwBitangentNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwFrameNode.cpp b/source/MaterialXGenHw/Nodes/HwFrameNode.cpp similarity index 87% rename from source/MaterialXGenShader/Nodes/HwFrameNode.cpp rename to source/MaterialXGenHw/Nodes/HwFrameNode.cpp index cd6a3319a8..d5154be84f 100644 --- a/source/MaterialXGenShader/Nodes/HwFrameNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwFrameNode.cpp @@ -3,8 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include + +#include #include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwFrameNode.h b/source/MaterialXGenHw/Nodes/HwFrameNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwFrameNode.h rename to source/MaterialXGenHw/Nodes/HwFrameNode.h index 4487a6a0b9..8ddbbf0478 100644 --- a/source/MaterialXGenShader/Nodes/HwFrameNode.h +++ b/source/MaterialXGenHw/Nodes/HwFrameNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWFRAMENODE_H #define MATERIALX_HWFRAMENODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Frame node implementation for hardware languages -class MX_GENSHADER_API HwFrameNode : public HwImplementation +class MX_GENHW_API HwFrameNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwGeomColorNode.cpp b/source/MaterialXGenHw/Nodes/HwGeomColorNode.cpp similarity index 93% rename from source/MaterialXGenShader/Nodes/HwGeomColorNode.cpp rename to source/MaterialXGenHw/Nodes/HwGeomColorNode.cpp index 0e86f415a6..94c700a1b5 100644 --- a/source/MaterialXGenShader/Nodes/HwGeomColorNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwGeomColorNode.cpp @@ -3,10 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include -#include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwGeomColorNode.h b/source/MaterialXGenHw/Nodes/HwGeomColorNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwGeomColorNode.h rename to source/MaterialXGenHw/Nodes/HwGeomColorNode.h index 314a6c8916..3f90520b30 100644 --- a/source/MaterialXGenShader/Nodes/HwGeomColorNode.h +++ b/source/MaterialXGenHw/Nodes/HwGeomColorNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWGEOMCOLORNODE_H #define MATERIALX_HWGEOMCOLORNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// GeomColor node implementation for Hw shader languages -class MX_GENSHADER_API HwGeomColorNode : public HwImplementation +class MX_GENHW_API HwGeomColorNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwGeomPropValueNode.cpp b/source/MaterialXGenHw/Nodes/HwGeomPropValueNode.cpp similarity index 95% rename from source/MaterialXGenShader/Nodes/HwGeomPropValueNode.cpp rename to source/MaterialXGenHw/Nodes/HwGeomPropValueNode.cpp index facd0a224c..bc47e07aae 100644 --- a/source/MaterialXGenShader/Nodes/HwGeomPropValueNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwGeomPropValueNode.cpp @@ -3,10 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include -#include +#include #include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwGeomPropValueNode.h b/source/MaterialXGenHw/Nodes/HwGeomPropValueNode.h similarity index 83% rename from source/MaterialXGenShader/Nodes/HwGeomPropValueNode.h rename to source/MaterialXGenHw/Nodes/HwGeomPropValueNode.h index deb940f4e9..98b5943f34 100644 --- a/source/MaterialXGenShader/Nodes/HwGeomPropValueNode.h +++ b/source/MaterialXGenHw/Nodes/HwGeomPropValueNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWGEOMPROPVALUENODE_H #define MATERIALX_HWGEOMPROPVALUENODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// GeomPropValue node implementation for Hw shader languages -class MX_GENSHADER_API HwGeomPropValueNode : public HwImplementation +class MX_GENHW_API HwGeomPropValueNode : public HwImplementation { public: static ShaderNodeImplPtr create(); @@ -24,7 +24,7 @@ class MX_GENSHADER_API HwGeomPropValueNode : public HwImplementation }; /// GeomPropValue node non-implementation for Hw shader languages -class MX_GENSHADER_API HwGeomPropValueNodeAsUniform : public HwImplementation +class MX_GENHW_API HwGeomPropValueNodeAsUniform : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwImageNode.cpp b/source/MaterialXGenHw/Nodes/HwImageNode.cpp similarity index 95% rename from source/MaterialXGenShader/Nodes/HwImageNode.cpp rename to source/MaterialXGenHw/Nodes/HwImageNode.cpp index 260359b50a..e645c10393 100644 --- a/source/MaterialXGenShader/Nodes/HwImageNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwImageNode.cpp @@ -3,11 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include +#include + +#include -#include +#include MATERIALX_NAMESPACE_BEGIN // Additional implementation arguments for image nodes diff --git a/source/MaterialXGenShader/Nodes/HwImageNode.h b/source/MaterialXGenHw/Nodes/HwImageNode.h similarity index 86% rename from source/MaterialXGenShader/Nodes/HwImageNode.h rename to source/MaterialXGenHw/Nodes/HwImageNode.h index 58ddb9305c..8e69b5c530 100644 --- a/source/MaterialXGenShader/Nodes/HwImageNode.h +++ b/source/MaterialXGenHw/Nodes/HwImageNode.h @@ -6,12 +6,14 @@ #ifndef MATERIALX_HWIMAGECODENODE_H #define MATERIALX_HWIMAGECODENODE_H +#include + #include MATERIALX_NAMESPACE_BEGIN /// Extending the SourceCodeNode with requirements for image nodes. -class MX_GENSHADER_API HwImageNode : public SourceCodeNode +class MX_GENHW_API HwImageNode : public SourceCodeNode { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwLightCompoundNodel.cpp b/source/MaterialXGenHw/Nodes/HwLightCompoundNode.cpp similarity index 95% rename from source/MaterialXGenShader/Nodes/HwLightCompoundNodel.cpp rename to source/MaterialXGenHw/Nodes/HwLightCompoundNode.cpp index 667c0b6eb3..bf86c31702 100644 --- a/source/MaterialXGenShader/Nodes/HwLightCompoundNodel.cpp +++ b/source/MaterialXGenHw/Nodes/HwLightCompoundNode.cpp @@ -3,10 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include +#include -#include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwLightCompoundNode.h b/source/MaterialXGenHw/Nodes/HwLightCompoundNode.h similarity index 85% rename from source/MaterialXGenShader/Nodes/HwLightCompoundNode.h rename to source/MaterialXGenHw/Nodes/HwLightCompoundNode.h index 4dafe30468..037412e190 100644 --- a/source/MaterialXGenShader/Nodes/HwLightCompoundNode.h +++ b/source/MaterialXGenHw/Nodes/HwLightCompoundNode.h @@ -6,14 +6,14 @@ #ifndef MATERIALX_HWLIGHTCOMPOUNDNODE_H #define MATERIALX_HWLIGHTCOMPOUNDNODE_H +#include + #include -#include -#include MATERIALX_NAMESPACE_BEGIN /// LightCompound node implementation for hardware languages. -class MX_GENSHADER_API HwLightCompoundNode : public CompoundNode +class MX_GENHW_API HwLightCompoundNode : public CompoundNode { public: HwLightCompoundNode(); diff --git a/source/MaterialXGenShader/Nodes/HwLightNode.cpp b/source/MaterialXGenHw/Nodes/HwLightNode.cpp similarity index 94% rename from source/MaterialXGenShader/Nodes/HwLightNode.cpp rename to source/MaterialXGenHw/Nodes/HwLightNode.cpp index 5a6b04b4bf..9d39d8e925 100644 --- a/source/MaterialXGenShader/Nodes/HwLightNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwLightNode.cpp @@ -3,9 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwLightNode.h b/source/MaterialXGenHw/Nodes/HwLightNode.h similarity index 83% rename from source/MaterialXGenShader/Nodes/HwLightNode.h rename to source/MaterialXGenHw/Nodes/HwLightNode.h index 48dd2163bd..a9e89eb309 100644 --- a/source/MaterialXGenShader/Nodes/HwLightNode.h +++ b/source/MaterialXGenHw/Nodes/HwLightNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWLIGHTNODE_H #define MATERIALX_HWLIGHTNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Light node implementation for hardware languages. -class MX_GENSHADER_API HwLightNode : public HwImplementation +class MX_GENHW_API HwLightNode : public HwImplementation { public: HwLightNode(); diff --git a/source/MaterialXGenShader/Nodes/HwLightSamplerNode.cpp b/source/MaterialXGenHw/Nodes/HwLightSamplerNode.cpp similarity index 90% rename from source/MaterialXGenShader/Nodes/HwLightSamplerNode.cpp rename to source/MaterialXGenHw/Nodes/HwLightSamplerNode.cpp index ea08acfea2..147b17f1c4 100644 --- a/source/MaterialXGenShader/Nodes/HwLightSamplerNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwLightSamplerNode.cpp @@ -3,7 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include + +#include +#include + +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwLightSamplerNode.h b/source/MaterialXGenHw/Nodes/HwLightSamplerNode.h similarity index 80% rename from source/MaterialXGenShader/Nodes/HwLightSamplerNode.h rename to source/MaterialXGenHw/Nodes/HwLightSamplerNode.h index ef447a9684..754e9d4ab3 100644 --- a/source/MaterialXGenShader/Nodes/HwLightSamplerNode.h +++ b/source/MaterialXGenHw/Nodes/HwLightSamplerNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWLIGHTSAMPLERNODE_H #define MATERIALX_HWLIGHTSAMPLERNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Utility node for sampling lights for hardware languages. -class MX_GENSHADER_API HwLightSamplerNode : public HwImplementation +class MX_GENHW_API HwLightSamplerNode : public HwImplementation { public: HwLightSamplerNode(); diff --git a/source/MaterialXGenShader/Nodes/HwLightShaderNode.cpp b/source/MaterialXGenHw/Nodes/HwLightShaderNode.cpp similarity index 92% rename from source/MaterialXGenShader/Nodes/HwLightShaderNode.cpp rename to source/MaterialXGenHw/Nodes/HwLightShaderNode.cpp index 2ee5bde519..288690f377 100644 --- a/source/MaterialXGenShader/Nodes/HwLightShaderNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwLightShaderNode.cpp @@ -3,8 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include +#include + +#include #include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwLightShaderNode.h b/source/MaterialXGenHw/Nodes/HwLightShaderNode.h similarity index 85% rename from source/MaterialXGenShader/Nodes/HwLightShaderNode.h rename to source/MaterialXGenHw/Nodes/HwLightShaderNode.h index 689e2c9654..96685137e0 100644 --- a/source/MaterialXGenShader/Nodes/HwLightShaderNode.h +++ b/source/MaterialXGenHw/Nodes/HwLightShaderNode.h @@ -6,14 +6,16 @@ #ifndef MATERIALX_HWLIGHTSHADERNODE_H #define MATERIALX_HWLIGHTSHADERNODE_H -#include +#include + #include +#include MATERIALX_NAMESPACE_BEGIN /// LightShader node implementation for hardware languages. /// Used for all light shaders implemented in source code. -class MX_GENSHADER_API HwLightShaderNode : public SourceCodeNode +class MX_GENHW_API HwLightShaderNode : public SourceCodeNode { public: HwLightShaderNode(); diff --git a/source/MaterialXGenShader/Nodes/HwNormalNode.cpp b/source/MaterialXGenHw/Nodes/HwNormalNode.cpp similarity index 94% rename from source/MaterialXGenShader/Nodes/HwNormalNode.cpp rename to source/MaterialXGenHw/Nodes/HwNormalNode.cpp index 86d213b1a8..7e86f17d35 100644 --- a/source/MaterialXGenShader/Nodes/HwNormalNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwNormalNode.cpp @@ -3,9 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwNormalNode.h b/source/MaterialXGenHw/Nodes/HwNormalNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwNormalNode.h rename to source/MaterialXGenHw/Nodes/HwNormalNode.h index fb19050600..4b35bf53ba 100644 --- a/source/MaterialXGenShader/Nodes/HwNormalNode.h +++ b/source/MaterialXGenHw/Nodes/HwNormalNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWNORMALNODE_H #define MATERIALX_HWNORMALNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Normal node implementation for hardware languages -class MX_GENSHADER_API HwNormalNode : public HwImplementation +class MX_GENHW_API HwNormalNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwNumLightsNode.cpp b/source/MaterialXGenHw/Nodes/HwNumLightsNode.cpp similarity index 91% rename from source/MaterialXGenShader/Nodes/HwNumLightsNode.cpp rename to source/MaterialXGenHw/Nodes/HwNumLightsNode.cpp index d08d0c403c..32d550b7f8 100644 --- a/source/MaterialXGenShader/Nodes/HwNumLightsNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwNumLightsNode.cpp @@ -3,9 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwNumLightsNode.h b/source/MaterialXGenHw/Nodes/HwNumLightsNode.h similarity index 83% rename from source/MaterialXGenShader/Nodes/HwNumLightsNode.h rename to source/MaterialXGenHw/Nodes/HwNumLightsNode.h index 06ab6edccf..fde087fddc 100644 --- a/source/MaterialXGenShader/Nodes/HwNumLightsNode.h +++ b/source/MaterialXGenHw/Nodes/HwNumLightsNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWNUMLIGHTSNODE_H #define MATERIALX_HWNUMLIGHTSNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Utility node for getting number of active lights for hardware languages. -class MX_GENSHADER_API HwNumLightsNode : public HwImplementation +class MX_GENHW_API HwNumLightsNode : public HwImplementation { public: HwNumLightsNode(); diff --git a/source/MaterialXGenShader/Nodes/HwPositionNode.cpp b/source/MaterialXGenHw/Nodes/HwPositionNode.cpp similarity index 94% rename from source/MaterialXGenShader/Nodes/HwPositionNode.cpp rename to source/MaterialXGenHw/Nodes/HwPositionNode.cpp index df7c11f4e6..05f1e4895b 100644 --- a/source/MaterialXGenShader/Nodes/HwPositionNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwPositionNode.cpp @@ -3,9 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwPositionNode.h b/source/MaterialXGenHw/Nodes/HwPositionNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwPositionNode.h rename to source/MaterialXGenHw/Nodes/HwPositionNode.h index ae2ce5c3f5..1f352cf54c 100644 --- a/source/MaterialXGenShader/Nodes/HwPositionNode.h +++ b/source/MaterialXGenHw/Nodes/HwPositionNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWPOSITIONNODE_H #define MATERIALX_HWPOSITIONNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Position node implementation for hardware languages -class MX_GENSHADER_API HwPositionNode : public HwImplementation +class MX_GENHW_API HwPositionNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwSurfaceNode.cpp b/source/MaterialXGenHw/Nodes/HwSurfaceNode.cpp similarity index 98% rename from source/MaterialXGenShader/Nodes/HwSurfaceNode.cpp rename to source/MaterialXGenHw/Nodes/HwSurfaceNode.cpp index eab478c109..07af222904 100644 --- a/source/MaterialXGenShader/Nodes/HwSurfaceNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwSurfaceNode.cpp @@ -3,10 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include -#include #include +#include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwSurfaceNode.h b/source/MaterialXGenHw/Nodes/HwSurfaceNode.h similarity index 86% rename from source/MaterialXGenShader/Nodes/HwSurfaceNode.h rename to source/MaterialXGenHw/Nodes/HwSurfaceNode.h index 126baec130..cdd79106fc 100644 --- a/source/MaterialXGenShader/Nodes/HwSurfaceNode.h +++ b/source/MaterialXGenHw/Nodes/HwSurfaceNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWSURFACENODE_H #define MATERIALX_HWSURFACENODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Surface node implementation for hardware languages. -class MX_GENSHADER_API HwSurfaceNode : public HwImplementation +class MX_GENHW_API HwSurfaceNode : public HwImplementation { public: HwSurfaceNode(); diff --git a/source/MaterialXGenShader/Nodes/HwTangentNode.cpp b/source/MaterialXGenHw/Nodes/HwTangentNode.cpp similarity index 94% rename from source/MaterialXGenShader/Nodes/HwTangentNode.cpp rename to source/MaterialXGenHw/Nodes/HwTangentNode.cpp index a6bba9ebce..27951b0686 100644 --- a/source/MaterialXGenShader/Nodes/HwTangentNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwTangentNode.cpp @@ -3,9 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwTangentNode.h b/source/MaterialXGenHw/Nodes/HwTangentNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwTangentNode.h rename to source/MaterialXGenHw/Nodes/HwTangentNode.h index b36d7f3c56..0a2e69cf74 100644 --- a/source/MaterialXGenShader/Nodes/HwTangentNode.h +++ b/source/MaterialXGenHw/Nodes/HwTangentNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWTANGENTNODE_H #define MATERIALX_HWTANGENTNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Tangent node implementation for hardware languages -class MX_GENSHADER_API HwTangentNode : public HwImplementation +class MX_GENHW_API HwTangentNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwTexCoordNode.cpp b/source/MaterialXGenHw/Nodes/HwTexCoordNode.cpp similarity index 94% rename from source/MaterialXGenShader/Nodes/HwTexCoordNode.cpp rename to source/MaterialXGenHw/Nodes/HwTexCoordNode.cpp index 3aa84400df..de878bc716 100644 --- a/source/MaterialXGenShader/Nodes/HwTexCoordNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwTexCoordNode.cpp @@ -3,9 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include +#include + +#include #include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwTexCoordNode.h b/source/MaterialXGenHw/Nodes/HwTexCoordNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwTexCoordNode.h rename to source/MaterialXGenHw/Nodes/HwTexCoordNode.h index 9aae3d18ce..3c20c40ca8 100644 --- a/source/MaterialXGenShader/Nodes/HwTexCoordNode.h +++ b/source/MaterialXGenHw/Nodes/HwTexCoordNode.h @@ -6,12 +6,13 @@ #ifndef MATERIALX_HWTEXCOORDNODE_H #define MATERIALX_HWTEXCOORDNODE_H -#include +#include +#include MATERIALX_NAMESPACE_BEGIN /// Generic texture coordinate node for hardware languages -class MX_GENSHADER_API HwTexCoordNode : public ShaderNodeImpl +class MX_GENHW_API HwTexCoordNode : public ShaderNodeImpl { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwTimeNode.cpp b/source/MaterialXGenHw/Nodes/HwTimeNode.cpp similarity index 88% rename from source/MaterialXGenShader/Nodes/HwTimeNode.cpp rename to source/MaterialXGenHw/Nodes/HwTimeNode.cpp index 918c62123d..c308c04adc 100644 --- a/source/MaterialXGenShader/Nodes/HwTimeNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwTimeNode.cpp @@ -3,9 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwTimeNode.h b/source/MaterialXGenHw/Nodes/HwTimeNode.h similarity index 83% rename from source/MaterialXGenShader/Nodes/HwTimeNode.h rename to source/MaterialXGenHw/Nodes/HwTimeNode.h index e5e1a2fcd4..f2e5955b3f 100644 --- a/source/MaterialXGenShader/Nodes/HwTimeNode.h +++ b/source/MaterialXGenHw/Nodes/HwTimeNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWTIMENODE_H #define MATERIALX_HWTIMENODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// Time node implementation for hardware languages -class MX_GENSHADER_API HwTimeNode : public HwImplementation +class MX_GENHW_API HwTimeNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwTransformNode.cpp b/source/MaterialXGenHw/Nodes/HwTransformNode.cpp similarity index 96% rename from source/MaterialXGenShader/Nodes/HwTransformNode.cpp rename to source/MaterialXGenHw/Nodes/HwTransformNode.cpp index a1f73859a5..ac976af5c4 100644 --- a/source/MaterialXGenShader/Nodes/HwTransformNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwTransformNode.cpp @@ -3,8 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include +#include + +#include + +#include #include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwTransformNode.h b/source/MaterialXGenHw/Nodes/HwTransformNode.h similarity index 84% rename from source/MaterialXGenShader/Nodes/HwTransformNode.h rename to source/MaterialXGenHw/Nodes/HwTransformNode.h index 2103f3b4c8..ecfbc0f70d 100644 --- a/source/MaterialXGenShader/Nodes/HwTransformNode.h +++ b/source/MaterialXGenHw/Nodes/HwTransformNode.h @@ -6,12 +6,15 @@ #ifndef MATERIALX_HWTRANSFORMNODE_H #define MATERIALX_HWTRANSFORMNODE_H -#include +#include + +#include +#include MATERIALX_NAMESPACE_BEGIN /// Generic transformation node for hardware languages -class MX_GENSHADER_API HwTransformNode : public ShaderNodeImpl +class MX_GENHW_API HwTransformNode : public ShaderNodeImpl { public: void createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const override; @@ -35,7 +38,7 @@ class MX_GENSHADER_API HwTransformNode : public ShaderNodeImpl }; /// Vector transform implementation for hardware languages -class MX_GENSHADER_API HwTransformVectorNode : public HwTransformNode +class MX_GENHW_API HwTransformVectorNode : public HwTransformNode { public: static ShaderNodeImplPtr create(); @@ -47,7 +50,7 @@ class MX_GENSHADER_API HwTransformVectorNode : public HwTransformNode }; /// Point transform implementation for hardware languages -class MX_GENSHADER_API HwTransformPointNode : public HwTransformVectorNode +class MX_GENHW_API HwTransformPointNode : public HwTransformVectorNode { public: static ShaderNodeImplPtr create(); @@ -57,7 +60,7 @@ class MX_GENSHADER_API HwTransformPointNode : public HwTransformVectorNode }; /// Normal transform implementation for hardware languages -class MX_GENSHADER_API HwTransformNormalNode : public HwTransformNode +class MX_GENHW_API HwTransformNormalNode : public HwTransformNode { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenShader/Nodes/HwViewDirectionNode.cpp b/source/MaterialXGenHw/Nodes/HwViewDirectionNode.cpp similarity index 93% rename from source/MaterialXGenShader/Nodes/HwViewDirectionNode.cpp rename to source/MaterialXGenHw/Nodes/HwViewDirectionNode.cpp index 6580e82360..26dba9d0b8 100644 --- a/source/MaterialXGenShader/Nodes/HwViewDirectionNode.cpp +++ b/source/MaterialXGenHw/Nodes/HwViewDirectionNode.cpp @@ -3,9 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include +#include #include +#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/Nodes/HwViewDirectionNode.h b/source/MaterialXGenHw/Nodes/HwViewDirectionNode.h similarity index 82% rename from source/MaterialXGenShader/Nodes/HwViewDirectionNode.h rename to source/MaterialXGenHw/Nodes/HwViewDirectionNode.h index 143d89d437..f021a10dbe 100644 --- a/source/MaterialXGenShader/Nodes/HwViewDirectionNode.h +++ b/source/MaterialXGenHw/Nodes/HwViewDirectionNode.h @@ -6,12 +6,12 @@ #ifndef MATERIALX_HWVIEWDIRECTIONNODE_H #define MATERIALX_HWVIEWDIRECTIONNODE_H -#include +#include MATERIALX_NAMESPACE_BEGIN /// ViewDirection node implementation for hardware languages -class MX_GENSHADER_API HwViewDirectionNode : public HwImplementation +class MX_GENHW_API HwViewDirectionNode : public HwImplementation { public: static ShaderNodeImplPtr create(); diff --git a/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp index ec5f45db12..b5c16456c0 100644 --- a/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp +++ b/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include diff --git a/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp index e6c1bc8d27..ea15eca7c2 100644 --- a/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp +++ b/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include diff --git a/source/MaterialXGenMsl/CMakeLists.txt b/source/MaterialXGenMsl/CMakeLists.txt index 317b7fa58e..d67bd953b7 100644 --- a/source/MaterialXGenMsl/CMakeLists.txt +++ b/source/MaterialXGenMsl/CMakeLists.txt @@ -7,7 +7,7 @@ mx_add_library(MaterialXGenMsl HEADER_FILES ${materialx_headers} MTLX_MODULES - MaterialXGenShader + MaterialXGenHw MaterialXCore EXPORT_DEFINE MATERIALX_GENMSL_EXPORTS) diff --git a/source/MaterialXGenMsl/MslResourceBindingContext.cpp b/source/MaterialXGenMsl/MslResourceBindingContext.cpp index 6599d53c0e..d20c4663af 100644 --- a/source/MaterialXGenMsl/MslResourceBindingContext.cpp +++ b/source/MaterialXGenMsl/MslResourceBindingContext.cpp @@ -5,6 +5,8 @@ #include +#include + MATERIALX_NAMESPACE_BEGIN // diff --git a/source/MaterialXGenMsl/MslResourceBindingContext.h b/source/MaterialXGenMsl/MslResourceBindingContext.h index cdb67b981d..5f42aca0bb 100644 --- a/source/MaterialXGenMsl/MslResourceBindingContext.h +++ b/source/MaterialXGenMsl/MslResourceBindingContext.h @@ -11,7 +11,7 @@ #include -#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenMsl/MslShaderGenerator.cpp b/source/MaterialXGenMsl/MslShaderGenerator.cpp index 5469b9b93f..659ce8ed21 100644 --- a/source/MaterialXGenMsl/MslShaderGenerator.cpp +++ b/source/MaterialXGenMsl/MslShaderGenerator.cpp @@ -4,28 +4,29 @@ // #include - #include +#include + #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "MslResourceBindingContext.h" diff --git a/source/MaterialXGenMsl/MslShaderGenerator.h b/source/MaterialXGenMsl/MslShaderGenerator.h index e4689a8cf5..6ab2dd0f23 100644 --- a/source/MaterialXGenMsl/MslShaderGenerator.h +++ b/source/MaterialXGenMsl/MslShaderGenerator.h @@ -11,7 +11,8 @@ #include -#include +#include +#include #define TEXTURE_NAME(t) ((t) + "_tex") #define SAMPLER_NAME(t) ((t) + "_sampler") diff --git a/source/MaterialXGenMsl/MslSyntax.cpp b/source/MaterialXGenMsl/MslSyntax.cpp index c3639a0ab4..b9a94fe623 100644 --- a/source/MaterialXGenMsl/MslSyntax.cpp +++ b/source/MaterialXGenMsl/MslSyntax.cpp @@ -6,7 +6,6 @@ #include #include -#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXGenShader/HwShaderGenerator.h b/source/MaterialXGenShader/HwShaderGenerator.h deleted file mode 100644 index b7d264f112..0000000000 --- a/source/MaterialXGenShader/HwShaderGenerator.h +++ /dev/null @@ -1,419 +0,0 @@ -// -// Copyright Contributors to the MaterialX Project -// SPDX-License-Identifier: Apache-2.0 -// - -#ifndef MATERIALX_HWSHADERGENERATOR_H -#define MATERIALX_HWSHADERGENERATOR_H - -/// @file -/// Hardware shader generator base class - -#include - -#include -#include - -MATERIALX_NAMESPACE_BEGIN - -/* -The HW shader generators have a number of predefined variables (inputs and uniforms) with binding rules. -When these are used by a shader the application must bind them to the expected data. The following table is -a listing of the variables with a description of what data they should be bound to. - -However, different renderers can have different requirements on naming conventions for these variables. -In order to facilitate this the generators will use token substitution for naming the variables. The -first column below shows the token names that should be used in source code before the token substitution -is done. The second row shows the real identifier names that will be used by default after substitution. -An generator can override these identifier names in order to use a custom naming convention for these. -Overriding identifier names is done by changing the entries in the identifiers map given to the function -replaceIdentifiers(), which is handling the token substitution on a shader stage. - ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - TOKEN NAME DEFAULT IDENTIFIER NAME TYPE BINDING ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -Vertex input variables : - $inPosition i_position vec3 Vertex position in object space - $inNormal i_normal vec3 Vertex normal in object space - $inTangent i_tangent vec3 Vertex tangent in object space - $inBitangent i_bitangent vec3 Vertex bitangent in object space - $inTexcoord_N i_texcoord_N vec2 Vertex texture coordinate for the N:th uv set - $inColor_N i_color_N vec4 Vertex color for the N:th color set (RGBA) - -Uniform variables : - $worldMatrix u_worldMatrix mat4 World transformation - $worldInverseMatrix u_worldInverseMatrix mat4 World transformation, inverted - $worldTransposeMatrix u_worldTransposeMatrix mat4 World transformation, transposed - $worldInverseTransposeMatrix u_worldInverseTransposeMatrix mat4 World transformation, inverted and transposed - $viewMatrix u_viewMatrix mat4 View transformation - $viewInverseMatrix u_viewInverseMatrix mat4 View transformation, inverted - $viewTransposeMatrix u_viewTransposeMatrix mat4 View transformation, transposed - $viewInverseTransposeMatrix u_viewInverseTransposeMatrix mat4 View transformation, inverted and transposed - $projectionMatrix u_projectionMatrix mat4 Projection transformation - $projectionInverseMatrix u_projectionInverseMatrix mat4 Projection transformation, inverted - $projectionTransposeMatrix u_projectionTransposeMatrix mat4 Projection transformation, transposed - $projectionInverseTransposeMatrix u_projectionInverseTransposeMatrix mat4 Projection transformation, inverted and transposed - $worldViewMatrix u_worldViewMatrix mat4 World-view transformation - $viewProjectionMatrix u_viewProjectionMatrix mat4 View-projection transformation - $worldViewProjectionMatrix u_worldViewProjectionMatrix mat4 World-view-projection transformation - $viewPosition u_viewPosition vec3 World-space position of the view (camera) - $viewDirection u_viewDirection vec3 World-space direction of the view (camera) - $frame u_frame float The current frame number as defined by the host application - $time u_time float The current time in seconds - $geomprop_ u_geomprop_ A named property of given where is the name of the variable on the geometry - $numActiveLightSources u_numActiveLightSources int The number of currently active light sources. Note that in shader this is clamped against - the maximum allowed number of lights sources. The maximum number is set by the generation - option GenOptions.hwMaxActiveLightSources. - $lightData[] u_lightData[] struct Array of struct LightData holding parameters for active light sources. - The LightData struct is built dynamically depending on requirements for - bound light shaders. - $envMatrix u_envMatrix mat4 Rotation matrix for the environment. - $envIrradiance u_envIrradiance sampler2D Sampler for the texture used for diffuse environment lighting. - $envIrradianceSampler2D u_envIrradiance sampler2D For split texture and sampler, takes form of sampler2D(tex, sampler) - $envRadiance u_envRadiance sampler2D Sampler for the texture used for specular environment lighting. - $envRadianceSampler2D u_envRadiance sampler2D For split texture and sampler, takes form of sampler2D(tex, sampler) - $envLightIntensity u_envLightIntensity float Linear multiplier for environment lighting - $envRadianceMips u_envRadianceMips int Number of mipmaps used on the specular environment texture. - $envRadianceSamples u_envRadianceSamples int Samples to use if Filtered Importance Sampling is used for specular environment lighting. - $texSamplerSampler2D tex_sampler sampler2D Texture sampler2D parameter. For split texture and sampler, calls sampler2D(tex_texture, tex_sampler). - $texSamplerSignature sampler2D tex_sampler signature For function signature declaration. - ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -*/ - -/// HW specific identifiers. -namespace HW -{ -/// Token identifiers -extern MX_GENSHADER_API const string T_IN_POSITION; -extern MX_GENSHADER_API const string T_IN_NORMAL; -extern MX_GENSHADER_API const string T_IN_TANGENT; -extern MX_GENSHADER_API const string T_IN_BITANGENT; -extern MX_GENSHADER_API const string T_IN_TEXCOORD; -extern MX_GENSHADER_API const string T_IN_GEOMPROP; -extern MX_GENSHADER_API const string T_IN_COLOR; -extern MX_GENSHADER_API const string T_POSITION_WORLD; -extern MX_GENSHADER_API const string T_NORMAL_WORLD; -extern MX_GENSHADER_API const string T_TANGENT_WORLD; -extern MX_GENSHADER_API const string T_BITANGENT_WORLD; -extern MX_GENSHADER_API const string T_POSITION_OBJECT; -extern MX_GENSHADER_API const string T_NORMAL_OBJECT; -extern MX_GENSHADER_API const string T_TANGENT_OBJECT; -extern MX_GENSHADER_API const string T_BITANGENT_OBJECT; -extern MX_GENSHADER_API const string T_TEXCOORD; -extern MX_GENSHADER_API const string T_COLOR; -extern MX_GENSHADER_API const string T_WORLD_MATRIX; -extern MX_GENSHADER_API const string T_WORLD_INVERSE_MATRIX; -extern MX_GENSHADER_API const string T_WORLD_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string T_WORLD_INVERSE_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string T_VIEW_MATRIX; -extern MX_GENSHADER_API const string T_VIEW_INVERSE_MATRIX; -extern MX_GENSHADER_API const string T_VIEW_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string T_VIEW_INVERSE_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string T_PROJ_MATRIX; -extern MX_GENSHADER_API const string T_PROJ_INVERSE_MATRIX; -extern MX_GENSHADER_API const string T_PROJ_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string T_PROJ_INVERSE_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string T_WORLD_VIEW_MATRIX; -extern MX_GENSHADER_API const string T_VIEW_PROJECTION_MATRIX; -extern MX_GENSHADER_API const string T_WORLD_VIEW_PROJECTION_MATRIX; -extern MX_GENSHADER_API const string T_VIEW_POSITION; -extern MX_GENSHADER_API const string T_VIEW_DIRECTION; -extern MX_GENSHADER_API const string T_FRAME; -extern MX_GENSHADER_API const string T_TIME; -extern MX_GENSHADER_API const string T_GEOMPROP; -extern MX_GENSHADER_API const string T_ALPHA_THRESHOLD; -extern MX_GENSHADER_API const string T_NUM_ACTIVE_LIGHT_SOURCES; -extern MX_GENSHADER_API const string T_ENV_MATRIX; -extern MX_GENSHADER_API const string T_ENV_RADIANCE; -extern MX_GENSHADER_API const string T_ENV_RADIANCE_SAMPLER2D; -extern MX_GENSHADER_API const string T_ENV_RADIANCE_MIPS; -extern MX_GENSHADER_API const string T_ENV_RADIANCE_SAMPLES; -extern MX_GENSHADER_API const string T_ENV_IRRADIANCE; -extern MX_GENSHADER_API const string T_ENV_IRRADIANCE_SAMPLER2D; -extern MX_GENSHADER_API const string T_ENV_LIGHT_INTENSITY; -extern MX_GENSHADER_API const string T_ENV_PREFILTER_MIP; -extern MX_GENSHADER_API const string T_REFRACTION_TWO_SIDED; -extern MX_GENSHADER_API const string T_ALBEDO_TABLE; -extern MX_GENSHADER_API const string T_ALBEDO_TABLE_SIZE; -extern MX_GENSHADER_API const string T_AMB_OCC_MAP; -extern MX_GENSHADER_API const string T_AMB_OCC_GAIN; -extern MX_GENSHADER_API const string T_SHADOW_MAP; -extern MX_GENSHADER_API const string T_SHADOW_MATRIX; -extern MX_GENSHADER_API const string T_VERTEX_DATA_INSTANCE; -extern MX_GENSHADER_API const string T_LIGHT_DATA_INSTANCE; -extern MX_GENSHADER_API const string T_TEX_SAMPLER_SAMPLER2D; -extern MX_GENSHADER_API const string T_TEX_SAMPLER_SIGNATURE; -extern MX_GENSHADER_API const string T_CLOSURE_DATA_CONSTRUCTOR; - -/// Default names for identifiers. -/// Replacing above tokens in final code. -extern MX_GENSHADER_API const string IN_POSITION; -extern MX_GENSHADER_API const string IN_NORMAL; -extern MX_GENSHADER_API const string IN_TANGENT; -extern MX_GENSHADER_API const string IN_BITANGENT; -extern MX_GENSHADER_API const string IN_TEXCOORD; -extern MX_GENSHADER_API const string IN_GEOMPROP; -extern MX_GENSHADER_API const string IN_COLOR; -extern MX_GENSHADER_API const string POSITION_WORLD; -extern MX_GENSHADER_API const string NORMAL_WORLD; -extern MX_GENSHADER_API const string TANGENT_WORLD; -extern MX_GENSHADER_API const string BITANGENT_WORLD; -extern MX_GENSHADER_API const string POSITION_OBJECT; -extern MX_GENSHADER_API const string NORMAL_OBJECT; -extern MX_GENSHADER_API const string TANGENT_OBJECT; -extern MX_GENSHADER_API const string BITANGENT_OBJECT; -extern MX_GENSHADER_API const string TEXCOORD; -extern MX_GENSHADER_API const string COLOR; -extern MX_GENSHADER_API const string WORLD_MATRIX; -extern MX_GENSHADER_API const string WORLD_INVERSE_MATRIX; -extern MX_GENSHADER_API const string WORLD_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string WORLD_INVERSE_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string VIEW_MATRIX; -extern MX_GENSHADER_API const string VIEW_INVERSE_MATRIX; -extern MX_GENSHADER_API const string VIEW_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string VIEW_INVERSE_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string PROJ_MATRIX; -extern MX_GENSHADER_API const string PROJ_INVERSE_MATRIX; -extern MX_GENSHADER_API const string PROJ_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string PROJ_INVERSE_TRANSPOSE_MATRIX; -extern MX_GENSHADER_API const string WORLD_VIEW_MATRIX; -extern MX_GENSHADER_API const string VIEW_PROJECTION_MATRIX; -extern MX_GENSHADER_API const string WORLD_VIEW_PROJECTION_MATRIX; -extern MX_GENSHADER_API const string VIEW_POSITION; -extern MX_GENSHADER_API const string VIEW_DIRECTION; -extern MX_GENSHADER_API const string FRAME; -extern MX_GENSHADER_API const string TIME; -extern MX_GENSHADER_API const string GEOMPROP; -extern MX_GENSHADER_API const string ALPHA_THRESHOLD; -extern MX_GENSHADER_API const string NUM_ACTIVE_LIGHT_SOURCES; -extern MX_GENSHADER_API const string ENV_MATRIX; -extern MX_GENSHADER_API const string ENV_RADIANCE; -extern MX_GENSHADER_API const string ENV_RADIANCE_SPLIT; -extern MX_GENSHADER_API const string ENV_RADIANCE_SAMPLER2D; -extern MX_GENSHADER_API const string ENV_RADIANCE_SAMPLER2D_SPLIT; -extern MX_GENSHADER_API const string ENV_RADIANCE_MIPS; -extern MX_GENSHADER_API const string ENV_RADIANCE_SAMPLES; -extern MX_GENSHADER_API const string ENV_IRRADIANCE; -extern MX_GENSHADER_API const string ENV_IRRADIANCE_SPLIT; -extern MX_GENSHADER_API const string ENV_IRRADIANCE_SAMPLER2D; -extern MX_GENSHADER_API const string ENV_IRRADIANCE_SAMPLER2D_SPLIT; -extern MX_GENSHADER_API const string ENV_LIGHT_INTENSITY; -extern MX_GENSHADER_API const string ENV_PREFILTER_MIP; -extern MX_GENSHADER_API const string REFRACTION_TWO_SIDED; -extern MX_GENSHADER_API const string ALBEDO_TABLE; -extern MX_GENSHADER_API const string ALBEDO_TABLE_SIZE; -extern MX_GENSHADER_API const string AMB_OCC_MAP; -extern MX_GENSHADER_API const string AMB_OCC_GAIN; -extern MX_GENSHADER_API const string SHADOW_MAP; -extern MX_GENSHADER_API const string SHADOW_MATRIX; -extern MX_GENSHADER_API const string VERTEX_DATA_INSTANCE; -extern MX_GENSHADER_API const string LIGHT_DATA_INSTANCE; -extern MX_GENSHADER_API const string LIGHT_DATA_MAX_LIGHT_SOURCES; - -/// Texture sampler parameters (for both combined and separate values) -extern MX_GENSHADER_API const string TEX_SAMPLER_SAMPLER2D; -extern MX_GENSHADER_API const string TEX_SAMPLER_SAMPLER2D_SPLIT; -extern MX_GENSHADER_API const string TEX_SAMPLER_SIGNATURE; -extern MX_GENSHADER_API const string TEX_SAMPLER_SIGNATURE_SPLIT; - -/// Variable blocks names. -extern MX_GENSHADER_API const string VERTEX_INPUTS; // Geometric inputs for vertex stage. -extern MX_GENSHADER_API const string VERTEX_DATA; // Connector block for data transfer from vertex stage to pixel stage. -extern MX_GENSHADER_API const string PRIVATE_UNIFORMS; // Uniform inputs set privately by application. -extern MX_GENSHADER_API const string PUBLIC_UNIFORMS; // Uniform inputs visible in UI and set by user. -extern MX_GENSHADER_API const string LIGHT_DATA; // Uniform inputs for light sources. -extern MX_GENSHADER_API const string PIXEL_OUTPUTS; // Outputs from the main/pixel stage. - -/// Variable names for lighting parameters. -extern MX_GENSHADER_API const string CLOSURE_DATA_TYPE; -extern MX_GENSHADER_API const string CLOSURE_DATA_ARG; -extern MX_GENSHADER_API const string DIR_N; -extern MX_GENSHADER_API const string DIR_L; -extern MX_GENSHADER_API const string DIR_V; -extern MX_GENSHADER_API const string WORLD_POSITION; -extern MX_GENSHADER_API const string OCCLUSION; - -/// Syntax for constructing ClosureData -extern MX_GENSHADER_API const string CLOSURE_DATA_CONSTRUCTOR; - -/// Attribute names. -extern MX_GENSHADER_API const string ATTR_TRANSPARENT; - -/// User data names. -extern MX_GENSHADER_API const string USER_DATA_LIGHT_SHADERS; -extern MX_GENSHADER_API const string USER_DATA_BINDING_CONTEXT; - -/// Type Descriptor for closure context data. -extern MX_GENSHADER_API const TypeDesc ClosureDataType; -} // namespace HW - -namespace Stage -{ -/// Identifier for vertex stage. -extern MX_GENSHADER_API const string VERTEX; -} // namespace Stage - -class HwLightShaders; -class HwShaderGenerator; -class HwResourceBindingContext; - -/// Shared pointer to a HwLightShaders -using HwLightShadersPtr = shared_ptr; -/// Shared pointer to a HwShaderGenerator -using HwShaderGeneratorPtr = shared_ptr; -/// Shared pointer to a HwResourceBindingContext -using HwResourceBindingContextPtr = shared_ptr; - -/// @class HwLightShaders -/// Hardware light shader user data -class MX_GENSHADER_API HwLightShaders : public GenUserData -{ - public: - /// Create and return a new instance. - static HwLightShadersPtr create() - { - return std::make_shared(); - } - - /// Bind a light shader to a light type id. - void bind(unsigned int type, ShaderNodePtr shader) - { - _shaders[type] = shader; - } - - /// Unbind a light shader previously bound to a light type id. - void unbind(unsigned int type) - { - _shaders.erase(type); - } - - /// Clear all light shaders previously bound. - void clear() - { - _shaders.clear(); - } - - /// Return the light shader bound to the given light type, - /// or nullptr if not light shader is bound to this type. - const ShaderNode* get(unsigned int type) const - { - auto it = _shaders.find(type); - return it != _shaders.end() ? it->second.get() : nullptr; - } - - /// Return the map of bound light shaders. - const std::unordered_map& get() const - { - return _shaders; - } - - protected: - std::unordered_map _shaders; -}; - -/// @class HwShaderGenerator -/// Base class for shader generators targeting HW rendering. -class MX_GENSHADER_API HwShaderGenerator : public ShaderGenerator -{ - public: - /// Emit code for active light count definitions and uniforms - virtual void addStageLightingUniforms(GenContext& context, ShaderStage& stage) const; - - /// Return true if the node needs the ClosureData struct added - bool nodeNeedsClosureData(const ShaderNode& node) const override; - - /// Logic to indicate whether code to support direct lighting should be emitted. - /// By default if the graph is classified as a shader, or BSDF node then lighting is assumed to be required. - /// Derived classes can override this logic. - virtual bool requiresLighting(const ShaderGraph& graph) const; - - /// Bind a light shader to a light type id, for usage in surface shaders created - /// by the generator. The lightTypeId should be a unique identifier for the light - /// type (node definition) and the same id should be used when setting light parameters on a - /// generated surface shader. - static void bindLightShader(const NodeDef& nodeDef, unsigned int lightTypeId, GenContext& context); - - /// Unbind a light shader previously bound to the given light type id. - static void unbindLightShader(unsigned int lightTypeId, GenContext& context); - - /// Unbind all light shaders previously bound. - static void unbindLightShaders(GenContext& context); - - /// Determine the prefix of vertex data variables. - virtual string getVertexDataPrefix(const VariableBlock& vertexData) const = 0; - - // Note : the order must match the order defined in libraries/pbrlib/genglsl/lib/mx_closure_type.glsl - // TODO : investigate build time mechanism for ensuring these stay in sync. - - /// Types of closure contexts for HW. - enum ClosureContextType - { - DEFAULT, - REFLECTION, - TRANSMISSION, - INDIRECT, - EMISSION, - LIGHTING, - CLOSURE - }; - - protected: - HwShaderGenerator(TypeSystemPtr typeSystem, SyntaxPtr syntax); - - /// Create and initialize a new HW shader for shader generation. - virtual ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const; -}; - -/// @class HwImplementation -/// Base class for HW node implementations. -class MX_GENSHADER_API HwImplementation : public ShaderNodeImpl -{ - public: - bool isEditable(const ShaderInput& input) const override; - - protected: - HwImplementation() { } - - // Integer identifiers for coordinate spaces. - // The order must match the order given for the space enum string in stdlib. - enum Space - { - MODEL_SPACE = 0, - OBJECT_SPACE = 1, - WORLD_SPACE = 2 - }; - - /// Internal string constants - static const string SPACE; - static const string INDEX; - static const string GEOMPROP; -}; - -/// @class HwResourceBindingContext -/// Class representing a context for resource binding for hardware resources. -class MX_GENSHADER_API HwResourceBindingContext : public GenUserData -{ - public: - virtual ~HwResourceBindingContext() { } - - // Initialize the context before generation starts. - virtual void initialize() = 0; - - // Emit directives required for binding support - virtual void emitDirectives(GenContext& context, ShaderStage& stage) = 0; - - // Emit uniforms with binding information - virtual void emitResourceBindings(GenContext& context, const VariableBlock& uniforms, ShaderStage& stage) = 0; - - // Emit struct uniforms with binding information - virtual void emitStructuredResourceBindings(GenContext& context, const VariableBlock& uniforms, - ShaderStage& stage, const std::string& structInstanceName, - const std::string& arraySuffix = EMPTY_STRING) = 0; -}; - -MATERIALX_NAMESPACE_END - -#endif diff --git a/source/MaterialXGenShader/Nodes/CompoundNode.cpp b/source/MaterialXGenShader/Nodes/CompoundNode.cpp index 71be06b48a..fbd8a0547c 100644 --- a/source/MaterialXGenShader/Nodes/CompoundNode.cpp +++ b/source/MaterialXGenShader/Nodes/CompoundNode.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -73,10 +72,11 @@ void CompoundNode::emitFunctionDefinition(const ShaderNode& node, GenContext& co shadergen.emitLineBegin(stage); shadergen.emitString("void " + _functionName + "(", stage); - if (context.getShaderGenerator().nodeNeedsClosureData(node)) - { - shadergen.emitString(HW::CLOSURE_DATA_TYPE + " " + HW::CLOSURE_DATA_ARG + ", ", stage); - } + shadergen.emitClosureDataParameter(node, context, stage); + // if (context.getShaderGenerator().nodeNeedsClosureData(node)) + // { + // shadergen.emitString(HW::CLOSURE_DATA_TYPE + " " + HW::CLOSURE_DATA_ARG + ", ", stage); + // } string delim; @@ -171,10 +171,11 @@ void CompoundNode::emitFunctionCall(const ShaderNode& node, GenContext& context, shadergen.emitString(_functionName + "(", stage); // Add an argument for closure data if needed - if (context.getShaderGenerator().nodeNeedsClosureData(node)) - { - shadergen.emitString(HW::CLOSURE_DATA_ARG + ", ", stage); - } + shadergen.emitClosureDataArg(node, context, stage); + // if (context.getShaderGenerator().nodeNeedsClosureData(node)) + // { + // shadergen.emitString(HW::CLOSURE_DATA_ARG + ", ", stage); + // } string delim; diff --git a/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp b/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp index 07e1a54f2f..90c099dc27 100644 --- a/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp +++ b/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp @@ -9,7 +9,6 @@ #include #include #include -#include MATERIALX_NAMESPACE_BEGIN @@ -190,10 +189,11 @@ void SourceCodeNode::emitFunctionCall(const ShaderNode& node, GenContext& contex // Emit function name. shadergen.emitString(_functionName + "(", stage); - if (context.getShaderGenerator().nodeNeedsClosureData(node)) - { - shadergen.emitString(HW::CLOSURE_DATA_ARG + ", ", stage); - } + shadergen.emitClosureDataArg(node, context, stage); + // if (context.getShaderGenerator().nodeNeedsClosureData(node)) + // { + // shadergen.emitString(HW::CLOSURE_DATA_ARG + ", ", stage); + // } string delim; diff --git a/source/MaterialXGenShader/ShaderGenerator.h b/source/MaterialXGenShader/ShaderGenerator.h index 2162a39c13..e91bb6f699 100644 --- a/source/MaterialXGenShader/ShaderGenerator.h +++ b/source/MaterialXGenShader/ShaderGenerator.h @@ -146,6 +146,14 @@ class MX_GENSHADER_API ShaderGenerator /// Return true if the node needs the additional ClosureData added virtual bool nodeNeedsClosureData(const ShaderNode& /*node*/) const { return false; } + /// Emit the closure data argument if required + /// Note this is an affordance for HwShaderGenerator + virtual void emitClosureDataArg(const ShaderNode& /*node*/, GenContext& /*context*/, ShaderStage& /*stage*/) const {} + + /// Emit the closure data parameter if required. + /// Note this is an affordance for HwShaderGenerator + virtual void emitClosureDataParameter(const ShaderNode& /*node*/, GenContext& /*context*/, ShaderStage& /*stage*/) const {} + /// Return the result of an upstream connection or value for an input. virtual string getUpstreamResult(const ShaderInput* input, GenContext& context) const; diff --git a/source/MaterialXGenShader/ShaderStage.cpp b/source/MaterialXGenShader/ShaderStage.cpp index 8e30e40112..7b27c5d0f6 100644 --- a/source/MaterialXGenShader/ShaderStage.cpp +++ b/source/MaterialXGenShader/ShaderStage.cpp @@ -20,6 +20,7 @@ namespace Stage { const string PIXEL = "pixel"; +const string VERTEX = "vertex"; } // namespace Stage diff --git a/source/MaterialXGenShader/ShaderStage.h b/source/MaterialXGenShader/ShaderStage.h index 52486fb5f9..e542fa70a6 100644 --- a/source/MaterialXGenShader/ShaderStage.h +++ b/source/MaterialXGenShader/ShaderStage.h @@ -45,6 +45,10 @@ namespace Stage /// Shader targets with multiple stages can add additional /// stage identifiers to the Stage namespace. extern MX_GENSHADER_API const string PIXEL; +// technically this might only be needed in MaterialXGenHW, but including it here +// now for simplicity - refactoring code in MaterialXGenShader may be possible +// in the future +extern MX_GENSHADER_API const string VERTEX; } // namespace Stage diff --git a/source/MaterialXGenShader/Util.cpp b/source/MaterialXGenShader/Util.cpp index 7c300a01bd..3b2f2ff02e 100644 --- a/source/MaterialXGenShader/Util.cpp +++ b/source/MaterialXGenShader/Util.cpp @@ -5,8 +5,6 @@ #include -#include - MATERIALX_NAMESPACE_BEGIN /// Gaussian kernel weights for different kernel sizes. diff --git a/source/MaterialXRender/CMakeLists.txt b/source/MaterialXRender/CMakeLists.txt index 742af264ec..5d96ab1e4d 100644 --- a/source/MaterialXRender/CMakeLists.txt +++ b/source/MaterialXRender/CMakeLists.txt @@ -15,6 +15,7 @@ mx_add_library(MaterialXRender ${materialx_headers} MTLX_MODULES MaterialXGenShader + MaterialXGenHw # TODO - should this dependency be moved to RenderHw - currently needed for GeometryHandler and LightHandler EXPORT_DEFINE MATERIALX_RENDER_EXPORTS) diff --git a/source/MaterialXRender/GeometryHandler.cpp b/source/MaterialXRender/GeometryHandler.cpp index 04520536fa..184b998595 100644 --- a/source/MaterialXRender/GeometryHandler.cpp +++ b/source/MaterialXRender/GeometryHandler.cpp @@ -5,7 +5,7 @@ #include -#include +#include #include #include diff --git a/source/MaterialXRender/LightHandler.cpp b/source/MaterialXRender/LightHandler.cpp index a0db622052..b8f48c586a 100644 --- a/source/MaterialXRender/LightHandler.cpp +++ b/source/MaterialXRender/LightHandler.cpp @@ -5,7 +5,7 @@ #include -#include +#include #include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXRenderGlsl/GlslMaterial.cpp b/source/MaterialXRenderGlsl/GlslMaterial.cpp index b80699750e..16e6a660e1 100644 --- a/source/MaterialXRenderGlsl/GlslMaterial.cpp +++ b/source/MaterialXRenderGlsl/GlslMaterial.cpp @@ -13,6 +13,8 @@ #include +#include + MATERIALX_NAMESPACE_BEGIN const std::string DISTANCE_UNIT_TARGET_NAME = "u_distanceUnitTarget"; diff --git a/source/MaterialXRenderGlsl/GlslProgram.cpp b/source/MaterialXRenderGlsl/GlslProgram.cpp index 9dbd939963..10ef5e9d05 100644 --- a/source/MaterialXRenderGlsl/GlslProgram.cpp +++ b/source/MaterialXRenderGlsl/GlslProgram.cpp @@ -11,8 +11,7 @@ #include #include -#include -#include +#include #include diff --git a/source/MaterialXRenderGlsl/GlslRenderer.cpp b/source/MaterialXRenderGlsl/GlslRenderer.cpp index 374305f32f..4105b3aaf2 100644 --- a/source/MaterialXRenderGlsl/GlslRenderer.cpp +++ b/source/MaterialXRenderGlsl/GlslRenderer.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include MATERIALX_NAMESPACE_BEGIN diff --git a/source/MaterialXRenderMsl/MslMaterial.mm b/source/MaterialXRenderMsl/MslMaterial.mm index c16cc0cc0e..da3c4bcd2f 100644 --- a/source/MaterialXRenderMsl/MslMaterial.mm +++ b/source/MaterialXRenderMsl/MslMaterial.mm @@ -10,6 +10,7 @@ #include #include #include +#include #include diff --git a/source/MaterialXRenderMsl/MslPipelineStateObject.mm b/source/MaterialXRenderMsl/MslPipelineStateObject.mm index 1792872839..3cbd67c458 100644 --- a/source/MaterialXRenderMsl/MslPipelineStateObject.mm +++ b/source/MaterialXRenderMsl/MslPipelineStateObject.mm @@ -10,9 +10,9 @@ #include #include -#include #include #include +#include #include diff --git a/source/MaterialXRenderMsl/MslRenderer.mm b/source/MaterialXRenderMsl/MslRenderer.mm index 07b0ed5470..4661be0397 100644 --- a/source/MaterialXRenderMsl/MslRenderer.mm +++ b/source/MaterialXRenderMsl/MslRenderer.mm @@ -6,7 +6,6 @@ #include #include #include -#include #include diff --git a/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp b/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp index 96f7a3af8c..0aaf539444 100644 --- a/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp +++ b/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace mx = MaterialX; diff --git a/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp b/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp index 6e2759e408..6f7e126649 100644 --- a/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp +++ b/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp @@ -11,7 +11,9 @@ #include +#include #include +#include #include #include diff --git a/source/MaterialXTest/MaterialXGenShader/GenShader.cpp b/source/MaterialXTest/MaterialXGenShader/GenShader.cpp index 83b226ffc9..09f194d6a6 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShader.cpp +++ b/source/MaterialXTest/MaterialXGenShader/GenShader.cpp @@ -11,9 +11,10 @@ #include #include -#include +#include #include #include +#include #ifdef MATERIALX_BUILD_GEN_GLSL #include diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp index 7e6348b143..cb1d2e00d3 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp @@ -12,9 +12,12 @@ #include #include +#include #include #include #include +#include +#include #ifdef MATERIALX_BUILD_OCIO #include diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h index 594af44083..869379f530 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include diff --git a/source/MaterialXView/CMakeLists.txt b/source/MaterialXView/CMakeLists.txt index 4ce4bb0f7f..f9f9eb256c 100644 --- a/source/MaterialXView/CMakeLists.txt +++ b/source/MaterialXView/CMakeLists.txt @@ -66,9 +66,9 @@ else() if(MSVC) add_compile_options(-wd4389) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wno-deprecated) + add_compile_options(-Wno-deprecated -Wno-unused-parameter) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - add_compile_options(-Wno-format-truncation -Wno-stringop-overflow -Wno-use-after-free) + add_compile_options(-Wno-format-truncation -Wno-stringop-overflow -Wno-use-after-free -Wno-unused-parameter) endif() # Disable NanoGUI compiler modifications for Clang diff --git a/source/MaterialXView/Editor.h b/source/MaterialXView/Editor.h index b99f1f160c..7d0d130359 100644 --- a/source/MaterialXView/Editor.h +++ b/source/MaterialXView/Editor.h @@ -6,7 +6,7 @@ #ifndef MATERIALXVIEW_EDITOR_H #define MATERIALXVIEW_EDITOR_H -#include +#include #include #include diff --git a/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp b/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp index 866d086561..e11cedf4d9 100644 --- a/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp +++ b/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace py = pybind11; namespace mx = MaterialX; diff --git a/source/PyMaterialX/PyMaterialXGenShader/CMakeLists.txt b/source/PyMaterialX/PyMaterialXGenShader/CMakeLists.txt index 5bee142c24..a3141e8bfd 100644 --- a/source/PyMaterialX/PyMaterialXGenShader/CMakeLists.txt +++ b/source/PyMaterialX/PyMaterialXGenShader/CMakeLists.txt @@ -21,6 +21,7 @@ target_link_libraries( PUBLIC PyMaterialXCore PyMaterialXFormat MaterialXGenShader + MaterialXGenHw PRIVATE ${CMAKE_DL_LIBS}) install(TARGETS PyMaterialXGenShader diff --git a/source/PyMaterialX/PyMaterialXGenShader/PyGenContext.cpp b/source/PyMaterialX/PyMaterialXGenShader/PyGenContext.cpp index ba58c6d6d6..e73090e964 100644 --- a/source/PyMaterialX/PyMaterialXGenShader/PyGenContext.cpp +++ b/source/PyMaterialX/PyMaterialXGenShader/PyGenContext.cpp @@ -6,7 +6,6 @@ #include #include -#include namespace py = pybind11; namespace mx = MaterialX; diff --git a/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp b/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp index 99a4ef82f5..e0cd36d3f9 100644 --- a/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp +++ b/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace py = pybind11; namespace mx = MaterialX;