diff --git a/.gitattributes b/.gitattributes index c13d6530868323dff84c3ecc89fd7c943f7eeb13..e5dbaf20ddab36a707ad6432f7d37424d44cf984 100644 --- a/.gitattributes +++ b/.gitattributes @@ -741,3 +741,60 @@ simready_assets/903/office_door.usd filter=lfs diff=lfs merge=lfs -text simready_assets/892/soap_basket.usd filter=lfs diff=lfs merge=lfs -text simready_assets/901/plastic_tote_2.92ftx2ft.usd filter=lfs diff=lfs merge=lfs -text simready_assets/902/plastic_tote_2.92ftx2ft_2.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/909/plastic_barrel_2.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/912/wooden_crate_1.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/904/exit_door.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/908/plastic_barrel_1.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/914/dock_shutter_14ftx14ft_open_version.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/913/dock_shutter_10ftx10ft_open_version.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/915/stack_nest_tote_1.7x1.25_ft.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/916/warehouse_pallet_1.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/917/warehouse_pallet_2.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/918/warehouse_pallet_3.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/919/warehouse_pallet_4.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/920/warehouse_pallet_5.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/921/warehouse_pallet_6.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/859/dryer_frontload_7kg.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/923/warehouse_pallet_8.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/925/warehouse_pallet_10.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/924/warehouse_pallet_9.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/926/warehouse_pallet_11.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/927/warehouse_pallet_12.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/928/warehouse_pallet_13.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/929/warehouse_pallet_14.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/922/warehouse_pallet_7.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/931/warehouse_pallet_16.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/930/warehouse_pallet_15.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/932/wooden_pallet_4_ft_X_4_ft_2.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/933/wooden_pallet_4_ft_X_3_33_ft.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/934/traffic_barrier_gate.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/937/wooden_crate_3.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/936/wooden_crate_2.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/938/wire_mesh_partition.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/935/tool_box.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/939/wire_mesh_partition_gate_6.93ftx6.77ft.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/942/hydraulic_dock_leveler_elevated.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/940/warehouse_rack_2.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/943/warehouse_electric_panel.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/941/hydraulic_dock_leveler.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/944/Metal_Storage_Locker_12in.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/945/Metal_storage_Locker_24in.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/946/office_desk.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/948/safety_bollard.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/949/high_bay_led_luminaire_3.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/947/emergency_exit_sign.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/950/high_bay_led_luminaire_2.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/955/Column_guard_1.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/953/office_chair.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/951/high_bay_led_luminaire_1.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/958/traffic_mirror_dome.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/957/fire_extinguisher.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/952/semi_trailer.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/959/Wall_panel_corrugated_metal.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/960/fire_alarm.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/961/fire_sprinkler.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/963/smoke_detector.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/962/large_first_aid_kit.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/954/forklift_1.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/964/scissor_lift.usd filter=lfs diff=lfs merge=lfs -text +simready_assets/967/iron_and_ironing_board.usd filter=lfs diff=lfs merge=lfs -text diff --git a/simready_assets/826/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/826/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7a8e7dfe5e244e7430a3b535ef1d656030bcc180 --- /dev/null +++ b/simready_assets/826/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-10T19:04:47", + "assets": [ + { + "asset": "outdoor_plant_7.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "6fdc32316dcc9af73acbb1637eb88e64a555f13aa57a610677701d783692c894", + "blake3": "9cb2de2e7f780a0fafa18f189c5c8c5a2d90de656311a1d277bbaad39ca4050f" + } +} diff --git a/simready_assets/826/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/826/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..88877fe31bc2d5a224abcdafdf8b121c91842456 --- /dev/null +++ b/simready_assets/826/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-10T19:04:47", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/826/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/826/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..da3683665c4486c5e359c2d3e92840298cdc5597 --- /dev/null +++ b/simready_assets/826/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,109 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/outdoor_plant_7/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/outdoor_plant_7.usd.png", + "size": 15362, + "hash": { + "sha256-flat-1mb": "f4e0a6c67ae00126be92f342d973046ff0c55fe7c9744a6d74e891f93c351ea8", + "sha256": "2adb7e0c05bb861fc73ac3371db6ec9f615a0403244c2f1a2b412d7e2376a0d2", + "blake3": "889fb35748d985422f8f2d609b819398f3a7ff9a11c5c4109f1656d53a679087" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_leaf_diffuse.jpg", + "size": 443043, + "hash": { + "sha256-flat-1mb": "7f00c4353f77102dc338dccc4eb433a353d3ca7f7bf20a88b565ab129125244d", + "sha256": "f122057cf87f30d6f08f197d190bfa4f01ebfd207914ef76fdf8ed84aa10ba7f", + "blake3": "701b5f7e812710abd536881c0c21e9ad8d5e4c80e6948d2a733d74f8acfe9d17" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_leaf_normal.jpg", + "size": 1537169, + "hash": { + "sha256-flat-1mb": "8e3366ff8d68185031bb84b9214616b4ba31f426b10c43536e19b31bee1d7463", + "sha256": "8e944a35e000dab071f7226f017e330c0756c7adb9ec7759af5929d0f73e023d", + "blake3": "17c0a399ecfaea553d5bffdc34acfc67e5aab38bfefdbc1243b109e64b04bc41", + "sha256-first1m": "28c2ea106a993edd1cd114917d2db731a34c58abbee154df1a38bc3ebb8784eb" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_soil_diffuse.jpg", + "size": 630871, + "hash": { + "sha256-flat-1mb": "65011932e693247aa6f1f5041dda05db0977b1f010ec8ae9e027ed18609b1c99", + "sha256": "62f3e6e6b1749b41555c898f4f42f4cc3d82b932a1c1e21e008c9910df34f06d", + "blake3": "8307e573ddd6702d29fbe463f086ba02c32aed563ea70927da97382e0eed06d7" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_soil_normal.jpg", + "size": 1162502, + "hash": { + "sha256-flat-1mb": "b5e4248e1c74873580fa30a182cec75d6a71f82d28c87d53d3ddbfa2f539a100", + "sha256": "fa6b8d4eb95ad7991000cdcb822a7b3f5efc17c528918c649b0a7c3aef5880cd", + "blake3": "7804c771474460387b736ab607ae34e83c30ae9188d5f00eeb468ed1a248c543", + "sha256-first1m": "d19269bda0c377479e778135eb11f60603d69178e5969334b9eed2a08f0b66a7" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_stem_diffuse.jpg", + "size": 256535, + "hash": { + "sha256-flat-1mb": "8d39c67716f85567dfbc32d7acbffd18ac1f925b68b6026d20c4b78338680520", + "sha256": "99b97e0e74a4a23dcfd2cb1a4c2d21696fbb508d5234c53b56ed698643a8e498", + "blake3": "41420af14af25bf289ea8ad3644c25343a777f7a3ba9b04132a5289736e62484" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_thumb.jpg", + "size": 208387, + "hash": { + "sha256-flat-1mb": "6df38171de52cb23deeaaa03987f1e565fe16909873d6087f9f87339adff62b8", + "sha256": "fd4be58405635b72fcfbe9143f4c0d522ea185e9e922fc4704788dc8a9bc6512", + "blake3": "2b8c3f81f02365345e6b9ada9a3ecbfa9aa0b50a5a8e664b54b2af867061f859" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_vase_diffuse.jpg", + "size": 530026, + "hash": { + "sha256-flat-1mb": "27640fe4900c6b9c25c3552b591231f8edb753a56d93acef45ace13e1cb17943", + "sha256": "54cdaacfd2a4a38996e0ca9e8738d410e5c77ef29651bc1a2fb5d6758cef226d", + "blake3": "3ac8f73541d1a4dc7069e53a8ef6cca83c55b1832599ce54e3f5f4d246cbf47b" + } + }, + { + "relative_path": "SubUSDs/textures/outdoor_plant_7_vase_normal.jpg", + "size": 1276439, + "hash": { + "sha256-flat-1mb": "7cc6ed6b1d808d65898b62b1bbebfa8abcde057f6a706a68351a90b126abab05", + "sha256": "6701cbd8464584be97385be6bbac2ac5786fe7e570bf9249ebd6d8b45f40b4e2", + "blake3": "fbc5fba4a5c2933c62f53df8adeb309fb48f41225f2e7c4fa0bcac060760041e", + "sha256-first1m": "ce99fae28ad137172b733254346cd06c23b0a056d047e9a4254503c6e6f27bad" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "outdoor_plant_7.usd", + "size": 4355777, + "hash": { + "sha256-flat-1mb": "ee1e98fd92d617318867e7956ac294289f615c5a053973aad5bb5adabc4b001f", + "sha256": "9d79580ec55763f2330ae34a0353435e8f0b073256f6b74f1bc8fcf90ce8871c", + "blake3": "b83ead2e0ac17997464ce778462eae2908ce88e3eeea4164d3bc48341b55221b", + "sha256-first1m": "e37dbeac7d1e985d390640f36c3758f5bdf215c8f95a268380848403a6762e4f" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/826/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/826/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..60b4a9b8b2d132508fa79e062ddb5b4a796e378d --- /dev/null +++ b/simready_assets/826/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "outdoor_plant_7.usd" + ] +} diff --git a/simready_assets/826/gltf/pbr.mdl b/simready_assets/826/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/826/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/859/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/859/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..ff2696b69378b03f34ee015a1c40874d4c349cc1 --- /dev/null +++ b/simready_assets/859/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-11T13:47:35", + "assets": [ + { + "asset": "dryer_frontload_7kg.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "aa108370a854c1e838beeb12291c2d33e10c397908ebd3c891ec5980351ba450", + "blake3": "ce2d3d14164e800b35591cb3ba42df439828249efed2bf0cbbac355b700f64bf" + } +} diff --git a/simready_assets/859/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/859/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7f3a8268ecdde2c6944ecdbd521de0d01c470fda --- /dev/null +++ b/simready_assets/859/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-11T13:47:35", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/859/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/859/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..9e58ba14767da8a817e8e7e44de844a378ce2eea --- /dev/null +++ b/simready_assets/859/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,54 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/dryer_frontload_7kg/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/dryer_frontload_7kg.usd.png", + "size": 16367, + "hash": { + "sha256-flat-1mb": "8e8171be6c697f7a994197b4e67903a8464db02e6e3765c3dcef06165dab565b", + "sha256": "25a354ab218f8356e2e816c191dab34a3c7a964904125b6623fbe6e4166d248f", + "blake3": "9b54401297c328905059b93ff4b74d42c61ba47ceee4c2f60810664dae79956d" + } + }, + { + "relative_path": "SubUSDs/textures/dryer_frontload_7kg_display_diffuse.png", + "size": 1503090, + "hash": { + "sha256-flat-1mb": "b7473c702bb022cdd8267e8aa9ac77e56b1c2c8bd63b0976d7ab27880ec0a894", + "sha256": "56818cf7f5acac6e5e9c6e69eda711f2388ce628e55b0820bc7a25b08a773739", + "blake3": "6395e90d3bef98141599dc4f6b90c588684fda84ef72c16816eb6e378ad7fcb7", + "sha256-first1m": "0f02b62ca1b838b09ebefa52995e3f5551789d38bc725b78763ef1b94e1109cc" + } + }, + { + "relative_path": "SubUSDs/textures/washing machine_door_glass_support_normal.jpg", + "size": 1384115, + "hash": { + "sha256-flat-1mb": "8f4696c95cb1dfc15270574996a0fb3f46c1aa18ecdb4544510664d7e3ab9384", + "sha256": "bcb55edff6c7b9d7add3062f7378d7e899f432a2ca6810548b583279ed32082a", + "blake3": "f14835db69205b4969095b144f0c59bc1b2189f022cf8bb75eef6020d7496b66", + "sha256-first1m": "f215482cae408bb5a20d767abddffb46e6b45c460d6e2bca72a5d065116cc59e" + } + }, + { + "relative_path": "dryer_frontload_7kg.usd", + "size": 101317634, + "hash": { + "sha256-flat-1mb": "4bc9bbd2d71128d4b44176ec44335472c6e4c6d6cfd4889e1e43ab4f6fdf0621", + "sha256": "b0a2e5232f1f972e2d7b1bd791319e224a9708cd3e0213e5871691426002df95", + "blake3": "65b3123b472004ffc980146f5e1eb37a7f9af91e7f152ba9f7364388d9cb0ec8", + "sha256-first1m": "f2390b8043ff6f2621827e6d9c0f0aced6dc90689cd0acb41c697964e2774ba3" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/859/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/859/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..fbebbab2a7db0d0591f21302e907d73789917ae5 --- /dev/null +++ b/simready_assets/859/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "dryer_frontload_7kg.usd" + ] +} diff --git a/simready_assets/859/dryer_frontload_7kg.usd b/simready_assets/859/dryer_frontload_7kg.usd new file mode 100644 index 0000000000000000000000000000000000000000..e33f7e486cef008209cb2fcd76a07be0000a53c8 --- /dev/null +++ b/simready_assets/859/dryer_frontload_7kg.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0a2e5232f1f972e2d7b1bd791319e224a9708cd3e0213e5871691426002df95 +size 101317634 diff --git a/simready_assets/859/gltf/pbr.mdl b/simready_assets/859/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/859/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/860/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/860/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..c1d2ba8f548200b79df52b4f7105b0dc8adf71fd --- /dev/null +++ b/simready_assets/860/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-13T22:22:04", + "assets": [ + { + "asset": "washing_machine_topload_8kg.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "d20a86ba127aeb5051c36fc470d12ac1d0d770cf4237da45e9315e4f7ec8c249", + "blake3": "d4ce75e8ff383675fa63dfd2cd2927264244c66ccc96c9935c57475c8aae460e" + } +} diff --git a/simready_assets/860/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/860/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7b2a21f66ef7c35594c8074698807bfc8b3d71d1 --- /dev/null +++ b/simready_assets/860/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-13T22:22:04", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/860/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/860/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..58c3275389c928342f5bcec5fb679faa8fe51958 --- /dev/null +++ b/simready_assets/860/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,52 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/washing_machine_topload_8kg/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/washing_machine_topload_8kg.usd.png", + "size": 11031, + "hash": { + "sha256-flat-1mb": "dc3ad23dcff5e3cec79e2db96729f2efb56806dd20361a7fb75974630a866c1d", + "sha256": "c5b57fbda049ba6922694e69fb96f920ee365e205a7a32430ef25832ad05b10d", + "blake3": "51442ebecba86be2de5d8fc75c70273ba624a15704190e367f224d8cc172e9e1" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "SubUSDs/textures/washing_machine_1_screen_panel_diffuse.png", + "size": 601544, + "hash": { + "sha256-flat-1mb": "c35476833ee7c33fad43764f71539f43a3edb4070a00baa7b4085d5e0afec3f2", + "sha256": "92e0b55d79104ecaee5e5f4d360b5a4f9c2deb23bffc455e0b58e77093b0b2e8", + "blake3": "e3f5254e6b3de803dea7ceac3eaa892738a8e01950f3e7c524440f6831a24d4d" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "washing_machine_topload_8kg.usd", + "size": 47041417, + "hash": { + "sha256-flat-1mb": "89c091eb415b95dfac486d3ef4287776a1b01e0f5a6e14a581df3d853d7430cb", + "sha256": "16e2f27acc228d7b2ab438bf2a7f9993f23bf39223a0ccb2edbea6db2f90679c", + "blake3": "e96378cdc12aee6d934323a4de97fae9b3c5b31adfcd08f1ebfeac3e99543db3", + "sha256-first1m": "26ff4e78dd0d5377b95c1ebd828d714775d58017d58d82d4811ac399a2e4c29f" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/860/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/860/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6109de726d1ca36e3cc165eb800106c9da887bb4 --- /dev/null +++ b/simready_assets/860/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "washing_machine_topload_8kg.usd" + ] +} diff --git a/simready_assets/860/SubUSDs/materials/pbr.mdl b/simready_assets/860/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/860/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/860/gltf/pbr.mdl b/simready_assets/860/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/860/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/861/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/861/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7788eb89d468c19845df10e81dcf287ac9bb4f64 --- /dev/null +++ b/simready_assets/861/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-11T21:13:24", + "assets": [ + { + "asset": "detergent_container_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "8067252607f8fd802a207d79c5b2d421dc6c6bdbb8d04ccd6148f0fb460d716c", + "blake3": "14105c0b2d5a1f939c7cabeb268c163bea836adcecb5545ca18af86f5f5baca5" + } +} diff --git a/simready_assets/861/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/861/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..f408fc9841fb4622f0b73150a74351328d59d809 --- /dev/null +++ b/simready_assets/861/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-11T21:13:24", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/861/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/861/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..cbc87b1090ca47a4d65e36c004d32714b8f4cce6 --- /dev/null +++ b/simready_assets/861/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/detergent_container_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/detergent_container_1.usd.png", + "size": 17685, + "hash": { + "sha256-flat-1mb": "ed7f368b6168855fa84044dd5dea9514640133848d8e579f204c04b2c4269448", + "sha256": "9bd76244979d262a20826bedbc57302d610a2acfad0d0121bdd29ea502c7f85f", + "blake3": "74302bd22ba6643e67e4fb79559548f7eb6a4207c422804816d3b94cc69a8cde" + } + }, + { + "relative_path": "SubUSDs/textures/detergent_container_1_diffuse.png", + "size": 1577878, + "hash": { + "sha256-flat-1mb": "f6e4f1212459c65f761555cd86929ff09929c7312b1acc46551faccd9362e13b", + "sha256": "4182beb85538167a02ee9c8425cec1ac78858a9dacff681ba349f0a9ccb0b833", + "blake3": "dc7b6aa0d16a36f5968d7e70e9d9acb233ea1533ca08003cff29fb4c264ad528", + "sha256-first1m": "4b0527b1b87a9067e9f1f96b93235f51b85cc6dfd4a3ccb8bb75d87904e39aac" + } + }, + { + "relative_path": "detergent_container_1.usd", + "size": 107189, + "hash": { + "sha256-flat-1mb": "db732a36ea7a228cc5dbc93a2ee5f50681d77e4154e81012697e38e53ef7b3c8", + "sha256": "19ba8db33d2c42a84e9a33b79728911da6b2b3deebedc0142ce1afb8a62d0bdf", + "blake3": "30c5e86f87ec39293a8bb60c07d57fd9db9b5e12539c4db758a304baba30faef" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/861/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/861/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..ce70850728375ec2b98673c0ba497f4f65a41ca2 --- /dev/null +++ b/simready_assets/861/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "detergent_container_1.usd" + ] +} diff --git a/simready_assets/861/gltf/pbr.mdl b/simready_assets/861/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/861/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/892/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/892/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..33098fa97ccd50b7d0858a6fcbadcd701961136d --- /dev/null +++ b/simready_assets/892/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T17:22:50", + "assets": [ + { + "asset": "soap_basket.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "41ca04ce942a99e1476b77f569a42579814f323765f61b4e5e453eaca000255d", + "blake3": "c3414103a335894f8b646b237103f29c130f56c55deeb186e7de6431b5e52128" + } +} diff --git a/simready_assets/892/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/892/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..d180b6abfba800a21c6450f1ea9223673bf1c77e --- /dev/null +++ b/simready_assets/892/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T17:22:50", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/892/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/892/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..e6c3e660c503c38c568113d04860bf3951de1760 --- /dev/null +++ b/simready_assets/892/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,63 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/soap_basket/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/soap_basket.usd.png", + "size": 39333, + "hash": { + "sha256-flat-1mb": "93efe3abb8ea255ec1b8b9db5374473de60a3705a9b2e6cdbbd6ab32a0cfba56", + "sha256": "3e44e375ceb9a07e14f75e82c3c6f37b58e9301dd1890c69b7c127ac2793ba1f", + "blake3": "c375c880452c91541fb7d82fd3fdd37999dce9a02cb5b90dc38d9994aa6e6e6c" + } + }, + { + "relative_path": "SubUSDs/textures/soap_basket_bottle_diffuse.jpg", + "size": 4170679, + "hash": { + "sha256-flat-1mb": "007da732dc88c5d3175ce4dd4a0c5cfe212eb0ecadc296a3472d9e95c3507bed", + "sha256": "a2e6edeb76395818f2600e139b497f70e2fd5eb66a911ad1e3700ca8a049fe26", + "blake3": "0a14fa8423cfe8f7a7d421d591be269c4975db4dcef3b8bff9b80c164b1fcf9e", + "sha256-first1m": "8faef83a5c5b148b869cf96a0799c401851f3bf9cdb1de26d6f561ec6cce5d12" + } + }, + { + "relative_path": "SubUSDs/textures/soap_basket_diffuse.jpg", + "size": 39491, + "hash": { + "sha256-flat-1mb": "22e1c94b50905f23f05dc7eaf1757fcc7e76f3e3a2c195faf4bb91d1faa738a7", + "sha256": "ff0ab29b7109e699a3b2c723726291c057004d753ac59f893b778d379451fb42", + "blake3": "2b9df70ca2e820c3464cfb2af848aceabe5b2ed0c323a30068be3718c77c4a4a" + } + }, + { + "relative_path": "SubUSDs/textures/soap_basket_gallen_diffuse.jpg", + "size": 3626438, + "hash": { + "sha256-flat-1mb": "d3bdde393eae1258308112e33d7917b49affc14574097bcba24c971d8f48d6bd", + "sha256": "04a40b15923ffcf5faf849e95a4849a2be07d15bfab38f9d3db591bbcb9cc867", + "blake3": "498fb1fa902afd69065615a8489ce82efb5024d1cf9167f429bd3ca4733f582a", + "sha256-first1m": "c440a078195510b99d87bc4f89d41549aa617bc45759da2fd645c36b5b46e5d9" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "soap_basket.usd", + "size": 37715822, + "hash": { + "sha256-flat-1mb": "e22184a7d19cc56f0285825444ae7b654d31d704d0a2da59f636a2b5cadf8799", + "sha256": "1d7f23c78872f56a3fde26633f64e7b99bff51788e4a5665bfe91007f747df68", + "blake3": "72730356f053351d88bf423d42349cbac2a48af95b97e2654b4807faca9e11ef", + "sha256-first1m": "00be7ad4e6f5c440fd02024a67e970e0b447d611ca2bf630773fcaee52fa220e" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/892/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/892/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..f440a54135b206e56996b586be31761c0fa3b322 --- /dev/null +++ b/simready_assets/892/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "soap_basket.usd" + ] +} diff --git a/simready_assets/892/gltf/pbr.mdl b/simready_assets/892/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/892/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/893/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/893/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..17d64a2ab7e0c27ee91d2f6e7585d6e3210f6b08 --- /dev/null +++ b/simready_assets/893/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T14:19:21", + "assets": [ + { + "asset": "fabric_softener_box.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "b6bfa3f6ccba188c37e97ff5adf72c8ed8910da0986c4b43faa6b3f99bdca3d8", + "blake3": "95e4e01625e02b50b29d4c6c1d4a0f7f57e9a4211786b5b9bef66c6150b871e3" + } +} diff --git a/simready_assets/893/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/893/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..1db983f5b76a13a64c8e7a17aad437c96a8a9d4c --- /dev/null +++ b/simready_assets/893/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T14:19:22", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/893/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/893/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..c1cb20cdb10dc4ec126292e745b58688a085a4ce --- /dev/null +++ b/simready_assets/893/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/fabric_softener_box/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/fabric_softener_box.usd.png", + "size": 36041, + "hash": { + "sha256-flat-1mb": "79bef8ec5cc9b0e159337546d6f7ec1895b6b9395d08d18c232ae8a6ab7de6ed", + "sha256": "0b7fc97b31e508f8c3166baf241afa3398a0cc0aa2cc5515706ca0f8aa1e8320", + "blake3": "2b469e2ac83a6de0007189be6aef8d189db96e579a2b5ffef04950d8d97f1147" + } + }, + { + "relative_path": "SubUSDs/textures/fabric_softener_box_1_diffuse.png", + "size": 2230051, + "hash": { + "sha256-flat-1mb": "a0513865177f0914410ef5c08d89a5fa262db2696ff6b3ba4f74ecbbf0f20d62", + "sha256": "9857e7f306cc11b143ae56d4093020917594a41dda8740a6b7370b130adb4e02", + "blake3": "bad90fa3ea9828c4282c8a9bc5958cd3747f66e5ad8e5028a913d6d6a347c3dd", + "sha256-first1m": "2955cf0eb13da0b901ecc49b0d25d18389f8de1f9b6b78127910fbdfe45ba4f1" + } + }, + { + "relative_path": "fabric_softener_box.usd", + "size": 12146, + "hash": { + "sha256-flat-1mb": "6346a22e11b8c956b10ca8e93d0aee399d510f7f8e721da0a0ab697ad203c360", + "sha256": "a8bf4c02c9bf2cf9070f68fe48098b9447dc625c47e8a1e88299500b99e019a7", + "blake3": "00659378b9a3f9bd7a4e598010a98f8a83317c1a7874e1a10d45f5380d722e2b" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/893/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/893/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..421524519aff47947841801ffeeb5c216f83dfa3 --- /dev/null +++ b/simready_assets/893/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "fabric_softener_box.usd" + ] +} diff --git a/simready_assets/893/gltf/pbr.mdl b/simready_assets/893/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/893/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/894/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/894/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..83d7685714124d79acf47eab933576773c6f550f --- /dev/null +++ b/simready_assets/894/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T15:24:25", + "assets": [ + { + "asset": "stain_remover_box.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "0b31724f99836c204573432248ac03b7ffed1ad6391dd1ae43c0ff1fde6d55f2", + "blake3": "1ad931d0c8c9230729768a2002eaf06053d0837657cb02921530898a3cfefd49" + } +} diff --git a/simready_assets/894/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/894/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7f32995f24ec530cc0441c0590d53187fe0f6691 --- /dev/null +++ b/simready_assets/894/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T15:24:25", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/894/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/894/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..af4d0a2429c80adc2d969f949c789d3594a982bc --- /dev/null +++ b/simready_assets/894/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/stain_remover_box/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/stain_remover_box.usd.png", + "size": 33781, + "hash": { + "sha256-flat-1mb": "a8d4bbb06c1e0a1f3196f70362f134eb2bafa41af3dda12301b71219052bd6f6", + "sha256": "455f446b9cfcc45ea8f402402774909592b1d26ba21c7334a65d69d02f11f079", + "blake3": "4b0ec4399e54816545745dab8253bba0c7afbad2b18c6cd15cb317c89b63c066" + } + }, + { + "relative_path": "SubUSDs/textures/stain_remover_box_1_diffuse.png", + "size": 2833083, + "hash": { + "sha256-flat-1mb": "7887812be1bb080067c0686d61cb9a8f2bde42a74331e38b3e9ac1d632cc4f0f", + "sha256": "bd0376edc42ee8324f209e486e3b2aa5ba926e60414d7c79e89671a6af780019", + "blake3": "9ba7eecac56ef1c19f2270e055c99ee0f6c90ec656a9fc2c434c3e1acd3a7489", + "sha256-first1m": "ac9661dc185ee1eebb4116f6aae7be89fd253a98ddba1cc1d7dba4c5354c700a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "stain_remover_box.usd", + "size": 19026, + "hash": { + "sha256-flat-1mb": "c2c53a6c4de97d69072e58bdbad8da384675e23e082e79560edbb66d9fb66763", + "sha256": "f0dd9d8d63199e690b9ed64e7cd9346d4cfbbe5752de746d7f82f4590d323740", + "blake3": "bab9d092b3464dbae9525359b1b72c240e5057fe8e06bf4c484b85b24353831d" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/894/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/894/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..b1c6db89481245a517def3981d28e7624ab41f74 --- /dev/null +++ b/simready_assets/894/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "stain_remover_box.usd" + ] +} diff --git a/simready_assets/894/gltf/pbr.mdl b/simready_assets/894/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/894/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/895/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/895/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..aa03a96b5a66124ca697dd93318f7f4ae15a13bb --- /dev/null +++ b/simready_assets/895/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T16:25:54", + "assets": [ + { + "asset": "laundry_pod_box.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "54dd24d33145aa724734cb83395ff77452efd37bf64465170717d9c4755207a6", + "blake3": "14a94e0045ad61c222cd9b95234c12933d34ccf8c97d243b5611d232a3e5ddba" + } +} diff --git a/simready_assets/895/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/895/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..4422c7c7110292de7110b25844c3a153f1f9ecf8 --- /dev/null +++ b/simready_assets/895/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-12T16:25:54", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/895/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/895/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..6d56a9df9e2bed412aee0525e341f738e341ca7d --- /dev/null +++ b/simready_assets/895/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/laundry_pod_box/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/laundry_pod_box.usd.png", + "size": 42806, + "hash": { + "sha256-flat-1mb": "5333d4afb358aba87addfe8db8920fbba549fa3098cb6ae5011f4f772430c044", + "sha256": "15ee1bf7c6c5598373f033e2e4e1eed89160721a142fe793ddcfb9dd3163105d", + "blake3": "4908eddf1272e7e5c72a4a04f6ff2181bdfd7ad21ab86e655474c42e0aeb7488" + } + }, + { + "relative_path": "SubUSDs/textures/laundry_pod_box_1_diffuse.png", + "size": 2698189, + "hash": { + "sha256-flat-1mb": "3a5a1144f89f0c36be6c500aa8238b1932e01a4325e2636d39346618666ca361", + "sha256": "b91596b565c27da9fa999da956a16fc3d914281a6fa1e17c231c65cb60a7d4c5", + "blake3": "a3452eb92c9da39934a813613f82fe782bedd97359625b3acb88f3b6ce320561", + "sha256-first1m": "e2222123f4ecd788edf2eeb12b4a3f062689de465e591111fb9e3f8a7943f76b" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "laundry_pod_box.usd", + "size": 36637, + "hash": { + "sha256-flat-1mb": "b241d40b42952c3ab29fb249e3114864047efb02d743da5c1e6ece6a9740be48", + "sha256": "56bc27222c7b4f8ca66ca07f758ebdd34bc7ac1a8a8769621d3ff9be5efa0367", + "blake3": "db5b3f23b1f01749c660497aed20a22ea36de2b899fcd733e00a07e675c9720f" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/895/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/895/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..99cf531128bcfaaa740e2e7e68a563dad0cc045c --- /dev/null +++ b/simready_assets/895/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "laundry_pod_box.usd" + ] +} diff --git a/simready_assets/895/gltf/pbr.mdl b/simready_assets/895/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/895/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/896/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/896/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..b7c240a84355e679f2f91e3acf222606e53ae61c --- /dev/null +++ b/simready_assets/896/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T16:22:15", + "assets": [ + { + "asset": "wet_floor_sign_board.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "a687c4f53467ddfea9255581e3c1755cb9615812ad6b9c7814684d18959985b3", + "blake3": "9af0d78fc666371f1a9718d7d7edda810cc4c30cca00ce1a7783ebeb99157bfd" + } +} diff --git a/simready_assets/896/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/896/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9b6f9032f4873e91c36fca46a013213e9d034978 --- /dev/null +++ b/simready_assets/896/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T16:22:15", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/896/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/896/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..036abed3586b85149f5711c2cbe3e49e0078fce2 --- /dev/null +++ b/simready_assets/896/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/wet_floor_sign_board/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wet_floor_sign_board.usd.png", + "size": 15595, + "hash": { + "sha256-flat-1mb": "2d6bde7eb23377919793f1b78ead193c9307282c9ce63687c059803131d81c1d", + "sha256": "557a5ae406bb80408112ff35e1b1f99c6f75a6bdcdeb910821544f2488e11e10", + "blake3": "9c50193b834bcb99bee21595bb5282676ae442e1b76e528cc333f4f9e0cf339f" + } + }, + { + "relative_path": "SubUSDs/textures/wet_floor_sign_board_diffuse.jpg", + "size": 399185, + "hash": { + "sha256-flat-1mb": "038edfcddbd0d161e8f4656020f2ae96a6d4d510dc29b721374ae5f0f274ab99", + "sha256": "6a7cec2c407fafaf3b508eb534777b75d97608404a89fa4290455e4f10d71613", + "blake3": "f1ea13dcc2766d6159eadddffab9bf1c079d70904f1c0f79fe2177da9e89af1a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "wet_floor_sign_board.usd", + "size": 1691653, + "hash": { + "sha256-flat-1mb": "0d102812dc368c3bfb9f756b8daf4a53a83fd0ac0c70bfa84225c15619f30105", + "sha256": "469737bb4b40aa4646968f8dd1177821e4b675ba117579f276dd98368ec5874d", + "blake3": "9ab5e4b633a697165b4f894930859cb42168af2a24c58fa9a89ace09df4e0103", + "sha256-first1m": "0e971ddda3ba157e99d8a00361e89314b815ab4bb18b240a9a89f1e9399bc17c" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/896/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/896/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..59edccc6f026269e953a0727e98c98adeae186dc --- /dev/null +++ b/simready_assets/896/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wet_floor_sign_board.usd" + ] +} diff --git a/simready_assets/896/gltf/pbr.mdl b/simready_assets/896/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/896/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/897/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/897/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..0afd7c6ac06590ccac649465da58f5f74167ad0f --- /dev/null +++ b/simready_assets/897/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T20:10:29", + "assets": [ + { + "asset": "traffic_cone.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "2f035115efd1ff228d9bb0a8e7fdefd4fd41b85764a070a407bd8e73b55892b8", + "blake3": "ea85159b73e901ce040db3726ab6f909ee7cd38c499ea1514cbd0c74b2fc3215" + } +} diff --git a/simready_assets/897/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/897/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9386f7740a7dedfd366bb3794a2d438548b2676c --- /dev/null +++ b/simready_assets/897/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T20:10:29", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/897/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/897/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..4f6ca9328b567e884bb360c5299ac08e96b08630 --- /dev/null +++ b/simready_assets/897/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/traffic_cone/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/traffic_cone.usd.png", + "size": 11750, + "hash": { + "sha256-flat-1mb": "d06b4c531a43579c6c8f6d802ef3f3b42eeae98da084860c8df1c79f1647f649", + "sha256": "4f2139e38496e7db3a4370ffac9c1275dfc306d8c0f555bd66c9d20cf7a1c463", + "blake3": "79762b6c46be23dabf38f763d0806770207df040f2d240064f6615e918a9c4e9" + } + }, + { + "relative_path": "SubUSDs/textures/traffic_cone_diffuse.png", + "size": 1600880, + "hash": { + "sha256-flat-1mb": "143cc1816c83148c4d6ec1bac31cd007401201c14a7e6f37dba4763e5edc9862", + "sha256": "93ac4bdff46d28a664f362842d9c5193e3cfa17e8a3b9ca330791527200a79cf", + "blake3": "fc5d48e77422420c31fd7c0cf714434174e3ce5d25119d5ce65cc4cb6c4ece0f", + "sha256-first1m": "d3c6251cf814a8c472bea3a24b5bd460d0db50aab7f08cffbd5d2496ba47150b" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "traffic_cone.usd", + "size": 166298, + "hash": { + "sha256-flat-1mb": "5a3ece10275659d2f56f6089f19c8d055acd873e71c4ad2781c55679a5be2454", + "sha256": "2f52d7ef002f9e1d71ee1d6ee703d1a14a85ba569ff2aef9b80f0ae882b7a1a3", + "blake3": "15f4efb05e9ca17bee9ccdae1e9b1b761dd5724ce00c34151b634ab0a414e348" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/897/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/897/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..479a221ad2352bc071b8cd0d1043e87e78833aa9 --- /dev/null +++ b/simready_assets/897/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "traffic_cone.usd" + ] +} diff --git a/simready_assets/897/gltf/pbr.mdl b/simready_assets/897/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/897/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/898/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/898/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..4582448f236a138b7ff253adbf4ca78296dfdaa7 --- /dev/null +++ b/simready_assets/898/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T22:29:56", + "assets": [ + { + "asset": "dock_shutter_10ftx10ft.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "b7ac7ce3a572241f66843bdd25129ff04621eedd8fc8ae1e937c7b6e424fbfa9", + "blake3": "a1d797ee2aa50929f1430130dfebef8a7386422eeb49dd68b7cacd2a07dca4b5" + } +} diff --git a/simready_assets/898/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/898/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..e36e327fcef3344db2eb580b84d96779651f4f5c --- /dev/null +++ b/simready_assets/898/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T22:29:56", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/898/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/898/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..a4e4984e32782fc726eb413752bd9ae559186f55 --- /dev/null +++ b/simready_assets/898/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,80 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/dock_shutter_10ftx10ft/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/dock_shutter_10ftx10ft.usd.png", + "size": 18279, + "hash": { + "sha256-flat-1mb": "c3f432afa9f729f1b0307fc0f5b9a84a37658cdc0033d62a4fb3984843983ba1", + "sha256": "9d9007d9dc2eff9594633bc1e7b38a0ff0cf4e75bc38b54ba2883410bdfc52cf", + "blake3": "0dbd3dbe92d509d43aebb363ab6ede500eab4258981945839306bd4fc3cfb81a" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_color.jpg", + "size": 911759, + "hash": { + "sha256-flat-1mb": "d4bcf3813f936f8bfc7caa806f93abaa23aa62b4933797c323679d0ea7f41519", + "sha256": "199718a151145b5aef4da4bfcacae08fe90921934c8611a72ab64b4785841a20", + "blake3": "c894064a5ce3e680e36b7eb8d831a7a7a112253f4ba17a08165f403620edf95a" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_metalness-dock_shutter_10ftx10ft_rail_roughness.png", + "size": 837966, + "hash": { + "sha256-flat-1mb": "8d22e42a0c0abe69ec1a1f5202d6150d88effb4c0adc02e5cea95ec5ddf4b307", + "sha256": "06ede3a564570d7187c94ed8225a2bcaa65a31b8fa8dbb6ee0e43007b80bbf69", + "blake3": "25d49c798e3ca533a77d11667760f989c1d03d15a283794c07edd0729621690d" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_normal.jpg", + "size": 343334, + "hash": { + "sha256-flat-1mb": "fbd378e76f7ead19cfa295547dcef0c0ed4dc47db0776aedd213897b2e6251c9", + "sha256": "25c913e64c7d2bfade44a9276fc0c98d6a7d114c0ca7b7ae16594691153f6f92", + "blake3": "e847474a2a14f10635e8c234c0b64ba693ae4b9531bf85d6ba0aeda5227abcad" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_metalness.png", + "size": 17023, + "hash": { + "sha256-flat-1mb": "22fec6b0f887ccc7186cf5200967bb23ad2b031194dd9c3f3903e80d58e68507", + "sha256": "78198096a4f01fc9ba3d0a337039c01749e6c372c57241f4f90989e72d334804", + "blake3": "acd4dea5f7afe8e28e0d5a950443bb6be141278e7c584859c1b6abb6df120148" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_normal.jpg", + "size": 1313392, + "hash": { + "sha256-flat-1mb": "0daf33fc8c5d01489c7d96f8d894b051b32175cf849b09974f25427ceca6e6ad", + "sha256": "79dfdb52230c00e1c24efcb07bfa4d1eda17186bca0e4766bc67499870dba255", + "blake3": "d7953d9e26eb768299f95d984e624406fcb70d869dd60d4dbefddb8fba0bf0c5", + "sha256-first1m": "96e0b3612a34f4647f2efbb7bc6364184779c1e4fe8d614222a2c38f5acee437" + } + }, + { + "relative_path": "dock_shutter_10ftx10ft.usd", + "size": 3517922, + "hash": { + "sha256-flat-1mb": "89e182d45d683b0eb0f6a87533da1d49b84b1835a09a8a50d740d8a31fba2f6d", + "sha256": "da03e0b8ee882b6658b0bc71060109dd29aed284111f857ba9fa421efe4ef248", + "blake3": "503013b96d6db9ddf1fc0d85c6f01c89b2eef2d62e82c07535a539303d7ff25c", + "sha256-first1m": "1b816e069eea48cd659c6b0556b30fe5296601ef568c121543175cd97bab89f2" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/898/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/898/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..1b0d949ab02d628a5f5bdf840be701256c971ad2 --- /dev/null +++ b/simready_assets/898/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "dock_shutter_10ftx10ft.usd" + ] +} diff --git a/simready_assets/898/gltf/pbr.mdl b/simready_assets/898/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/898/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/899/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/899/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..576c7a6d35cfc90adeb7f3bd9cae65f6b3aeb6ec --- /dev/null +++ b/simready_assets/899/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T22:35:57", + "assets": [ + { + "asset": "dock_shutter_14ftx14ft.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "99404d5b87272fbf12955eedaadeb4eb5a44edc4fe088b0936daafbd5be60988", + "blake3": "f09245b999ecb3722c22c23661411509e7ead1d94d0461eda25679b16442a79c" + } +} diff --git a/simready_assets/899/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/899/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..0641861a55cf9cdb4d367fd88cdc994834f895a1 --- /dev/null +++ b/simready_assets/899/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T22:35:57", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/899/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/899/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..fbf6bcc2e2c268dd7ea6ecc5b94d7358a59a1023 --- /dev/null +++ b/simready_assets/899/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/dock_shutter_14ftx14ft/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/dock_shutter_14ftx14ft.usd.png", + "size": 17054, + "hash": { + "sha256-flat-1mb": "a377699ba8ccb7582619399685d3bc23598909f5d271b295b9ee1c1830d8c143", + "sha256": "dfc74b114b43b99d0ed6cd59f48d2319df6f9b730d1b2ffe897bad5d32cdb433", + "blake3": "372e7a817a9c6686ab315bebb1dd11ec55d351b5cd7a61d6af6b353af118c5bb" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_metalness-dock_shutter_10ftx10ft_rail_roughness.png", + "size": 837966, + "hash": { + "sha256-flat-1mb": "8d22e42a0c0abe69ec1a1f5202d6150d88effb4c0adc02e5cea95ec5ddf4b307", + "sha256": "06ede3a564570d7187c94ed8225a2bcaa65a31b8fa8dbb6ee0e43007b80bbf69", + "blake3": "25d49c798e3ca533a77d11667760f989c1d03d15a283794c07edd0729621690d" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_normal.jpg", + "size": 343334, + "hash": { + "sha256-flat-1mb": "fbd378e76f7ead19cfa295547dcef0c0ed4dc47db0776aedd213897b2e6251c9", + "sha256": "25c913e64c7d2bfade44a9276fc0c98d6a7d114c0ca7b7ae16594691153f6f92", + "blake3": "e847474a2a14f10635e8c234c0b64ba693ae4b9531bf85d6ba0aeda5227abcad" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_metalness.png", + "size": 17023, + "hash": { + "sha256-flat-1mb": "22fec6b0f887ccc7186cf5200967bb23ad2b031194dd9c3f3903e80d58e68507", + "sha256": "78198096a4f01fc9ba3d0a337039c01749e6c372c57241f4f90989e72d334804", + "blake3": "acd4dea5f7afe8e28e0d5a950443bb6be141278e7c584859c1b6abb6df120148" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_normal.jpg", + "size": 1313392, + "hash": { + "sha256-flat-1mb": "0daf33fc8c5d01489c7d96f8d894b051b32175cf849b09974f25427ceca6e6ad", + "sha256": "79dfdb52230c00e1c24efcb07bfa4d1eda17186bca0e4766bc67499870dba255", + "blake3": "d7953d9e26eb768299f95d984e624406fcb70d869dd60d4dbefddb8fba0bf0c5", + "sha256-first1m": "96e0b3612a34f4647f2efbb7bc6364184779c1e4fe8d614222a2c38f5acee437" + } + }, + { + "relative_path": "dock_shutter_14ftx14ft.usd", + "size": 3518109, + "hash": { + "sha256-flat-1mb": "b29b19ec6d9497314b5c9b1652191364879e1d5f39283c60267791ff7be4f82d", + "sha256": "1d2b6f1de5b71c33c9aca5d23f4497757c582c58dcf3c8cd8fc8bbe208b60ec9", + "blake3": "4860ac1edcf2c669e661cfdb001a41ca355b0bbad9526672692aece4fe1274b2", + "sha256-first1m": "84124456acc987e3995759e63a1d7c3473d96c3ab759761a16607ab7c666fb6c" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/899/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/899/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..65e83e605f90fba3d9d5e5221411a9338366a2ff --- /dev/null +++ b/simready_assets/899/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "dock_shutter_14ftx14ft.usd" + ] +} diff --git a/simready_assets/899/gltf/pbr.mdl b/simready_assets/899/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/899/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/900/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/900/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..5084039690edfbe353f88e86dcb81e1bf2fb772c --- /dev/null +++ b/simready_assets/900/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T23:39:11", + "assets": [ + { + "asset": "plastic_tote_3ftx2ft.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "43ade4a87e118d5787b5c608cc5d5433e4095bdaeb207ed971bab67def4d5322", + "blake3": "b235f018b548913976df56f31bc94736956dcb2a569ecb2dd4c14fead2dc68de" + } +} diff --git a/simready_assets/900/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/900/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..2c16851a5873e424245b441318f8cce5812e4a8d --- /dev/null +++ b/simready_assets/900/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T23:39:11", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/900/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/900/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..d5c8728a3fa80393c716755e4b69bd6b483322d6 --- /dev/null +++ b/simready_assets/900/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/plastic_tote_3ftx2ft/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/plastic_tote_3ftx2ft.usd.png", + "size": 20703, + "hash": { + "sha256-flat-1mb": "35bf3926bfa755370fb1322b2266b71e3b87dd2bb7d6964197ccae1cfc2865f4", + "sha256": "909a8430a3b3e88633e77dffe32e41801608e057510b43bdc883fe29e96189f5", + "blake3": "9fbee80de29d0036377da7f8f68b27c70cd3f42bfe8e25620f92a68636aa699c" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "plastic_tote_3ftx2ft.usd", + "size": 2005090, + "hash": { + "sha256-flat-1mb": "e96715fb10c2a6ea0c227ddc02592425a8e0f738cad8e72a61b9632c89092b12", + "sha256": "951beca30ffb1e7253653f47e969ca374f43e580a602dd6fb49fd5ddc7280252", + "blake3": "747bee1b8d0e97a9a2e752b403dc3aeff122bbff52dafdbaaae4d9700b0c1f9f", + "sha256-first1m": "86658429c4cd2bb6be5a3f3041e65fe2fc5379ccae489cf1eb479ec7f9025fb9" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/900/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/900/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..7960a5a3fa07ee4fdb9ae8bf5a010e1000469f2c --- /dev/null +++ b/simready_assets/900/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "plastic_tote_3ftx2ft.usd" + ] +} diff --git a/simready_assets/900/gltf/pbr.mdl b/simready_assets/900/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/900/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/901/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/901/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..8bb6b3514e1ae2a9d23b5353cc6c7edec4011ebd --- /dev/null +++ b/simready_assets/901/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T23:40:27", + "assets": [ + { + "asset": "plastic_tote_2.92ftx2ft.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "2cf5a992e4ac5ca8f315cb3e8e6b75951e61ffb91221def0aeceea0e35c3eb59", + "blake3": "3632d2b77299b14e453b903e0e0a50d4bb3b48f8801138c494fd116b03a05cfc" + } +} diff --git a/simready_assets/901/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/901/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..88ec93604980371d00a70f442b3b1e29671f80d2 --- /dev/null +++ b/simready_assets/901/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T23:40:27", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/901/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/901/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..7faf5a2115d6b2e99d5ca19004f7a59f9f22cb36 --- /dev/null +++ b/simready_assets/901/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/plastic_tote_2_92ftx2ft/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/plastic_tote_2.92ftx2ft.usd.png", + "size": 26764, + "hash": { + "sha256-flat-1mb": "f7f9029872576e9e8f81829b7134222aba08e505ec150d653f308679d197b69e", + "sha256": "60e1230f923fc25bad38ca6f1a03ffa909c7c845857f9528816471beecb58eab", + "blake3": "6d54a8f3e6daec8b6a8283b87f8a397c8e1513329ba0f798579c213fa13e6282" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "plastic_tote_2.92ftx2ft.usd", + "size": 1355925, + "hash": { + "sha256-flat-1mb": "dee0e11b081cf7e03a30a34cc8e660ab42edfac70b41d830ec18242c0b166022", + "sha256": "c9df33d05a9f51449a7dbec6ced57dc7ae26a052288c5bc805b91a1c35a2746c", + "blake3": "048795af3ecece6cabe786a58eada097f06561e18c090a4cd8915ff1a3ef71ba", + "sha256-first1m": "edd0d6979805e4725f7ea876c4d437a26d26eaef548770e059820ba938e4a41a" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/901/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/901/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6d7e9fceded981d1070f811765ce2a66967b9ab2 --- /dev/null +++ b/simready_assets/901/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "plastic_tote_2.92ftx2ft.usd" + ] +} diff --git a/simready_assets/901/gltf/pbr.mdl b/simready_assets/901/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/901/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/902/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/902/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..520bda813487664477346825287976367698058a --- /dev/null +++ b/simready_assets/902/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T23:42:02", + "assets": [ + { + "asset": "plastic_tote_2.92ftx2ft_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "e78e9ec6ce6c70158b5e0c976d4e96e3c8da4d544db5444c52f5dc72f54f4ea3", + "blake3": "d8b165c04f495a64155ad55492ffd1f44b469fabd2221caff289c280408edda2" + } +} diff --git a/simready_assets/902/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/902/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..6bbe90ac00e810f135ebaf08d0bbf89f22a7d487 --- /dev/null +++ b/simready_assets/902/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-14T23:42:02", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/902/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/902/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..3164c22cac7cba130035306196907e6ac2eac3af --- /dev/null +++ b/simready_assets/902/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/plastic_tote_2_92ftx2ft_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/plastic_tote_2.92ftx2ft_2.usd.png", + "size": 20444, + "hash": { + "sha256-flat-1mb": "4cbad88986be7f0f545afb60d1d1cd83c7fb56d6570da6dd48a0e152cb149241", + "sha256": "ee967c378590f1588ef4f92f7009967ef4226d226285adf08ee65a9c106b22d3", + "blake3": "61682b64f0c45f1d0ef1d83353e5c380622b1523da5ef9e41d28f99753d10338" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_tote_2.92ftx2ft_2_plastic_normal.jpg", + "size": 331693, + "hash": { + "sha256-flat-1mb": "1a49482d4f3dda0711f0095318a8979f8754d5a6fedb5c3dc4a02860ef25c018", + "sha256": "ba911be8181c6df93dd19830f49dcaa09e73f09a3465125f081625ef9db45510", + "blake3": "025fdbfebaf8bd177a2081a7cd5a9a874f80871597c6fc1c75cdab486d6f55fd" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "plastic_tote_2.92ftx2ft_2.usd", + "size": 1859356, + "hash": { + "sha256-flat-1mb": "119a3712adacc5b3117c808fe35152bd48abc5d1a8fc81a910948c74da1c2fff", + "sha256": "89398996ee8131ce91542e25f603d962e6ef47d0ef0ab46e08e3340b14c2807d", + "blake3": "9268f8a5658d0c21ea4b9177c635d00a36c2a0d988d2d39165ac51ffb3b8b485", + "sha256-first1m": "0a9b20d32a320fc1a89b3b74d47083da82348b7088e8240be27ff7f0721dc0a4" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/902/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/902/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..05c51841206ee6ebdc5e265b9e23b9f25a144905 --- /dev/null +++ b/simready_assets/902/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "plastic_tote_2.92ftx2ft_2.usd" + ] +} diff --git a/simready_assets/902/gltf/pbr.mdl b/simready_assets/902/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/902/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/903/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/903/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..57601901662986a5b9579c5914319b586a119537 --- /dev/null +++ b/simready_assets/903/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T19:13:09", + "assets": [ + { + "asset": "office_door.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "be03ddba38cf9cec1c2e0ebe1deb914ef11ec6bf8fe384440ad91077917b9f59", + "blake3": "5f99c97b58048916a925b3307ad8331564e3422c83a91909fc88f93c1263a524" + } +} diff --git a/simready_assets/903/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/903/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..a18008ce264d5bb66a3ea9694c818d0da1c469e0 --- /dev/null +++ b/simready_assets/903/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T19:13:09", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/903/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/903/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..9078d72fd5c648a79d1431cc8ea974ec0d14857c --- /dev/null +++ b/simready_assets/903/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,63 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/office_door/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/office_door.usd.png", + "size": 15621, + "hash": { + "sha256-flat-1mb": "402e07d3a38d331db756165237f1f28cf0e852229bc29afe5dabd39c5d350708", + "sha256": "abc5d3fab5062a5ca99bbdd7eb47265e88533ea8bd2fd5158d9fd8a87bd31c46", + "blake3": "24fee4bdc99e7d3220410e290a4942e831406c96ffeafc49d5c1f8af25652259" + } + }, + { + "relative_path": "SubUSDs/textures/office_door_wood_diffuse.jpg", + "size": 17593557, + "hash": { + "sha256-flat-1mb": "4e8d72f46b798df22abe143b25a5820bdd2c9243ddc0e4dd4e1f0b607b7ced9f", + "sha256": "94e78f110cbc747676940ba00fdf646d7361cb1f701112e3be752d026bc2e6f4", + "blake3": "454ad08fdf35300d75056a9b7f26fec7d2ad939952564e634e6af255a9fa3636", + "sha256-first1m": "d57604d9324ca722c0d65ff1875b4d37b7dbd4b49741ecd0b233e6e059fa061b" + } + }, + { + "relative_path": "SubUSDs/textures/office_door_wood_normal.jpg", + "size": 30623636, + "hash": { + "sha256-flat-1mb": "b93bfcac308e4b517b9a519cd73af6f850a58508b98c5c19b8e5662828e30d73", + "sha256": "3950f11dbd4d87a1929f1345855cee882bd658fce35a37df8680d840cf8b0b49", + "blake3": "bd3e8fa7999f97262f4c6208da4cd2b78b2b5c8b14bcde16995ee450dfbd875b", + "sha256-first1m": "673d980532f4948e8127192b04f5af54c70175a44538600d85b81b4d3dde7bc9" + } + }, + { + "relative_path": "SubUSDs/textures/office_door_wood_roughness.png", + "size": 14214949, + "hash": { + "sha256-flat-1mb": "72d967973840d8888212ce0e5b6e26fc051023fdb36fe3efdae438d4b79ce759", + "sha256": "6ae2a4d6d6a9d5b1a5d73e4977d475ad6d880efe188868aa65fb39075553394d", + "blake3": "0844b1db9a817afb6cc35c317cf94a5b0897962b16887c8881d4cd7a45367c16", + "sha256-first1m": "f3c2c168d7b3669a705cdce018f629a2d35d2db03556aecedfb0d9ab79dfbc1d" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "office_door.usd", + "size": 374794, + "hash": { + "sha256-flat-1mb": "50971b57eb4a8c0566e5c11eb0b84ef74e47b73ad0c2e4ba4536c8899e4d25fd", + "sha256": "8411b8f082b277e26c4404f196f67ed298fb00ef6d34dd96d2e084f28f1a4226", + "blake3": "86753db0be62ea9e805a0439e593cf94e0f23517b53bc289f8b0c3d2da89aab0" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/903/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/903/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..254491047cd1d253d17bc675526b85297a9f04bb --- /dev/null +++ b/simready_assets/903/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "office_door.usd" + ] +} diff --git a/simready_assets/903/gltf/pbr.mdl b/simready_assets/903/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/903/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/904/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/904/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..91217b9d71e391e94327a2b218ea24ed7078581b --- /dev/null +++ b/simready_assets/904/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T17:06:16", + "assets": [ + { + "asset": "exit_door.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "9727a64e98a2299c7f113c33693f26a3a64e915785335d7668e3fec8c6661d91", + "blake3": "a316897f5c8fb95ea3257d3fcb69914634706a48e9ed2a9b645df99c8b3748e2" + } +} diff --git a/simready_assets/904/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/904/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..02e3331e031a57bc24e6b122807a4e1b895e5982 --- /dev/null +++ b/simready_assets/904/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T17:06:16", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/904/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/904/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..d31bacd9759cb71b3308e738529ab85110d71c06 --- /dev/null +++ b/simready_assets/904/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,33 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/exit_door/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/exit_door.usd.png", + "size": 9002, + "hash": { + "sha256-flat-1mb": "9b3e6d560748c978bcbce9a6f756f247cdb888ce6d3481e3dd5171222b42f325", + "sha256": "771a51f096598afc04ed4d190a3131cc7a66182609f3dfb36345b9fd39943c28", + "blake3": "4592419aa4eb5d07363f90d8f1bd825aac7f40d044d86eecbc81dbe4e7dab37d" + } + }, + { + "relative_path": "exit_door.usd", + "size": 1047759, + "hash": { + "sha256-flat-1mb": "d6043e83fc500d1b4ec15d1bc990c4ec6e8c65d7764e2b2ec8f7c80321615ef6", + "sha256": "0d853014276d87d480875c06a09b3bb5a09b4d4730278a4480f559c624cb96ea", + "blake3": "c0dedb8bd58303c80fc576a1f2c02e669dc240e59645500a5c2ccf6c192e0f5b" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/904/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/904/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..24cc56c5cb244ca72ac04fb01a54020c86a70637 --- /dev/null +++ b/simready_assets/904/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "exit_door.usd" + ] +} diff --git a/simready_assets/904/exit_door.usd b/simready_assets/904/exit_door.usd new file mode 100644 index 0000000000000000000000000000000000000000..b6491f6e6be353832178e88cbc735f2d0b650d67 --- /dev/null +++ b/simready_assets/904/exit_door.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c3b60e930f9f4d2b8dbd8956415b812a12a053a1acedd38a975b63dd3711135 +size 1049230 diff --git a/simready_assets/904/gltf/pbr.mdl b/simready_assets/904/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/904/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/905/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/905/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..3d8bf50a93ee8c544190996923dc7732bc8ee275 --- /dev/null +++ b/simready_assets/905/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:25:01", + "assets": [ + { + "asset": "parcel_box_3_5ft_x_2_75ft_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "2d0c073284d8cbd8b85c4dc21cd163e7777e40bbe2064d1d0dee6c05fbd777f1", + "blake3": "64034900bc065d5d8f0b1752d2f2f9b7ea27235f44aff7c242b76b876ec029f9" + } +} diff --git a/simready_assets/905/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/905/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..05144e4cc2e03f4ad5f2548a4581ee7a8bd2ec85 --- /dev/null +++ b/simready_assets/905/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:25:01", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/905/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/905/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..f14aa239c40c2bbd131498307287e8af68716f10 --- /dev/null +++ b/simready_assets/905/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/parcel_box_3_5ft_x_2_75ft_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/parcel_box_3_5ft_x_2_75ft_1.usd.png", + "size": 27150, + "hash": { + "sha256-flat-1mb": "27ea39dfd95a9a63039c14912255c126487d1f1d0ce2be1b7e5100a48227d8b2", + "sha256": "457b6351df36081667400bdac7408338ea702474c4196e195f82bca3ef16b472", + "blake3": "7401f9b1a238848d4e7589308d645f335402d0e50db4ed156a2e1ae32e404d87" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_3.5ft_x_2.75ft_1_diffuse.png", + "size": 2238582, + "hash": { + "sha256-flat-1mb": "ff05acd9914da72b099763eae4a011a1ab13fff63b5d5e8e05a0de9cd0da0ca6", + "sha256": "d68be8b141d003afcf33ce48538dac9de1c1327f691d93e10ea763be1c50fff1", + "blake3": "0753ecaf4f22404617d7a2c44393d2d32905a21006197e4c88fadea5ed1571cb", + "sha256-first1m": "82545ce216532a8e5c13a38b5014a536c5b2dc7dac8716311898acc1f6c718f9" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "parcel_box_3_5ft_x_2_75ft_1.usd", + "size": 32634, + "hash": { + "sha256-flat-1mb": "d3fd0a2eb12880a6e86e353def004e6bd79cfa86bbd42c3e7eae9b86a14d26b0", + "sha256": "9b035df305d5007db2f36795df418fe7df31b4ecc360fd0103fb960dfc317cc3", + "blake3": "981f6fbbdf69ee64c354052e41ef6265aa4955f77ff2b4fa7221794c804f00a1" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/905/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/905/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..7961f2c74e225a8a29b209e4107b55eca81ccc7f --- /dev/null +++ b/simready_assets/905/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "parcel_box_3_5ft_x_2_75ft_1.usd" + ] +} diff --git a/simready_assets/905/gltf/pbr.mdl b/simready_assets/905/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/905/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/906/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/906/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..1f997690d013288b9a611de5030d12bde5dcf9c4 --- /dev/null +++ b/simready_assets/906/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:42:15", + "assets": [ + { + "asset": "parcel_box_3.5ft_x_2.75ft_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "74d16cda81d5fa75d8c1eb16129e31e71ab1333f955daf0d26efa50a0ef80181", + "blake3": "6a48a8e422a95a74dfdafd502a7ef67bc373dffa1fbf43d6fe4787e3adec5d8d" + } +} diff --git a/simready_assets/906/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/906/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..77e452bcdc12d30ac591bdc9e306ec5c077d1f53 --- /dev/null +++ b/simready_assets/906/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:42:16", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/906/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/906/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..f0aaee26aced13cd75c85f81f1a677f22692a663 --- /dev/null +++ b/simready_assets/906/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/parcel_box_3_5ft_x_2_75ft_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/parcel_box_3.5ft_x_2.75ft_2.usd.png", + "size": 32690, + "hash": { + "sha256-flat-1mb": "e80d5f6218254fc46377ed67f25b3f0f51b6940c73146518d171f159232c965c", + "sha256": "a23b20adfa26a187b97b6781fc47830de9b4a0e21d0a539ae076ce5e1feebd74", + "blake3": "066ec42fde9a8561215b5143cf48761e623e0fb07f827e1bc6e68f5e91c1c444" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_3.5ft_x_2.75ft_2_diffuse.png", + "size": 2553828, + "hash": { + "sha256-flat-1mb": "e2146d7216a413ead4f97c2480c8fd6909798a7d22366650bd7c3a8b31b893f6", + "sha256": "67ec8d4a7a147d175e4d4bee1e1913659668a9f87fd4f9a49189d10bef3ebe9a", + "blake3": "62a8860766a24ce5a14b72670c3232eacc0777baa1bb68759758bbb699a94970", + "sha256-first1m": "b6c04e9772d16b286230c450ddf8362b2c4c42235e10fc583644b7c75785e385" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "parcel_box_3.5ft_x_2.75ft_2.usd", + "size": 32574, + "hash": { + "sha256-flat-1mb": "1e378eb22a86ecfa3a175a01a95e3e7b1d167fd3a876fc7641b7da03d6510a0b", + "sha256": "92352afa949c860ab9435a6549ea30328ac56f24188e9ead5b2e7eaeb40e803e", + "blake3": "0301e374f22e4f6dd27d61da62f0a5e340f4aef21d52d8d0a7885ee10ba7a825" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/906/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/906/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..d6fd38218446e59ecb5e48e79432f06ba3df6d4d --- /dev/null +++ b/simready_assets/906/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "parcel_box_3.5ft_x_2.75ft_2.usd" + ] +} diff --git a/simready_assets/906/gltf/pbr.mdl b/simready_assets/906/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/906/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/907/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/907/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9bde93499ac2fb289a8fa95d2711d1d215b31ed0 --- /dev/null +++ b/simready_assets/907/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:55:57", + "assets": [ + { + "asset": "parcel_box_3.5ft_x_2.75ft_3.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "5eff16551cff9976a0c6a04931913ec2bab14d5a354fc27790f27bd272140305", + "blake3": "d88698ddfd4c85aec89545ff50dabf692b4ebbe6cf77989d29fd4edcce9d0394" + } +} diff --git a/simready_assets/907/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/907/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..e36af39df38166c71edca36444fc7038dcd4fc5c --- /dev/null +++ b/simready_assets/907/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:55:57", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/907/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/907/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..7ce0c0d7f2ab3c473490a459a37189e5175135ab --- /dev/null +++ b/simready_assets/907/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/parcel_box_3_5ft_x_2_75ft_3/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/parcel_box_3.5ft_x_2.75ft_3.usd.png", + "size": 33885, + "hash": { + "sha256-flat-1mb": "f49a3644a75e95ceb872d8a7c5242e4385855f2a66fdd036092d4f97f36157ef", + "sha256": "91f65b3622e9d1e3dd1edaf445aa2d8190a4075cc60efb6589fcbe538c13fa86", + "blake3": "fa4608f60009bcf562d36a0990b079820968dcf16ffa55f1ce41ffef34745218" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_3.5ft_x_2.75ft_3_diffuse.png", + "size": 2669378, + "hash": { + "sha256-flat-1mb": "1afa75cd012a5c28b52449248e2edecdbdf4a19400e61040d0d339022d5ca5aa", + "sha256": "923a9e0cfc85634c2a147711442645a32ee08501004a7e0e71e8b6311bde8072", + "blake3": "3ffc68099008fabcee4bd422924345a9875fb709f0391df66eecf4bac9e966f1", + "sha256-first1m": "5ebd1effab4b298b5e8b924361927709af31a6076b30a2d80c803d0805c6f913" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "parcel_box_3.5ft_x_2.75ft_3.usd", + "size": 32558, + "hash": { + "sha256-flat-1mb": "a08c18733a37a5ff100f095b42c294429966052aaa672bc4f3967c777b60b51a", + "sha256": "7d512726ee65b7122486e31cd1904aa1b80bd1b10ebf0f7474c2fed7e5c4e8b6", + "blake3": "ec593dbca612a0ae1656986ba84ee9c883d2f4f604c14373f39865bbc92b2afe" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/907/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/907/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..bc391ab8804f1995cc6a392da2318b5245f92295 --- /dev/null +++ b/simready_assets/907/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "parcel_box_3.5ft_x_2.75ft_3.usd" + ] +} diff --git a/simready_assets/907/gltf/pbr.mdl b/simready_assets/907/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/907/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/908/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/908/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..b3e36b66b96abc975203119f26105524ef5fdf12 --- /dev/null +++ b/simready_assets/908/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:47:40", + "assets": [ + { + "asset": "plastic_barrel_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "12ec207f4ab31d884d032644ea61d6ee5ebe509c44cbeb6cd79b7977036c8bae", + "blake3": "ead132947f099c9c6af0a50c49a7fb0db5e8e340ddd1a5eae283a4032d96f4a0" + } +} diff --git a/simready_assets/908/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/908/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..646ff86b69ca55e70babe62b1afdaf4b04e8d033 --- /dev/null +++ b/simready_assets/908/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:47:40", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/908/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/908/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..722a799b4eedaa35ff252ee70477d2185abdb9ea --- /dev/null +++ b/simready_assets/908/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,94 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/plastic_barrel_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/plastic_barrel_1.usd.png", + "size": 18534, + "hash": { + "sha256-flat-1mb": "c51a6e50520691896958cbceacac5ce4540a1ca29bb56cf620007ff45f225621", + "sha256": "5e4febdef8b17cffe4020e28db9536cc4b4311fd83a661565875eb4282d05918", + "blake3": "9e585c8e25c512b8bfd27ba124a79a4a9d77975ad65f93c2efb70035610c2456" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_1_barrel_diffuse.jpg", + "size": 1845960, + "hash": { + "sha256-flat-1mb": "d5460ca526aab0c13d74df8ed74fd5a04c5be52e59af566900937b4a59da5484", + "sha256": "da2f5266dff63429e956c90c4c5e28b0c0dfa8667b06556b106dcb74c03c8105", + "blake3": "17b55247c0ccdf3a15d66671dce442a2e9492f2c5605fb42c24013d3c1570284", + "sha256-first1m": "589193a07c320c01a10abba6c915ebe0bd22c4f179f9662532e227d5df219107" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_1_barrel_normal.jpg", + "size": 5297317, + "hash": { + "sha256-flat-1mb": "25164e04f6eb671bd233b8b99356318868ec7b4530cf410e158cebbec5b55f2a", + "sha256": "a8b678ba6e17822dc586b085e05f60ec1a714ebdd0e0c4ead63c88799998e826", + "blake3": "d3f5b853f105125f1884ab33ed795aeb4d30196856e5c3d9b6efc3a109930816", + "sha256-first1m": "de116ccfcbad79b817c21a57752df2a937d917a2c59f3e1a38da37df94ed3d47" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_1_barrel_roughness.png", + "size": 3439522, + "hash": { + "sha256-flat-1mb": "45bf357be4bc839f3146f1827adcc8f296de81dc31d250b04f67d77b78623481", + "sha256": "fccc4fe724f13edc5b885460ce8960414051257f990f07b2829da7c4ad7badff", + "blake3": "1cd168dde74893877f4900208fa04cb8917c0cd4997dde3d443531251f55de2f", + "sha256-first1m": "46891203fd7bfb107f3f175ce079afc3943b4ebd9a8e5048525fba0885b661d3" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_1_lid_diffuse.jpg", + "size": 1313038, + "hash": { + "sha256-flat-1mb": "074ee5502142bf26ea5320467e5f28b6838d979dd28b65b2b38947a8d8ef869e", + "sha256": "5b512952e290126f495721262e72171d88252cb2af708dba1f1c78d690128ff3", + "blake3": "533f7561e437491ced9dc9f102936061277bbaa658607eea9a75518b827caa4c", + "sha256-first1m": "69725814e9a8f00127d38ecbf288af5934300c7ce5d3f8a8225bb37086120c95" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_1_lid_normal.jpg", + "size": 5816972, + "hash": { + "sha256-flat-1mb": "e3b4559d1e777d7c1a0f042700974e7f8b647c547ab5e116b6952a594208e84f", + "sha256": "264e25dc85bbde4d8b0a6e4ac6b3e96b67a96113ec3adbd7b2174d7418e879a6", + "blake3": "81fc25ff249ba18d300230f8114ba8009cc6aae08350aa3f1e150bca153dfd76", + "sha256-first1m": "31c3e3e46506ccc096a6ba6ae9088b9fa45efc30a9f962042c35a300e9764c60" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_1_lid_roughness.png", + "size": 3513170, + "hash": { + "sha256-flat-1mb": "deb5abc687ef528a8a95b2e5216bc9ee52b6230d650d74522d808ca4fbc3c70e", + "sha256": "6d54c5c766216b9eed01d7703a9ea36ccf3652aac039b127925b7237d36ac20d", + "blake3": "0872ca2285a629c8d2ca7a52479c0c0a84560bf4e599964b1d84e40ad4ee5b67", + "sha256-first1m": "b24cab5277dc4166caad9693cb8e859800aa9fef3998b36b7b445f4c5a04f73c" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "plastic_barrel_1.usd", + "size": 3584540, + "hash": { + "sha256-flat-1mb": "c3b079375cb8ab213062242c7a5a2e0aa563aed7dc454f377c4d91e3b6f8dc97", + "sha256": "8eb54587eed6e781a538cc7b81615fd56d02da1d594f8905c77def3dc1d92fa6", + "blake3": "ba79f1a4597d956decddedb1766ba56c35cede81c1e533593fb8a1d7c92302df", + "sha256-first1m": "4e57aff424a89bddb7d4ea84f976f1e40fcf0e23cf29d106da58e2e2a4c703c8" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/908/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/908/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..2995daf48be302fe1289d9ae4f4aaf61e6567d97 --- /dev/null +++ b/simready_assets/908/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "plastic_barrel_1.usd" + ] +} diff --git a/simready_assets/908/gltf/pbr.mdl b/simready_assets/908/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/908/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/908/plastic_barrel_1.usd b/simready_assets/908/plastic_barrel_1.usd new file mode 100644 index 0000000000000000000000000000000000000000..480e5ec2e9bdb1e890ab8977071b9a4233b5dc15 --- /dev/null +++ b/simready_assets/908/plastic_barrel_1.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8eb54587eed6e781a538cc7b81615fd56d02da1d594f8905c77def3dc1d92fa6 +size 3584540 diff --git a/simready_assets/909/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/909/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..df00d99370b32191dcee58706b91f4fad2c8c1a8 --- /dev/null +++ b/simready_assets/909/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:52:08", + "assets": [ + { + "asset": "plastic_barrel_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "675351a4ef8a5e580e5d9f2a85acfff44833e1d6fdf6099fad41504cfdce2023", + "blake3": "dce0b08683a236b3c025700d80b7586f4a26e5ce7ff30431c3e9ab00f616c73f" + } +} diff --git a/simready_assets/909/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/909/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..c9169846990a81a59864d9425ce5132078442549 --- /dev/null +++ b/simready_assets/909/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T21:52:08", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/909/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/909/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..6b81084b429c355875525541abf036c4de52888a --- /dev/null +++ b/simready_assets/909/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,84 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/plastic_barrel_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/plastic_barrel_2.usd.png", + "size": 13443, + "hash": { + "sha256-flat-1mb": "586542abeed3a179b4d18341b6c3f666d1d086a9e8556ec5714beb2dd554b5c4", + "sha256": "48642a6e04c8ad6f0a4bb41f4b783a603f84c8bce9b0bd81210b95cfa2ca02b7", + "blake3": "875995fc0c8e72327c53ab5c7c7278fdae9cf019d25a82038a039bd86a767bbc" + } + }, + { + "relative_path": "SubUSDs/textures/Plastic008_2K-JPG_Roughness.png", + "size": 1931844, + "hash": { + "sha256-flat-1mb": "2b4c60d82693546a5a8b7fdceaa6775639a0e229c6c643c794d018a70fbf9b1d", + "sha256": "916cad13c93254932f5325a237a297cece50acdbe5915c6bdd07e1c9bc77588f", + "blake3": "770ba2a6f9446859a9f08bb40d26234f40ef283121dbc46918c3ecac9227ec9e", + "sha256-first1m": "67bb8fd4d2c4589a2cf062ec7dc9be8223e9a29fa32f393f6bc6dcdc1cc8a877" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_2_handle_diffuse.jpg", + "size": 1313038, + "hash": { + "sha256-flat-1mb": "074ee5502142bf26ea5320467e5f28b6838d979dd28b65b2b38947a8d8ef869e", + "sha256": "5b512952e290126f495721262e72171d88252cb2af708dba1f1c78d690128ff3", + "blake3": "533f7561e437491ced9dc9f102936061277bbaa658607eea9a75518b827caa4c", + "sha256-first1m": "69725814e9a8f00127d38ecbf288af5934300c7ce5d3f8a8225bb37086120c95" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_2_handle_roughness.png", + "size": 3513170, + "hash": { + "sha256-flat-1mb": "deb5abc687ef528a8a95b2e5216bc9ee52b6230d650d74522d808ca4fbc3c70e", + "sha256": "6d54c5c766216b9eed01d7703a9ea36ccf3652aac039b127925b7237d36ac20d", + "blake3": "0872ca2285a629c8d2ca7a52479c0c0a84560bf4e599964b1d84e40ad4ee5b67", + "sha256-first1m": "b24cab5277dc4166caad9693cb8e859800aa9fef3998b36b7b445f4c5a04f73c" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_2_normal.jpg", + "size": 5420148, + "hash": { + "sha256-flat-1mb": "38e0bd0cadcf31944a07955b70deeb5534141d3107124c87ca87531b434c0242", + "sha256": "87ed42fd5f5b32e68e1b83284818781305c01693ed4e9df4289cbc6cce701ca8", + "blake3": "3b7cde9271f7a985a86f5f5b2de3f704a1ec24664bfa5d3d1205573b5ca63293", + "sha256-first1m": "ac23aa513db0f5dc1e66b65fb0468384d326cca412a08a0475d4058ffff4f0a5" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_barrel_2_roughness.png", + "size": 1931844, + "hash": { + "sha256-flat-1mb": "2b4c60d82693546a5a8b7fdceaa6775639a0e229c6c643c794d018a70fbf9b1d", + "sha256": "916cad13c93254932f5325a237a297cece50acdbe5915c6bdd07e1c9bc77588f", + "blake3": "770ba2a6f9446859a9f08bb40d26234f40ef283121dbc46918c3ecac9227ec9e", + "sha256-first1m": "67bb8fd4d2c4589a2cf062ec7dc9be8223e9a29fa32f393f6bc6dcdc1cc8a877" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "plastic_barrel_2.usd", + "size": 1321033, + "hash": { + "sha256-flat-1mb": "ddb6b35d3822c677ece16ca56cd8922d4688235f50c8075f67ec0707a9124ef8", + "sha256": "1a911eab4d6d1e883b52ae3104d70dc1942b58b06d1b5718a874ed0d5ffbe589", + "blake3": "024886b34e1c4ed84e55cd9f15d9b4a10726c783f4a0cc70817558f2f8be4eb6", + "sha256-first1m": "11d87a429d787a294068c7fd82bce10cc2b95492d2b3e76c082e29f43607298b" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/909/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/909/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..b7bcded33ae7d05464a209e740b0e05dac9e7bed --- /dev/null +++ b/simready_assets/909/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "plastic_barrel_2.usd" + ] +} diff --git a/simready_assets/909/gltf/pbr.mdl b/simready_assets/909/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/909/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/909/plastic_barrel_2.usd b/simready_assets/909/plastic_barrel_2.usd new file mode 100644 index 0000000000000000000000000000000000000000..b85b2533a4c9f9517a4f589f37ac4518bbe93f72 --- /dev/null +++ b/simready_assets/909/plastic_barrel_2.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4bac2afd4e0f078c94b805cbfb19e8e5409b615fabd0fc835ae8576dc10211be +size 1322052 diff --git a/simready_assets/910/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/910/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..75a422faf6e1891739637c3c510cf3210be1f168 --- /dev/null +++ b/simready_assets/910/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T22:36:54", + "assets": [ + { + "asset": "parcel_box_6.5ft_x_1.5ft_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "80254664f3c8bb4f219cc435df766c102e6b733a7983d65b4075525a3581d344", + "blake3": "9f2894fcf186c24776d5df059176aec9ca288d76930da522bd72164bd2f5e427" + } +} diff --git a/simready_assets/910/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/910/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..23e6df849753fedb8dc64275375d2d5c02258b85 --- /dev/null +++ b/simready_assets/910/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T22:36:54", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/910/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/910/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..5a714d0e6cf5c202102bccb682d7535b81375b58 --- /dev/null +++ b/simready_assets/910/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/parcel_box_6_5ft_x_1_5ft_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/parcel_box_6.5ft_x_1.5ft_1.usd.png", + "size": 19479, + "hash": { + "sha256-flat-1mb": "88543d357dbc3903afb20d8f6a0627112198cbba92518123ba0e6619e0cbd969", + "sha256": "54b55064bca9a4749ab1e48ab9cd5560ba784a3f75046d1424bc9d6c2b952687", + "blake3": "1dedc104a6b231678372660a9dfc28ae3af65305613913fab736e4eb56332136" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_6.5ft_x_1.5ft_1_diffuse.jpg", + "size": 1809838, + "hash": { + "sha256-flat-1mb": "3661ecbea96289574d5ee9467c938271d705b5a67ca694822aa8cfe905cc036e", + "sha256": "50fb4b71b295e61987177593d5fe4819e566ec3c053c8c243fab32de3cd7b401", + "blake3": "c19ad59b68d177565daf7d1f8ed31a60637b15fc2952173af65edd6fbfb95134", + "sha256-first1m": "f3948fd0d924883e9ebc790bd53523249ca7e79c0f7f847ffab017d9d823e6ab" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "parcel_box_6.5ft_x_1.5ft_1.usd", + "size": 32531, + "hash": { + "sha256-flat-1mb": "b2c03c266ba7d641f919a8c2ad674c2986f6ebb84a9d387fbd7bd8f32f725aa4", + "sha256": "d50be3e751684e3bd9d8b2ff0ee7546ecc693c77ea1ecc4a2251b0680920a6b4", + "blake3": "bdd192d11d737da0f2a25760519a04ee35c3754f2860c84d56bb7db4aae55721" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/910/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/910/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..3503ad37d0a577d10d396fc9c6804ead79aebcc9 --- /dev/null +++ b/simready_assets/910/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "parcel_box_6.5ft_x_1.5ft_1.usd" + ] +} diff --git a/simready_assets/910/gltf/pbr.mdl b/simready_assets/910/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/910/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/911/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/911/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..c292eac75b6260d62b04f607251460afee6c26a0 --- /dev/null +++ b/simready_assets/911/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T22:52:33", + "assets": [ + { + "asset": "parcel_box_6.5ft_x_1.5ft_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "e50c77b002cf740f07ef5625cb516c727011442b22b8126584997b158c4f9d5d", + "blake3": "78ad95dce2d356d47d993da1cacc5ceffc4ce9a68158eaeb31ee84506ed757e4" + } +} diff --git a/simready_assets/911/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/911/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..deb743d0ad254919b13b9430c42db45c8d8e6bec --- /dev/null +++ b/simready_assets/911/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-18T22:52:33", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/911/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/911/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..3e43c7635ca82d7edad7beaf1758ccb763be33bd --- /dev/null +++ b/simready_assets/911/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/parcel_box_6_5ft_x_1_5ft_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/parcel_box_6.5ft_x_1.5ft_2.usd.png", + "size": 21580, + "hash": { + "sha256-flat-1mb": "ffd79a1bbce3aa43b9f202d543a8a654e3daf4771b9a9e7a8247854ba3a1324d", + "sha256": "7471df21738d5762e481ce05bd37fcedd4e1609e0c4ae3dbba9bb2aa79424b6b", + "blake3": "17f52c1ec121dc4e0870ff8e98548b973409a10e49080d11fa4b543c6144289c" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_6.5ft_x_1.5ft_2_diffuse.png", + "size": 2480863, + "hash": { + "sha256-flat-1mb": "1472b8d1fcadc4a6b3943addb441d2b72985840779bd21f01fb748f7a53650a6", + "sha256": "7dff915f7d858caa051146776fa73677afd208aec82980fb4b800dea98186241", + "blake3": "1459296a85f5c0c90e94a92a97a232e1d0078b6248dbe24b401ef4ad29c6a44e", + "sha256-first1m": "9471e634056f8fe525c84a1e87a80aeb153e565c5c50edde04d0e7eef58f6359" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "parcel_box_6.5ft_x_1.5ft_2.usd", + "size": 32567, + "hash": { + "sha256-flat-1mb": "fe9207fcfc2d935e1baf02c6fa6fe18a82096fe1dc43e6dec2c587778b10c95c", + "sha256": "f914d268e1f90a3ed6eef8c4bdfcde5bac2f5f25d6dae8a9401cd52f3b9cc128", + "blake3": "886124a022eeec58238dde064875f6a61910023a53e45c7fa38d90dc5882d290" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/911/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/911/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..df84ca40f3a3da26e20f9503410d5ade05ca1362 --- /dev/null +++ b/simready_assets/911/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "parcel_box_6.5ft_x_1.5ft_2.usd" + ] +} diff --git a/simready_assets/911/gltf/pbr.mdl b/simready_assets/911/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/911/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/912/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/912/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..f746f10fdd6ff124bae1af60b6622f04710a27f6 --- /dev/null +++ b/simready_assets/912/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T19:34:38", + "assets": [ + { + "asset": "wooden_crate_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "d4b7a262bdbbe74632b533f747f31333e69efcd6bd656699ad57981a265b800e", + "blake3": "203a677880e0c3c9e0a9a82713afdd401b3b01eac2e4c61a6dd6edee0881af04" + } +} diff --git a/simready_assets/912/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/912/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..5beb8a39bf77fc6d5a6c47c98e9ef5a73f066301 --- /dev/null +++ b/simready_assets/912/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T19:34:39", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/912/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/912/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..27065fb04e2a5ee3c045e36b024a1ec0efef7517 --- /dev/null +++ b/simready_assets/912/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,73 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/wooden_crate_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wooden_crate_1.usd.png", + "size": 25502, + "hash": { + "sha256-flat-1mb": "9f62bcead32545aeabd8f05b9d8859f9c5836606205e7b97b5b9cb27b52791e5", + "sha256": "505f553457bf4ed6f1f4666dd8970bc27cd1a9526a9cea86e67907ad8cd4eb29", + "blake3": "ef54f9c7bb9ffc08a831c3ac9b5b6cd2b7e5a8d39322e95cbace53608f950929" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_1.jpg", + "size": 2532630, + "hash": { + "sha256-flat-1mb": "de3539807e8959db497f7d91dd5cedf2df7cd8ec57685a8221aed1a6601b8fe6", + "sha256": "617e4945cb475e0e0c6e4d4c30f1d1f4d3d66c11f77348c42312ed45c0dd2212", + "blake3": "e5be0a401f56a71824f05e479be273aba3d91dfd08f36690e9ed663f85eb8031", + "sha256-first1m": "af3040bbc782d555bdd86aacb99ebcfccd98720e993fbd159f60d6bbaf1b8a51" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_1_woo_roughness.png", + "size": 3502077, + "hash": { + "sha256-flat-1mb": "d3245b8e15639954d84ad49751f964fdbd38809ae09d567513d5a6cc45e226ef", + "sha256": "0b480506a50855793a473257dead3a7d48e5c84ff06840480ab610f223915d42", + "blake3": "bfc6e335e28ce771f4645c55e8bf44d045769479476772dda270f10b8e33aabb", + "sha256-first1m": "3114cad9b085ff3d0b05b3bfc55cfed12a9492bad0c93caca6bb112a66cba574" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_1_wood_diffuse.png", + "size": 6596393, + "hash": { + "sha256-flat-1mb": "43fdf46cbe44a40626987f50f9a33b342e24b9fe337f4024c175994e5b21b895", + "sha256": "9f1b4ef313a958778b362823f58cd3a6b5726fb98dd427d2e32ee7f272b284b4", + "blake3": "6c840fed60df5e30eeabddfdb9490002f82c5c53dd2e7aa9a3d130a24663343d", + "sha256-first1m": "3303e8ca0608b7292d8cbd35d93c587d499ff787a7401c2c733b60d4762b558a" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_1_wood_normal.png", + "size": 22751297, + "hash": { + "sha256-flat-1mb": "b8814f101aa12ac5ae4a11be3ea9fe354fa377c0b73668f92077564961f96fe3", + "sha256": "46d7304acf86f7e639cfc56a161b25d6eec1f9bf0f6512adf890208407165a4f", + "blake3": "62095882c3ac0caadef59dd8edd5d4422c987d2a62a602eabd482d4fa70c314e", + "sha256-first1m": "8716e64ceb3fda34a45dab10d0da76f09ec0040be807bf4c871f2f2173a1a763" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "wooden_crate_1.usd", + "size": 567050, + "hash": { + "sha256-flat-1mb": "0b1406a4acd650e8e21cf617da1969d80bac9e0f1f01967e0f51facd360ad7d3", + "sha256": "92dd598d77fdc6dcc21b677f35fcd7de2fb2b186bf18cde25beb4d56f166394f", + "blake3": "01bbba1a825957c158197d5ad3150e6d57298546f8f7867736e281f20681c63d" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/912/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/912/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..2d048265bddf79059f559807d2c0dcf7fa4d5581 --- /dev/null +++ b/simready_assets/912/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wooden_crate_1.usd" + ] +} diff --git a/simready_assets/912/gltf/pbr.mdl b/simready_assets/912/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/912/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/912/wooden_crate_1.usd b/simready_assets/912/wooden_crate_1.usd new file mode 100644 index 0000000000000000000000000000000000000000..70c49cd248e07d9c29c990483a544324fde45483 --- /dev/null +++ b/simready_assets/912/wooden_crate_1.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4df09a6665cf4dc1a13e5568abca53387e6ef261d551eed0564462220766a076 +size 567939 diff --git a/simready_assets/913/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/913/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..39ec2cc1389df2120228b24d048683f4ae2e73a6 --- /dev/null +++ b/simready_assets/913/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T13:33:41", + "assets": [ + { + "asset": "dock_shutter_10ftx10ft_open_version.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "61a836e9f0145c9e08cb12519c6b5eb121e1fff546d719de0cbb81d9b974a07d", + "blake3": "bcc133ddf520dbe854a6cab81da3b7c94f1dec56e741d0f60fd813f2ca5569ee" + } +} diff --git a/simready_assets/913/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/913/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..bb7c3deb476befa94a4ffe93171b56c593a560ca --- /dev/null +++ b/simready_assets/913/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T13:33:41", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/913/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/913/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..44e2e0f60ffb807b52fbb894f4392dd4d2b2bb62 --- /dev/null +++ b/simready_assets/913/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,80 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/dock_shutter_10ftx10ft_open_version/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/dock_shutter_10ftx10ft_open_version.usd.png", + "size": 9194, + "hash": { + "sha256-flat-1mb": "b675abb596faf179d5afe0a8ab7a19a6f9d65e3a9b991fa31edb2294038203c4", + "sha256": "2ddef0caf6655b6c762acd9ededb0361768e2a1500c13a677541e4290b27b05a", + "blake3": "626f720ce36dd114ac41b75935e3f29605796044e0d82704046f0d810f845e64" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_color.jpg", + "size": 911759, + "hash": { + "sha256-flat-1mb": "d4bcf3813f936f8bfc7caa806f93abaa23aa62b4933797c323679d0ea7f41519", + "sha256": "199718a151145b5aef4da4bfcacae08fe90921934c8611a72ab64b4785841a20", + "blake3": "c894064a5ce3e680e36b7eb8d831a7a7a112253f4ba17a08165f403620edf95a" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_metalness-dock_shutter_10ftx10ft_rail_roughness.png", + "size": 837966, + "hash": { + "sha256-flat-1mb": "8d22e42a0c0abe69ec1a1f5202d6150d88effb4c0adc02e5cea95ec5ddf4b307", + "sha256": "06ede3a564570d7187c94ed8225a2bcaa65a31b8fa8dbb6ee0e43007b80bbf69", + "blake3": "25d49c798e3ca533a77d11667760f989c1d03d15a283794c07edd0729621690d" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_normal.jpg", + "size": 343334, + "hash": { + "sha256-flat-1mb": "fbd378e76f7ead19cfa295547dcef0c0ed4dc47db0776aedd213897b2e6251c9", + "sha256": "25c913e64c7d2bfade44a9276fc0c98d6a7d114c0ca7b7ae16594691153f6f92", + "blake3": "e847474a2a14f10635e8c234c0b64ba693ae4b9531bf85d6ba0aeda5227abcad" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_metalness.png", + "size": 17023, + "hash": { + "sha256-flat-1mb": "22fec6b0f887ccc7186cf5200967bb23ad2b031194dd9c3f3903e80d58e68507", + "sha256": "78198096a4f01fc9ba3d0a337039c01749e6c372c57241f4f90989e72d334804", + "blake3": "acd4dea5f7afe8e28e0d5a950443bb6be141278e7c584859c1b6abb6df120148" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_normal.jpg", + "size": 1313392, + "hash": { + "sha256-flat-1mb": "0daf33fc8c5d01489c7d96f8d894b051b32175cf849b09974f25427ceca6e6ad", + "sha256": "79dfdb52230c00e1c24efcb07bfa4d1eda17186bca0e4766bc67499870dba255", + "blake3": "d7953d9e26eb768299f95d984e624406fcb70d869dd60d4dbefddb8fba0bf0c5", + "sha256-first1m": "96e0b3612a34f4647f2efbb7bc6364184779c1e4fe8d614222a2c38f5acee437" + } + }, + { + "relative_path": "dock_shutter_10ftx10ft_open_version.usd", + "size": 3029156, + "hash": { + "sha256-flat-1mb": "d75f04569a2b388735b8579df35237af71a9c4d0dd6a389cc13fd117c88d537f", + "sha256": "b07d8a5541a1a54bc1841c67aca48086f05e4a31b257f553b3c427b9fbe165f1", + "blake3": "e46f153b011661f3f4fa7a1b91761537438f65fb087c681982b47d48cc3e8ea7", + "sha256-first1m": "ff4a7b97ad5749f934e037de424500ab564980fd64216d3287e8554429b2ead2" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/913/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/913/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..bf9dc733914caaa30000b04b0143f39a8275a178 --- /dev/null +++ b/simready_assets/913/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "dock_shutter_10ftx10ft_open_version.usd" + ] +} diff --git a/simready_assets/913/dock_shutter_10ftx10ft_open_version.usd b/simready_assets/913/dock_shutter_10ftx10ft_open_version.usd new file mode 100644 index 0000000000000000000000000000000000000000..35a2f1fc6961c573bbb69bcb17705800cd7085a7 --- /dev/null +++ b/simready_assets/913/dock_shutter_10ftx10ft_open_version.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b07d8a5541a1a54bc1841c67aca48086f05e4a31b257f553b3c427b9fbe165f1 +size 3029156 diff --git a/simready_assets/913/gltf/pbr.mdl b/simready_assets/913/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/913/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/914/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/914/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..4abf694d3da0fbab0f6ea6fecab81cc8e19896d4 --- /dev/null +++ b/simready_assets/914/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T13:44:50", + "assets": [ + { + "asset": "dock_shutter_14ftx14ft_open_version.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "b0f7e8cde233bde2550d2b792e63a16fc0ded966753db73bcd6c9f3df882c3d9", + "blake3": "13549b441179e8f599beaab2b7ff7c9776dbc7d6f5090ebd8282c4a5be80b585" + } +} diff --git a/simready_assets/914/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/914/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7c51cd6ab912e12249d178d45a874183e40da858 --- /dev/null +++ b/simready_assets/914/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T13:44:50", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/914/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/914/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..bef10fc1026455de03e0896d3760979f51af2b70 --- /dev/null +++ b/simready_assets/914/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/dock_shutter_14ftx14ft_open_version/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/dock_shutter_14ftx14ft_open_version.usd.png", + "size": 7895, + "hash": { + "sha256-flat-1mb": "6da5a7e20b031b5164d0d8affa752dfb02122e2ab2ed8f8dc6ee7df6b21e0ac0", + "sha256": "5ec86b9d099a743caeece589ba98881feab8d14330a279aae76202bb1db05362", + "blake3": "586d3fd97dfff69c966b92cf7146da2e29dfbe8447a9ffe11caa801216f2220d" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_metalness-dock_shutter_10ftx10ft_rail_roughness.png", + "size": 837966, + "hash": { + "sha256-flat-1mb": "8d22e42a0c0abe69ec1a1f5202d6150d88effb4c0adc02e5cea95ec5ddf4b307", + "sha256": "06ede3a564570d7187c94ed8225a2bcaa65a31b8fa8dbb6ee0e43007b80bbf69", + "blake3": "25d49c798e3ca533a77d11667760f989c1d03d15a283794c07edd0729621690d" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_rail_normal.jpg", + "size": 343334, + "hash": { + "sha256-flat-1mb": "fbd378e76f7ead19cfa295547dcef0c0ed4dc47db0776aedd213897b2e6251c9", + "sha256": "25c913e64c7d2bfade44a9276fc0c98d6a7d114c0ca7b7ae16594691153f6f92", + "blake3": "e847474a2a14f10635e8c234c0b64ba693ae4b9531bf85d6ba0aeda5227abcad" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_metalness.png", + "size": 17023, + "hash": { + "sha256-flat-1mb": "22fec6b0f887ccc7186cf5200967bb23ad2b031194dd9c3f3903e80d58e68507", + "sha256": "78198096a4f01fc9ba3d0a337039c01749e6c372c57241f4f90989e72d334804", + "blake3": "acd4dea5f7afe8e28e0d5a950443bb6be141278e7c584859c1b6abb6df120148" + } + }, + { + "relative_path": "SubUSDs/textures/dock_shutter_10ftx10ft_slat_normal.jpg", + "size": 1313392, + "hash": { + "sha256-flat-1mb": "0daf33fc8c5d01489c7d96f8d894b051b32175cf849b09974f25427ceca6e6ad", + "sha256": "79dfdb52230c00e1c24efcb07bfa4d1eda17186bca0e4766bc67499870dba255", + "blake3": "d7953d9e26eb768299f95d984e624406fcb70d869dd60d4dbefddb8fba0bf0c5", + "sha256-first1m": "96e0b3612a34f4647f2efbb7bc6364184779c1e4fe8d614222a2c38f5acee437" + } + }, + { + "relative_path": "dock_shutter_14ftx14ft_open_version.usd", + "size": 3003489, + "hash": { + "sha256-flat-1mb": "f7836555d548c4246a8d5045cf83f8e7a334efae1a3e496ab9ed45e2ae3553db", + "sha256": "16d83a9043d0dd5b6afdb3d9bd4b12ea08cc3a3453e1a883dbd189499dcd9f96", + "blake3": "7683baf8b394460196651f3852134b770903e119b2c9ff5ea2e44e9f40e55994", + "sha256-first1m": "99b694c68a5f927b8e1cf1f23bbc5398561c0eab302f4870decb4de2fa74f710" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/914/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/914/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..1909d0a35fbba6a187c6b710ee15c957e6802cf9 --- /dev/null +++ b/simready_assets/914/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "dock_shutter_14ftx14ft_open_version.usd" + ] +} diff --git a/simready_assets/914/dock_shutter_14ftx14ft_open_version.usd b/simready_assets/914/dock_shutter_14ftx14ft_open_version.usd new file mode 100644 index 0000000000000000000000000000000000000000..64c35c09fa7d731b3f851401617101b2ab7d456f --- /dev/null +++ b/simready_assets/914/dock_shutter_14ftx14ft_open_version.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16d83a9043d0dd5b6afdb3d9bd4b12ea08cc3a3453e1a883dbd189499dcd9f96 +size 3003489 diff --git a/simready_assets/914/gltf/pbr.mdl b/simready_assets/914/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/914/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/915/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/915/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..8046131e973d25f4c573aa581d4684352d04cd26 --- /dev/null +++ b/simready_assets/915/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:26:27", + "assets": [ + { + "asset": "stack_nest_tote_1.7x1.25_ft.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "fef50254ebe3a95311c57d07dc066404c9558bc9e72d18a07374352434540bd7", + "blake3": "62eb37609527f1356a5acdf8bb6695e9a492832f8d60a38c627936ba30486ed1" + } +} diff --git a/simready_assets/915/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/915/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..4e1b25f238dec5f91612329eca1df5c4bbfcc4bc --- /dev/null +++ b/simready_assets/915/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:26:27", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/915/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/915/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..10fce21e8f3091d058886f04466142f60829a9b9 --- /dev/null +++ b/simready_assets/915/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,54 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/stack_nest_tote_1_7x1_25_ft/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/stack_nest_tote_1.7x1.25_ft.usd.png", + "size": 19765, + "hash": { + "sha256-flat-1mb": "face3f77e0d66c0e3a081245b49b058b270c1d447b23b73f533ad851a8c6c329", + "sha256": "7cbb8d68a2aa6b2b4096139e346fc33ef0be75b257fec05a0ab0d70202fa14f0", + "blake3": "7a649ba91bcc3bb4100e25e0d9fea515f87f446d35d848b6d0903468bd9fff92" + } + }, + { + "relative_path": "SubUSDs/textures/stack_nest_tote_1_lid_normal.jpg", + "size": 5297317, + "hash": { + "sha256-flat-1mb": "25164e04f6eb671bd233b8b99356318868ec7b4530cf410e158cebbec5b55f2a", + "sha256": "a8b678ba6e17822dc586b085e05f60ec1a714ebdd0e0c4ead63c88799998e826", + "blake3": "d3f5b853f105125f1884ab33ed795aeb4d30196856e5c3d9b6efc3a109930816", + "sha256-first1m": "de116ccfcbad79b817c21a57752df2a937d917a2c59f3e1a38da37df94ed3d47" + } + }, + { + "relative_path": "SubUSDs/textures/stack_nest_tote_1_lid_roughness.png", + "size": 3439522, + "hash": { + "sha256-flat-1mb": "45bf357be4bc839f3146f1827adcc8f296de81dc31d250b04f67d77b78623481", + "sha256": "fccc4fe724f13edc5b885460ce8960414051257f990f07b2829da7c4ad7badff", + "blake3": "1cd168dde74893877f4900208fa04cb8917c0cd4997dde3d443531251f55de2f", + "sha256-first1m": "46891203fd7bfb107f3f175ce079afc3943b4ebd9a8e5048525fba0885b661d3" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "stack_nest_tote_1.7x1.25_ft.usd", + "size": 2764075, + "hash": { + "sha256-flat-1mb": "454d5e62d1a62c4f24bd4b922f241bbf1613984959a8a74c4a18c23d0a2ce38b", + "sha256": "00b6bbde5f62db184a36aee0920a05ccce1484050ea5d2d4dcd98ad3c4e24e26", + "blake3": "f4e8f5e743c54512a855182f5d96e17c3198a5053921898fe7c88f4648ba8521", + "sha256-first1m": "e1b8f793f2c0ec319ebbd38e8bf43b15785fe7663067969acc7d7ab4dd5ba32d" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/915/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/915/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..09beb63470f121be0a1719d3e3ffc55d14551dc3 --- /dev/null +++ b/simready_assets/915/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "stack_nest_tote_1.7x1.25_ft.usd" + ] +} diff --git a/simready_assets/915/gltf/pbr.mdl b/simready_assets/915/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/915/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/915/stack_nest_tote_1.7x1.25_ft.usd b/simready_assets/915/stack_nest_tote_1.7x1.25_ft.usd new file mode 100644 index 0000000000000000000000000000000000000000..1a9a9b03b9c860d317c2b63224e1e88ddc44b7a9 --- /dev/null +++ b/simready_assets/915/stack_nest_tote_1.7x1.25_ft.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00b6bbde5f62db184a36aee0920a05ccce1484050ea5d2d4dcd98ad3c4e24e26 +size 2764075 diff --git a/simready_assets/916/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/916/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..30ad0d9a9d405b90cc4e68547e7faf0ffcc07187 --- /dev/null +++ b/simready_assets/916/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:49:31", + "assets": [ + { + "asset": "warehouse_pallet_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "a6e9af85fa4dec7890e62d39412f283e3225e17bc286d813395c234220e1dc8d", + "blake3": "0cce6563515c1c900177b07133d80791411f3fc992dfe3cfa92a6cfce13389c1" + } +} diff --git a/simready_assets/916/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/916/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..b22722d73dc80c01829bc788f8e145dc654f4831 --- /dev/null +++ b/simready_assets/916/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:49:31", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/916/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/916/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..0ba6ed4a1ef69d205b4a4bb5d083d69483717545 --- /dev/null +++ b/simready_assets/916/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_1.usd.png", + "size": 19072, + "hash": { + "sha256-flat-1mb": "185dabad89eb52c496d565e3870815bfd4990fc7a363dbe9345e5d81d90cf7e2", + "sha256": "df3fe2a84d35cc6013634a6592c82c1abeb412423eed3399381fed86a3763935", + "blake3": "d0ee4a4840b43dfaf4e6b7102565759896a895db3391f9a147f59dd528ca49d7" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_4ft_diffuse.png", + "size": 1981803, + "hash": { + "sha256-flat-1mb": "1e477a8f95083c9671d52d92f0ac13494e1aa60d2a52bde35fe67f423858dfbb", + "sha256": "77bc95c37d2c3822017397a212ed773fdb460af4e81b6f6d4adbb86293b03098", + "blake3": "cce27662396e77644708184156fe51d0bc69569272e11af39b1575e5941e607a", + "sha256-first1m": "21499ecbd7236e00a638984bb5f3c97ad3d240e57b7b919bbb899553ebd707fd" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_1.usd", + "size": 417841, + "hash": { + "sha256-flat-1mb": "9dfc1ad0e101c2e656236f8db4f526bbde37c2a2bd7a0f1654bc7a6d7ac3759a", + "sha256": "e20050ee0274353cf31b2d8657548421b20c5d05f7a2bf34916337f6a5b0d44c", + "blake3": "4d18162e7a93189caaae323c1e262b0b0b13227213b5d9458a5d74897e22bd62" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/916/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/916/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6bf63075b5f708fe84cbeb635e1dd21fe4e91802 --- /dev/null +++ b/simready_assets/916/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_1.usd" + ] +} diff --git a/simready_assets/916/SubUSDs/materials/pbr.mdl b/simready_assets/916/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/916/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/916/SubUSDs/materials/pbr_1.mdl b/simready_assets/916/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/916/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/916/gltf/pbr.mdl b/simready_assets/916/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/916/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/916/warehouse_pallet_1.usd b/simready_assets/916/warehouse_pallet_1.usd new file mode 100644 index 0000000000000000000000000000000000000000..e084a58131cbfd286e8260fedd9eeee95f39bc8d --- /dev/null +++ b/simready_assets/916/warehouse_pallet_1.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e20050ee0274353cf31b2d8657548421b20c5d05f7a2bf34916337f6a5b0d44c +size 417841 diff --git a/simready_assets/917/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/917/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7ae4a3b3d485ad909373853854b20bb26fc341 --- /dev/null +++ b/simready_assets/917/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T15:06:44", + "assets": [ + { + "asset": "warehouse_pallet_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "30a6cd54d4794586b1a9649b496d065d7f5f302895e6fbb12aa44d444c855ab1", + "blake3": "7bc89aaccd38d0b51fc74e65dec543af6bb311a4267fb1ad47087193752a62bd" + } +} diff --git a/simready_assets/917/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/917/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..c35bb109fc892035d65048ee6ba258770e0cb9fc --- /dev/null +++ b/simready_assets/917/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T15:06:44", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/917/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/917/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..ae12afbf4acd7cfc8cac552b9a3b496bbf5f7716 --- /dev/null +++ b/simready_assets/917/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_2.usd.png", + "size": 26180, + "hash": { + "sha256-flat-1mb": "fa3278dff3ad515393b4e9d7ed7955ce855452a3ad74bccef819149a2e034a44", + "sha256": "02ca92f85521dec725637e7ca3f43b02a96b2b4c9a921e2985ab005f28bc7064", + "blake3": "c8c0a9b44d75f6c6675fb406566bca500da4564c2c474a7d601ee4c925c889c0" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_4ft_diffuse.png", + "size": 1981803, + "hash": { + "sha256-flat-1mb": "1e477a8f95083c9671d52d92f0ac13494e1aa60d2a52bde35fe67f423858dfbb", + "sha256": "77bc95c37d2c3822017397a212ed773fdb460af4e81b6f6d4adbb86293b03098", + "blake3": "cce27662396e77644708184156fe51d0bc69569272e11af39b1575e5941e607a", + "sha256-first1m": "21499ecbd7236e00a638984bb5f3c97ad3d240e57b7b919bbb899553ebd707fd" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_2.usd", + "size": 418199, + "hash": { + "sha256-flat-1mb": "2862a69801a686b56ec36cd235e4060b15a42af10b7c6db3d2bdfbc4b6d596a2", + "sha256": "15a7c7f85ec4f41ae19c64acdcda9d4352f13496e4e5f930e98b139e3f2e490b", + "blake3": "fe0124517546658c00ddecbb7b5d81d3a48278f3b151302a7b87e083653ed10e" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/917/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/917/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..01eadf945d60f5c7e18cead82004b7c23b7dbd87 --- /dev/null +++ b/simready_assets/917/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_2.usd" + ] +} diff --git a/simready_assets/917/SubUSDs/materials/pbr.mdl b/simready_assets/917/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/917/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/917/SubUSDs/materials/pbr_1.mdl b/simready_assets/917/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/917/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/917/gltf/pbr.mdl b/simready_assets/917/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/917/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/917/warehouse_pallet_2.usd b/simready_assets/917/warehouse_pallet_2.usd new file mode 100644 index 0000000000000000000000000000000000000000..b77b17fb405d8e14784859b27640dbf785c5f0ba --- /dev/null +++ b/simready_assets/917/warehouse_pallet_2.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15a7c7f85ec4f41ae19c64acdcda9d4352f13496e4e5f930e98b139e3f2e490b +size 418199 diff --git a/simready_assets/918/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/918/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..24586d206b8159f5a4c7f94b1306cc5dc2e1fc20 --- /dev/null +++ b/simready_assets/918/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:32:44", + "assets": [ + { + "asset": "warehouse_pallet_3.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "1e516901cc264ce5736f587b777c64f7b7ffd508ca755a042904eb5357b62f82", + "blake3": "d40ede268d1a89cd30afa427d883b18986b6bc1f5b3edc5e86eb4fc268536251" + } +} diff --git a/simready_assets/918/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/918/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..1562329cc3f09a8eb76c7219db7fe414482a3068 --- /dev/null +++ b/simready_assets/918/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:32:45", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/918/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/918/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..45fe367673d3b8b2ad25fd6098c7aee8bf73b073 --- /dev/null +++ b/simready_assets/918/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_3/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_3.usd.png", + "size": 24740, + "hash": { + "sha256-flat-1mb": "630e1544c322f7f3878bd20603b80df937d9e89c98c9be0cdf0166f21dec72c3", + "sha256": "c05ca75b225043bf396bdb1f2d5097ea55c9e3316696c4fc8f635e27583a8cf6", + "blake3": "1ddc535c658286a7d9f77e7bfeea68bd9db2cf7081aee80626849c74bc31b43a" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_4ft_diffuse.png", + "size": 1981803, + "hash": { + "sha256-flat-1mb": "1e477a8f95083c9671d52d92f0ac13494e1aa60d2a52bde35fe67f423858dfbb", + "sha256": "77bc95c37d2c3822017397a212ed773fdb460af4e81b6f6d4adbb86293b03098", + "blake3": "cce27662396e77644708184156fe51d0bc69569272e11af39b1575e5941e607a", + "sha256-first1m": "21499ecbd7236e00a638984bb5f3c97ad3d240e57b7b919bbb899553ebd707fd" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_3.usd", + "size": 418657, + "hash": { + "sha256-flat-1mb": "586aed349152dd6935695781182668dc72d5b61656840bb48f007df5b13884ca", + "sha256": "6ea13908112d4a6702e329231889a929db8b9abc52c16155df1ed3891bde9265", + "blake3": "4b644b95b64322b3838215a2eab24237d10707c54685274877fc1fee684e5b13" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/918/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/918/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..581e8fc0d470ce67d5de2d530dd38f2da15e8711 --- /dev/null +++ b/simready_assets/918/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_3.usd" + ] +} diff --git a/simready_assets/918/SubUSDs/materials/pbr.mdl b/simready_assets/918/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/918/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/918/SubUSDs/materials/pbr_1.mdl b/simready_assets/918/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/918/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/918/gltf/pbr.mdl b/simready_assets/918/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/918/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/918/warehouse_pallet_3.usd b/simready_assets/918/warehouse_pallet_3.usd new file mode 100644 index 0000000000000000000000000000000000000000..54613b6531e2d8e914feb5a529844e5891c62f6a --- /dev/null +++ b/simready_assets/918/warehouse_pallet_3.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ea13908112d4a6702e329231889a929db8b9abc52c16155df1ed3891bde9265 +size 418657 diff --git a/simready_assets/919/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/919/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..5e45d72b16070c85537a3aedbbca2de92744a4cd --- /dev/null +++ b/simready_assets/919/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:35:22", + "assets": [ + { + "asset": "warehouse_pallet_4.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "705a8cd34943b709d785d779d0fb100cc54680e2d2d6642e8817152c8359b52c", + "blake3": "bf523609bfeb3a571c7bcca0e347ed9d8f6811bb318a169b5167d39a98e00e9c" + } +} diff --git a/simready_assets/919/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/919/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..40200cac6f73719a8c04ef174cf6bbdc85cf6738 --- /dev/null +++ b/simready_assets/919/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:35:22", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/919/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/919/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..e108515926ba6568fe008044c4cd760f082078b8 --- /dev/null +++ b/simready_assets/919/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,70 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_4/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_4.usd.png", + "size": 18245, + "hash": { + "sha256-flat-1mb": "06b5556f3089bd2c5fbef2d362af01bc5b6a700ef28770bbcdacb303e958a3f8", + "sha256": "d0f8dfa45c102c33a7cedf11c653f6130cff13cfa19b0a5614d13f15382d15f8", + "blake3": "7a22c336dd573d70ebd8102dcb3a5c2ed558d17998efdcd76f4beaf24968ac32" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_2ft_diffuse.jpg", + "size": 923719, + "hash": { + "sha256-flat-1mb": "29bccdf9822570ba7c47960669c04d6967a3ac436500c1e190356555138aaf5d", + "sha256": "14da62f0c6bf4374e6f127095cfd0e11eee20989e71becd47b3ded067e2635f9", + "blake3": "18dd3bacd73a74a2ba7ebb5f2bd436df4a1a29fb66a000a987ff2926d06fa044" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_4.usd", + "size": 418410, + "hash": { + "sha256-flat-1mb": "d706513012cca36fba235f1d319987020d1bb48dd9ea342731b8c918446051f3", + "sha256": "8a995d18d51d1538d46c74d24a217a2ad7cba10d8b9206055561d13234c5b500", + "blake3": "f5ac796bcb88dd3a441fcba2dfa08b5e65376d0139b9fef2039eef85f63045ba" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/919/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/919/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..2e95d479fc1931ad6a4b75a2842ee8d28d1b325f --- /dev/null +++ b/simready_assets/919/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_4.usd" + ] +} diff --git a/simready_assets/919/SubUSDs/materials/pbr.mdl b/simready_assets/919/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/919/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/919/SubUSDs/materials/pbr_1.mdl b/simready_assets/919/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/919/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/919/gltf/pbr.mdl b/simready_assets/919/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/919/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/919/warehouse_pallet_4.usd b/simready_assets/919/warehouse_pallet_4.usd new file mode 100644 index 0000000000000000000000000000000000000000..7598ba2edfdd518476613ca702ca8ba7aeff3e7b --- /dev/null +++ b/simready_assets/919/warehouse_pallet_4.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a995d18d51d1538d46c74d24a217a2ad7cba10d8b9206055561d13234c5b500 +size 418410 diff --git a/simready_assets/920/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/920/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..3180f7d604ef2f26d933811eece99521f6116bf2 --- /dev/null +++ b/simready_assets/920/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:38:25", + "assets": [ + { + "asset": "warehouse_pallet_5.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "61498dc44ea267d46bf121dcef87d4d0fe0b90820ebfe8cd2ce624f3c4a3d2ba", + "blake3": "c362fb205f55a81ebfb05e19f99cb06ca870a5a5d1803cceedda9ebab07d1dd5" + } +} diff --git a/simready_assets/920/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/920/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..67c33298fc2cce15677744d7377850126649756a --- /dev/null +++ b/simready_assets/920/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:38:25", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/920/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/920/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..03c8522f09a647150902d529f62ec927748cdd0f --- /dev/null +++ b/simready_assets/920/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,70 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_5/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_5.usd.png", + "size": 24691, + "hash": { + "sha256-flat-1mb": "c0144a02756328cf3157b096b693091f2c3c055745de5d41ada5435aefac32dc", + "sha256": "cab9ba98437860c6548933e7cb4dc9f8c3403b108d88d4ea55f28ada9c6a535e", + "blake3": "0dcf7e3fb5060590a35a9dfa6a9d2ed6bbff028ab861e46ea80b448041afc0b5" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_2ft_diffuse.jpg", + "size": 923719, + "hash": { + "sha256-flat-1mb": "29bccdf9822570ba7c47960669c04d6967a3ac436500c1e190356555138aaf5d", + "sha256": "14da62f0c6bf4374e6f127095cfd0e11eee20989e71becd47b3ded067e2635f9", + "blake3": "18dd3bacd73a74a2ba7ebb5f2bd436df4a1a29fb66a000a987ff2926d06fa044" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_5.usd", + "size": 420048, + "hash": { + "sha256-flat-1mb": "2173504d3013a0041e8514d3a77b05bcf9091b2f6d8a26a847ba08aa1cb7d347", + "sha256": "72c2da03a0b856dbf6c17771cb18bd0828d349df5515b3fdfdee832e6fa62d87", + "blake3": "0dd963b06640f5da8db8bfc1f67603d27c85cb52ecb56e3c2fe815b10f821009" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/920/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/920/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..f66158b4cc9dbda63fe0518479189c0101935b5c --- /dev/null +++ b/simready_assets/920/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_5.usd" + ] +} diff --git a/simready_assets/920/SubUSDs/materials/pbr.mdl b/simready_assets/920/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/920/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/920/SubUSDs/materials/pbr_1.mdl b/simready_assets/920/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/920/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/920/gltf/pbr.mdl b/simready_assets/920/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/920/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/920/warehouse_pallet_5.usd b/simready_assets/920/warehouse_pallet_5.usd new file mode 100644 index 0000000000000000000000000000000000000000..17357b5dbde2fff2faf5d9f3048995f76bed886a --- /dev/null +++ b/simready_assets/920/warehouse_pallet_5.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72c2da03a0b856dbf6c17771cb18bd0828d349df5515b3fdfdee832e6fa62d87 +size 420048 diff --git a/simready_assets/921/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/921/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..bf12084c210933ce70db25a6d64378d8757c42f9 --- /dev/null +++ b/simready_assets/921/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:52:16", + "assets": [ + { + "asset": "warehouse_pallet_6.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "a9f2b7feff1a72a9a379620ab817e15175cd55d2e3fbdd919f96f77ba6b266e9", + "blake3": "59de2243629a4438f752224adb48495836c05419ca1e238c2235e57bacc9261c" + } +} diff --git a/simready_assets/921/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/921/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..a747f03fdc3e603602ec76975f83d5ac7b8a875b --- /dev/null +++ b/simready_assets/921/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:52:16", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/921/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/921/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..f34ed0d5c080353e333e987ed32ca215fabbdeaa --- /dev/null +++ b/simready_assets/921/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,70 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_6/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_6.usd.png", + "size": 23340, + "hash": { + "sha256-flat-1mb": "7991eaec9d02f83f1c22875307c7e60f1612b02d92ffe45498b867884bc3b482", + "sha256": "9043571ccbf840e83e5b9d5125cf583bbfd39ebaaae125ce81c8ac6de8bbc135", + "blake3": "ebeac1c0e74c62acd1a9a742044d16159d8b1ab3daa8f32f9e3f06ac69af073e" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_2ft_diffuse.jpg", + "size": 923719, + "hash": { + "sha256-flat-1mb": "29bccdf9822570ba7c47960669c04d6967a3ac436500c1e190356555138aaf5d", + "sha256": "14da62f0c6bf4374e6f127095cfd0e11eee20989e71becd47b3ded067e2635f9", + "blake3": "18dd3bacd73a74a2ba7ebb5f2bd436df4a1a29fb66a000a987ff2926d06fa044" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_6.usd", + "size": 420834, + "hash": { + "sha256-flat-1mb": "6fbf07b9d7bf442ce9f109cd41361001cb334033b08222fc6df9a49df4e8b465", + "sha256": "64c3ce99d46606543289813a6344390ab001a483a7cbb990ba7fff971a3791f3", + "blake3": "b3b1c37a9dc9e3463ed52c7c259d8d0c9e8284b8add478185df32de5483bf86b" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/921/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/921/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..9c3200d6c0fa0628d5256243ad350058810f047c --- /dev/null +++ b/simready_assets/921/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_6.usd" + ] +} diff --git a/simready_assets/921/SubUSDs/materials/pbr.mdl b/simready_assets/921/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/921/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/921/SubUSDs/materials/pbr_1.mdl b/simready_assets/921/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/921/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/921/gltf/pbr.mdl b/simready_assets/921/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/921/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/921/warehouse_pallet_6.usd b/simready_assets/921/warehouse_pallet_6.usd new file mode 100644 index 0000000000000000000000000000000000000000..618ec44e7874a143c22f2dff1533ecb595d36592 --- /dev/null +++ b/simready_assets/921/warehouse_pallet_6.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64c3ce99d46606543289813a6344390ab001a483a7cbb990ba7fff971a3791f3 +size 420834 diff --git a/simready_assets/922/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/922/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..b9ee2a8d9dafd58594d5d1d8f1b49f814df5943a --- /dev/null +++ b/simready_assets/922/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:55:16", + "assets": [ + { + "asset": "warehouse_pallet_7.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "0f72be7b262a04ba306d89432348759c78f0562858ccd109810e54c706b0702a", + "blake3": "a2566b3174cebc7b7f20d0186178eecbc99aff2cb63f70f1d8c56f163ff53351" + } +} diff --git a/simready_assets/922/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/922/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..360951631132325aa7bc58ac97953ec73db33cc8 --- /dev/null +++ b/simready_assets/922/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:55:16", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/922/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/922/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e97b40f085c122aa3bc7d8c1296b63ef1f802f --- /dev/null +++ b/simready_assets/922/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,81 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_7/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_7.usd.png", + "size": 28933, + "hash": { + "sha256-flat-1mb": "e6236e50e0c53c214fb42a7c9cd108c27fc7589cae0108354cc530ba36a53d07", + "sha256": "6c781197017694c58ba444d4c34c8b3147310bfd4a9c2386cb155a5ce0022c8c", + "blake3": "204d22d57a4dad8310d395a3c74247ba1133bf7ecf06f3da95fd8e07a2a828e8" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/carton box_1_diffuse.jpg.jpg", + "size": 1758100, + "hash": { + "sha256-flat-1mb": "543fe7a1328bc1601aed0a01f6d918e3dce117076c1e2a707e710012718d87fe", + "sha256": "b4e3ea669b3e3c1abea81a1bab3876386803bae4432649e516b94b30cf161f03", + "blake3": "62f577e1f2a1af30975eb0b4a2c506c1ee3449590d0152a660ab20d276933a09", + "sha256-first1m": "4a192ad84005064d845cbca1ebbe422dc5160137469913d5a44d2f2ff4ff3fa1" + } + }, + { + "relative_path": "SubUSDs/textures/carton box_1_normal.jpg", + "size": 141331, + "hash": { + "sha256-flat-1mb": "c1c6a26ada7a52add900e342a5e5cd7d12989b0e3fa072faaf77ecbe995d6dfc", + "sha256": "e251b8a01e8b83a9b7bec24ba0295c97fee0aa9bcde06cf36f20295fa187e3e3", + "blake3": "29dd58c69902543273bd8706e747d6460a0e373120f4201825f78d832809228d" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_7.usd", + "size": 2432633, + "hash": { + "sha256-flat-1mb": "14b6ea585841165ff869eb13ecbc1d34630369d4237d0de4dc44b4e278322363", + "sha256": "05dd96df6b0b4b6f98f6c57e7283a5eab22008904c20b0fba71255e6595fdae6", + "blake3": "c7d3b92ea01d49afb29d79f1920f22e255468f383419f57763e748745c2ce1e8", + "sha256-first1m": "34f99b7743a45b1d3a6e862d5aabc1fcaa2acfc9aa92c0e8471b7624fc8eaca8" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/922/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/922/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..9973c8fb25727d225c45d2faa450c168f62c0d36 --- /dev/null +++ b/simready_assets/922/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_7.usd" + ] +} diff --git a/simready_assets/922/SubUSDs/materials/pbr.mdl b/simready_assets/922/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/922/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/922/SubUSDs/materials/pbr_1.mdl b/simready_assets/922/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/922/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/922/gltf/pbr.mdl b/simready_assets/922/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/922/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/922/warehouse_pallet_7.usd b/simready_assets/922/warehouse_pallet_7.usd new file mode 100644 index 0000000000000000000000000000000000000000..b9ac2030d787ee72df5835d517c91c27c8c31e65 --- /dev/null +++ b/simready_assets/922/warehouse_pallet_7.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05dd96df6b0b4b6f98f6c57e7283a5eab22008904c20b0fba71255e6595fdae6 +size 2432633 diff --git a/simready_assets/923/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/923/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..ff7099a5954f678e94efcd5a4e8a6b1f0e622314 --- /dev/null +++ b/simready_assets/923/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:58:25", + "assets": [ + { + "asset": "warehouse_pallet_8.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "496dbe93bc313f34caf6c49462e127ecaaed65f3c438a3411000a1c274801ff8", + "blake3": "5d83c001d35f4357c69c983afdaa4f6742e26f1e9ea1df24fe443f5fe10d46cc" + } +} diff --git a/simready_assets/923/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/923/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7cf5b85ba07bb11d27d5a9e91f75bd811ece0dd0 --- /dev/null +++ b/simready_assets/923/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T21:58:25", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/923/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/923/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..83670329df1ee35b714c356b0aba741b5123b06b --- /dev/null +++ b/simready_assets/923/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,81 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_8/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_8.usd.png", + "size": 31091, + "hash": { + "sha256-flat-1mb": "a2beab22ee3cbe50fc97f2aec435abbfe59aed6aa4d886d1b8976c9dba9ba785", + "sha256": "bee28cb80644cf5b98640e2bce2bd7c722ce3e75296ab6cf8a20a6ec77dfdcf6", + "blake3": "8accb7911b459f6cc961c6cb2d6bd17310e6899dd8829d71bb8602f75857e7cb" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/carton box_1_normal.jpg", + "size": 141331, + "hash": { + "sha256-flat-1mb": "c1c6a26ada7a52add900e342a5e5cd7d12989b0e3fa072faaf77ecbe995d6dfc", + "sha256": "e251b8a01e8b83a9b7bec24ba0295c97fee0aa9bcde06cf36f20295fa187e3e3", + "blake3": "29dd58c69902543273bd8706e747d6460a0e373120f4201825f78d832809228d" + } + }, + { + "relative_path": "SubUSDs/textures/carton box_2_diffuse.png", + "size": 2522554, + "hash": { + "sha256-flat-1mb": "f7d382acf84e38183711f5babe8bff600422adb5b87669fdedb79c1829c4bfff", + "sha256": "33b17ca65c937d3d5530816fca64384328f31a92c242b3e5b60ab312ec42a9f9", + "blake3": "48cecfe75e3215d6828b09f49be4a3293f3a72c895f66f28bad4891c19f924fb", + "sha256-first1m": "d364c65dad0f58237e8ccc6372cfe44576e14eed361ae3b66568ecfa9b273a78" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_8.usd", + "size": 3252713, + "hash": { + "sha256-flat-1mb": "b802209778446e0a6a1a01feaccc89625871472deb1145a645102127fd85cb8f", + "sha256": "2eac27e3bc19d29fd652828f9a5dc62660c661c932d971998c11988e13d0c10d", + "blake3": "64e3bab39b76519f8085f73a729d00d99f31a30001fa45878afda72760a0656e", + "sha256-first1m": "b928ca9d5a484595cc924038b56187c0b26c1fe2fe787b25a520353e983f1f57" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/923/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/923/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..51a69d1a1e27a7a2cac69108112f36c90d7a811e --- /dev/null +++ b/simready_assets/923/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_8.usd" + ] +} diff --git a/simready_assets/923/SubUSDs/materials/pbr.mdl b/simready_assets/923/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/923/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/923/SubUSDs/materials/pbr_1.mdl b/simready_assets/923/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/923/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/923/gltf/pbr.mdl b/simready_assets/923/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/923/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/923/warehouse_pallet_8.usd b/simready_assets/923/warehouse_pallet_8.usd new file mode 100644 index 0000000000000000000000000000000000000000..36a1d4c28dd2937b013585caef670dec8ab61168 --- /dev/null +++ b/simready_assets/923/warehouse_pallet_8.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2eac27e3bc19d29fd652828f9a5dc62660c661c932d971998c11988e13d0c10d +size 3252713 diff --git a/simready_assets/924/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/924/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..891eeb2bd6495667780518595622e0b01da2095f --- /dev/null +++ b/simready_assets/924/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:02:50", + "assets": [ + { + "asset": "warehouse_pallet_9.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "89394401ccebf207f33721e51d2b1334af75d834002fb5fc5f76f5195fef6789", + "blake3": "f90adbe9bffef6c6773631f033cdca09199e67fdf639c0d278283131c75885d8" + } +} diff --git a/simready_assets/924/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/924/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..36cab20b89716873e59e42859a1a0f344cc328dd --- /dev/null +++ b/simready_assets/924/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:02:50", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/924/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/924/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..1fb0f8a2051accce397c23207f4d671f76188c9f --- /dev/null +++ b/simready_assets/924/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,70 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_9/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_9.usd.png", + "size": 22265, + "hash": { + "sha256-flat-1mb": "d4236cf055748d9cb04743d2f21ed3595488862bd6fcab44f35ff3ae4a01dcb9", + "sha256": "19925a5970a15d826b0bb797acbd4a5fa49640b65f902dc39c1af0205980321a", + "blake3": "7a4d7b83a01cb1dd9312f877fadb80650f8bbd15a2d86823d3fe4fd7efe53552" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_2ft_x_2ft.jpg", + "size": 616942, + "hash": { + "sha256-flat-1mb": "56787209258464bb5fc58bbe14d576790cc8205796979e889cd62d9788d719a1", + "sha256": "9f719e933ac1caee0e70b80fac0be4d3e97e8da5559b505e7ecd25db2bb41295", + "blake3": "9d7d8814d506a63af6bc7b89b4513d94adf0f437f54f2a9f19b7267d3b0bdde1" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_9.usd", + "size": 419135, + "hash": { + "sha256-flat-1mb": "00e148bf8bbe35e61651a5dd4eac94cf5a7dbe97c55104af5a9d4fa823b94295", + "sha256": "c917a628b03fbe8d4c1385aee02ce6cecd535c842a593f4178f4017ca0a6f9f8", + "blake3": "c4baf50f467cf0d3dcf8767540a557138bf67d7ef50aacfd2bd3402b498cc560" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/924/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/924/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..604b96ad4f05c756ac07653f711b72f59d0b910a --- /dev/null +++ b/simready_assets/924/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_9.usd" + ] +} diff --git a/simready_assets/924/SubUSDs/materials/pbr.mdl b/simready_assets/924/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/924/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/924/SubUSDs/materials/pbr_1.mdl b/simready_assets/924/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/924/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/924/gltf/pbr.mdl b/simready_assets/924/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/924/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/924/warehouse_pallet_9.usd b/simready_assets/924/warehouse_pallet_9.usd new file mode 100644 index 0000000000000000000000000000000000000000..7e78bb254afbc2173262f7bb716838ab65d35bc5 --- /dev/null +++ b/simready_assets/924/warehouse_pallet_9.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c917a628b03fbe8d4c1385aee02ce6cecd535c842a593f4178f4017ca0a6f9f8 +size 419135 diff --git a/simready_assets/925/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/925/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..c5d3759a42fc9201dab4300ec89190834c18c4a1 --- /dev/null +++ b/simready_assets/925/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:03:54", + "assets": [ + { + "asset": "warehouse_pallet_10.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "f5a79c747311e3aabd7b2f113a145b7fa83a674a2dd0fcdb7d6ff376fa94ad52", + "blake3": "c304a283bf67c4b6377c3633fd583dfa1a593ad4cfd980b4a84055c0cf738590" + } +} diff --git a/simready_assets/925/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/925/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..f89d1be29d9c0c1dac9d89dcfd3f0938ff2d0a75 --- /dev/null +++ b/simready_assets/925/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:03:54", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/925/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/925/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..f66884cfd77aaf2e17e92ebf3c4772fc17e1703b --- /dev/null +++ b/simready_assets/925/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,70 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_10/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_10.usd.png", + "size": 33901, + "hash": { + "sha256-flat-1mb": "8458284b3ff2bccdfe6854adbcc83d94f66b14cb7da2023ca0e11d9e03d0b796", + "sha256": "f9762b6b806bc43c41d509d42daad58c102cbea47c364ce3a54d5b611dc0f2a3", + "blake3": "05cc0c62b381c2b09f6b1891bd398e50bf719d478f6ff7ca80977300a72417bd" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_2ft_x_2ft.jpg", + "size": 616942, + "hash": { + "sha256-flat-1mb": "56787209258464bb5fc58bbe14d576790cc8205796979e889cd62d9788d719a1", + "sha256": "9f719e933ac1caee0e70b80fac0be4d3e97e8da5559b505e7ecd25db2bb41295", + "blake3": "9d7d8814d506a63af6bc7b89b4513d94adf0f437f54f2a9f19b7267d3b0bdde1" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_10.usd", + "size": 420359, + "hash": { + "sha256-flat-1mb": "5757173ac9e59625aa7fb0ef5fc51239be55e5e201b02e9bb5422b503d32731f", + "sha256": "871994d8054b72b6364d33cf667ab28f29388c851726ec752e8f621cd93d8b94", + "blake3": "1c31dc0f1d156378031ed5c099ee18130a2ea3d901aa9353ad14dbf300eb7f58" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/925/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/925/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..4de3f48feda0b99e3e5eb9654741ddb93da2f96e --- /dev/null +++ b/simready_assets/925/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_10.usd" + ] +} diff --git a/simready_assets/925/SubUSDs/materials/pbr.mdl b/simready_assets/925/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/925/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/925/SubUSDs/materials/pbr_1.mdl b/simready_assets/925/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/925/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/925/gltf/pbr.mdl b/simready_assets/925/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/925/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/925/warehouse_pallet_10.usd b/simready_assets/925/warehouse_pallet_10.usd new file mode 100644 index 0000000000000000000000000000000000000000..e74f83f80b68264f43dca45dacd50a858d011fe0 --- /dev/null +++ b/simready_assets/925/warehouse_pallet_10.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:871994d8054b72b6364d33cf667ab28f29388c851726ec752e8f621cd93d8b94 +size 420359 diff --git a/simready_assets/926/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/926/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..146a491c1ada8a540e88330998cfa3e4a8840e00 --- /dev/null +++ b/simready_assets/926/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:05:01", + "assets": [ + { + "asset": "warehouse_pallet_11.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "9929e6e24b3785fc120fac3b71dd9a0526ce7aaa07f5a5f23d685d6d7c8d2519", + "blake3": "a91d245feca09aee3c6b353e8451e517fb25652b1af784b5025d2a87550dff6f" + } +} diff --git a/simready_assets/926/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/926/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..757b73c673a63d8c2732289bba2849d31422463d --- /dev/null +++ b/simready_assets/926/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:05:01", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/926/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/926/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..ff899cbc19aa4609d7a66dcddf617b0be15bd562 --- /dev/null +++ b/simready_assets/926/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,70 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_11/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_11.usd.png", + "size": 30671, + "hash": { + "sha256-flat-1mb": "31be82fb6de2f6d878b0f40f8df5127b69f62f9b710edb74e7c8049434226a43", + "sha256": "827a1c01d6c21120d43626a9f64a9dfda64df1781f50a0417fd2af79e793ccc7", + "blake3": "562234e46e9a46d595614f8e2d2e3ade97c26f9424a39a90ec8b69e7efc1075b" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_2ft_x_2ft.jpg", + "size": 616942, + "hash": { + "sha256-flat-1mb": "56787209258464bb5fc58bbe14d576790cc8205796979e889cd62d9788d719a1", + "sha256": "9f719e933ac1caee0e70b80fac0be4d3e97e8da5559b505e7ecd25db2bb41295", + "blake3": "9d7d8814d506a63af6bc7b89b4513d94adf0f437f54f2a9f19b7267d3b0bdde1" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_11.usd", + "size": 421804, + "hash": { + "sha256-flat-1mb": "42bf441e82a11f062b1ce808a720663f49ff165876c89c0b753a240572e84a11", + "sha256": "796ee041c2d40a194932db54d2544a8b86eeb5b1c191beb5216ae8cbc965c685", + "blake3": "b6bb8ff12ed4de11362330a6052832976ae81b1a872916a889a1d390719ebaf2" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/926/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/926/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..7e364c5ee9738576638af7b46bbd81b86b3cc6a0 --- /dev/null +++ b/simready_assets/926/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_11.usd" + ] +} diff --git a/simready_assets/926/SubUSDs/materials/pbr.mdl b/simready_assets/926/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/926/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/926/SubUSDs/materials/pbr_1.mdl b/simready_assets/926/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/926/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/926/gltf/pbr.mdl b/simready_assets/926/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/926/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/926/warehouse_pallet_11.usd b/simready_assets/926/warehouse_pallet_11.usd new file mode 100644 index 0000000000000000000000000000000000000000..ad93488955a041d63c3cb58aecc4bfee8112b760 --- /dev/null +++ b/simready_assets/926/warehouse_pallet_11.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:796ee041c2d40a194932db54d2544a8b86eeb5b1c191beb5216ae8cbc965c685 +size 421804 diff --git a/simready_assets/927/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/927/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..617eb0f610bc1a8c8a8d56c4533e8d6f12fc372f --- /dev/null +++ b/simready_assets/927/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:08:23", + "assets": [ + { + "asset": "warehouse_pallet_12.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "9070dc31955fe6c24fff0fa04f887efe7ff8157c780e1d54b95fc78e7f2d31a8", + "blake3": "1200434c7cc3254087ced5ddb2ea53b5d001211a24cd5b2e2ec3a0b039198303" + } +} diff --git a/simready_assets/927/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/927/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..782b90083558f714ace5c525142a32a9a47eee59 --- /dev/null +++ b/simready_assets/927/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:08:24", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/927/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/927/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..e6ea6cea8784302d6c91f6e69003d32da5c9a69f --- /dev/null +++ b/simready_assets/927/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_12/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_12.usd.png", + "size": 20929, + "hash": { + "sha256-flat-1mb": "49c5bf5057d88f22be761c0b94485960d855f38ad989696034659f33685ad2bd", + "sha256": "9a2cefc1c97bdcafd65422188cab5a0290436a43e536e61287ebaa7e4911160a", + "blake3": "ccfbcb94e4c97094067072fae58273dc5f643171eca995cd29b7e4c03f8274f7" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_2.5ft_diffuse.png", + "size": 1347302, + "hash": { + "sha256-flat-1mb": "96d83dbf018d5f967fb733dd0b0b97c9564c7cbe0d806b9b1a4e3f57909b9edf", + "sha256": "fba177196f868c132f2e4f089cf0462d69dca2dc831764a6833eb30a93fd17e0", + "blake3": "3223b1208cc2fef541158c1a68a08dbf6d7f1312ddb8953d024e777337a7526a", + "sha256-first1m": "09e8c876a2bf8b7314142c501f4929be056a1f5d4915caf95d1e13797ac06b2e" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_12.usd", + "size": 438106, + "hash": { + "sha256-flat-1mb": "13b93e45393c873fcbf9fc5eb3cde3d8cf44c14daf9dccdcf7288316f6d18c79", + "sha256": "6b8efcc827e0ec83125dc75a405430c90d185421576d1431c22f6558279221fb", + "blake3": "30b75b2566c1a969fa417775ae8156169d9f7d24a01452d67773b92941e74932" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/927/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/927/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..9c755b1330474244e80c35ed0efaad3115a34068 --- /dev/null +++ b/simready_assets/927/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_12.usd" + ] +} diff --git a/simready_assets/927/SubUSDs/materials/pbr.mdl b/simready_assets/927/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/927/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/927/SubUSDs/materials/pbr_1.mdl b/simready_assets/927/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/927/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/927/gltf/pbr.mdl b/simready_assets/927/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/927/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/927/warehouse_pallet_12.usd b/simready_assets/927/warehouse_pallet_12.usd new file mode 100644 index 0000000000000000000000000000000000000000..42a5125d744022947a71d8b9165148317381831d --- /dev/null +++ b/simready_assets/927/warehouse_pallet_12.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b8efcc827e0ec83125dc75a405430c90d185421576d1431c22f6558279221fb +size 438106 diff --git a/simready_assets/928/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/928/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..a4b4fda5ad7e7f6f2ed709d47c63b8a77e1fb8d7 --- /dev/null +++ b/simready_assets/928/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:09:24", + "assets": [ + { + "asset": "warehouse_pallet_13.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "ff39ac0983fc6e012442bd193def8e67cc04559bd5b4ac954bbfb3df64cd9541", + "blake3": "c1e4463100b8948322f3db64738912d9862e42ee40f9860054433c39ec9d511e" + } +} diff --git a/simready_assets/928/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/928/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..791177e633d0c980819e662fda518e3055188379 --- /dev/null +++ b/simready_assets/928/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:09:24", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/928/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/928/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..10c11fb7516f0e36bdb7dbd8686487e802052938 --- /dev/null +++ b/simready_assets/928/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_13/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_13.usd.png", + "size": 32625, + "hash": { + "sha256-flat-1mb": "8e56167910293a9ca900912b6792515ff6965c16869cd1674fe14fded2c86f40", + "sha256": "dbd823773b2b0213668c532d630f9699d916168f31d7996791d52d488b73e393", + "blake3": "e482af7beddbc18f99d8c6caa55c5615de728f73019b505aa30e869302706ea7" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_2.5ft_diffuse.png", + "size": 1347302, + "hash": { + "sha256-flat-1mb": "96d83dbf018d5f967fb733dd0b0b97c9564c7cbe0d806b9b1a4e3f57909b9edf", + "sha256": "fba177196f868c132f2e4f089cf0462d69dca2dc831764a6833eb30a93fd17e0", + "blake3": "3223b1208cc2fef541158c1a68a08dbf6d7f1312ddb8953d024e777337a7526a", + "sha256-first1m": "09e8c876a2bf8b7314142c501f4929be056a1f5d4915caf95d1e13797ac06b2e" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_13.usd", + "size": 438548, + "hash": { + "sha256-flat-1mb": "e592bee52a9eacdd124de57eed4de71f117d3307ed2e00970e6b00afd2c671c5", + "sha256": "08261fdca5ddce17aba709be787f0d2746ec30d45769d33bcd135b2320beb7e6", + "blake3": "fbc11875f4e1dcdb93d85c25bda0f086e4da5544c97d9a6d1d1b717648ccf01f" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/928/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/928/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..cb3d8ffc592fb4314680ea6edcfb3c15dc928dc8 --- /dev/null +++ b/simready_assets/928/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_13.usd" + ] +} diff --git a/simready_assets/928/SubUSDs/materials/pbr.mdl b/simready_assets/928/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/928/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/928/SubUSDs/materials/pbr_1.mdl b/simready_assets/928/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/928/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/928/gltf/pbr.mdl b/simready_assets/928/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/928/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/928/warehouse_pallet_13.usd b/simready_assets/928/warehouse_pallet_13.usd new file mode 100644 index 0000000000000000000000000000000000000000..3ab4d7d01480c7f83ad2dcc9ebfc0544c278572d --- /dev/null +++ b/simready_assets/928/warehouse_pallet_13.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08261fdca5ddce17aba709be787f0d2746ec30d45769d33bcd135b2320beb7e6 +size 438548 diff --git a/simready_assets/929/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/929/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..eb127819389e20cc3e0cf05fb07849378482215b --- /dev/null +++ b/simready_assets/929/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:11:02", + "assets": [ + { + "asset": "warehouse_pallet_14.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "268e697a8fb4e382e86c779efb938cb30ee33b0c4bf4a6dd134fcdb69345b63d", + "blake3": "49412fd31302e9d48b21246e6cfe964b95946b6b64603d48f2e00f9462e9d1d5" + } +} diff --git a/simready_assets/929/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/929/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7283cacaeac95faca488d0120eeacc5620c83599 --- /dev/null +++ b/simready_assets/929/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:11:02", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/929/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/929/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..9ecde6c57ab9c11ced06a3de314ac0a9b5e72f6d --- /dev/null +++ b/simready_assets/929/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,71 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_14/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_14.usd.png", + "size": 25432, + "hash": { + "sha256-flat-1mb": "fec38c498eabf696b71323aef83589355818b78cf96968e6501c9eb1c52a6a29", + "sha256": "05d11e7cbcc8099178d0e61ce8a32e39d9168e708978d79f82b13c5302acf118", + "blake3": "8dcc764741650f92972256ca28bf1f8227f7d482e77e7836e1deef19324e78be" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_4ft_x_2.5ft_diffuse.png", + "size": 1347302, + "hash": { + "sha256-flat-1mb": "96d83dbf018d5f967fb733dd0b0b97c9564c7cbe0d806b9b1a4e3f57909b9edf", + "sha256": "fba177196f868c132f2e4f089cf0462d69dca2dc831764a6833eb30a93fd17e0", + "blake3": "3223b1208cc2fef541158c1a68a08dbf6d7f1312ddb8953d024e777337a7526a", + "sha256-first1m": "09e8c876a2bf8b7314142c501f4929be056a1f5d4915caf95d1e13797ac06b2e" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_14.usd", + "size": 438970, + "hash": { + "sha256-flat-1mb": "6582a73f1a2ca6fa73b65b9305b8673b908eb8d7235da8207dceaa0ec0d6d8b8", + "sha256": "0e8958bce16c5875dd7e07c676e2355ea0640b1fd041e00300d925a607599806", + "blake3": "ccd26627d014d7e4504f8b1a4abd7841940300c296276cfd6459d6f3cea352f7" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/929/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/929/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..5ae0f1b1aa0b4f22fee04e0af071b8fb6717e70f --- /dev/null +++ b/simready_assets/929/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_14.usd" + ] +} diff --git a/simready_assets/929/SubUSDs/materials/pbr.mdl b/simready_assets/929/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/929/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/929/SubUSDs/materials/pbr_1.mdl b/simready_assets/929/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/929/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/929/gltf/pbr.mdl b/simready_assets/929/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/929/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/929/warehouse_pallet_14.usd b/simready_assets/929/warehouse_pallet_14.usd new file mode 100644 index 0000000000000000000000000000000000000000..67fdc817d6cf3637dd5ce47f68454d6900ed235e --- /dev/null +++ b/simready_assets/929/warehouse_pallet_14.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e8958bce16c5875dd7e07c676e2355ea0640b1fd041e00300d925a607599806 +size 438970 diff --git a/simready_assets/930/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/930/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..3f75072f23f21e4fdff09f81f27affa5ae71d18e --- /dev/null +++ b/simready_assets/930/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:17:17", + "assets": [ + { + "asset": "warehouse_pallet_15.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "3b5b5e396f7423a0b9a748536aefcae763895ef7bda2ef027d93d34a5b56cc0f", + "blake3": "493137c1d3e47bc9e1f589e945820f1eb6372e2429c5a45120dd1895a5191192" + } +} diff --git a/simready_assets/930/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/930/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..f434c3da75557c7916da2a5f0fff716e45808c67 --- /dev/null +++ b/simready_assets/930/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:17:17", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/930/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/930/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..3da12c4a27e1db2966b82d4aade2b026dbb2d20b --- /dev/null +++ b/simready_assets/930/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,91 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_15/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_15.usd.png", + "size": 27576, + "hash": { + "sha256-flat-1mb": "bf29271c9b1ee426df5d149cf90eb89374292034e3da905eb9546367b2a9a2bc", + "sha256": "6f40d1c6278cc8654f9a5f1026eeb129c819c05d20cd46b110e3a059a920f1ec", + "blake3": "161838e0fb91225cd1280cee005d353ec8221c54dcfb88ade72ef36d42ccbbee" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/barrel_diffuse.png", + "size": 2513496, + "hash": { + "sha256-flat-1mb": "250236fd8d389759ccd09a1e10018ee6474aceafb636022d2a87193fdb49233c", + "sha256": "f757afae70d9db1c5aad0960900040d2dbff35aee0d3d87fc3eedd9751bf1ece", + "blake3": "8cc7ab985afd512a1a89eac8c85ea322084519864795fcd7f07ca2332dca0385", + "sha256-first1m": "6d60e23256c876b28b3d8f3dad94ebc23162f3639bff43adbccb5033cc677a23" + } + }, + { + "relative_path": "SubUSDs/textures/barrel_matlic.jpg", + "size": 6224517, + "hash": { + "sha256-flat-1mb": "fe854fda60c744fa7776fae8142e2303d6e354099c054364e7185acd535fc32c", + "sha256": "e72431e7b77369070e515f25285b9bb35cb88926045fbba22ca486c96932a34b", + "blake3": "e3dff1ffaeafb282b1961908537b5d00ec1e8c5f8bc29de611a542abd7048dbf", + "sha256-first1m": "c9c0e17111e37b6d0ac85df18eb84c895b4f31d61b4b786fdd39d98cc591aed5" + } + }, + { + "relative_path": "SubUSDs/textures/barrel_normal.png", + "size": 586297, + "hash": { + "sha256-flat-1mb": "dd1c0dba6e7a3135ef3d17450d6820c7eafc509a17fed447f2291d7b99be3634", + "sha256": "0116bd25deb95220bfb9791ec2233110fda2c03f2f1f3d361c97a975cee0f2bc", + "blake3": "1e84b213658e1283028360435e53e6bc77ddbf814d101833fbccbba66b2e075a" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_15.usd", + "size": 1787648, + "hash": { + "sha256-flat-1mb": "3659f927a7490228ab09d61e922377b4154cafceb7f7897e74512b4ffff04749", + "sha256": "2b4b5d79a4fb785024c6614d8b152293a2debfba015665b249884fecb88757d6", + "blake3": "8c173a6a824b1ef6f9b8ead8ec90eccfdfbf791155a1b6cd3d6ce3d1edc5678c", + "sha256-first1m": "af4180557cdb2318c26d169fe2fb761c858373fe7b047bc4e2d0604b7fdc1894" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/930/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/930/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..14fd8da9a1f941e3e34d1cd7c3d7e51eeb102658 --- /dev/null +++ b/simready_assets/930/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_15.usd" + ] +} diff --git a/simready_assets/930/SubUSDs/materials/pbr.mdl b/simready_assets/930/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/930/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/930/SubUSDs/materials/pbr_1.mdl b/simready_assets/930/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/930/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/930/gltf/pbr.mdl b/simready_assets/930/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/930/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/930/warehouse_pallet_15.usd b/simready_assets/930/warehouse_pallet_15.usd new file mode 100644 index 0000000000000000000000000000000000000000..44c0770907601f347b8ddbb87590139b08981942 --- /dev/null +++ b/simready_assets/930/warehouse_pallet_15.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b4b5d79a4fb785024c6614d8b152293a2debfba015665b249884fecb88757d6 +size 1787648 diff --git a/simready_assets/931/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/931/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..2a8afd815cd48903bc45b6d3a380e67340f2e2d4 --- /dev/null +++ b/simready_assets/931/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:14:28", + "assets": [ + { + "asset": "warehouse_pallet_16.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "5ed2d9a7e3d8d8b420675e7fb54d70c48da8bd8b422cdc4fc57867cd05bcdd34", + "blake3": "c79965a2fe94895adb61343475d9fd48be2d023ff88a22369115b0eec50548db" + } +} diff --git a/simready_assets/931/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/931/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..11ea8181518759124248318eccfd97cda1b67ac4 --- /dev/null +++ b/simready_assets/931/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T22:14:29", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/931/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/931/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..441477a2452e9be1d2b0edb883d8a72f21687f18 --- /dev/null +++ b/simready_assets/931/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,91 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_pallet_16/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_pallet_16.usd.png", + "size": 23055, + "hash": { + "sha256-flat-1mb": "0bb9e0d8bf8326ae4fe3af1da68145acd2a7e4f173ddaf08616b490487ec4442", + "sha256": "17de3e3b24802d67bb536264f7340b65acbd362c5140345fea0ef583daa7ffef", + "blake3": "4780010ac5c249919b70fdf922e510052595efef409835082738eca8b64c2ec5" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/textures/barrel_diffuse.png", + "size": 2513496, + "hash": { + "sha256-flat-1mb": "250236fd8d389759ccd09a1e10018ee6474aceafb636022d2a87193fdb49233c", + "sha256": "f757afae70d9db1c5aad0960900040d2dbff35aee0d3d87fc3eedd9751bf1ece", + "blake3": "8cc7ab985afd512a1a89eac8c85ea322084519864795fcd7f07ca2332dca0385", + "sha256-first1m": "6d60e23256c876b28b3d8f3dad94ebc23162f3639bff43adbccb5033cc677a23" + } + }, + { + "relative_path": "SubUSDs/textures/barrel_matlic.jpg", + "size": 6224517, + "hash": { + "sha256-flat-1mb": "fe854fda60c744fa7776fae8142e2303d6e354099c054364e7185acd535fc32c", + "sha256": "e72431e7b77369070e515f25285b9bb35cb88926045fbba22ca486c96932a34b", + "blake3": "e3dff1ffaeafb282b1961908537b5d00ec1e8c5f8bc29de611a542abd7048dbf", + "sha256-first1m": "c9c0e17111e37b6d0ac85df18eb84c895b4f31d61b4b786fdd39d98cc591aed5" + } + }, + { + "relative_path": "SubUSDs/textures/barrel_normal.png", + "size": 586297, + "hash": { + "sha256-flat-1mb": "dd1c0dba6e7a3135ef3d17450d6820c7eafc509a17fed447f2291d7b99be3634", + "sha256": "0116bd25deb95220bfb9791ec2233110fda2c03f2f1f3d361c97a975cee0f2bc", + "blake3": "1e84b213658e1283028360435e53e6bc77ddbf814d101833fbccbba66b2e075a" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet_wood_diffuse.jpg", + "size": 2571401, + "hash": { + "sha256-flat-1mb": "04443509734364ad642f82d896dc8f7aa2d67d0a1da94be7b3199dd4f7a80ffc", + "sha256": "a91cd09ad91bb8007ba778d797591a68ba45ffa19c24edbb6e1a32787fc3943c", + "blake3": "21c5bcf2b88165ee9056c578e154bdef7f03783ff6ca7e895b9611b067d21400", + "sha256-first1m": "81b5b80a9325d1c6ed6ab329078a337dfe4c22d053740044eb0aeeede1f2e49a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_pallet_16.usd", + "size": 1807274, + "hash": { + "sha256-flat-1mb": "dc54233255c929babf16edf759e5415097289cc75d2cd5b2e0e3051e4d2d0e51", + "sha256": "6f943771de4eb51e0a2f1427da7a8f06618c87230be8e64e1361c15c255fbc49", + "blake3": "dd260d8ad67639999eac4a2cedc763b97fee70242c10d334ac1f2fa466a6dcc3", + "sha256-first1m": "533af7854e3d13844248273e48b51efaa796fd6c19b138df52f3ed2e5b55c82d" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/931/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/931/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..a23904b57403cb1f7c9495536c14a24c22776888 --- /dev/null +++ b/simready_assets/931/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_pallet_16.usd" + ] +} diff --git a/simready_assets/931/SubUSDs/materials/pbr.mdl b/simready_assets/931/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/931/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/931/SubUSDs/materials/pbr_1.mdl b/simready_assets/931/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/931/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/931/gltf/pbr.mdl b/simready_assets/931/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/931/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/931/warehouse_pallet_16.usd b/simready_assets/931/warehouse_pallet_16.usd new file mode 100644 index 0000000000000000000000000000000000000000..426628663447a7d6609bb50f475f50971cab9f2c --- /dev/null +++ b/simready_assets/931/warehouse_pallet_16.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f943771de4eb51e0a2f1427da7a8f06618c87230be8e64e1361c15c255fbc49 +size 1807274 diff --git a/simready_assets/932/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/932/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..d50ad719c5d4cfcb0315fdfd44635bd24715fdbe --- /dev/null +++ b/simready_assets/932/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:47:38", + "assets": [ + { + "asset": "wooden_pallet_4_ft_X_4_ft_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "dad2b35fecd7e1ce84648be96d80a481f290389c2880f6ee999c4a582406fc17", + "blake3": "5028bb17477dbfcb40aa54ad3e7c149468f2b7df808fe22544eec23e11cdfeec" + } +} diff --git a/simready_assets/932/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/932/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..757dcedf29f4a9febec43543e5ac5365a82368fe --- /dev/null +++ b/simready_assets/932/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:47:38", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/932/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/932/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..16a073c3c2ad4f7fe5015a6e9499f404ee3dbeec --- /dev/null +++ b/simready_assets/932/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/wooden_pallet_4_ft_x_4_ft_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wooden_pallet_4_ft_X_4_ft_2.usd.png", + "size": 20175, + "hash": { + "sha256-flat-1mb": "1df1ccf27db6c42ca0f37509ce78ed9e9c23cf1036a706860cd4bfd09de80475", + "sha256": "dbf2787e166c9be639b2dfe35c087a2428419e0561a28a6460313fab62de7341", + "blake3": "0b6b59cf5077727cb915452ff1ec705baee57fea9c3efee2de2acd25e292bc06" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet 4_ft_X_4_ft_diffuse.jpg", + "size": 4079775, + "hash": { + "sha256-flat-1mb": "5be795b146e175f040a6e74ffdb9f9948094b2c3feb72fc2914019d9b4d47168", + "sha256": "12eaaf16da4b6bca32a425d2640011ef4291848539eab1465a3d132ecacdde03", + "blake3": "3ff596aa204ca6ed4ef3a9aac52356e95f5eadabc5478dc72cd9227dacaf3c09", + "sha256-first1m": "a989fa83c52fd39a780cfc1c90808923c77bfd7e2bf8571dd9e36a46ede92607" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "wooden_pallet_4_ft_X_4_ft_2.usd", + "size": 372223, + "hash": { + "sha256-flat-1mb": "059f937a276585757b12f92f7552917ba9c3ccf7a33f83f1cc4133281c3f1fe1", + "sha256": "6d0180f54889295fd8ecd570ac20e0201d4f36fe3c3fc1adcff76236553e6b52", + "blake3": "862c6d16c043ff6e3aeff29f22851c8196d752b958b359ee876c7a3f27878a04" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/932/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/932/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6784131cdfe9eac8254b2ecd538a94730299a0b6 --- /dev/null +++ b/simready_assets/932/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wooden_pallet_4_ft_X_4_ft_2.usd" + ] +} diff --git a/simready_assets/932/gltf/pbr.mdl b/simready_assets/932/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/932/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/932/wooden_pallet_4_ft_X_4_ft_2.usd b/simready_assets/932/wooden_pallet_4_ft_X_4_ft_2.usd new file mode 100644 index 0000000000000000000000000000000000000000..4304ae747f59099ca9ae51894b1e50a2c89b533e --- /dev/null +++ b/simready_assets/932/wooden_pallet_4_ft_X_4_ft_2.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d0180f54889295fd8ecd570ac20e0201d4f36fe3c3fc1adcff76236553e6b52 +size 372223 diff --git a/simready_assets/933/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/933/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9a3c163aacb4802ffdc3d6ec2c5568e1f57e031b --- /dev/null +++ b/simready_assets/933/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:42:32", + "assets": [ + { + "asset": "wooden_pallet_4_ft_X_3_33_ft.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "984bf3831498bfbec73b864e2d7646afebbeb2c8d2aac450b530d67106223a20", + "blake3": "0959d3ce91bfd46e740b39e437b4ef8c3a0017710e9e9d1fc30cd9b50cbec90c" + } +} diff --git a/simready_assets/933/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/933/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..d1fe9575897f10fc2a97054be30c89611227416d --- /dev/null +++ b/simready_assets/933/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T14:42:33", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/933/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/933/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..5b3dfd16fddcc455b168bbf7bd930190d4ca6d65 --- /dev/null +++ b/simready_assets/933/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/wooden_pallet_4_ft_x_3_33_ft/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wooden_pallet_4_ft_X_3_33_ft.usd.png", + "size": 23703, + "hash": { + "sha256-flat-1mb": "43ce8596191111b69b1e125f3471b2c1abd74c4446dfefb3fd6f2687b81f3fcf", + "sha256": "26b273b5d585ababff8a230761707ab209acaa5ed6fb19a2ea089ee2bfe77c9a", + "blake3": "36708093cf136574b261e0317e741ac50b2e7f4fcf051d908b000b7107daeed4" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_pallet 4_ft_X_3.33_ft_diffuse.jpg", + "size": 4079775, + "hash": { + "sha256-flat-1mb": "5be795b146e175f040a6e74ffdb9f9948094b2c3feb72fc2914019d9b4d47168", + "sha256": "12eaaf16da4b6bca32a425d2640011ef4291848539eab1465a3d132ecacdde03", + "blake3": "3ff596aa204ca6ed4ef3a9aac52356e95f5eadabc5478dc72cd9227dacaf3c09", + "sha256-first1m": "a989fa83c52fd39a780cfc1c90808923c77bfd7e2bf8571dd9e36a46ede92607" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "wooden_pallet_4_ft_X_3_33_ft.usd", + "size": 432978, + "hash": { + "sha256-flat-1mb": "2f70804babb27fd55696c1c41e15c88975d1034c05b8cd72923f35a07b8424cb", + "sha256": "8b9cd784a404433300cfcfd86ab5239976c938889a2cbe33a0359d2916ebfd5e", + "blake3": "871b7566fb6eeac8039b753762052e541f66a62e6047551eabb346704a59b5c4" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/933/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/933/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..7a9451e94318424c99b2d04807d99b1af1851ade --- /dev/null +++ b/simready_assets/933/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wooden_pallet_4_ft_X_3_33_ft.usd" + ] +} diff --git a/simready_assets/933/gltf/pbr.mdl b/simready_assets/933/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/933/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/933/wooden_pallet_4_ft_X_3_33_ft.usd b/simready_assets/933/wooden_pallet_4_ft_X_3_33_ft.usd new file mode 100644 index 0000000000000000000000000000000000000000..f57b4359a333eade598348a8cd1bc1a1c4aa2461 --- /dev/null +++ b/simready_assets/933/wooden_pallet_4_ft_X_3_33_ft.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b9cd784a404433300cfcfd86ab5239976c938889a2cbe33a0359d2916ebfd5e +size 432978 diff --git a/simready_assets/934/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/934/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..56228c6cfcd7ca8af5dcc95812686287b09b675c --- /dev/null +++ b/simready_assets/934/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T18:27:34", + "assets": [ + { + "asset": "traffic_barrier_gate.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "b0de284dda3548f69d1597c31b99e511f437f192974e4c2d581c0e727615c25f", + "blake3": "e9d63325993d02d5a573f2e8c5a9e83e203d9942396347b9ad06bdcbd0e2ff1c" + } +} diff --git a/simready_assets/934/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/934/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..21d3966e751006f1cf50b9b394f12c069f9afece --- /dev/null +++ b/simready_assets/934/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T18:27:34", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/934/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/934/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..2443e3d1633b0d6bc0ab418f4bf169cb2aa94cd9 --- /dev/null +++ b/simready_assets/934/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,52 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/traffic_barrier_gate/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/traffic_barrier_gate.usd.png", + "size": 11025, + "hash": { + "sha256-flat-1mb": "ae8c18251f0bb0320ab2cadead34f428cc0f8de6a562653cd90f94f01cfebdee", + "sha256": "729e36ff9b00f655077cea417b5c1806900897a70c7cdaf687829118f7570ef8", + "blake3": "291116149bd8f6646f82b753f32550bb6e3e32c662011703228247f3b624dac2" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_plastic_normal.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_stop_sign_diff.jpg", + "size": 70547, + "hash": { + "sha256-flat-1mb": "732059901b810ac6b3bffae2bf5c386208bb70a22c6970c5b8e007c6f7fa2790", + "sha256": "ffda0d2d75bf11b10de0c2d83f0d3025771538e75c8ffde413805f84abe788ab", + "blake3": "ff7950842c7924b252f5c2e0ea9e41506e98150d88e07dc5a097e5126c1f462f" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "traffic_barrier_gate.usd", + "size": 1638774, + "hash": { + "sha256-flat-1mb": "23320c574f9eef93d165cc9d3f6fe37ee346ffa2be24d6535f5db423db8e814c", + "sha256": "1a4bb6732160aaf88ebdc79216ff9a385893437700f2935956e8f1a7bbf31d4e", + "blake3": "63421b28d9c196945b0dc5ece88ead92a17c0041050365ae83880c11de80eb1e", + "sha256-first1m": "7091d1dd01a25b7ed8e398ed6b4b63cab6768f3aa4f1eeeb620609a6e92ea012" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/934/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/934/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..99381cce05e52e3c7777948fbacc5f4c1e5aa366 --- /dev/null +++ b/simready_assets/934/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "traffic_barrier_gate.usd" + ] +} diff --git a/simready_assets/934/gltf/pbr.mdl b/simready_assets/934/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/934/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/934/traffic_barrier_gate.usd b/simready_assets/934/traffic_barrier_gate.usd new file mode 100644 index 0000000000000000000000000000000000000000..0e00112dac12231e87e0712861fa8c4aa5f0980c --- /dev/null +++ b/simready_assets/934/traffic_barrier_gate.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a4bb6732160aaf88ebdc79216ff9a385893437700f2935956e8f1a7bbf31d4e +size 1638774 diff --git a/simready_assets/935/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/935/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..cc6911c97a39c7fa16fa1f3997eff5dbab90da87 --- /dev/null +++ b/simready_assets/935/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T18:29:00", + "assets": [ + { + "asset": "tool_box.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "cff05e09da02cbd49a44b985528891163bf986674d927a9012d8d5d3cd353f0f", + "blake3": "db41ef42dbb207b619cd988899d518a29d472c38ca1f68581663a31d7f9a51f7" + } +} diff --git a/simready_assets/935/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/935/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..a554ee2b316f9bdf9ce4a76bcab95da96b1405f6 --- /dev/null +++ b/simready_assets/935/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T18:29:00", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/935/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/935/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..97298fa3a9df6127587a0808456bd793a5b19421 --- /dev/null +++ b/simready_assets/935/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,44 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/tool_box/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/tool_box.usd.png", + "size": 14329, + "hash": { + "sha256-flat-1mb": "dc7f6e4fc8c6406dceae2cbc51b45fbc0668c91aabf0fd60689acc87bdca5f45", + "sha256": "5552f054ec4f84f3ee29d35243c89f223b144a6e5d77c334c1c7ae3e5694cdcf", + "blake3": "2ef69dcb0b404156ce8a3b401cc0862fe6450c080eaf3cce9504bdbb7b8540b0" + } + }, + { + "relative_path": "SubUSDs/textures/tool_box_top_diffuse.jpg", + "size": 19406580, + "hash": { + "sha256-flat-1mb": "7f3fdb54188c693851d3e670a8670a1879cc91b6b138fe78792193b6681b0652", + "sha256": "a51f8566bbc195d694bba6f1403191be01748e261614b774a37cf49d86041710", + "blake3": "547d8c420e0970b744e2e2d1f3c9c68d8eede4554058f1ea66649858dd82a6a1", + "sha256-first1m": "a599d13d05702ab1bebbddc63f26dd9622d1edc397ac9355bdad9be6e3367048" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "tool_box.usd", + "size": 5973913, + "hash": { + "sha256-flat-1mb": "59bca937809dca1e28d2a49d450f6846f9dc9ee9d010a6979d8ffb744a27f717", + "sha256": "ea2714459fefa3f5b4dbabdc2648868682c92c88d864ec301a1a9b3e85a87b20", + "blake3": "13af683df0bc7be39fce9e3b78eb911d93878f476ddda1c0cd86d220566d6e87", + "sha256-first1m": "4b75323634d8ffaaa03d8402b4234f26b902bfd973ab381b3df09614d6f0f980" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/935/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/935/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..0673cf72ebccf2e8b2d0051d4b7d856ad6cb6163 --- /dev/null +++ b/simready_assets/935/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "tool_box.usd" + ] +} diff --git a/simready_assets/935/gltf/pbr.mdl b/simready_assets/935/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/935/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/935/tool_box.usd b/simready_assets/935/tool_box.usd new file mode 100644 index 0000000000000000000000000000000000000000..f25c751f956ae01f9f530998d1fc575cfc31045d --- /dev/null +++ b/simready_assets/935/tool_box.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea2714459fefa3f5b4dbabdc2648868682c92c88d864ec301a1a9b3e85a87b20 +size 5973913 diff --git a/simready_assets/936/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/936/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..ab0cba1a17870e6f870e502076ae05d4a29304c3 --- /dev/null +++ b/simready_assets/936/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T13:21:56", + "assets": [ + { + "asset": "wooden_crate_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "ea0a6a11471d6fe2f5a62eac6aec2934993b560fd0a8a13ce41a7529a89337dd", + "blake3": "93167073f33bef799e435d846ca3ea58479905d3136b5d070bb2b77bf8cdc3a8" + } +} diff --git a/simready_assets/936/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/936/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..d8a2ada34ce4ddc35029175d61e778b68418e120 --- /dev/null +++ b/simready_assets/936/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T13:21:57", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/936/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/936/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..d14f997294d8033fd73e3dd76074abcc17c8119f --- /dev/null +++ b/simready_assets/936/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,53 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/wooden_crate_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wooden_crate_2.usd.png", + "size": 34070, + "hash": { + "sha256-flat-1mb": "d8c7ae5c009d7292486ba62e43f6d976613138ebbf31b01d6b36f96465f4cb91", + "sha256": "7221c5b9199f06ef0ce6139105b5aebbfd14e530f570181b672953bb43ea954e", + "blake3": "8b2a2ec9af2e5476eeabc27fc38af9610e2f1e521a41cc90d0ad7bf887afd907" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_2_diffuse.png", + "size": 2891616, + "hash": { + "sha256-flat-1mb": "4cc0cfb9351f2e85e6f2fa7b2009a043bef31d0614da99afea47b88c60c9cd75", + "sha256": "dedb5594e94610870c27daeb3b33d0d7d0c0393124e7b527b1a47c6d21d1badd", + "blake3": "525a03419f524a390bc9d89d3395dfbc7b36cd96e4a93fbbbe2d60711ba7b375", + "sha256-first1m": "73bb3f9eba24a783e0b43e3bed3c0f7187558b9777f52a1b83580f0cbdf84486" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_2_normal.jpg", + "size": 3678940, + "hash": { + "sha256-flat-1mb": "c2cf947cb872bfaba79d1ee544c82aee3dd32d7a0270db79dafefeff1fd1d3f8", + "sha256": "6ee780c31b9f4a8761daf26b6d7a69f30fb47c2b6fbc1abfd4d11e0b92177261", + "blake3": "c307fd272035ef05715653956607a5c70e1d7fa31ea35ff630ba11897890fc89", + "sha256-first1m": "ea0a6cbcd959b60e12037579b50ade5aea62843b28fdc120ef307ec22e80be3a" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "wooden_crate_2.usd", + "size": 152636, + "hash": { + "sha256-flat-1mb": "ef8a8edc5089f02a0faa246105a07cae32b846df4c7960a0a8e1f40d432867f9", + "sha256": "e6fcdfb58e6bca52b81eb928f236d256b364920f630a8f82d35ecdda41eec3bc", + "blake3": "0cb08bef2a4c9137a1eed392d4804b2223a312ed52bdcbcd0f89e079a3ebc0a6" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/936/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/936/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6a7e6b94e89289687d81151c7441779b9f4e8a0f --- /dev/null +++ b/simready_assets/936/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wooden_crate_2.usd" + ] +} diff --git a/simready_assets/936/gltf/pbr.mdl b/simready_assets/936/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/936/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/936/wooden_crate_2.usd b/simready_assets/936/wooden_crate_2.usd new file mode 100644 index 0000000000000000000000000000000000000000..35097ee436f24575dbc42f0c61498304f71a077e --- /dev/null +++ b/simready_assets/936/wooden_crate_2.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4fed3e6dad9b4528fcf343e9fa10450fa51de76ae0277917514027b9f46b9ddc +size 153341 diff --git a/simready_assets/937/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/937/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..671da6da060d4fcdcb39e1073e8b4b69e3f3e09d --- /dev/null +++ b/simready_assets/937/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T21:17:24", + "assets": [ + { + "asset": "wooden_crate_3.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "0c6dd4659b560a0d7459dbe3dd21f1da3aefbf7b6b69b6dae853a5f0cec2bce8", + "blake3": "8944c33af24e5def16e67ff32f35ec31ceeef54e26d03839c9ab4309429137e4" + } +} diff --git a/simready_assets/937/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/937/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..2177685e376eb9a528bfac340c39813ff80fafe7 --- /dev/null +++ b/simready_assets/937/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T21:17:24", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/937/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/937/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..ddc3a1ee3999455c7972899949e1ed1e3ec20112 --- /dev/null +++ b/simready_assets/937/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,53 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/wooden_crate_3/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wooden_crate_3.usd.png", + "size": 44167, + "hash": { + "sha256-flat-1mb": "934ea66622929068fd86d122b69f572d42ff79e703935f32d57628026e74850e", + "sha256": "20ed6e11137bf75d9f2a072eef571deae1ea449a2ebfb941d64469c9cada471c", + "blake3": "7ab0002a8a7c6746855a2992af859510bc85b575894ae3923cbe81ac2962ff1b" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_3_diffuse.png", + "size": 3070648, + "hash": { + "sha256-flat-1mb": "09706219d77bc9dff395c79f19796ca1f599e9c4fda5fa4f9c68e4665bb3b278", + "sha256": "4a0e6a82d5fd6c5fa14ad5bdb02b85f4b4c821609bbd2e3d01b244d9b58e8fe8", + "blake3": "627009532b7bf5d944dcf6b84ba0729319c5788f49928dac98b42e0a8c922329", + "sha256-first1m": "8fe763e045bfcec82d4d519a182564f743c51ef79a93152eec75d527be189daa" + } + }, + { + "relative_path": "SubUSDs/textures/wooden_crate_3_normal.jpg", + "size": 3790414, + "hash": { + "sha256-flat-1mb": "fd4d78eb42a641ea9cb5e8c36ebc2346108c2676a7a8b6f9fd40f4f159a9e749", + "sha256": "985e219647024a5d8cd4bf5b19e26f03184c257c696a533ba7d6f89d5b58f8ff", + "blake3": "9d7e4b6a857091443ff0d0460c3dab71f38e069133f79eccb5f01e99e0309990", + "sha256-first1m": "a5f238c00b6b1ba78bf2f3eea511457681e731fc7d692ec33167dcc5a054a564" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "wooden_crate_3.usd", + "size": 162564, + "hash": { + "sha256-flat-1mb": "cce034268d56a7e3088e2041050eba0437821da954e1fa42b324d62fbcae4f87", + "sha256": "09c345ddda90b7a5a46e12d982c054d6edce2df76c1bb3aae5c10fc49abb6970", + "blake3": "6aa6e7dadf33307468b9d67a11e1dbbba7fc88980fc197e65c8d90aa05e29239" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/937/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/937/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..19e378c6a49719b4084b4852b7dba74dea65ddd9 --- /dev/null +++ b/simready_assets/937/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wooden_crate_3.usd" + ] +} diff --git a/simready_assets/937/gltf/pbr.mdl b/simready_assets/937/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/937/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/937/wooden_crate_3.usd b/simready_assets/937/wooden_crate_3.usd new file mode 100644 index 0000000000000000000000000000000000000000..dfbccc88e600e8e2858c4d340638953b4629f70c --- /dev/null +++ b/simready_assets/937/wooden_crate_3.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb20affb1875a2a09af50dca14217c78b27563a62d5978410be45048a78b5fd5 +size 163298 diff --git a/simready_assets/938/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/938/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..8a7c318520615416cd8b4c9f87957e15d3389c12 --- /dev/null +++ b/simready_assets/938/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T13:49:09", + "assets": [ + { + "asset": "wire_mesh_partition.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "94bd962a63bc50a79011d43d1cc5f1dbcdc2246d27f0726f8e312f7b299e43a9", + "blake3": "974cf44798afcfc8df0b3308b36617569f60579e8eb652bdb8fa741b0aa0abcb" + } +} diff --git a/simready_assets/938/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/938/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..67db3dd5cae22f63891ea6c34d0ada47bebedebb --- /dev/null +++ b/simready_assets/938/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T13:49:09", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/938/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/938/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..36e84fe7b7ebee439cd35a073975e8fb391586e3 --- /dev/null +++ b/simready_assets/938/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/wire_mesh_partition/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wire_mesh_partition.usd.png", + "size": 22230, + "hash": { + "sha256-flat-1mb": "ae709f2249a5efe3bf82c0057e37a470121b07b04bcc279dcc890b49b0215786", + "sha256": "ceb160b07415132b5239d08e4e5cac966dfd4af5986fe9040b83199a101f1ae3", + "blake3": "6bd79081cb64e56a3a5fe564ba868636b91d937bce09841d62b5ca25cbdfaa55" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "wire_mesh_partition.usd", + "size": 4471711, + "hash": { + "sha256-flat-1mb": "2fdcfa3215b4b7ec4bf8b9fefffb63334895cae3aa38b606b1954972a1612878", + "sha256": "3a1d347e5012f7d44b9d9f245eada87d7404f23755679a7af4c0e02133c21fb3", + "blake3": "5a6cc29277ff2ba2773c8bd2feb9ea71110162641a6d8d137bdf9fadf85b1065", + "sha256-first1m": "92d722ebaf1da3170a022602005fc0f9f01a21b24c82f104aefeff632ef45296" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/938/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/938/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..a974249252459d768f54b8bee7d86c449ba6f52d --- /dev/null +++ b/simready_assets/938/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wire_mesh_partition.usd" + ] +} diff --git a/simready_assets/938/gltf/pbr.mdl b/simready_assets/938/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/938/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/938/wire_mesh_partition.usd b/simready_assets/938/wire_mesh_partition.usd new file mode 100644 index 0000000000000000000000000000000000000000..9e560a3bcfcb05270aafe65e2cafd2533a72eb3b --- /dev/null +++ b/simready_assets/938/wire_mesh_partition.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a1d347e5012f7d44b9d9f245eada87d7404f23755679a7af4c0e02133c21fb3 +size 4471711 diff --git a/simready_assets/939/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/939/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..905cb611085a0af74413b612cfe0a99906955111 --- /dev/null +++ b/simready_assets/939/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T14:38:27", + "assets": [ + { + "asset": "wire_mesh_partition_gate_6.93ftx6.77ft.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "a59793ca5de0414f0984561f687ae7c92f2d913d7088d545c2cf52185f8c9997", + "blake3": "d91c06459c9ac8f58e863d51f8b8619b96644a2bf82a1606dec08edb12a8d5bb" + } +} diff --git a/simready_assets/939/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/939/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..1980fbfffd2440e262aec86b945a6c1d27e19e08 --- /dev/null +++ b/simready_assets/939/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T14:38:27", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/939/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/939/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..2a024914a20e09f34f52a430a002230a467469d3 --- /dev/null +++ b/simready_assets/939/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/wire_mesh_partition_gate_6_93ftx6_77ft/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/wire_mesh_partition_gate_6.93ftx6.77ft.usd.png", + "size": 18764, + "hash": { + "sha256-flat-1mb": "d793d2404d6282e04faf95e221faa770ea81a63c3e4db06b349cd6941c3d94e2", + "sha256": "2eff892b09c54c56e66e7678c2d76550fdae6d3048445ea96a20a5cf5ed35de8", + "blake3": "0974d3b481c5d7c182fa31fc205862b8cdbddc2f611168240a613c7dd16e2aff" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "wire_mesh_partition_gate_6.93ftx6.77ft.usd", + "size": 4274933, + "hash": { + "sha256-flat-1mb": "d238a2b483940bd0fe5e764d26eff91b71f3078f08280486195517a2409bb090", + "sha256": "aa99bd8f0f8a694bf385c4176111896d127b424523b61b4f261951d18111c331", + "blake3": "78a80769f4e99c65dfff67a313dfebccff6eadeaf58e658e1883f58802a32643", + "sha256-first1m": "6c765b7fc375792160422dd0a6fc4bad8bba77f82df508e103e65bb374c87a96" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/939/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/939/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..652e2900f12e56b1ffe4138365f5839b35da898e --- /dev/null +++ b/simready_assets/939/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "wire_mesh_partition_gate_6.93ftx6.77ft.usd" + ] +} diff --git a/simready_assets/939/gltf/pbr.mdl b/simready_assets/939/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/939/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/939/wire_mesh_partition_gate_6.93ftx6.77ft.usd b/simready_assets/939/wire_mesh_partition_gate_6.93ftx6.77ft.usd new file mode 100644 index 0000000000000000000000000000000000000000..1a38a0ec341990b8313b940e8ca30c139fae1742 --- /dev/null +++ b/simready_assets/939/wire_mesh_partition_gate_6.93ftx6.77ft.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aa99bd8f0f8a694bf385c4176111896d127b424523b61b4f261951d18111c331 +size 4274933 diff --git a/simready_assets/940/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/940/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..8418ae127fe734227d17117d7c772453f0bfbc9d --- /dev/null +++ b/simready_assets/940/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T21:10:50", + "assets": [ + { + "asset": "warehouse_rack_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "5ca723556fbeface6faed7f02239987b7a72c8d13af134e32d8f4b136772f616", + "blake3": "46572fc80152c25c615d0b2eb41440aba13da990892f8bbcade526b491ec45ad" + } +} diff --git a/simready_assets/940/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/940/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..84fc2cc9ea35e378612a5e20e553dfb1feff7c50 --- /dev/null +++ b/simready_assets/940/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T21:10:50", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/940/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/940/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..3eea1e4013f5a3995ef912cecba9f48e61f04d4f --- /dev/null +++ b/simready_assets/940/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/warehouse_rack_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_rack_2.usd.png", + "size": 12474, + "hash": { + "sha256-flat-1mb": "1922d4176248cfe7b896934c21ca965c12f1c7cf7ade4621c8b28417f2045c6a", + "sha256": "a15e3138765bec49ec608d21650304affbfb021fa1219a7bed87d55eb2c68bef", + "blake3": "19f7698bfbf6dddbb17b50121dff05c304540ff8e0397963e97c23f7bc5202d6" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "warehouse_rack_2.usd", + "size": 3942704, + "hash": { + "sha256-flat-1mb": "8d65737e50b47e4d23064c25042fb3f7caa86518b1ee5336a7256cc4adc21640", + "sha256": "3911e7662d66b98b4437a675c1bbc0fb6f349bc51a39bd352ca4c311dff8209f", + "blake3": "d961aaf3b09786f5415a8ab6452008990e573153541fcaca1757feba76697e2a", + "sha256-first1m": "1f5f6ee2310737fca6b6642904f46cad7b60d8657ad4af82af9f16f734ae51d4" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/940/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/940/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..df1f4e46a5c1fd37f5cfd951387e9864463ce9c4 --- /dev/null +++ b/simready_assets/940/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_rack_2.usd" + ] +} diff --git a/simready_assets/940/gltf/pbr.mdl b/simready_assets/940/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/940/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/940/warehouse_rack_2.usd b/simready_assets/940/warehouse_rack_2.usd new file mode 100644 index 0000000000000000000000000000000000000000..a0ee4aa031223859445e199dcfd46bf02eb29b91 --- /dev/null +++ b/simready_assets/940/warehouse_rack_2.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3911e7662d66b98b4437a675c1bbc0fb6f349bc51a39bd352ca4c311dff8209f +size 3942704 diff --git a/simready_assets/941/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/941/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..2d4be7102c99653c2edf0a58bbd0109775ff471c --- /dev/null +++ b/simready_assets/941/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T20:30:32", + "assets": [ + { + "asset": "hydraulic_dock_leveler.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "0423b688336a939bf4813b3b2af98cae8ac1e81ace6a1e6ef48d04b0305c3946", + "blake3": "ec095818a0002c7ea4ccae1154b7696ddd69e81be85b0adf3319301222159685" + } +} diff --git a/simready_assets/941/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/941/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..90c17b0d92feb9f7f0c27795ddb72e52c5423d5d --- /dev/null +++ b/simready_assets/941/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T20:30:33", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/941/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/941/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..5fc4f332a7db7c1a5e2f6192f8b5d5e4ec519489 --- /dev/null +++ b/simready_assets/941/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,121 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/hydraulic_dock_leveler/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/hydraulic_dock_leveler.usd.png", + "size": 26636, + "hash": { + "sha256-flat-1mb": "3a9ddc89ac7205ab9edc6d66716111681247535e6821a17a0e79d6d7dccffe5c", + "sha256": "f03843cc9367ac146cd432d3eab689d3df12dde0069438fd3811279a10b3fcc5", + "blake3": "4101acb797adf4439532682f69421816da08ff8e2af7e3fa88472fbe3dede7c4" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_blue_metal_diff.jpg", + "size": 1606292, + "hash": { + "sha256-flat-1mb": "8279ee3d9bd1e369a5ca7c4a51c879a7619be89263659f692bb861c60b5df32c", + "sha256": "51fb63ed1f01ddd7b73c2e1a37b0452d604bedc21d3b9d68e1d0703c87c50d9d", + "blake3": "0bc5f587ccfd5e1a510c47a9ab5522787a14482bc9a03e6e1e93c78fb45fd858", + "sha256-first1m": "d983eb986a9b4ef83e6f9ea72c1edcb676098028a0dba974ad8b9653689bcd76" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_blue_metal_rough.png", + "size": 2894711, + "hash": { + "sha256-flat-1mb": "ae1df360f1bccc34ae9a30b08e451a823ce91de29fa089bccc8fcca81ded1256", + "sha256": "490f50a06a829337949ec0054f16b43a8bcb785ffece4dc8f1bd20c370afd78b", + "blake3": "a270fc2ae4a2f8a42c69f4b5da9aeade09dbda0e8b131d34f1f14a57e0415da9", + "sha256-first1m": "e6da27cf6c536fc923f076c876e1ab8bf838162625e8e4c7e9f73cc709b8b570" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_normal.jpg.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_pattern_3_dff.png", + "size": 156881, + "hash": { + "sha256-flat-1mb": "7c96d7901e4bd76e20d28bd6a44511764fb39b28d21fc391650f183559768d05", + "sha256": "e8432441ffedfc5fec525287f10e079727ed4066cdb7ad0679de7f22018f4903", + "blake3": "540b5a5eab3705fb2edc9a979e5261960499ef7e7e99e1b6e1694ab0524fad53" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_pattern_dff.png", + "size": 85981, + "hash": { + "sha256-flat-1mb": "2660dc7e8d306ebaea44751e8c9f0393327e7279a4c0c7f6c7ebae96459a9fe8", + "sha256": "072dd56821b8d015132e2d374d81daea1def59b3237c8ef6a28d318d16f46932", + "blake3": "f8944171f20654a4dc30d9e15786bcb3f621fd3f72af51b5eb33cf9c84b8c98f" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_suface_normal.png", + "size": 22929427, + "hash": { + "sha256-flat-1mb": "d8638a695f5345524fa48d7880cec7a8e8642ac68568a45682d57e0643be987b", + "sha256": "ca2993877cedc99958c8a385fcc57e010b655901323ac6b671ce0d05304104b4", + "blake3": "6f465a6ba872d49dd9fd1b510f608b8e11bb8fc4a734bf691d2650f47be0876f", + "sha256-first1m": "b477754b88a1ace44feac1bace3d764bc0663aabeb75a6a165e7381cdf9bd0b7" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_white_metal_diff.png", + "size": 3760481, + "hash": { + "sha256-flat-1mb": "bde07916b64d4238a57f0931eba07dfb129b487ce6c9cf47ec1382e65da27494", + "sha256": "75b01648f0e95b59206a70f282543941c79cb77eac4ca0d7bce4b936136113ab", + "blake3": "b02ad5585a3b43b35c581e9eb210adba899463460e6841482352646577ff118f", + "sha256-first1m": "4babadc5411c3ed6b7c0c146d9744396e512d819864471d9a80b755bd356f788" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_white_metal_metal-opaque_white_metal_rough.png", + "size": 1837143, + "hash": { + "sha256-flat-1mb": "0e7d5e74aa525b2b2051537d9ed35f2e7ba7e378a2e7d0ff645d3d04e89bfd04", + "sha256": "9d3647ea9b1d678abd4231f883f60aefa318b9dfc97fc15cfee37fcc1f6557f0", + "blake3": "6882d8f25cecb55ea562b433f182df33dcc6edcf9d60bf52e0dd27940177e3f1", + "sha256-first1m": "3749849883f645f6774dff339510d9a84e3dc2395746d3f7e86c612a45e60a1b" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_white_metal_normal.png", + "size": 16591547, + "hash": { + "sha256-flat-1mb": "0a56acc8371ea3170390bc4e0cd998d656992badbd060b84fd05a220995279db", + "sha256": "91a74bb5bf5c7909674f7a58d82b879720580c1a11c8610be9c4d444e3f94d96", + "blake3": "604f405be25939b2a03633760460af558910491e0c4e1061604406a040d3eb3a", + "sha256-first1m": "3fabcd7bc7270ec74af7951a4832cab58b97cfacbf85af61969f55b1eaf3e340" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "hydraulic_dock_leveler.usd", + "size": 6493469, + "hash": { + "sha256-flat-1mb": "9249e529967fc13d2f072c9c74fc78fa1a57e5335c087fd7d02a57e709137a91", + "sha256": "bafa18a105b67d6e246d4b040559a36a1b262ab38a2ed4a9e7448eb96de6b99f", + "blake3": "639535e423b68bd19cd944d55f0c1b4076a5a65d6b0dfd1ee6a2686d6d6826c1", + "sha256-first1m": "379c66fd3c9351712440d14cb534605630213eee19389645920087c046b1a9ea" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/941/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/941/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..a702da850410c081d56968efc2ecbe3955ec61fe --- /dev/null +++ b/simready_assets/941/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "hydraulic_dock_leveler.usd" + ] +} diff --git a/simready_assets/941/gltf/pbr.mdl b/simready_assets/941/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/941/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/941/hydraulic_dock_leveler.usd b/simready_assets/941/hydraulic_dock_leveler.usd new file mode 100644 index 0000000000000000000000000000000000000000..293565230da6a5b248e645d07a3c7b13ed77d93f --- /dev/null +++ b/simready_assets/941/hydraulic_dock_leveler.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bafa18a105b67d6e246d4b040559a36a1b262ab38a2ed4a9e7448eb96de6b99f +size 6493469 diff --git a/simready_assets/942/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/942/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9592a5d1a46ed267e7f0e23325eb0866bb33461e --- /dev/null +++ b/simready_assets/942/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T20:37:42", + "assets": [ + { + "asset": "hydraulic_dock_leveler_elevated.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "bbafb3ddf4b0f9dfda6bbde692e916ae48256059ed164b3d4738eb06ab34dd98", + "blake3": "6ae12b09f49950db8568c67d79f631075dc6e9326e9346c67d923b408bf51878" + } +} diff --git a/simready_assets/942/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/942/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..bbdbefe2d5bf5a3548de65851cbb121e48155240 --- /dev/null +++ b/simready_assets/942/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-20T20:37:42", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/942/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/942/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..a1efe9b96ce4edca7ac6f18fc6dd3be2732ae61b --- /dev/null +++ b/simready_assets/942/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,121 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/hydraulic_dock_leveler_elevated/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/hydraulic_dock_leveler_elevated.usd.png", + "size": 25329, + "hash": { + "sha256-flat-1mb": "8bff0fb528958462b064b1ff4db6df24e496431f6d802d98e4ba93a17cfb8e4b", + "sha256": "2840c1e8f05dff1c54a4554cbdb067eee7edf51052592f60f620711919bed8c1", + "blake3": "8939ab95d6b330b70bc4909991768d9c50f2f6b4d2263d6d16c447ce2d049667" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_blue_metal_diff.jpg", + "size": 1606292, + "hash": { + "sha256-flat-1mb": "8279ee3d9bd1e369a5ca7c4a51c879a7619be89263659f692bb861c60b5df32c", + "sha256": "51fb63ed1f01ddd7b73c2e1a37b0452d604bedc21d3b9d68e1d0703c87c50d9d", + "blake3": "0bc5f587ccfd5e1a510c47a9ab5522787a14482bc9a03e6e1e93c78fb45fd858", + "sha256-first1m": "d983eb986a9b4ef83e6f9ea72c1edcb676098028a0dba974ad8b9653689bcd76" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_blue_metal_rough.png", + "size": 2894711, + "hash": { + "sha256-flat-1mb": "ae1df360f1bccc34ae9a30b08e451a823ce91de29fa089bccc8fcca81ded1256", + "sha256": "490f50a06a829337949ec0054f16b43a8bcb785ffece4dc8f1bd20c370afd78b", + "blake3": "a270fc2ae4a2f8a42c69f4b5da9aeade09dbda0e8b131d34f1f14a57e0415da9", + "sha256-first1m": "e6da27cf6c536fc923f076c876e1ab8bf838162625e8e4c7e9f73cc709b8b570" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_normal.jpg.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_pattern_3_dff.png", + "size": 156881, + "hash": { + "sha256-flat-1mb": "7c96d7901e4bd76e20d28bd6a44511764fb39b28d21fc391650f183559768d05", + "sha256": "e8432441ffedfc5fec525287f10e079727ed4066cdb7ad0679de7f22018f4903", + "blake3": "540b5a5eab3705fb2edc9a979e5261960499ef7e7e99e1b6e1694ab0524fad53" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_pattern_dff.png", + "size": 85981, + "hash": { + "sha256-flat-1mb": "2660dc7e8d306ebaea44751e8c9f0393327e7279a4c0c7f6c7ebae96459a9fe8", + "sha256": "072dd56821b8d015132e2d374d81daea1def59b3237c8ef6a28d318d16f46932", + "blake3": "f8944171f20654a4dc30d9e15786bcb3f621fd3f72af51b5eb33cf9c84b8c98f" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_suface_normal.png", + "size": 22929427, + "hash": { + "sha256-flat-1mb": "d8638a695f5345524fa48d7880cec7a8e8642ac68568a45682d57e0643be987b", + "sha256": "ca2993877cedc99958c8a385fcc57e010b655901323ac6b671ce0d05304104b4", + "blake3": "6f465a6ba872d49dd9fd1b510f608b8e11bb8fc4a734bf691d2650f47be0876f", + "sha256-first1m": "b477754b88a1ace44feac1bace3d764bc0663aabeb75a6a165e7381cdf9bd0b7" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_white_metal_diff.png", + "size": 3760481, + "hash": { + "sha256-flat-1mb": "bde07916b64d4238a57f0931eba07dfb129b487ce6c9cf47ec1382e65da27494", + "sha256": "75b01648f0e95b59206a70f282543941c79cb77eac4ca0d7bce4b936136113ab", + "blake3": "b02ad5585a3b43b35c581e9eb210adba899463460e6841482352646577ff118f", + "sha256-first1m": "4babadc5411c3ed6b7c0c146d9744396e512d819864471d9a80b755bd356f788" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_white_metal_metal-opaque_white_metal_rough.png", + "size": 1837143, + "hash": { + "sha256-flat-1mb": "0e7d5e74aa525b2b2051537d9ed35f2e7ba7e378a2e7d0ff645d3d04e89bfd04", + "sha256": "9d3647ea9b1d678abd4231f883f60aefa318b9dfc97fc15cfee37fcc1f6557f0", + "blake3": "6882d8f25cecb55ea562b433f182df33dcc6edcf9d60bf52e0dd27940177e3f1", + "sha256-first1m": "3749849883f645f6774dff339510d9a84e3dc2395746d3f7e86c612a45e60a1b" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_white_metal_normal.png", + "size": 16591547, + "hash": { + "sha256-flat-1mb": "0a56acc8371ea3170390bc4e0cd998d656992badbd060b84fd05a220995279db", + "sha256": "91a74bb5bf5c7909674f7a58d82b879720580c1a11c8610be9c4d444e3f94d96", + "blake3": "604f405be25939b2a03633760460af558910491e0c4e1061604406a040d3eb3a", + "sha256-first1m": "3fabcd7bc7270ec74af7951a4832cab58b97cfacbf85af61969f55b1eaf3e340" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "hydraulic_dock_leveler_elevated.usd", + "size": 6493126, + "hash": { + "sha256-flat-1mb": "7c35cdc2f453f59b9717c095024ff9afa13c684fd35719f567e37d81c919d012", + "sha256": "d78da6e61ae503312753ebb475c4c6f1ba9a51337bc1f1c6959b72e7d53a0b23", + "blake3": "ffce085bb069eb4bd6be1af4822be58a8d04eb2c849abc2f3c3e261efe1ef03b", + "sha256-first1m": "1fbb298e9f00ab131aaa94203b743e61a493424d53a0d3b5420eb8a023bd5f4c" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/942/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/942/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..dab25b82335c7662ba21e048822eafd79a1e0f67 --- /dev/null +++ b/simready_assets/942/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "hydraulic_dock_leveler_elevated.usd" + ] +} diff --git a/simready_assets/942/gltf/pbr.mdl b/simready_assets/942/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/942/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/942/hydraulic_dock_leveler_elevated.usd b/simready_assets/942/hydraulic_dock_leveler_elevated.usd new file mode 100644 index 0000000000000000000000000000000000000000..8ada94c1f2b748c07c5e3550355e3aeca7f9d584 --- /dev/null +++ b/simready_assets/942/hydraulic_dock_leveler_elevated.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d78da6e61ae503312753ebb475c4c6f1ba9a51337bc1f1c6959b72e7d53a0b23 +size 6493126 diff --git a/simready_assets/943/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/943/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..f06f141075cac433e47b0d3b3cf427914406fcae --- /dev/null +++ b/simready_assets/943/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T18:38:25", + "assets": [ + { + "asset": "warehouse_electric_panel.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "afa823a4964634774387a0fcf6712f0fcc57bcdbc8d612facb4a49329c928752", + "blake3": "8ab27143f915b3b7c08a033a85c1b0daf394845d9cd2a1a1f6bc2ae561988ae2" + } +} diff --git a/simready_assets/943/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/943/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..496955f6e7acfac8f2b1e8cc4e5d0441f0abb4ef --- /dev/null +++ b/simready_assets/943/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T18:38:25", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/943/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/943/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..28eae6fd0a7236f55cb72dfa8a5edaba221246c4 --- /dev/null +++ b/simready_assets/943/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,61 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/warehouse_electric_panel/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/warehouse_electric_panel.usd.png", + "size": 16268, + "hash": { + "sha256-flat-1mb": "8d84c3a7ae1ac4fc03212c12e99642cb2008228d94b39d892a34c34695809738", + "sha256": "12d753f0a5646715dc76a1ba6b8e3b1c54072e5043461c15ce6531b2476bf6bc", + "blake3": "c9b1d767dd241dccc9a7e234ba3a7fadf80860b134a69d666ca423104dabbcdd" + } + }, + { + "relative_path": "SubUSDs/textures/warehouse_electric_paneL_indication_diffuse.jpg", + "size": 71003, + "hash": { + "sha256-flat-1mb": "0c280445607f39e17a46acfb1aa6f1261ff1c99a61db3d13be3ac487388365f2", + "sha256": "86803a5a18d231f3c7c6e744c41eb9361032a6a628709275b1694a81aaa4f5c1", + "blake3": "17bf3388ac8a0c7c1fd0e4548c51e160f29f7295e8f53cb6936681071aff0bf9" + } + }, + { + "relative_path": "SubUSDs/textures/warehouse_electric_panel_knob_diffuse.jpg", + "size": 35478, + "hash": { + "sha256-flat-1mb": "2a448baed39c0054a8ffd9c4b2f3302ace8868865bc170217d67770ebf54c591", + "sha256": "4083ba218b71bb577db4e150062bb1693c8f965717bdb550c6fc948bf0924e2e", + "blake3": "11d4ab74f632a904fd76eb1996bc73cec9e13ccd6c8a272897c8769d45e27063" + } + }, + { + "relative_path": "SubUSDs/textures/warehouse_electric_panel_meter_diffuse.jpg", + "size": 453631, + "hash": { + "sha256-flat-1mb": "f9c7f6256c1beb61928a211b1cfd63c71e70fe8f7c4ea49adcf509a3a1ddf146", + "sha256": "504c0917c3cbc3ed6f23fe1570cd224a4cb5195db34e637a232f210508e37034", + "blake3": "fe38a88150a5ac5c10b6aae5a1212288853a1bf3b6c83559133a7deebf89d97b" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "warehouse_electric_panel.usd", + "size": 2790112, + "hash": { + "sha256-flat-1mb": "17ae562c4e307ad515ea47ebaea5b781bdf96e0b362e2fda7125faf64faec7a6", + "sha256": "a9c70779bf23be627ef20d0550b5442350bb0dd39c5e20e1591aacc7ae8f2134", + "blake3": "1922ba1dc1ea46ddf1b6b45dfe303ab8648a41644685e73795ef0461ba90b240", + "sha256-first1m": "23f52b90e02c2ec959ae49f9b704f3b35f5067fa065b0bbf4a7951252e754eef" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/943/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/943/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..e153ef0c970037c2fd38236387676b16e34c1b79 --- /dev/null +++ b/simready_assets/943/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "warehouse_electric_panel.usd" + ] +} diff --git a/simready_assets/943/gltf/pbr.mdl b/simready_assets/943/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/943/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/943/warehouse_electric_panel.usd b/simready_assets/943/warehouse_electric_panel.usd new file mode 100644 index 0000000000000000000000000000000000000000..c00d46e3170d5b97507a06d1681aa6ee6c62ccdb --- /dev/null +++ b/simready_assets/943/warehouse_electric_panel.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c91b7e4a2f8081531d7c893a201b16f274f2846e688ee9cb55a46c54cf2afbf +size 2792608 diff --git a/simready_assets/944/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/944/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..93a0d992a2d53254efda92a54215b5546b679f27 --- /dev/null +++ b/simready_assets/944/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T18:41:22", + "assets": [ + { + "asset": "Metal_Storage_Locker_12in.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "4054f6081242828091f2af733e8bf17f8fd68949a36886f73ccb4c21deadd228", + "blake3": "49671a447a5825c978b4a6ae4f4dcc575e51fbdbc43c84cd413c35223bdc3ea1" + } +} diff --git a/simready_assets/944/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/944/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..264cd13cd7b5445163d44d202260e58cfa243ea7 --- /dev/null +++ b/simready_assets/944/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T18:41:23", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/944/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/944/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..745ca0d698fe75b2e7866ac9aa06551b56d92e80 --- /dev/null +++ b/simready_assets/944/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/metal_storage_locker_12in/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/Metal_Storage_Locker_12in.usd.png", + "size": 6126, + "hash": { + "sha256-flat-1mb": "f8c5acd55bd6b30f7538aa1f3fff7d6b2359aa103dbef911100b36a9ad2abae8", + "sha256": "7530166f262ada4a6e9a4577cfec6e0b468f04ba3e7a1cbcc7502aac92242afa", + "blake3": "805b6cda486ca42bf56f60ca2021b8791902562e64731b0ad6481a8337c8fefd" + } + }, + { + "relative_path": "Metal_Storage_Locker_12in.usd", + "size": 1619563, + "hash": { + "sha256-flat-1mb": "8fb6addd9af60e612bc37bd06c5ca3e2981490204142e8d25e0e63890ebe32e0", + "sha256": "aeb1bf012c4722f66f51adee0f659f2dae5bd1aafe6861b9f3bb6337064d3147", + "blake3": "79da9ad60fa2427d0359622a90475ca4b0d5558e5370054962fe345eed31db91", + "sha256-first1m": "eede81e5fb6be70c30f16ea0d6bbc5a1393a4fc89ad452343f71faaba76891f5" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/944/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/944/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..ae0a9bc795e4fc843067e1d2d923497b652c91c7 --- /dev/null +++ b/simready_assets/944/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "Metal_Storage_Locker_12in.usd" + ] +} diff --git a/simready_assets/944/Metal_Storage_Locker_12in.usd b/simready_assets/944/Metal_Storage_Locker_12in.usd new file mode 100644 index 0000000000000000000000000000000000000000..6d85ee19c08dbefe107a463141af64b65f7fe755 --- /dev/null +++ b/simready_assets/944/Metal_Storage_Locker_12in.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6bd184b0306e59c7e75e94913d62b02e346f38e1a0226eed97dbf313c34adbe +size 1620890 diff --git a/simready_assets/944/gltf/pbr.mdl b/simready_assets/944/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/944/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/945/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/945/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..6ca972e7c7cf2ebd085c123c40261f84d7001d63 --- /dev/null +++ b/simready_assets/945/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T18:44:11", + "assets": [ + { + "asset": "Metal_storage_Locker_24in.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "349dd4bc821c132bb112c517b34f1ce5b8f408b8a35de800b0122fb22011d546", + "blake3": "55806de8041af79f61b11656e571408cafd160fa01fefe81a815f5e3a5fa8ffb" + } +} diff --git a/simready_assets/945/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/945/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..0570a821c3826a7b3a63f3c0af394bfb2f630b51 --- /dev/null +++ b/simready_assets/945/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T18:44:11", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/945/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/945/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..5be51e7dd0636eeaf5d777714352cdcf4fdd93a8 --- /dev/null +++ b/simready_assets/945/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/metal_storage_locker_24in/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/Metal_storage_Locker_24in.usd.png", + "size": 7887, + "hash": { + "sha256-flat-1mb": "1e59951235226bdc665f44abde85f667251170b74ba65a641f715b36497b1186", + "sha256": "2b0d6c1ecf8fd26190ab88bb8ae9e51ffc522bd7ab2f1916c3dad30e918aeb1b", + "blake3": "a24e3fd217480aa073c0fdfdd03cde759ddbf7fd4b6497f0b126da114b81dc5f" + } + }, + { + "relative_path": "Metal_storage_Locker_24in.usd", + "size": 1754730, + "hash": { + "sha256-flat-1mb": "11afc64f69cff3df26aa4e5fab9178b16f4f6aecbe197f94cc38bd59c9542624", + "sha256": "5f2e20d176068abc01a0f949f02ca23b6d4d8079d352034c4319efc39ff36a16", + "blake3": "ae7e21fa0c16cae28af2cac54c460c3a452e12e5940cf58cc87ced2f9b6c1861", + "sha256-first1m": "458d81663331f4ad8ea4b5d483e5cbfee6b14a7c0002bf77342782c16af240b3" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/945/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/945/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..2d43cd81e617ec23d3a9c7198a0b0cf9a3e9992a --- /dev/null +++ b/simready_assets/945/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "Metal_storage_Locker_24in.usd" + ] +} diff --git a/simready_assets/945/Metal_storage_Locker_24in.usd b/simready_assets/945/Metal_storage_Locker_24in.usd new file mode 100644 index 0000000000000000000000000000000000000000..dd775e1497f3c3d90677207cb73fa391208d42f8 --- /dev/null +++ b/simready_assets/945/Metal_storage_Locker_24in.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31d3a9e095971c8c48e6f058b4ea0088d82c10e5e41c168ddadfbaae158501b7 +size 1756019 diff --git a/simready_assets/945/gltf/pbr.mdl b/simready_assets/945/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/945/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/946/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/946/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7356a1798ae63a49ac7ee39ea4b8418753772fcc --- /dev/null +++ b/simready_assets/946/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T19:41:33", + "assets": [ + { + "asset": "office_desk.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "f99780505c85fa745cc9a9ff9be4a747309b3024a43432a8c7b29a3b96d2e313", + "blake3": "3950cc840b43ea0f6c298c29f4287537d0b09c9758f32c15e91083d67df5d2ec" + } +} diff --git a/simready_assets/946/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/946/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..2101e65837383eeb60aa81d0ad5b4db55ebf6225 --- /dev/null +++ b/simready_assets/946/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-24T19:41:33", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/946/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/946/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..a7c954b0e74e44d737d1dc21bb3da536a7e26904 --- /dev/null +++ b/simready_assets/946/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,33 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/office_desk/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/office_desk.usd.png", + "size": 14327, + "hash": { + "sha256-flat-1mb": "17c42e9d8ea82983aae5bb6408223b137a1eae93fd8077f877b27327b5887465", + "sha256": "076e4ae87d6700bd654bab62de16395a8a9ee8452d0f79fe5f9c183c2977495d", + "blake3": "8f57e28377d462c412eceedfd75930a62a8b8938efbf6602c2f0c0a7561b549b" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "office_desk.usd", + "size": 972042, + "hash": { + "sha256-flat-1mb": "7fb32993f4898a04be49ff0ab4e2fbc7b246d406dd2857fd106a85751a7ad2b5", + "sha256": "9db7124b4866d05083b7586b2a6b1d1a7879a6f99bc9ee3f3a4b077694b32bed", + "blake3": "03d1b73b14026ae70c1d7f45e1a114fd45a3774f5cbadac46568698738bf51ed" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/946/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/946/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6d2e7ab04b0a42228b1ffc4a6406f36567c937c8 --- /dev/null +++ b/simready_assets/946/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "office_desk.usd" + ] +} diff --git a/simready_assets/946/gltf/pbr.mdl b/simready_assets/946/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/946/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/946/office_desk.usd b/simready_assets/946/office_desk.usd new file mode 100644 index 0000000000000000000000000000000000000000..7cf82c438120ad5ff3541d5bc1a5b1898354ad88 --- /dev/null +++ b/simready_assets/946/office_desk.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:383ebbd5f0ec8578c12523ae5ce44da5159c76dfbb60c634da718c1a3000fedb +size 973590 diff --git a/simready_assets/947/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/947/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..4062bcd9747d5d3452d4f925a25fd27b9fb5b92a --- /dev/null +++ b/simready_assets/947/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T20:55:36", + "assets": [ + { + "asset": "emergency_exit_sign.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "ae1da92183d1986219a1b47efa63efc687a45c03f6de13dff4bbc4375183ce7a", + "blake3": "1fd5972d2680f9494d72f320271c2649cb58001515eb62bca4f4716caf7fab90" + } +} diff --git a/simready_assets/947/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/947/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9fbbc031e84a76aa00f8c5c38f9eb9e23be27691 --- /dev/null +++ b/simready_assets/947/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T20:55:36", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/947/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/947/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..4fe2ff3ed03b4901624c6c14af6272774fe0736e --- /dev/null +++ b/simready_assets/947/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,51 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/emergency_exit_sign/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/emergency_exit_sign.usd.png", + "size": 23960, + "hash": { + "sha256-flat-1mb": "8c98d2a5f6a6093206d25d16fd151096b82e65ed8e701152049301e70a7e164f", + "sha256": "f230b35b5ba8e22b7e5b8e71d8827f273c2d365b272a03cf867967e44fa94170", + "blake3": "74ed8efd4bf2efa865a84df069005047aa740522b50ed095fd666b8a35e9c286" + } + }, + { + "relative_path": "SubUSDs/textures/emergency_exit_sign_arrow_dff.jpg", + "size": 120869, + "hash": { + "sha256-flat-1mb": "cf65931b7b28f21ee4207c229cb2842af2ee4ac6fdfd55e732ab4d9620917a71", + "sha256": "682d928dd76f56e0f160a24263760933fb51d7f65872adc77233bc0b7752113d", + "blake3": "2b6a42325c5ffaf04240bd176b35fa4fa2eea230109f34e8986890dfd4affaef" + } + }, + { + "relative_path": "SubUSDs/textures/emergency_exit_sign_metal_normal.jpg", + "size": 193215, + "hash": { + "sha256-flat-1mb": "2193a4df31476351c1a4845ee50dd55b1c26a5afb890fd35669ba96a68a40b2e", + "sha256": "08c4d6857ba98235119b96931a962e67c90713160a63f7206dd71e2635855d5f", + "blake3": "6f19d574cebd1b522db5a36868a2c7bdb30eebcf167709bc7a2f545767aa5241" + } + }, + { + "relative_path": "emergency_exit_sign.usd", + "size": 1002899, + "hash": { + "sha256-flat-1mb": "59f62f28ba7abad7a2f53f849cf0d430fdc298e987c2ca15b57860f85d72f7a9", + "sha256": "7d62fc62dc69ce32a02b4c71c19e7944510825e2465bd0fbcbde6b60c1b321ad", + "blake3": "c008da4e7c09dd612c372d0a292f0d77bfa2336611b54b4d31c37188b7c6284e" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/947/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/947/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..ea336d24df1f1964f6886e0d605acc19f425d579 --- /dev/null +++ b/simready_assets/947/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "emergency_exit_sign.usd" + ] +} diff --git a/simready_assets/947/emergency_exit_sign.usd b/simready_assets/947/emergency_exit_sign.usd new file mode 100644 index 0000000000000000000000000000000000000000..670757f85300c81aaead95760587ff9712b0b9df --- /dev/null +++ b/simready_assets/947/emergency_exit_sign.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d62fc62dc69ce32a02b4c71c19e7944510825e2465bd0fbcbde6b60c1b321ad +size 1002899 diff --git a/simready_assets/947/gltf/pbr.mdl b/simready_assets/947/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/947/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/948/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/948/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..c804a04b01f2c1ce3330767f0d7793ab74df6c25 --- /dev/null +++ b/simready_assets/948/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T20:06:02", + "assets": [ + { + "asset": "safety_bollard.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "aa403752310dd39b7ce72f307764301e66b8f1dcfb7dd66cc499e3ebeba658b7", + "blake3": "af40d62e36226756fb77b2624a3c7b2bfafb8937d1750c5aed1447dd0b3672a9" + } +} diff --git a/simready_assets/948/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/948/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..0b9c755ba21d428d2723cc268aae0dd023168996 --- /dev/null +++ b/simready_assets/948/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T20:06:02", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/948/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/948/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..ededec17df38a2abaae52e4a66684e4fdf6369fb --- /dev/null +++ b/simready_assets/948/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/safety_bollard/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/safety_bollard.usd.png", + "size": 7929, + "hash": { + "sha256-flat-1mb": "a43fc55f3796ff6b053a024ecd0a0ceedf3bbaac2fc91d9a2cfc93a5f7e1fdf4", + "sha256": "992de10cdd9825304af35a09333ef593e7acf413cbf56964f41cd081c84c5872", + "blake3": "7dc72a77fff751693f6a0a9b257b22f54f3ed2d557c0ee787f1259a50183c426" + } + }, + { + "relative_path": "SubUSDs/textures/safety_bollard_pole_diffuse.png", + "size": 2700121, + "hash": { + "sha256-flat-1mb": "83fee45db1c9a58571653a2de45809838c98fdee59bee75c4c63522e0bfccfe0", + "sha256": "f6d61e755c359804d2985545531fa7e3504447a1003b7d6d2f387b553e06414e", + "blake3": "0d90599e469acc61e7aa50fc2507ed18bbeaffd12c89ec4c648327ed2533034b", + "sha256-first1m": "865828153cf56f6f9291f125b55a59eca04dfa68b93e53171d9b0db4c75d61fa" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "safety_bollard.usd", + "size": 422063, + "hash": { + "sha256-flat-1mb": "9720d5e97106cca6fa34c6ffbeb17ce017e30f414d439cee5ddac4b253e4975a", + "sha256": "2320ce602bde930000e9edc99acbf35a1cfad72cb214816b7113f99a2b3a0512", + "blake3": "4b2ef4c5882dc689ee10da165b10ead8ce7e0f7fa5730deb2140d48d7c0f1fbb" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/948/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/948/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..f5f384b8eeeb58e3ef244354af983b5f97290507 --- /dev/null +++ b/simready_assets/948/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "safety_bollard.usd" + ] +} diff --git a/simready_assets/948/gltf/pbr.mdl b/simready_assets/948/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/948/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/948/safety_bollard.usd b/simready_assets/948/safety_bollard.usd new file mode 100644 index 0000000000000000000000000000000000000000..83ec47c933048358324df498de71c649a13d1d8d --- /dev/null +++ b/simready_assets/948/safety_bollard.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2320ce602bde930000e9edc99acbf35a1cfad72cb214816b7113f99a2b3a0512 +size 422063 diff --git a/simready_assets/949/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/949/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..45092c0f883ac517bc5e7008e9b873899d2f786e --- /dev/null +++ b/simready_assets/949/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T21:06:56", + "assets": [ + { + "asset": "high_bay_led_luminaire_3.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "c23a4468a2288302a2d6ffa73bb2ef760305514c191811aba05f4d72de063253", + "blake3": "ef46fbed140b4bc550eb2b5915c70de5ad2e5115d5e05feff2b86287926b0831" + } +} diff --git a/simready_assets/949/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/949/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..fc48276fb21d52f973340eba0a5aa159679dac42 --- /dev/null +++ b/simready_assets/949/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T21:06:56", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/949/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/949/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..ae4c7f578020bbc971d6c4916caf156e82a379a4 --- /dev/null +++ b/simready_assets/949/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/high_bay_led_luminaire_3/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/high_bay_led_luminaire_3.usd.png", + "size": 6987, + "hash": { + "sha256-flat-1mb": "1fa5c2e60d225ece3d757674e868523e32a950073749f88bff30c9986d36224e", + "sha256": "ecaa8b45b9e38fadff1cfe238c882c32123b60123c7523d5ad42fc8afa74bad6", + "blake3": "608a513f68f4f82f714d0f950ac9ab64a4da19d1ce3e603e4a2d009d5b7c65fd" + } + }, + { + "relative_path": "SubUSDs/textures/high_bay_led_luminaire_3_metal_normal.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "high_bay_led_luminaire_3.usd", + "size": 1332024, + "hash": { + "sha256-flat-1mb": "a3f4a896563003d68c80315c585984bcf317fd79399b7508fcfe5fdfc6b0d922", + "sha256": "d068f5624666d7425fd11e7f24c3833fb263880f7841659530286d9488211688", + "blake3": "a601f146926f4f7b6e345e97b090b3e32c469a4d9243103a032ab47aad86abac", + "sha256-first1m": "05a6a870684173c48fdca322153d2ed29734ffb61a0d70d792b436c56ded5836" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/949/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/949/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..fa6bf65912670160303b690a6ff56b4900c56e36 --- /dev/null +++ b/simready_assets/949/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "high_bay_led_luminaire_3.usd" + ] +} diff --git a/simready_assets/949/gltf/pbr.mdl b/simready_assets/949/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/949/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/949/high_bay_led_luminaire_3.usd b/simready_assets/949/high_bay_led_luminaire_3.usd new file mode 100644 index 0000000000000000000000000000000000000000..7320c0c6608457bd3122d3a1f1577dc0be620b9e --- /dev/null +++ b/simready_assets/949/high_bay_led_luminaire_3.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d068f5624666d7425fd11e7f24c3833fb263880f7841659530286d9488211688 +size 1332024 diff --git a/simready_assets/950/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/950/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..0ee1c252ed489607af9b32af64fcb96fdf8af133 --- /dev/null +++ b/simready_assets/950/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T21:03:09", + "assets": [ + { + "asset": "high_bay_led_luminaire_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "a0ec5e9e98f65bb6ae044fe90f4d699c286962ff745665d216aba2048b5c3715", + "blake3": "0b597df61c7d1d938932fb103fdfbd0ad20eb669e0cbbe077e5022f6f87dc301" + } +} diff --git a/simready_assets/950/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/950/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7f45948eed55c1295a64f7b07054bd0c507393 --- /dev/null +++ b/simready_assets/950/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-21T21:03:09", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/950/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/950/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..ad38087eb8e30828a845d2f10049095c1da853f8 --- /dev/null +++ b/simready_assets/950/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/high_bay_led_luminaire_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/high_bay_led_luminaire_2.usd.png", + "size": 8641, + "hash": { + "sha256-flat-1mb": "271a7075bbc70afde591e9d46a15d80005f3709ac7af0089c1b75e09056a66f9", + "sha256": "80ff2b66be3fd47ffa91cb492dbf3fbcaba734aa22f241a70ee0949080c13513", + "blake3": "78254f01c68789510eed66fc89b7ea00a9aac64c11a13c2f4ac7ef1292ee22e7" + } + }, + { + "relative_path": "SubUSDs/textures/high_bay_led_luminaire_2_metal_normal.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "high_bay_led_luminaire_2.usd", + "size": 6678681, + "hash": { + "sha256-flat-1mb": "3e13ee0246c6d8df4533815deaa88ab7cc87ac4496edb5d5042851ff6c465673", + "sha256": "e0dafc4abd6918ff2080d65535f1e61b89ae475a968b840fa7f9a9b9b7a31e1a", + "blake3": "82dc03999adf1a8e33003d611657329cb30cff70f77f2c162a8bef445050da8b", + "sha256-first1m": "beddd24973f49d9d094ac1f2cce3cff4589078f698834e6311748ad0b202a180" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/950/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/950/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..bcbb1b050d6abc102414ef1bbed3b599ed4a3885 --- /dev/null +++ b/simready_assets/950/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "high_bay_led_luminaire_2.usd" + ] +} diff --git a/simready_assets/950/gltf/pbr.mdl b/simready_assets/950/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/950/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/950/high_bay_led_luminaire_2.usd b/simready_assets/950/high_bay_led_luminaire_2.usd new file mode 100644 index 0000000000000000000000000000000000000000..343f745e21c35facc250f80461fcd3df0589f7c0 --- /dev/null +++ b/simready_assets/950/high_bay_led_luminaire_2.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e13eb3d3bce0e59e7dd4408225dd9570e6b8571197764ac007ff7b5854c7c66 +size 6682649 diff --git a/simready_assets/951/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/951/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..d173be588970b6c13024fb5a51a7ae0f5e15e254 --- /dev/null +++ b/simready_assets/951/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T19:58:44", + "assets": [ + { + "asset": "high_bay_led_luminaire_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "c5fec3a4a040d4070338e8ff47ea405037e0d0632a780a088817b606b7b8e73c", + "blake3": "e51af25f5146f6826c62972189c8a23cf9d9e5a3461c9b49957a7073f07b6b1e" + } +} diff --git a/simready_assets/951/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/951/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..e9eba005eb4fead0edfc4bf8be1b85b2a571a7ca --- /dev/null +++ b/simready_assets/951/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-19T19:58:44", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/951/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/951/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..40d04d0f0c7589e0df37d8066414e7ce5aefba20 --- /dev/null +++ b/simready_assets/951/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/high_bay_led_luminaire_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/high_bay_led_luminaire_1.usd.png", + "size": 7042, + "hash": { + "sha256-flat-1mb": "ed3f5c30a971c54566b85c8f0ad6776b112e5a7c9c9d8747521039e19828a807", + "sha256": "4fdfa8351e5364ffca8dcb46a76b75028543d1cdde9a0f85c279f207a1dadfd0", + "blake3": "f8ba7ec8678e58e0947e35d712681acf692a068a474370dc0d4b4ee515770b9a" + } + }, + { + "relative_path": "SubUSDs/textures/opaque_metal_normal.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "high_bay_led_luminaire_1.usd", + "size": 4533962, + "hash": { + "sha256-flat-1mb": "f657f6f4c02c70deef0d4ff0071983e8d9a3b8cd6ded518b87b0ab3b8a2c775c", + "sha256": "c518a938be154a8b2e140b81d32f9387c61f5087e8cf09126e89760e22aa8832", + "blake3": "059cdbbae18b12ef254197513b72fec5718b96a1ae42e63cb7cf27ca63147ac0", + "sha256-first1m": "c8b68e1a80816a3c620f4aebcb5d157ca0c5c337c7a58ed44ed7e4d33c3ce026" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/951/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/951/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6e7f456794413ce57bf5dea5f7a2960ea345f937 --- /dev/null +++ b/simready_assets/951/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "high_bay_led_luminaire_1.usd" + ] +} diff --git a/simready_assets/951/gltf/pbr.mdl b/simready_assets/951/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/951/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/951/high_bay_led_luminaire_1.usd b/simready_assets/951/high_bay_led_luminaire_1.usd new file mode 100644 index 0000000000000000000000000000000000000000..5227bde212a176153f713507ec51f17157900ea1 --- /dev/null +++ b/simready_assets/951/high_bay_led_luminaire_1.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c518a938be154a8b2e140b81d32f9387c61f5087e8cf09126e89760e22aa8832 +size 4533962 diff --git a/simready_assets/952/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/952/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..dee7284903f2a2a3debc065a60d60f1bcda116d7 --- /dev/null +++ b/simready_assets/952/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T14:56:04", + "assets": [ + { + "asset": "semi_trailer.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "0d8bcb77955f85501cfbdfab1368c89a543227d6e817f751b5bb8ef888a8d5fc", + "blake3": "3ab851267380459e6029b409503f3ea2194de5cd2a6865e4329407d9c060745c" + } +} diff --git a/simready_assets/952/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/952/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..971e0f778c6bfcdf52395b9e9c63c921ad611cb1 --- /dev/null +++ b/simready_assets/952/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T14:56:04", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/952/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/952/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..b717ee6bbcc60cd3a8f6cc5f351d89ac41482f8b --- /dev/null +++ b/simready_assets/952/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,257 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/semi_trailer/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/semi_trailer.usd.png", + "size": 16011, + "hash": { + "sha256-flat-1mb": "c5499387bb4aec88fb703e5d2caeeaa80b4eb8c65a2c80723d1571939f44863b", + "sha256": "1d7ea47d76f3b5d2f30f3da540563955910ed2663815ff912016c7de80b59654", + "blake3": "a969189660b47977df6dd13c6b505d49f38dc2a13632c7dff47fc5915c6a6a1b" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_body_normal.jpg", + "size": 304336, + "hash": { + "sha256-flat-1mb": "bd7cb9bbcc16c0b84b624d4bbd0ae921c60fd05260a6b6b7928d6c35de5f4e5c", + "sha256": "58b6404392aa0f79bd0609394e61fdf2e1e8d364d0aa184d76dbc8e1a6b2880e", + "blake3": "8b9b7f68b9b3e2b701bb2296af23c35fede93ec5a825df7004f027d512eeea09" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_body_roughness.png", + "size": 551517, + "hash": { + "sha256-flat-1mb": "be3bb6b64692713d30bb1039167ccbb5cec575a0f1ea4211d1bb0e52ce5dafad", + "sha256": "8cc4484dec71741e8ebdf5e4112aba6591cf1723be8417729cbb411948e7e777", + "blake3": "3be6e66ff69158b6e6eff9734aedcc9bd36058661107601554666dabb79e7a71" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_bottom_diffuse.png", + "size": 4748712, + "hash": { + "sha256-flat-1mb": "cf6128fa619ed4b330b3df03120c26d4f41c4fe85f133af4abc5e3ed156579c5", + "sha256": "c43caf48d94f200af2e6b62b008155e21f47c29faa517170ea8a0babbcb0ec56", + "blake3": "b5fba6ce0f5c3c4735a457fc3e52e64ab71ec5dbc028d665bf224b5e36d65646", + "sha256-first1m": "ec1f42cb8cca06ca1ec1055943051a0a84f1d187c9df46f704f057323d5c44df" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_bottom_normal.png", + "size": 20849344, + "hash": { + "sha256-flat-1mb": "9480057fb3706a293e491562bd0b0e83bba1391747b7da535e637800e9f6d138", + "sha256": "21000e91feb4cf2fb9fd664ac3047a8e435d7d01a547c354d9d6a80de66bdc0f", + "blake3": "da4292db3b5df442d087f174c9dc823abce464f934ed83888fa918cf4a290d17", + "sha256-first1m": "4f09ca9495087bf28a2dc5da3a5041c282abf6c3556d2888c061db59d5c01de0" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_bottom_roughness.png", + "size": 3699094, + "hash": { + "sha256-flat-1mb": "5d801fbf693fb299c8ca0487ba6cfc2137d7e44edd25baeddaf1d46782ecb978", + "sha256": "d19d4be92959f4bad82c3876c12e358cb026e631b03e73f1fba2e00b929bb43a", + "blake3": "553debb2fc571b4702e7178fc7ff21201be4c83f365a7bdef538f182965eec15", + "sha256-first1m": "4e81d1702e61bb5fa8ffbe67c12d3eaf3ec8991bb8b9d06aa6f62d73690d544c" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_display_diffuse.png", + "size": 1466097, + "hash": { + "sha256-flat-1mb": "c882d1f3cc741dc9de1c6be32e8950eb8696a3f886bb9ab50315fa8f9f8a3f30", + "sha256": "f184514e63b35e5b5cf9a5a14bcc5b46d95119b804918d181096cd59a9b67171", + "blake3": "e967e45bc532ddd0ee66e5a8f1e66a4e4435f233ff3081a61bf25f8e99a7cbaf", + "sha256-first1m": "7e5718de7a3f74c59136803e782c58bb2b1d9920ca673693b3df14795f024958" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_frame_metalness.jpg.png", + "size": 154722, + "hash": { + "sha256-flat-1mb": "9a7f83c901e1c0e7a678adf2862f06ef434af141751538b0c289b4e999a171e6", + "sha256": "bdc0738f89c411a3340e9cc01848e99b43aac5814ae03422e24d6d5659a1b349", + "blake3": "fabd17ddf160285b8f0f561514f5fa791b848ed1c07ffe372bbbdc523e4cc15c" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_frame_normal.jpg.jpg", + "size": 288948, + "hash": { + "sha256-flat-1mb": "b20f18e0f5ebdaa8d57df80bf959de5817a216a62ea88e03cbf588aeb53de249", + "sha256": "a69193d6a60173cb21fd1cbb6def7dd21df18de1a7bd393569a1cc4e29162447", + "blake3": "f0f6aa75ade9f3574ba0939ec8ac21f43869c04131c8cf5316ff6bf51dc21b59" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_interior_diffuse.png.png", + "size": 6336735, + "hash": { + "sha256-flat-1mb": "0d135b66f001f796d640cca83ebd4ea158b82ecfd894887d72adaf07b107791f", + "sha256": "0662baecfffb4945b3051b0ab7226b1e3b1b8e6291443f71683b83bbdc302d86", + "blake3": "e70a8bc6ef229ce638311b4af32c18f276a57bfd3c764a0df00c0d8a9d56c156", + "sha256-first1m": "a3b71dbdcb419d2fa11a0af8ef3e43935f18aa621b92b2933bcf302cf7e79a08" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_interior_normal.png.png", + "size": 19067981, + "hash": { + "sha256-flat-1mb": "3668839c0ef4d6c14e7aa683f279c37c9d19173b3a4363778fcea1035c8b2d4e", + "sha256": "ce946c130b179a04c133b42fa4ba297fe46e401d6c607f65b800a3c440d66c73", + "blake3": "0e5d364cd103926c2fb0f388bd4fa0db465a4a4f3b4f463de3b8fd8de5ed341c", + "sha256-first1m": "6df4ea183d58772625c07d552a26ddddb30993f8ee1fe2f66d7836a2913ead47" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_light_normal.jpg", + "size": 343334, + "hash": { + "sha256-flat-1mb": "fbd378e76f7ead19cfa295547dcef0c0ed4dc47db0776aedd213897b2e6251c9", + "sha256": "25c913e64c7d2bfade44a9276fc0c98d6a7d114c0ca7b7ae16594691153f6f92", + "blake3": "e847474a2a14f10635e8c234c0b64ba693ae4b9531bf85d6ba0aeda5227abcad" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_mudguard_normal.jpg", + "size": 5297317, + "hash": { + "sha256-flat-1mb": "25164e04f6eb671bd233b8b99356318868ec7b4530cf410e158cebbec5b55f2a", + "sha256": "a8b678ba6e17822dc586b085e05f60ec1a714ebdd0e0c4ead63c88799998e826", + "blake3": "d3f5b853f105125f1884ab33ed795aeb4d30196856e5c3d9b6efc3a109930816", + "sha256-first1m": "de116ccfcbad79b817c21a57752df2a937d917a2c59f3e1a38da37df94ed3d47" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_mudguard_roughness.png", + "size": 3439522, + "hash": { + "sha256-flat-1mb": "45bf357be4bc839f3146f1827adcc8f296de81dc31d250b04f67d77b78623481", + "sha256": "fccc4fe724f13edc5b885460ce8960414051257f990f07b2829da7c4ad7badff", + "blake3": "1cd168dde74893877f4900208fa04cb8917c0cd4997dde3d443531251f55de2f", + "sha256-first1m": "46891203fd7bfb107f3f175ce079afc3943b4ebd9a8e5048525fba0885b661d3" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_net_diffuse.png", + "size": 2674149, + "hash": { + "sha256-flat-1mb": "7d8dfeada5c93bc346de7023ad4f50824b309d8052865a50a1560c41f4817a75", + "sha256": "ad6839e9b1a0d57d334cab2e79ec26218061f09a8322f03a4aafe58589bb7f29", + "blake3": "75eeeb6a7552df8de623f89c75e79483b48cae3780439440019245bc32573fe2", + "sha256-first1m": "48a617a26c1be999a85078dfa82fd3a7cdad672929014efc7f2013ca382dcebc" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_reflector_diffuse.png", + "size": 214466, + "hash": { + "sha256-flat-1mb": "09e4c329acafe52fb192776bef68dd97d5ac408bfc12ab337ce79a4bcc4b6539", + "sha256": "26b0527bd8bc0e8cdd1d1034a174e08c6fd2d84acf8bb645eaf1aa1b781a15fc", + "blake3": "5badc398786132185d1f3c3dbedaeeb9cdf74b01bf5b7cb64494d1a9bb25685a" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_rim_diffuse.png.png", + "size": 2087919, + "hash": { + "sha256-flat-1mb": "a7407ba9a19c703a696799ba346802a449c433972c9da2d57f9ed4c081c120c3", + "sha256": "fdeb66251f24eb399e698286e6b92fb354ee3c0df8cde6057011e4af92ae8899", + "blake3": "0d590c102ea30f3e82645568510e124e2976af6a1f463cc59dbff87ce88544ac", + "sha256-first1m": "be253ae6d115b934389785d2c94ac7356f76ce3c57b45fe8e9a9f4c857cc82ec" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_rim_metalness.png.png", + "size": 59418, + "hash": { + "sha256-flat-1mb": "ff76869fa3dd23e2fdb074e60bc00eb408260b4a2bafc5c0e6e07b130324bed2", + "sha256": "ff52e19eabdc597ad32e2584b58fd86cdc5caeeefb7ccd0e934efb87c9dee64f", + "blake3": "2d292dca826013c6102c635c75da66abbaef8e13323c9af3496b144d90068969" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_rim_normal.png.png", + "size": 18866515, + "hash": { + "sha256-flat-1mb": "c17223deacc031cd641c8c5219a197254c9030a15bbba9e45e55e302d07ac93f", + "sha256": "d960ac0e73482e1e9a600485491177628ee1e5997110b0d18d6ae1c5e24a34a7", + "blake3": "467dfbad38dc427680d48149a4676edc78cbee7654077d1d575c3cb19f3a06c3", + "sha256-first1m": "5046b94cf080b9ba7dcee4a72342e4507271701cba0367b4d57f38669f26b761" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_tanks_normal.jpg", + "size": 5816972, + "hash": { + "sha256-flat-1mb": "e3b4559d1e777d7c1a0f042700974e7f8b647c547ab5e116b6952a594208e84f", + "sha256": "264e25dc85bbde4d8b0a6e4ac6b3e96b67a96113ec3adbd7b2174d7418e879a6", + "blake3": "81fc25ff249ba18d300230f8114ba8009cc6aae08350aa3f1e150bca153dfd76", + "sha256-first1m": "31c3e3e46506ccc096a6ba6ae9088b9fa45efc30a9f962042c35a300e9764c60" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_tanks_roughness.png", + "size": 3513170, + "hash": { + "sha256-flat-1mb": "deb5abc687ef528a8a95b2e5216bc9ee52b6230d650d74522d808ca4fbc3c70e", + "sha256": "6d54c5c766216b9eed01d7703a9ea36ccf3652aac039b127925b7237d36ac20d", + "blake3": "0872ca2285a629c8d2ca7a52479c0c0a84560bf4e599964b1d84e40ad4ee5b67", + "sha256-first1m": "b24cab5277dc4166caad9693cb8e859800aa9fef3998b36b7b445f4c5a04f73c" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_tire_diffuse.png", + "size": 1704020, + "hash": { + "sha256-flat-1mb": "ac3ddd3e4954094076914c9af935b2c71b10fd509201eddd8e0919c95c65b9a2", + "sha256": "2fd182794d8d6217e834caf969dbb6b7656fbb2d0a8450509a3e828897178790", + "blake3": "59a4ce5a650941f18cf96b33445d20510d10a64aa2fee2fdf2505b12995c1cc5", + "sha256-first1m": "b4e2f609b3acc7eaf400f4a80f8ced98df167e701caa542b90e4aec29f8578a2" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_tire_normal.png", + "size": 23775370, + "hash": { + "sha256-flat-1mb": "eba934614c4f124fdfedb234047f7f622e9b196723677ce3de1363ac98965955", + "sha256": "87cfc1706dd33330dfc72c36d8336f09ab416130b311a405e524a38d57b4594e", + "blake3": "44a0a7b1c8d21f4f97c684a6d4060c243428c070a214830bb412d8ca938631bb", + "sha256-first1m": "0b1516b88ee76973bd0aab7ede5d6613b36d33090cb3edb3eab6fbff7fee970f" + } + }, + { + "relative_path": "SubUSDs/textures/semi_trailer_tire_roughness.png", + "size": 4802379, + "hash": { + "sha256-flat-1mb": "e6ca4415ad048d355ed6365ca4cccc291bfae33bdf4763a983310d84ea106c65", + "sha256": "929673d8860402499b90313ed682ed52105bad5352b4179681bdfd6dc3c1d930", + "blake3": "08d3109ddb9c5e42079960150dd7ff9ba812fe27a6820f34fa636919f0f0a496", + "sha256-first1m": "455704721699d7a672051ac80c8fd9b7f0ebb64e69739850c64df5409182f437" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "semi_trailer.usd", + "size": 24167498, + "hash": { + "sha256-flat-1mb": "78b11f67490440f02dde3af16168e3bc5f29f06f06f83585cd66d17be8fb67e8", + "sha256": "bb149e303549b0a48279bee8cda4b89bb5e6c9399331a3616871a2fa2eb35518", + "blake3": "1914b78d02cb92025eac7f842d6710608549875c5237b5f14b1ac6d290da49ba", + "sha256-first1m": "4c85a3ede00c483b765ad1135c0e0184a35c3fec69a1b8601fd56394451e0fed" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/952/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/952/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..95d5444304ae12ecfa437d09fbe1986e8c21a4c9 --- /dev/null +++ b/simready_assets/952/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "semi_trailer.usd" + ] +} diff --git a/simready_assets/952/gltf/pbr.mdl b/simready_assets/952/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/952/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/952/semi_trailer.usd b/simready_assets/952/semi_trailer.usd new file mode 100644 index 0000000000000000000000000000000000000000..cedc89e1066f1ca15d08dfbf9274930ce1a975ae --- /dev/null +++ b/simready_assets/952/semi_trailer.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb149e303549b0a48279bee8cda4b89bb5e6c9399331a3616871a2fa2eb35518 +size 24167498 diff --git a/simready_assets/953/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/953/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..86d38ae83ca14d3b2ef3b5d649d6606f83813e65 --- /dev/null +++ b/simready_assets/953/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T12:57:09", + "assets": [ + { + "asset": "office_chair.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "73f79aa738e835f1e8b0fc9becbfb83182dafb800e4d420d2e59b44247126c91", + "blake3": "a26814ad7c237ca7d2cae72aa954ef1d411a3d107e32f9fc780097b78bc78967" + } +} diff --git a/simready_assets/953/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/953/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..be1021b6603a7d122b7da0e24c748c161af7e6b3 --- /dev/null +++ b/simready_assets/953/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T12:57:09", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/953/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/953/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..73856c00a10393c602fc5042b15ad791d560dc3d --- /dev/null +++ b/simready_assets/953/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,44 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/office_chair/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/office_chair.usd.png", + "size": 13164, + "hash": { + "sha256-flat-1mb": "87aa1ab2cacb069d5a2eb7e245e5538f13047f1ab0bd1c36894f72c30183f086", + "sha256": "f791f94503ae323dc5cad703f43fcd9f95995b67358db8e9b7d1b02c84f6d0c0", + "blake3": "6e88e5214f68d2326c5e8e1fd823d874e97ca3b12770d9aa9295d5957f819569" + } + }, + { + "relative_path": "SubUSDs/textures/office_chair_seat_normal.jpg", + "size": 12934583, + "hash": { + "sha256-flat-1mb": "ed1e59975003a964c0a5f50c62b66aa8ab8ceb1db1a7abc1ae8b2b159b3db8e7", + "sha256": "c6a294e621fa0fb8e07f9ae3534be210df157023d4522068c29c5491936dae55", + "blake3": "0f453f30618803d71021045d4df60ee05816a0ce535b6fa21e82b458eedad5f7", + "sha256-first1m": "8a8792df2f5407c29c0f42e5a132d3334ccb013ce501b4e03dc46b2dd9d05460" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "office_chair.usd", + "size": 19659721, + "hash": { + "sha256-flat-1mb": "f88ad66dbbba173abf204b0ca2dd30742152f18daab2e64c29cc0d4881c74c58", + "sha256": "52452a82fc4449650076dba8e87dd8ba32d63104872f3f6c9d352dfd87bef89d", + "blake3": "6153879d9a9834363cb30f4ead8194a5db0486fb6a3cce769468f648425af018", + "sha256-first1m": "84115ea5eb187f3a79e22166de05312a8f91f450669fef38319635d8d8ec05c1" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/953/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/953/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..d787b3721a9777fbb00fdb6566d769fb2f76df8f --- /dev/null +++ b/simready_assets/953/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "office_chair.usd" + ] +} diff --git a/simready_assets/953/gltf/pbr.mdl b/simready_assets/953/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/953/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/953/office_chair.usd b/simready_assets/953/office_chair.usd new file mode 100644 index 0000000000000000000000000000000000000000..954f6308c7558e116dbd2e7bcffa5d98afb8b540 --- /dev/null +++ b/simready_assets/953/office_chair.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c9a4397fcca3af82a34f5be69803e6a32241f7fc29fbb13da8e131c9f4985a6 +size 19661279 diff --git a/simready_assets/954/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/954/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..e16b0a64501c32efb94744bd1f53e15f7637be9e --- /dev/null +++ b/simready_assets/954/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T15:52:30", + "assets": [ + { + "asset": "forklift_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "b338b5e512595b5c27b647ec9c7c4567fbd77aa13812cd98d9641a0ed451ae8b", + "blake3": "128eeb824a333efb214ccc4fcb29dc1d4e6eda13f24e4c3367403ab42e9132c1" + } +} diff --git a/simready_assets/954/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/954/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..94717765177b4f972ff6d9e707281a331da2e7b6 --- /dev/null +++ b/simready_assets/954/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T15:52:30", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/954/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/954/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..54cdd55186dbf1cf008d8841525fdffe587bfd25 --- /dev/null +++ b/simready_assets/954/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,183 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/forklift_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/forklift_1.usd.png", + "size": 24803, + "hash": { + "sha256-flat-1mb": "3b99f58bab25b67f39205137c936b9367fec5352e0a5338fc881ddca89ad7c32", + "sha256": "7990a61a4bc3d7f2626712d1e48f4e7fbaabb709d8a899f2458254d0aa2f5339", + "blake3": "a1d273debdaa661a704a8e83d889732cb7e6f1448d76bd4d634b0bd7af77550a" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_bodypaint_normal.png.png", + "size": 19067981, + "hash": { + "sha256-flat-1mb": "3668839c0ef4d6c14e7aa683f279c37c9d19173b3a4363778fcea1035c8b2d4e", + "sha256": "ce946c130b179a04c133b42fa4ba297fe46e401d6c607f65b800a3c440d66c73", + "blake3": "0e5d364cd103926c2fb0f388bd4fa0db465a4a4f3b4f463de3b8fd8de5ed341c", + "sha256-first1m": "6df4ea183d58772625c07d552a26ddddb30993f8ee1fe2f66d7836a2913ead47" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_bodypaint_roughness.png", + "size": 3639315, + "hash": { + "sha256-flat-1mb": "109083db34721a9f2d33751309badaaa4564d3e9fc05e7900116156c885c63ca", + "sha256": "49d0332c0f622fba1699a9024c892936963695a6515f4d7dcad284a76494c279", + "blake3": "94903bf990d1c3411d0dec168d12500892126553c845cfbede09945474cddea4", + "sha256-first1m": "fb6af0427c9f8aa0f12ea9e94e54ca1f200c7b1e723d03254281657dfe6db456" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_display_diffuse.png", + "size": 1935517, + "hash": { + "sha256-flat-1mb": "98bc2e3da0752da22603e2572525d9c14a14daa3944c430b111d66e720d0d66d", + "sha256": "6378ad6a3855e54a43c9c1f7a1045aeba9c713cf08e170feb3693707b7c935df", + "blake3": "c86814d24c6b6845160d279554da57c1b4529a60cc8f5b7b2d2bea17ebc7c15e", + "sha256-first1m": "d6e155c58ce87916db3b60576c00849b79ca5f724429bbdaf2fb5c716d879d30" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_frame_normal.jpg", + "size": 288948, + "hash": { + "sha256-flat-1mb": "b20f18e0f5ebdaa8d57df80bf959de5817a216a62ea88e03cbf588aeb53de249", + "sha256": "a69193d6a60173cb21fd1cbb6def7dd21df18de1a7bd393569a1cc4e29162447", + "blake3": "f0f6aa75ade9f3574ba0939ec8ac21f43869c04131c8cf5316ff6bf51dc21b59" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_frame_roughness.png", + "size": 1051829, + "hash": { + "sha256-flat-1mb": "888f4e96018e60b8c9a26c93d3dcec535cc72eb584eb494b32405152017f7d0e", + "sha256": "6b07f4d56d94f3a921384da54de3c5e8d544204cf8abb358e32e267e8d109a05", + "blake3": "14884c26235d117b46b173df2e86ca5ebb6c616e0881283ad2fd594a8dacf58d", + "sha256-first1m": "3e3e08c2f9120d8071c73995198f7e25466764fa882b0c5cc0f04f620856b77a" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_plastic_normal.jpg", + "size": 5297317, + "hash": { + "sha256-flat-1mb": "25164e04f6eb671bd233b8b99356318868ec7b4530cf410e158cebbec5b55f2a", + "sha256": "a8b678ba6e17822dc586b085e05f60ec1a714ebdd0e0c4ead63c88799998e826", + "blake3": "d3f5b853f105125f1884ab33ed795aeb4d30196856e5c3d9b6efc3a109930816", + "sha256-first1m": "de116ccfcbad79b817c21a57752df2a937d917a2c59f3e1a38da37df94ed3d47" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_plastic_roughness.png", + "size": 3439522, + "hash": { + "sha256-flat-1mb": "45bf357be4bc839f3146f1827adcc8f296de81dc31d250b04f67d77b78623481", + "sha256": "fccc4fe724f13edc5b885460ce8960414051257f990f07b2829da7c4ad7badff", + "blake3": "1cd168dde74893877f4900208fa04cb8917c0cd4997dde3d443531251f55de2f", + "sha256-first1m": "46891203fd7bfb107f3f175ce079afc3943b4ebd9a8e5048525fba0885b661d3" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_rim_normal.png", + "size": 18866515, + "hash": { + "sha256-flat-1mb": "c17223deacc031cd641c8c5219a197254c9030a15bbba9e45e55e302d07ac93f", + "sha256": "d960ac0e73482e1e9a600485491177628ee1e5997110b0d18d6ae1c5e24a34a7", + "blake3": "467dfbad38dc427680d48149a4676edc78cbee7654077d1d575c3cb19f3a06c3", + "sha256-first1m": "5046b94cf080b9ba7dcee4a72342e4507271701cba0367b4d57f38669f26b761" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_rim_normal.png.png", + "size": 18866515, + "hash": { + "sha256-flat-1mb": "c17223deacc031cd641c8c5219a197254c9030a15bbba9e45e55e302d07ac93f", + "sha256": "d960ac0e73482e1e9a600485491177628ee1e5997110b0d18d6ae1c5e24a34a7", + "blake3": "467dfbad38dc427680d48149a4676edc78cbee7654077d1d575c3cb19f3a06c3", + "sha256-first1m": "5046b94cf080b9ba7dcee4a72342e4507271701cba0367b4d57f38669f26b761" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_rim_roughness.png", + "size": 2971692, + "hash": { + "sha256-flat-1mb": "551790c4f2735fffd0a6791a643a022cb08a9f37928795cff76917176f719e35", + "sha256": "9d3982529e3d92f34e3a75caea061e1ef027aad690ebd9c38b42cd7f767207df", + "blake3": "267cdf3580857e29cafe9f32f90c9855cb9b5b6cb64edd0e507625f610f6580a", + "sha256-first1m": "60a6b6364f2081c5d48550d588bb8c7f1ef351ad8caaa65d84d5da8f381fe208" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_rim_roughness.png.png", + "size": 2971692, + "hash": { + "sha256-flat-1mb": "551790c4f2735fffd0a6791a643a022cb08a9f37928795cff76917176f719e35", + "sha256": "9d3982529e3d92f34e3a75caea061e1ef027aad690ebd9c38b42cd7f767207df", + "blake3": "267cdf3580857e29cafe9f32f90c9855cb9b5b6cb64edd0e507625f610f6580a", + "sha256-first1m": "60a6b6364f2081c5d48550d588bb8c7f1ef351ad8caaa65d84d5da8f381fe208" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_seat_normal.png", + "size": 22352793, + "hash": { + "sha256-flat-1mb": "b8e178d1faea0ac34f55e73aeee1f01d6bde2d8768bd5abe3c52bc6486fd494c", + "sha256": "2a90551d22460fec2e6ea74bfaa42f39187a577e15f32675ae406ceac5f812a3", + "blake3": "6f902f0832ed982500950b42758fc4fc56c44813426ebe96ee665dab8b3b7eec", + "sha256-first1m": "8e6c5126be30b5ad261ddc8f010957a4eec398abc4ca93397c1d6c167f7986b3" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_seat_roughness.png", + "size": 5741904, + "hash": { + "sha256-flat-1mb": "738a91ff6ec03c23a779bc4763045eb3dfb5ee530e2197a9593db8637add871c", + "sha256": "396f1f6bcc149fb3757eaa252a236c40a27ca00c49df5c35d07fabd2599a775b", + "blake3": "b45c928abda69b4dee7b5da9bea036702f02e88843010c8eca6e779730ecd6d7", + "sha256-first1m": "6a8ce08fef802b62e44b1cf328e338abfce31a9e7ee5b79a8d106bc8031b17cf" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_tire_normal.png", + "size": 23775370, + "hash": { + "sha256-flat-1mb": "eba934614c4f124fdfedb234047f7f622e9b196723677ce3de1363ac98965955", + "sha256": "87cfc1706dd33330dfc72c36d8336f09ab416130b311a405e524a38d57b4594e", + "blake3": "44a0a7b1c8d21f4f97c684a6d4060c243428c070a214830bb412d8ca938631bb", + "sha256-first1m": "0b1516b88ee76973bd0aab7ede5d6613b36d33090cb3edb3eab6fbff7fee970f" + } + }, + { + "relative_path": "SubUSDs/textures/forklift_1_tire_roughness.png", + "size": 4802379, + "hash": { + "sha256-flat-1mb": "e6ca4415ad048d355ed6365ca4cccc291bfae33bdf4763a983310d84ea106c65", + "sha256": "929673d8860402499b90313ed682ed52105bad5352b4179681bdfd6dc3c1d930", + "blake3": "08d3109ddb9c5e42079960150dd7ff9ba812fe27a6820f34fa636919f0f0a496", + "sha256-first1m": "455704721699d7a672051ac80c8fd9b7f0ebb64e69739850c64df5409182f437" + } + }, + { + "relative_path": "forklift_1.usd", + "size": 45370097, + "hash": { + "sha256-flat-1mb": "b93aab203194790b932bf2f7a189edcff68232761d5df311c0828ecbb5c49eb3", + "sha256": "5c806cc249e9ad75267a3a87afa2ca61bed04e73729a1ed69543af5556e7b356", + "blake3": "b82622189752f9527ff5a8e0abbf8c773a5ce941ccc7a8330dc9894e2c4bd6d2", + "sha256-first1m": "6f3bb650422edca567cbb9d9615c4e184b7270c364d57537a3b37e8582b064fe" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/954/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/954/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..d34edfe2bfe7dc15bfff71a28e3eb3f930023e86 --- /dev/null +++ b/simready_assets/954/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "forklift_1.usd" + ] +} diff --git a/simready_assets/954/forklift_1.usd b/simready_assets/954/forklift_1.usd new file mode 100644 index 0000000000000000000000000000000000000000..a7f93aaae4087f01f7f3b6e8a95203ef341cf6ab --- /dev/null +++ b/simready_assets/954/forklift_1.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c806cc249e9ad75267a3a87afa2ca61bed04e73729a1ed69543af5556e7b356 +size 45370097 diff --git a/simready_assets/954/gltf/pbr.mdl b/simready_assets/954/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/954/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/955/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/955/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..bb31d3f6123aa3c1cdf7b7dc00d1d89ec8f372ef --- /dev/null +++ b/simready_assets/955/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T19:44:38", + "assets": [ + { + "asset": "Column_guard_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "fb5e690e8eccf24182ab41acbbce517daab26c7a880a9497f0686316c3ad6748", + "blake3": "a5d91b216cf8e1c6ebac86e8e4d47890c2383a142f761f39f8450355ecb6244d" + } +} diff --git a/simready_assets/955/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/955/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..8627730bc2c160e039509547a783a755e5286fe1 --- /dev/null +++ b/simready_assets/955/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T19:44:38", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/955/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/955/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..46c7dbd00cded60c705857284f0651ef96548e72 --- /dev/null +++ b/simready_assets/955/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,33 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/column_guard_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/Column_guard_1.usd.png", + "size": 9395, + "hash": { + "sha256-flat-1mb": "81fa3d029644d5c5f4244dd066f4f52438c3068aea7005d56883b3fc1afb201d", + "sha256": "d4dc320c6e2db40d218086007c8fc7550e196393ba0b25bef1555e386ef9686f", + "blake3": "5214d219433f75177e7435c396a721e12ca7ea055acd81b78e11af20e405dc55" + } + }, + { + "relative_path": "Column_guard_1.usd", + "size": 232277, + "hash": { + "sha256-flat-1mb": "64fbd117cc1986b50c824b953ba077f2188aac60990bc9247ec7456682ea9851", + "sha256": "140d979ca5f54e2b9c66fd77638c9c821fa56fa7235956cbdf6c2db23244be78", + "blake3": "9135e3536299809ed12ab51b28fb8f85e498e894a3a066e08239666e588eefd2" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/955/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/955/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..1fad6d52a0d4a86556d374971eb50ed1eafb8239 --- /dev/null +++ b/simready_assets/955/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "Column_guard_1.usd" + ] +} diff --git a/simready_assets/955/Column_guard_1.usd b/simready_assets/955/Column_guard_1.usd new file mode 100644 index 0000000000000000000000000000000000000000..3d05a854c401a6546e8055d0677248790d31d7a1 --- /dev/null +++ b/simready_assets/955/Column_guard_1.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eec99acc4bfc0b47b58c0cf5c1c3c4dd0cc274cc68e0cac5838fc4c45a189d65 +size 232996 diff --git a/simready_assets/955/gltf/pbr.mdl b/simready_assets/955/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/955/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/956/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/956/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..206f2aaa04a6a7932ebb16ad8645710f6e1caccd --- /dev/null +++ b/simready_assets/956/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T20:05:12", + "assets": [ + { + "asset": "Column_guard_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "0ef0380fd3c798cba91d196183dbc8d8295f12a1be5eb0b91b08b7ca195e125b", + "blake3": "f37d305c9bd0ea39fc3ab11011af18af5d8950666059c215493574242a35dc84" + } +} diff --git a/simready_assets/956/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/956/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..0cb544b98f57aab689debe4ab9177521cbc2842a --- /dev/null +++ b/simready_assets/956/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T20:05:12", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/956/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/956/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..50811dd5dedacd0c4aebf955df3795b47cf9a7b8 --- /dev/null +++ b/simready_assets/956/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,42 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/column_guard_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/Column_guard_2.usd.png", + "size": 11768, + "hash": { + "sha256-flat-1mb": "66d4cbbe4596d1dd5a93f7ec94611d5a2045b2584776010eb5758c93c7d9ec95", + "sha256": "d3a6581693ef985bd3c963a2b43f12ca3f2205b28b464b2d6b5856252ac2bef5", + "blake3": "5b8e4943cbdd12c33ec62747c082e6fca80a077120f3fa370433339985a1e3ce" + } + }, + { + "relative_path": "Column_guard_2.usd", + "size": 46256, + "hash": { + "sha256-flat-1mb": "ff5e1dcfba3d5033e7c11a020b9a5ddbd0c022a8ad2c3bdebd38d858df626f42", + "sha256": "eb2b7c910413dd60bf09522c68441e551fe22c53bffcdcee5e23ac0570d22d97", + "blake3": "3238fed678d6dbcd6bb994de2c4ce08bf643619cb381dd5c87257148ccbb97b7" + } + }, + { + "relative_path": "SubUSDs/textures/Column guard_diffuse.jpg", + "size": 258046, + "hash": { + "sha256-flat-1mb": "298fa750c4c3c3df656f11b7ffd62d8da9b83b4d079f9236680496735ddd6f04", + "sha256": "d71c134c1773ef02e029fd5da44c2d19432d7f46fdc60f83ce5e5f7089e49a21", + "blake3": "90ad67b46b7620483fe3962760e793f4aafb9ddd1341dbc08eeb049d6a4b871b" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/956/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/956/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..37f2811c42560d035029d69bcef25b53c0119ca1 --- /dev/null +++ b/simready_assets/956/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "Column_guard_2.usd" + ] +} diff --git a/simready_assets/956/gltf/pbr.mdl b/simready_assets/956/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/956/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/957/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/957/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..c5d4ad0496dcfcc784699c25201d60c02ee8948b --- /dev/null +++ b/simready_assets/957/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T19:46:26", + "assets": [ + { + "asset": "fire_extinguisher.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "57e40baa622981efd0193343caec553f03e857a71c7d64c44cc4870e9d5c4ec3", + "blake3": "de0d5dd2325c4abcb6dd1517b25308c22d06c43d6dc1a6e72b5199e6be1cb444" + } +} diff --git a/simready_assets/957/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/957/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..97caa0fd38473c6cafbf1b8baf6a32ee68449141 --- /dev/null +++ b/simready_assets/957/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T19:46:26", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/957/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/957/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..621f8a8f3ec9f50c945ccb4fe34e329d39256e13 --- /dev/null +++ b/simready_assets/957/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,64 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/fire_extinguisher/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/fire_extinguisher.usd.png", + "size": 19654, + "hash": { + "sha256-flat-1mb": "c82d07ab4643a1a4d9981bd8e0683a5ac8a088111732804de5ece680379aee9b", + "sha256": "369f269da97b1c0f9e45de92003564119ac34e6ef1ffc2935b23ea5732e5b874", + "blake3": "49be0931a215a49fc0690eabe6738b3660872c7103191d49af91ce730d1ee3e7" + } + }, + { + "relative_path": "SubUSDs/textures/fire_extinguisher_cylinder_diffuse.png", + "size": 2594817, + "hash": { + "sha256-flat-1mb": "ac29ac924dc120c3a77b6a338d151bb807fb9d11aab66e433358e8bf3ff8a304", + "sha256": "433b666a2b7cf59a6d5376c16d495ac2ed4d531c2193470fff9fa1caa39153ce", + "blake3": "a7b98055fa951000d2b5d4de35a9c19be4ef50f8e6c18d2cd9bb6a4ffa5e1de6", + "sha256-first1m": "a8c559f4e5df65cbfd6324442f5d283c831a748d68e60097884e7e0bd50e78c6" + } + }, + { + "relative_path": "SubUSDs/textures/fire_extinguisher_cylinder_normal.png", + "size": 3343791, + "hash": { + "sha256-flat-1mb": "7d788bc6b20ca8e9a34a84843c0758e5c5f5f34a8a3985eb51d4751a17adf32f", + "sha256": "315440ad66a4ee4936323fc387e2eae5ee41908d7aaadf3c774d592bc6650691", + "blake3": "313138fe12420fdea1093195b1eb7da37402ad538a2ded7d5cc09d73421521f5", + "sha256-first1m": "c5f0d680c06559ff885e3ced496a010343fd2714841bfc47a038066cfaaa56bf" + } + }, + { + "relative_path": "SubUSDs/textures/fire_extinguisher_temp_logo_diffuse.png", + "size": 2093566, + "hash": { + "sha256-flat-1mb": "e389ba8536401eea898821afa33ad0bcb4f57f6168e03d11abd2dd33da655c56", + "sha256": "6886d8d750846f832226c9ca16e6967310d57b335937ffc48a4270cf6f2345f5", + "blake3": "c48f4520de36d668c6ede75b9ea5f2267e375881a51b65522051e0ef0b323fa2", + "sha256-first1m": "925f3f080db30eeb6f0b12c6c0ea280848c29c489eba2b1983f1ff7b1b77589e" + } + }, + { + "relative_path": "fire_extinguisher.usd", + "size": 11536038, + "hash": { + "sha256-flat-1mb": "ca4f25ab9fbf3758d2c97f2bb7dc270b088c2938204b88a162e8d8011e25dc6d", + "sha256": "cb0d6e2badd65adb688db9b47100a8d10ccd0754fb65bf55b5eaa043ad673aeb", + "blake3": "0dc894169dda12b8c402273f1e5307eceb7bb4b8df06a7bf047eba3f91572cbf", + "sha256-first1m": "6946fdb101fe534118b5b168305c635708a04e446fce441c3cab484f66d14cb5" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/957/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/957/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..911c73dcd73854543e26981b8f8bcf938d43e6a8 --- /dev/null +++ b/simready_assets/957/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "fire_extinguisher.usd" + ] +} diff --git a/simready_assets/957/fire_extinguisher.usd b/simready_assets/957/fire_extinguisher.usd new file mode 100644 index 0000000000000000000000000000000000000000..abd60364cd2ecffb31541077da36f53427b1ae8a --- /dev/null +++ b/simready_assets/957/fire_extinguisher.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb0d6e2badd65adb688db9b47100a8d10ccd0754fb65bf55b5eaa043ad673aeb +size 11536038 diff --git a/simready_assets/957/gltf/pbr.mdl b/simready_assets/957/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/957/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/958/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/958/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..2ce195c00c02f551198907e99878d64f02d6f8da --- /dev/null +++ b/simready_assets/958/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T16:00:00", + "assets": [ + { + "asset": "traffic_mirror_dome.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "8c3cf6abbb593af2b369b6be5b32b24cdd062e77445abd51f6c0e8110c377a63", + "blake3": "faf44cc7f26df861094592ef535649c89c6280e612a9cd236ddd58c3349493c3" + } +} diff --git a/simready_assets/958/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/958/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..20697d5bb392279d0036915d4a90b79a00fe3c01 --- /dev/null +++ b/simready_assets/958/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-25T16:00:00", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/958/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/958/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..5de6500716d2e91dc8d064eee2566bc2c94fd2bf --- /dev/null +++ b/simready_assets/958/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,43 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/traffic_mirror_dome/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/traffic_mirror_dome.usd.png", + "size": 31784, + "hash": { + "sha256-flat-1mb": "ac60c06506576e0962c6bd27e6c9b6025503b7b34cbd60206885bc0bb37d01b3", + "sha256": "fcf50abb30ae2d974180a37c0c19cb03b048e459ef1499767f2c965659d36d09", + "blake3": "56bbe7607b0dbd72ec8f5bc70733f835caae73b89fa413b05904d8340562d00f" + } + }, + { + "relative_path": "SubUSDs/textures/traffic_mirror_dome_noise_normal.jpg.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "traffic_mirror_dome.usd", + "size": 2377317, + "hash": { + "sha256-flat-1mb": "45cffaa3f85f6608b8b77980210395f233a3c43fae6b8bd2e529f64a3123097d", + "sha256": "8f015bac92fc6f9736f9f421ac869f668e0dfd28b60637dc1a0ee22bb139fb13", + "blake3": "bc557793732ddcb60cb2040e5b3d7f96423c3c3f61545f395660703a86464904", + "sha256-first1m": "1a7fe80446a164d248b0671c5917430b464f29dad05da34f97eb1edbb78adaf7" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/958/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/958/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..19d6fd895751838ae039c1c8990223942e4933ca --- /dev/null +++ b/simready_assets/958/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "traffic_mirror_dome.usd" + ] +} diff --git a/simready_assets/958/gltf/pbr.mdl b/simready_assets/958/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/958/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/958/traffic_mirror_dome.usd b/simready_assets/958/traffic_mirror_dome.usd new file mode 100644 index 0000000000000000000000000000000000000000..b52bad99f04730e2ba6d49703acf86a059982f39 --- /dev/null +++ b/simready_assets/958/traffic_mirror_dome.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f015bac92fc6f9736f9f421ac869f668e0dfd28b60637dc1a0ee22bb139fb13 +size 2377317 diff --git a/simready_assets/959/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/959/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..288d45449528ae50f58138c154a3a05a2686d9ae --- /dev/null +++ b/simready_assets/959/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T13:54:38", + "assets": [ + { + "asset": "Wall_panel_corrugated_metal.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "9d7062257970a8cdf008540efa046971726e6240119bb6b1fb81e15bf3cd388c", + "blake3": "da581834c6ecc86fb665c440612703421a7808a0aa5b55af097a7c8352388902" + } +} diff --git a/simready_assets/959/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/959/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..272f7575d078186a433525680a2729bcef55ee9e --- /dev/null +++ b/simready_assets/959/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T13:54:38", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/959/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/959/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..66c4d4e6569a189abf1c2eb58765eec60c07f256 --- /dev/null +++ b/simready_assets/959/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,33 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/wall_panel_corrugated_metal/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/Wall_panel_corrugated_metal.usd.png", + "size": 8375, + "hash": { + "sha256-flat-1mb": "2e4a8a37608a0404c908fc3a18acf3ebd64eaa5e4a4e642f54e4fb571cca481c", + "sha256": "3c0484ed25d84ed21476aa9d6af3b3455ba9810b6a65672db36e888c4b2b4612", + "blake3": "951baa437b419d2cf7439a662a3b3e612465e9c6c519bcfd1642c31260b5b585" + } + }, + { + "relative_path": "Wall_panel_corrugated_metal.usd", + "size": 405848, + "hash": { + "sha256-flat-1mb": "4c518c6afce51444677e5bb24f154e4fa96450a265bacccdd1b13f31651d33c8", + "sha256": "dc1923967e6c642333f73e615a06c037082ec72792d4477322799f5b6b75f92e", + "blake3": "cee7bf13e9f6009782ca2c23f60c3ec56a6eac29ed8dbd8067926870a16c8a83" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/959/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/959/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..186e10dfccf0d9ec2740e9ba015111218c5c70e3 --- /dev/null +++ b/simready_assets/959/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "Wall_panel_corrugated_metal.usd" + ] +} diff --git a/simready_assets/959/Wall_panel_corrugated_metal.usd b/simready_assets/959/Wall_panel_corrugated_metal.usd new file mode 100644 index 0000000000000000000000000000000000000000..e12d31c3dd8907aeb2f1cf21bed90df799566644 --- /dev/null +++ b/simready_assets/959/Wall_panel_corrugated_metal.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a63e4cc7aa7fe038d63e093c42c7ac876b0d367624eafedb4628892f4bef3e0 +size 406531 diff --git a/simready_assets/959/gltf/pbr.mdl b/simready_assets/959/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/959/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/960/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/960/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..03f444f30732a3a93c6f08b0c318a19dc6fae252 --- /dev/null +++ b/simready_assets/960/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T21:01:10", + "assets": [ + { + "asset": "fire_alarm.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "4c56d1b792e0c1bff143e020ca910c51291f7bbefe12586d19843c28376310d4", + "blake3": "4316997ecdd620f4fdb19f1e8ee0524b19eed2eaabf881b1e3e3b32d44f51c99" + } +} diff --git a/simready_assets/960/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/960/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7edeecac6e5ab8a505388f4be790713b177eb428 --- /dev/null +++ b/simready_assets/960/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T21:01:11", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/960/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/960/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..9cec4780c3baa2ea14f5171d6eb22811c0ef2d45 --- /dev/null +++ b/simready_assets/960/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,42 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/fire_alarm/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/fire_alarm.usd.png", + "size": 19407, + "hash": { + "sha256-flat-1mb": "b53451f71ae7f2466f0d2ebb630b3283d3916b683626e4612bb031bc239ed886", + "sha256": "8723e915fd33e62ff802c3e9b636f35d467635b6e0ed8f78e6bfd52feb13c867", + "blake3": "08be480849ce82c56b7b04c2c23240863b21b2a9a2ede40b10159b67924430df" + } + }, + { + "relative_path": "SubUSDs/textures/fire_alarm_light_diffuse.jpg", + "size": 63074, + "hash": { + "sha256-flat-1mb": "a51cc477e99af36bd60208440edc5b0dec802a2bf04cf2feeace88377b789367", + "sha256": "01fb1a0d4e5aac1f181376068f19543ff6b98ade7969ace1ad10be12413c9304", + "blake3": "d6ad1c790d0ddf89baebfb389f73cd69150667e7f2a363916c732b86296cb53e" + } + }, + { + "relative_path": "fire_alarm.usd", + "size": 867107, + "hash": { + "sha256-flat-1mb": "685339dc3ba33387ce4b8a147a733d707d24b7cce12f8cdcf870893daae9c21c", + "sha256": "d2625cb4cc8f92bbac514ce0df15b69064dfa9ba93a8971bd0b280805b108e6e", + "blake3": "1b8aa9c3ca06a8839f6cbfebb5c7d6de2133798c0531835a5066a351eabdc6aa" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/960/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/960/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..9c92f77f86bb7bcd64badfbf0a5178c9301ec3d7 --- /dev/null +++ b/simready_assets/960/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "fire_alarm.usd" + ] +} diff --git a/simready_assets/960/fire_alarm.usd b/simready_assets/960/fire_alarm.usd new file mode 100644 index 0000000000000000000000000000000000000000..606277cba7b9b0d20a5a7268afdeb017e3672e83 --- /dev/null +++ b/simready_assets/960/fire_alarm.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d2625cb4cc8f92bbac514ce0df15b69064dfa9ba93a8971bd0b280805b108e6e +size 867107 diff --git a/simready_assets/960/gltf/pbr.mdl b/simready_assets/960/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/960/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/961/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/961/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..6e0a9e9b9116167d59ffe41f5ab04b1c8d1056ed --- /dev/null +++ b/simready_assets/961/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T20:47:54", + "assets": [ + { + "asset": "fire_sprinkler.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "8f5a9b59608f7d03b7160185db8ef46b77021ca61e676234112cbc7492dfc1d8", + "blake3": "b944d3e91df31b69338e8cd5ff97a011b6b9cafa89330b944ed47893c1e796b3" + } +} diff --git a/simready_assets/961/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/961/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..96ae0089e7d1e28ba4f3be4200f52f2cccc83774 --- /dev/null +++ b/simready_assets/961/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T20:47:54", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/961/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/961/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..89c35a2d0a04361d4dbd8c022cce2f64a5786694 --- /dev/null +++ b/simready_assets/961/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/fire_sprinkler/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/fire_sprinkler.usd.png", + "size": 16560, + "hash": { + "sha256-flat-1mb": "5f484c4b801e00c8f7df0791a00be81735a350f3f0fc35c3aa5417dfe3e1810b", + "sha256": "ac38169320ef2cb6194f07d752bc1d163c48810cad34a4f6a91a5d2fa7d0b534", + "blake3": "4662c134c26651f9ad70d6e819b21c10a26cf24973d2369d8d70a5f23755a685" + } + }, + { + "relative_path": "fire_sprinkler.usd", + "size": 2175278, + "hash": { + "sha256-flat-1mb": "25e8fa0502e10a9e381aad631b3dbcb35100960abc59b997edd18636ed784be2", + "sha256": "fa92075c48ae2b15d4221d3b4e9e47c9343899369d9e742a75dd47cb1f51dc11", + "blake3": "a56d8d4023e4b94706bd74165b88357bb7d05d0b207039dfab98ae1a3d44fb26", + "sha256-first1m": "1f1cc06f097fe2a34f74d8c0c76a45c5734c65f204041501f9f3f137a6632f5c" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/961/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/961/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..11377308ed02de23646d848be103314b2d441d64 --- /dev/null +++ b/simready_assets/961/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "fire_sprinkler.usd" + ] +} diff --git a/simready_assets/961/fire_sprinkler.usd b/simready_assets/961/fire_sprinkler.usd new file mode 100644 index 0000000000000000000000000000000000000000..08f51874e35349d8617b8e9a354d7cacb8791d95 --- /dev/null +++ b/simready_assets/961/fire_sprinkler.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa92075c48ae2b15d4221d3b4e9e47c9343899369d9e742a75dd47cb1f51dc11 +size 2175278 diff --git a/simready_assets/961/gltf/pbr.mdl b/simready_assets/961/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/961/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/962/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/962/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..d96604ee67b879ef232cf931da0ae09c652ce32f --- /dev/null +++ b/simready_assets/962/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T16:23:43", + "assets": [ + { + "asset": "large_first_aid_kit.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "e2399d2e2a3609f43b3b70e1e7197fe47b7eb8def2f8f06726cb8ac6691edb3a", + "blake3": "61a4fc22d3ade6523010383b74eca590534b91f45fde48688d3177e5489808f3" + } +} diff --git a/simready_assets/962/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/962/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..38014e5c23addbbcc0bf1624b38ed8aec37a376c --- /dev/null +++ b/simready_assets/962/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T16:23:43", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/962/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/962/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..9de0bfae7be8458e684619b2b7216475a9266e5a --- /dev/null +++ b/simready_assets/962/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,167 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/large_first_aid_kit/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/large_first_aid_kit.usd.png", + "size": 20911, + "hash": { + "sha256-flat-1mb": "79a1fd5e6c3f48de9f77cd0b514f66f3796cb996c1cee9e2d0a346ea5a149ed0", + "sha256": "5ddfa8547bd78c578be16ed207713c3d99edf227cc6db2b6db7c05f7c351b152", + "blake3": "de4e96d8431ea808bd355ed7d4686d16b8ae74771f5d507d0dde4e5d55349493" + } + }, + { + "relative_path": "SubUSDs/textures/Aromatechscent_bottle_Label10.jpg", + "size": 208871, + "hash": { + "sha256-flat-1mb": "cf76b711c7e3f84810264aeb04b57ad64ae6772029ecd3edb1f29a8347d73f4c", + "sha256": "12d91e9bd79d9606a9d93fea30450ef910acbbebfde98b6735e65c3a0536be8a", + "blake3": "c46c6215f8d9d4592a7210d16449951c738c446c6ec6099b028bb448ea241641" + } + }, + { + "relative_path": "SubUSDs/textures/Biotin Complex_label_base_06.jpg", + "size": 2495901, + "hash": { + "sha256-flat-1mb": "cf3429306560a05d36ec5a5e8022044e09acc9fbf948270d0e302b55e149856a", + "sha256": "1fb0c688a3fad1a16694d5818b0b0e01ba2992eeead70a3a9f004e33360a3888", + "blake3": "ac99bccc07e30c589e18f7a1e1830cad64a53982ceb44ac1189c7d00a0bf3f75", + "sha256-first1m": "7c39965ff64c945b87e2f5c70acac9f92d62f5daf8394c68ea0e2ab2436f51c4" + } + }, + { + "relative_path": "SubUSDs/textures/antiseptic_healing_ointment_diffuse.jpg", + "size": 99263, + "hash": { + "sha256-flat-1mb": "df9ac06458fa0cc765f8c4c3f1138c6b77d1c2c3aba4d76018a2fa50a68d864f", + "sha256": "13fef1e5a3c5ffb54eb2a88af1cf92f21483418839f2032957249b7c60c4d80b", + "blake3": "e23024fe4a42491a7809eb3dcba3b7f6b3ab73eb702d641ed9515e92038151d6" + } + }, + { + "relative_path": "SubUSDs/textures/boxed_medicines (1).jpg", + "size": 5584473, + "hash": { + "sha256-flat-1mb": "7e19a57ec90339a94300c505c316ba2cc782b36c5b884577576c909c7561960a", + "sha256": "5d5bec2e6e0e943601148e52478adfe1666e06ad27cb227cde9b0f069d7990b5", + "blake3": "4bb5413493ba2e8ad0e1628d252cc9f335a5602b66d9f35979e296b1a96a86b8", + "sha256-first1m": "bc2ba74b13f9285a208d3441ea674f175434ce8bc6585faa114966116f9001ba" + } + }, + { + "relative_path": "SubUSDs/textures/cold_flu_relief_box_diffuse.jpg", + "size": 202408, + "hash": { + "sha256-flat-1mb": "6be74b1aae2e8e24fee45ed37ea3435bb2d07fb39c5d342bdfbb4697fab43998", + "sha256": "69f279073c916f5ff3c4c2f97199e566623bbaa5e7407c5093d829ca7d407c0b", + "blake3": "ad13b454129adbedef0bd7ca79e1ff0c14c9fbea74deff683e609ce9289c3b26" + } + }, + { + "relative_path": "SubUSDs/textures/large_first _aid _kit_bandage_fabric_diffuse.jpg", + "size": 2212293, + "hash": { + "sha256-flat-1mb": "9dcc6fb404b54aae999d31401b5786def7e33303f4f598195b84beb31e8f1f46", + "sha256": "841e8d1d226100fdc79cc42cbc105dcf8c3f5e9ee381f34df43588bda5c9570a", + "blake3": "71b2b0221fba0a49ddf5a77405be41e119851224a258dda31786be8cbc2a3a04", + "sha256-first1m": "7c5815c1838ded4a1dc944b66dbdcf5e580ab74319cdb841f7ebbee13594ca49" + } + }, + { + "relative_path": "SubUSDs/textures/large_first _aid _kit_bandage_fabric_normal.png", + "size": 9969137, + "hash": { + "sha256-flat-1mb": "09c28712fe21f4a66769519e1cb74e5df24b377cb579451f2a3a3fb742d76d70", + "sha256": "e40dbf2a3ce5dcd508018cbd4a6e79254b16b295c4d7b27bcf68baad2ad86283", + "blake3": "6910bfa5fa00fc537d6b0a0df301ef941c37d88a51f7299f1bc0ab9cee9fed6c", + "sha256-first1m": "1de5f211d8031ec60d627e853b9e0eaef274c7ad13f3f4b885014d12bce692ed" + } + }, + { + "relative_path": "SubUSDs/textures/large_first _aid _kit_bottle_normal.jpg", + "size": 470117, + "hash": { + "sha256-flat-1mb": "ce9f1f8d97eaf1d8a75fc48a3a212a0ba6839b4ed4f046777aacea19711dde90", + "sha256": "dadfe23d20009312822962485d60f10b498c9f058af1ed2db2e7f9b366e85ced", + "blake3": "4db4021be32aa3ee44ec82e3560e04e104e4b577198427fa054d1bc13351c509" + } + }, + { + "relative_path": "SubUSDs/textures/large_first_aid_kit_handle_diffuse.jpg", + "size": 4511546, + "hash": { + "sha256-flat-1mb": "07fd16bea6734c5a77f8ea1e87679373941977534fe2ee99ad0f0e2cc0aca32d", + "sha256": "2a8967ba4c4c39aeb6401dcf9baf387f48368a9407a0a095bb660da142a8e07f", + "blake3": "5f43c35a5958096d078f8688b3c262dc28c3de23324f783bdce123430151a3f8", + "sha256-first1m": "3a8292dfb4627ee4af6429770206567fe720e827d51ae320a8d21f8543ff9815" + } + }, + { + "relative_path": "SubUSDs/textures/large_first_aid_kit_noise_normal.jpg", + "size": 971412, + "hash": { + "sha256-flat-1mb": "f29b42414259abf821a469ec86966995087b04cd0b6545a554142c66f2460ed8", + "sha256": "92412b81cea1c43b79274a69c3a3a0af4a33ac7a4dd197a3d4d5aac8246cc51a", + "blake3": "baeabffdda0c521dc67290fd76f7059073b260b7db52fb55883319e1a4b57fbf" + } + }, + { + "relative_path": "SubUSDs/textures/multi_symptom_tablets_box_diffuse.jpg", + "size": 204725, + "hash": { + "sha256-flat-1mb": "bfcc2c5cb8128f7b2f5aa62dd629a422d3b3d49b8bb64555bb44e574db96916b", + "sha256": "f8827a8b53b51359c103c6a3278e8d4a1e6d43de96ebcb141f80ac30a1923ef5", + "blake3": "1e847b4f047425c1dfbf098fef77bb3b4db4f3cbb09d957231f777270afe7f12" + } + }, + { + "relative_path": "SubUSDs/textures/multivitamin_mineral_capsule_diffuse.png", + "size": 1067142, + "hash": { + "sha256-flat-1mb": "bc2e865eed0d029d7155f70085055dc9991ee34757b3cd9f9ede7fa383c974b5", + "sha256": "2c30db35518fceb173f3e0a63293af755e4361643ccaadf05801cf879d63a812", + "blake3": "f40f15adeb58095a42eb7ee83bbb23ea3bcfb8eaf9b93a5e480c52d28ccda189", + "sha256-first1m": "ef6563672113f30c43e797efa2e43ec74a3248e36d6703b15b4bb0f8a511aef6" + } + }, + { + "relative_path": "SubUSDs/textures/pain_relief_gel_diffuse.png", + "size": 1874606, + "hash": { + "sha256-flat-1mb": "f712f2b9e8c9f4e95daabb17253d5d3be8435db14cd640a677954f192f52012a", + "sha256": "5eafa500580ea4b7708393f888e5a3686081142c98bcabd213e8885cac7939da", + "blake3": "84052956cde51b8bd993b587ccf3cd8dfb54c75c29c9fa72957c1ea56916e6e0", + "sha256-first1m": "cf670ebdd69e30691764bb49fd3bed85bfa9543293bbe13e3d98d3760315510e" + } + }, + { + "relative_path": "SubUSDs/textures/rehydration_care_diffuse.jpg", + "size": 113131, + "hash": { + "sha256-flat-1mb": "ab29714b7adbe5e731445a4b693c2e014ff2b21d4652221ca16332cf838bd1e8", + "sha256": "aac1bf7224c96fc370caf853eab223a96575fd1f8422458b3f0ae72017c4cd3e", + "blake3": "9e6de3342f773fb49e9b09a68ed42b70520e0ce9e6d756e9722da2083eb1f602" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "large_first_aid_kit.usd", + "size": 14443933, + "hash": { + "sha256-flat-1mb": "ddeec145be5cd91561912eb9cd407c94dc4ecf1b12de469768673e9b97209f47", + "sha256": "315b72c37dece44dcef19fcb0e5cb84cec1efcc44fd0c27690c397ab5cfd3f48", + "blake3": "e0661b39c64ff639db32d713a9ba18ab5804635c6098bf21d51b0bc3761c19be", + "sha256-first1m": "251544b8a76517700f28278158ef200fc291df6f373225d4820fcf5319c42bf9" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/962/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/962/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..205c3cdf51793bfa8eef8c3360cddc140fe60717 --- /dev/null +++ b/simready_assets/962/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "large_first_aid_kit.usd" + ] +} diff --git a/simready_assets/962/gltf/pbr.mdl b/simready_assets/962/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/962/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/962/large_first_aid_kit.usd b/simready_assets/962/large_first_aid_kit.usd new file mode 100644 index 0000000000000000000000000000000000000000..17527d0f04338d969efae53285d37a5cbc354aa2 --- /dev/null +++ b/simready_assets/962/large_first_aid_kit.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:315b72c37dece44dcef19fcb0e5cb84cec1efcc44fd0c27690c397ab5cfd3f48 +size 14443933 diff --git a/simready_assets/963/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/963/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..b1fdcf1911e15cacfe139075f5482b4721a3b406 --- /dev/null +++ b/simready_assets/963/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T20:49:00", + "assets": [ + { + "asset": "smoke_detector.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "13b69717bc4d3b95abe5454078c8c5576818b800f663a4f0c8dffdc3bed58203", + "blake3": "ed515b72e5bc8ccbc25a83a5df1f1dd305fbcfd3939e3f8b7202e4de77b1ccc6" + } +} diff --git a/simready_assets/963/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/963/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..56564ab18b61b6e4d32c1c0b0fb0fd8de3af7e46 --- /dev/null +++ b/simready_assets/963/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-26T20:49:00", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/963/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/963/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..5f250052b26a118f3a0841d68d0ef8c71bc6d8d8 --- /dev/null +++ b/simready_assets/963/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/smoke_detector/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/smoke_detector.usd.png", + "size": 12332, + "hash": { + "sha256-flat-1mb": "8593a84580b5b08651b15bff9543031b5b88aa068225073992d04dfc3eea2585", + "sha256": "539306f976d8647a05e830eb16669e5968e1c6f21e78b211ef45d4cea48b3a07", + "blake3": "19d9d4b347554ee591767d7798a72b29768334e3bd8a645fa045f914d5730ef4" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "smoke_detector.usd", + "size": 1954015, + "hash": { + "sha256-flat-1mb": "207100b0458a3d198bf4b4a01f02584064243e119600735739efdc1b821b41e2", + "sha256": "2f8a8730f8747e1acc8502667bab9840ebd75e2d4dcc36bfecf944d8b6b31a58", + "blake3": "6b268d811f81dac3986bf3c48e1a35b3f25570d75e220f46c38783ad80316099", + "sha256-first1m": "e5dbebabfee47f886d4541e4329cb1b5e15e703ba29bfa5c4c05c7d486caaa68" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/963/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/963/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..8f273fc8917b1cebff7f44f3d88e115d99250543 --- /dev/null +++ b/simready_assets/963/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "smoke_detector.usd" + ] +} diff --git a/simready_assets/963/gltf/pbr.mdl b/simready_assets/963/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/963/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/963/smoke_detector.usd b/simready_assets/963/smoke_detector.usd new file mode 100644 index 0000000000000000000000000000000000000000..c90a7d7641e781a5e47c8139f89c1914f2cea8e6 --- /dev/null +++ b/simready_assets/963/smoke_detector.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f8a8730f8747e1acc8502667bab9840ebd75e2d4dcc36bfecf944d8b6b31a58 +size 1954015 diff --git a/simready_assets/964/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/964/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..74fc216a37afbd53c7fa197ac52efbe2a98ff577 --- /dev/null +++ b/simready_assets/964/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T13:23:55", + "assets": [ + { + "asset": "scissor_lift.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "8885f7b79e7d79c3c74125a0455c64312b74a7b3efaa39b5df0ef3682a5374be", + "blake3": "56d5db9e911e5f4792938210866e3cd7f448082ba657d827206ac58020c12ff8" + } +} diff --git a/simready_assets/964/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/964/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..1fb91722310357dc61676c8635c2572158b937b8 --- /dev/null +++ b/simready_assets/964/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T13:23:55", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/964/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/964/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..434d27a5fdb8bd090a99696e1b6358de24136299 --- /dev/null +++ b/simready_assets/964/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/scissor_lift/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/scissor_lift.usd.png", + "size": 22570, + "hash": { + "sha256-flat-1mb": "cb7cc776b408df7e602178be8b3485e7dbecc8a5018fa2696fe707a7f2a0ea6f", + "sha256": "9a173d6996571ced8b3f9b1c9421b6a91ecafd1662a5c34b33238ecaeafa84af", + "blake3": "0d99c8071122661ecb693e6d4aa3721e968e1444d63b65086e7ca640c646f0f7" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "scissor_lift.usd", + "size": 8266971, + "hash": { + "sha256-flat-1mb": "ef5a0b7ccec23ccb43f7fc8f14298be750d425c873f8d51dd261aef6dc6578b2", + "sha256": "93fc23cf374ba26e26768bad136129d6d42bb5f59daff49bd0a6136338ee3e41", + "blake3": "38839853d3832292a8bd5f130120eb7947bd8ae80c4c782086391c941eee9625", + "sha256-first1m": "2f4fed16633cb2f4746bd75b9dbde8270fbca3c667a6fe91b7be4250900c0672" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/964/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/964/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..8f5673ab32fb589240dbed91c1014621c34c1f99 --- /dev/null +++ b/simready_assets/964/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "scissor_lift.usd" + ] +} diff --git a/simready_assets/964/gltf/pbr.mdl b/simready_assets/964/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/964/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/964/scissor_lift.usd b/simready_assets/964/scissor_lift.usd new file mode 100644 index 0000000000000000000000000000000000000000..8c47b9acbaeb2c272a6fc5ef89828cae1b2ed2b1 --- /dev/null +++ b/simready_assets/964/scissor_lift.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de6cfbb7f84238ff31db15406ceb1cc7e9b4e2f5c6b0e1c1fed72c24a3f1a562 +size 8268262 diff --git a/simready_assets/965/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/965/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9760935cbc98a41eb67583061bb87ea9ccbdd800 --- /dev/null +++ b/simready_assets/965/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T13:30:59", + "assets": [ + { + "asset": "conveyor_belt_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "bb7c2976136fd055606e54475e741f1bbc36088e67c83dfcf0b9ba162313c553", + "blake3": "d081949927cf224e5913320066318006e292bb3012502087d95a67dfab2b977a" + } +} diff --git a/simready_assets/965/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/965/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..11048f9fdcbb04ed7d977c7719e7ff7d0cce59b9 --- /dev/null +++ b/simready_assets/965/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T13:30:59", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/965/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/965/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..febc0a162f8bd6ae5d16509e5337018ef8e9eebd --- /dev/null +++ b/simready_assets/965/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,220 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/conveyor_belt_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/conveyor_belt_1.usd.png", + "size": 22325, + "hash": { + "sha256-flat-1mb": "13bc8c484194c4a90328856822fddec5a4e4aa53167a4c51a6f4e7f8a3297582", + "sha256": "8ed03ad8e37326c86414a7ca116bd5bc68c3e118c0940e54bef37e80b2c0315f", + "blake3": "1700449b677ac831856a2b66cb4d2143b0f75e18f4380828df3e78bedbb6b633" + } + }, + { + "relative_path": "SubUSDs/materials/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "SubUSDs/materials/pbr_1.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_diffuse.jpg", + "size": 4337281, + "hash": { + "sha256-flat-1mb": "45ce0d041f1584a4211ea32e6ed9aefb423bd7214610d05e0caf964e991aa47f", + "sha256": "9d560551d0beae1726f98c8a72a12441a01e28413417ebd0c8229bcec20dbcfc", + "blake3": "319fdb2a0edf61bc085430ec1368b922b788111cea5540567f399e19f4aeab76", + "sha256-first1m": "32f4068007975e7607d74d956303ff45e7a3b3080bbd4ee6b6b00e0f83579c96" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_diffuse_1.jpg", + "size": 4337281, + "hash": { + "sha256-flat-1mb": "45ce0d041f1584a4211ea32e6ed9aefb423bd7214610d05e0caf964e991aa47f", + "sha256": "9d560551d0beae1726f98c8a72a12441a01e28413417ebd0c8229bcec20dbcfc", + "blake3": "319fdb2a0edf61bc085430ec1368b922b788111cea5540567f399e19f4aeab76", + "sha256-first1m": "32f4068007975e7607d74d956303ff45e7a3b3080bbd4ee6b6b00e0f83579c96" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_diffuse_2.jpg", + "size": 4337281, + "hash": { + "sha256-flat-1mb": "45ce0d041f1584a4211ea32e6ed9aefb423bd7214610d05e0caf964e991aa47f", + "sha256": "9d560551d0beae1726f98c8a72a12441a01e28413417ebd0c8229bcec20dbcfc", + "blake3": "319fdb2a0edf61bc085430ec1368b922b788111cea5540567f399e19f4aeab76", + "sha256-first1m": "32f4068007975e7607d74d956303ff45e7a3b3080bbd4ee6b6b00e0f83579c96" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_diffuse_3.jpg", + "size": 4337281, + "hash": { + "sha256-flat-1mb": "45ce0d041f1584a4211ea32e6ed9aefb423bd7214610d05e0caf964e991aa47f", + "sha256": "9d560551d0beae1726f98c8a72a12441a01e28413417ebd0c8229bcec20dbcfc", + "blake3": "319fdb2a0edf61bc085430ec1368b922b788111cea5540567f399e19f4aeab76", + "sha256-first1m": "32f4068007975e7607d74d956303ff45e7a3b3080bbd4ee6b6b00e0f83579c96" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_diffuse_4.jpg", + "size": 4337281, + "hash": { + "sha256-flat-1mb": "45ce0d041f1584a4211ea32e6ed9aefb423bd7214610d05e0caf964e991aa47f", + "sha256": "9d560551d0beae1726f98c8a72a12441a01e28413417ebd0c8229bcec20dbcfc", + "blake3": "319fdb2a0edf61bc085430ec1368b922b788111cea5540567f399e19f4aeab76", + "sha256-first1m": "32f4068007975e7607d74d956303ff45e7a3b3080bbd4ee6b6b00e0f83579c96" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_normal.jpg", + "size": 9352711, + "hash": { + "sha256-flat-1mb": "10bf02b9859ec71d9cf59e1787e4fd0fe8f61e2fa6a4c0cf09609cd1bfda5a9d", + "sha256": "d7cdf99f10958a4c2e53b80deb2c14ee0675f0622dcdc070309559d1da999865", + "blake3": "26f1208f9206d50e04ea72b52cd92ab8c3a691ab455f883c9d5255d49c0977e4", + "sha256-first1m": "8da662b0f675a6dcdbdef5ba4e3617ab673bc0291076e247d1df3734c48ac2e8" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_normal_1.jpg", + "size": 9352711, + "hash": { + "sha256-flat-1mb": "10bf02b9859ec71d9cf59e1787e4fd0fe8f61e2fa6a4c0cf09609cd1bfda5a9d", + "sha256": "d7cdf99f10958a4c2e53b80deb2c14ee0675f0622dcdc070309559d1da999865", + "blake3": "26f1208f9206d50e04ea72b52cd92ab8c3a691ab455f883c9d5255d49c0977e4", + "sha256-first1m": "8da662b0f675a6dcdbdef5ba4e3617ab673bc0291076e247d1df3734c48ac2e8" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_normal_2.jpg", + "size": 9352711, + "hash": { + "sha256-flat-1mb": "10bf02b9859ec71d9cf59e1787e4fd0fe8f61e2fa6a4c0cf09609cd1bfda5a9d", + "sha256": "d7cdf99f10958a4c2e53b80deb2c14ee0675f0622dcdc070309559d1da999865", + "blake3": "26f1208f9206d50e04ea72b52cd92ab8c3a691ab455f883c9d5255d49c0977e4", + "sha256-first1m": "8da662b0f675a6dcdbdef5ba4e3617ab673bc0291076e247d1df3734c48ac2e8" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_normal_3.jpg", + "size": 9352711, + "hash": { + "sha256-flat-1mb": "10bf02b9859ec71d9cf59e1787e4fd0fe8f61e2fa6a4c0cf09609cd1bfda5a9d", + "sha256": "d7cdf99f10958a4c2e53b80deb2c14ee0675f0622dcdc070309559d1da999865", + "blake3": "26f1208f9206d50e04ea72b52cd92ab8c3a691ab455f883c9d5255d49c0977e4", + "sha256-first1m": "8da662b0f675a6dcdbdef5ba4e3617ab673bc0291076e247d1df3734c48ac2e8" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_normal_4.jpg", + "size": 9352711, + "hash": { + "sha256-flat-1mb": "10bf02b9859ec71d9cf59e1787e4fd0fe8f61e2fa6a4c0cf09609cd1bfda5a9d", + "sha256": "d7cdf99f10958a4c2e53b80deb2c14ee0675f0622dcdc070309559d1da999865", + "blake3": "26f1208f9206d50e04ea72b52cd92ab8c3a691ab455f883c9d5255d49c0977e4", + "sha256-first1m": "8da662b0f675a6dcdbdef5ba4e3617ab673bc0291076e247d1df3734c48ac2e8" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_roughness.png", + "size": 4805468, + "hash": { + "sha256-flat-1mb": "e2b47500a881c287b6671e83c79e41700a96ead6e5335536ae58dfa5ce3f4b62", + "sha256": "b8c43e8af821a9dea5325994271a315a09bfa8042fb88479240e46e472f90a87", + "blake3": "43b0fa6a8803f36d98da27c9d1edfde55d44667d4ecee492f9b21c5f0cde6e7a", + "sha256-first1m": "7a23d659f89d39ce99c5f72836dffa2a3a28cf9961501252725a1de0b870c84f" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_roughness_1.png", + "size": 4805468, + "hash": { + "sha256-flat-1mb": "e2b47500a881c287b6671e83c79e41700a96ead6e5335536ae58dfa5ce3f4b62", + "sha256": "b8c43e8af821a9dea5325994271a315a09bfa8042fb88479240e46e472f90a87", + "blake3": "43b0fa6a8803f36d98da27c9d1edfde55d44667d4ecee492f9b21c5f0cde6e7a", + "sha256-first1m": "7a23d659f89d39ce99c5f72836dffa2a3a28cf9961501252725a1de0b870c84f" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_roughness_2.png", + "size": 4805468, + "hash": { + "sha256-flat-1mb": "e2b47500a881c287b6671e83c79e41700a96ead6e5335536ae58dfa5ce3f4b62", + "sha256": "b8c43e8af821a9dea5325994271a315a09bfa8042fb88479240e46e472f90a87", + "blake3": "43b0fa6a8803f36d98da27c9d1edfde55d44667d4ecee492f9b21c5f0cde6e7a", + "sha256-first1m": "7a23d659f89d39ce99c5f72836dffa2a3a28cf9961501252725a1de0b870c84f" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_roughness_3.png", + "size": 4805468, + "hash": { + "sha256-flat-1mb": "e2b47500a881c287b6671e83c79e41700a96ead6e5335536ae58dfa5ce3f4b62", + "sha256": "b8c43e8af821a9dea5325994271a315a09bfa8042fb88479240e46e472f90a87", + "blake3": "43b0fa6a8803f36d98da27c9d1edfde55d44667d4ecee492f9b21c5f0cde6e7a", + "sha256-first1m": "7a23d659f89d39ce99c5f72836dffa2a3a28cf9961501252725a1de0b870c84f" + } + }, + { + "relative_path": "SubUSDs/textures/conveyor_belt_roughness_4.png", + "size": 4805468, + "hash": { + "sha256-flat-1mb": "e2b47500a881c287b6671e83c79e41700a96ead6e5335536ae58dfa5ce3f4b62", + "sha256": "b8c43e8af821a9dea5325994271a315a09bfa8042fb88479240e46e472f90a87", + "blake3": "43b0fa6a8803f36d98da27c9d1edfde55d44667d4ecee492f9b21c5f0cde6e7a", + "sha256-first1m": "7a23d659f89d39ce99c5f72836dffa2a3a28cf9961501252725a1de0b870c84f" + } + }, + { + "relative_path": "SubUSDs/textures/parcel_box_2ft_x_2ft.jpg", + "size": 616942, + "hash": { + "sha256-flat-1mb": "56787209258464bb5fc58bbe14d576790cc8205796979e889cd62d9788d719a1", + "sha256": "9f719e933ac1caee0e70b80fac0be4d3e97e8da5559b505e7ecd25db2bb41295", + "blake3": "9d7d8814d506a63af6bc7b89b4513d94adf0f437f54f2a9f19b7267d3b0bdde1" + } + }, + { + "relative_path": "SubUSDs/textures/plastic_tote_2.92ftx2ft_2_plastic_normal.jpg", + "size": 331693, + "hash": { + "sha256-flat-1mb": "1a49482d4f3dda0711f0095318a8979f8754d5a6fedb5c3dc4a02860ef25c018", + "sha256": "ba911be8181c6df93dd19830f49dcaa09e73f09a3465125f081625ef9db45510", + "blake3": "025fdbfebaf8bd177a2081a7cd5a9a874f80871597c6fc1c75cdab486d6f55fd" + } + }, + { + "relative_path": "conveyor_belt_1.usd", + "size": 26531273, + "hash": { + "sha256-flat-1mb": "931a2d82f315e94c5a04b826cab147f571012226b2fa7f9ed07ca5e848c8aa6c", + "sha256": "ff8b821548ac16f3ea4210616001323dbf086b9705371038650bc0058ed61bbb", + "blake3": "88b519bfd271fc05d5a895a8ecc88a6aa4209d1dc66d2272d2be12a6de45a532", + "sha256-first1m": "22037fab8ee5dac286aff07be9e146b50b0ff1ddd1ea96acfae2703bbd5f6b15" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/965/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/965/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..6df3440ec08e3ac41322c6d8f391429675c4bd59 --- /dev/null +++ b/simready_assets/965/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "conveyor_belt_1.usd" + ] +} diff --git a/simready_assets/965/SubUSDs/materials/pbr.mdl b/simready_assets/965/SubUSDs/materials/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/965/SubUSDs/materials/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/965/SubUSDs/materials/pbr_1.mdl b/simready_assets/965/SubUSDs/materials/pbr_1.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/965/SubUSDs/materials/pbr_1.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/965/gltf/pbr.mdl b/simready_assets/965/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/965/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/966/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/966/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7ca74e51161144f1351dd00de623548cf178e6d3 --- /dev/null +++ b/simready_assets/966/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T16:18:10", + "assets": [ + { + "asset": "scissor_lift_open.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "584defdc993e242944031f2aa4e39fc903d8afa1e2b68d890a6f6b7912d80253", + "blake3": "4049d6b38f0e22823ba437bc8145e4c86c17e5e5ff42d3151f88603d07c91163" + } +} diff --git a/simready_assets/966/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/966/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..fe14025c189a085352a36986b37c6bd8f01c9468 --- /dev/null +++ b/simready_assets/966/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T16:18:10", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/966/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/966/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..c574ce80c15b4ff0871b31c79b3571efafeffad5 --- /dev/null +++ b/simready_assets/966/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/scissor_lift_open/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/scissor_lift_open.usd.png", + "size": 18710, + "hash": { + "sha256-flat-1mb": "819460306f891ef4acc95845317740d8cb13fa23d496b75f30657d21e6b20953", + "sha256": "97719293cd58cc02120f182bd6e74d9ac43f836df669de3d1befd05f9f99e3bf", + "blake3": "3252cda115b47fbe95ca1259430f650d399e75575d2266445641b7a7ba262ec7" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + }, + { + "relative_path": "scissor_lift_open.usd", + "size": 8291931, + "hash": { + "sha256-flat-1mb": "97f6608c08aa6a2125e94567b9a469aae89b8c53f671d60619266033435a56ba", + "sha256": "095380553c5d2e0bb2de655f7570a204938923b66014280305a352219e957b8e", + "blake3": "101557b295da4c52a4cd988255c44b8c82e1d707ee9572067a8f069bef7d98ed", + "sha256-first1m": "7eee40720b461b76da1f9b1f8514ee4a9fe98d4b5fdd2779c726d2f52af24111" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/966/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/966/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..47e1321b47f853eaf290315dda23207f6a776d34 --- /dev/null +++ b/simready_assets/966/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "scissor_lift_open.usd" + ] +} diff --git a/simready_assets/966/gltf/pbr.mdl b/simready_assets/966/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/966/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/967/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/967/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..3553508a20f0337c3f804ce5612a94d41cfe454e --- /dev/null +++ b/simready_assets/967/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T20:09:01", + "assets": [ + { + "asset": "iron_and_ironing_board.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "b16caff66ad40d7152f6deee8ccb9f7b344d453d883133fbc3d8f7453cf63e8e", + "blake3": "66152fdccd96593ca46413a32be7a509a90abafb5deab7f81d33ebc592a04d89" + } +} diff --git a/simready_assets/967/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/967/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..728b0461f1a63934e06aef26bbda2bf21c6f32f8 --- /dev/null +++ b/simready_assets/967/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-27T20:09:01", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/967/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/967/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..d417aff559f9937b3b5f1deb58951bb4fb209131 --- /dev/null +++ b/simready_assets/967/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,80 @@ +{ + "format_version": "1.0", + "content_root": "file:///C:/Validation/output/.packages/iron_and_ironing_board/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/iron_and_ironing_board.usd.png", + "size": 17398, + "hash": { + "sha256-flat-1mb": "4c68f00acc32001a202124208bd5afc7ea1d70ec4052610efa4e7117cc90133f", + "sha256": "298bdb06377d9717e3983631669a721f866a60209f183e00ea381dc069f0a412", + "blake3": "20fa0eb51d9c5268437b9248f4730c44c1d7ecd9ec025d65f53b8d31c669ac55" + } + }, + { + "relative_path": "SubUSDs/textures/iron_and_ironing_board _heat _level_logo_Normal.jpg", + "size": 99543, + "hash": { + "sha256-flat-1mb": "b4399be73b8325120fcfb7581cf7103899ff746b688de1bae8aebc4d21b084a1", + "sha256": "498494224c26f21fd999a2eee385defcd2281f462fa8179c439e0a71b7ac3ed2", + "blake3": "95d026c353182c86b6c5085f12b622bad0008d71f078949e420e772c2d5a8ecd" + } + }, + { + "relative_path": "SubUSDs/textures/iron_and_ironing_board_fabric_diffuse.jpg", + "size": 367434, + "hash": { + "sha256-flat-1mb": "68bd5c688f365410106eb701a6d9679554e8ca9da13f25763afd215f7ca47656", + "sha256": "75320f97ef08ce642eaef493a80597f3c5df6fa6a5f315dad02f21051a48a9fc", + "blake3": "e183cdae09f8f89b345ed71b39e9587c692c32b610be272184aaddd9080863f6" + } + }, + { + "relative_path": "SubUSDs/textures/iron_and_ironing_board_heat_level_logo_Diffuse.jpg", + "size": 141503, + "hash": { + "sha256-flat-1mb": "27b16243a59e999c3456b96257cf280561d813e5df7c074269b4a445140398f7", + "sha256": "088683fa71ae546273d0e52f218a625ce86df7d0b3451ded099a564d636fbf01", + "blake3": "53d1023ed01f126ce139fec64248ca1ce4b819d63d7d00450ffa775432ded339" + } + }, + { + "relative_path": "SubUSDs/textures/iron_and_ironing_board_wood_Normal.jpg", + "size": 601765, + "hash": { + "sha256-flat-1mb": "2dfb96801cc0b9a01a94ebabb3dcd8f2c91c8a4043b6513923ecbf7006818bfa", + "sha256": "8b5328c5e1a04990abd65957b7a6c077c594af91f5ff3aadbfd9c7b49c66d4d0", + "blake3": "d647f6755434e0e48ba0382cacb4a033f2ecd9e7a579816f41cbdda1cfed47a9" + } + }, + { + "relative_path": "SubUSDs/textures/iron_and_ironing_board_wood_diffuse.jpg", + "size": 1077417, + "hash": { + "sha256-flat-1mb": "50df29e8ed7b7393ddeb189d5a498629c2dc700ea9ffa3e78645c5a762017e49", + "sha256": "5ac146f82eb10de4b2b9d99447500081af99e86dae74f80140a7d33d859784f9", + "blake3": "15f59eb79911442f49a5155f9e73af5a2282705c6e81d32f799f3c7b5a4547c9", + "sha256-first1m": "c6a017d12bb1ddfe38d2802b86969beb2acfa03f5051372fee2f29b635e39d4d" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + }, + { + "relative_path": "iron_and_ironing_board.usd", + "size": 3011238, + "hash": { + "sha256-flat-1mb": "06c50c1c974c1f2bfba68a110d79f58bd4252d5c84a56ec26cf6606e5870638b", + "sha256": "b1a8fec92ea753eb38488d7f3a6fbe183802d0c75643ef7b2d844d3f56448f4f", + "blake3": "2d603f28dbfc6de6a337270422cc24c5cf8c0080a4a5c05118945668504f5f74", + "sha256-first1m": "1d702baee003aadb7addb727c5482d4cfca5b10d6324f32754271be294b369f4" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/967/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/967/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..8b163f7b2f16a7633fe2e16995769c5aac71af63 --- /dev/null +++ b/simready_assets/967/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "iron_and_ironing_board.usd" + ] +} diff --git a/simready_assets/967/gltf/pbr.mdl b/simready_assets/967/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/967/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/967/iron_and_ironing_board.usd b/simready_assets/967/iron_and_ironing_board.usd new file mode 100644 index 0000000000000000000000000000000000000000..5c037796f8cd05aaaf37d73111e4d050ba46fecb --- /dev/null +++ b/simready_assets/967/iron_and_ironing_board.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1a8fec92ea753eb38488d7f3a6fbe183802d0c75643ef7b2d844d3f56448f4f +size 3011238 diff --git a/simready_assets/991/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/991/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..62068f6a69f5292e86d5ef52b98499f9c309629e --- /dev/null +++ b/simready_assets/991/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-31T13:34:21", + "assets": [ + { + "asset": "electric_pallet_truck.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "9e362d283b7a246878a6f804c20b8e48dc7fb7cb4a978f290f32e77fcad1e9b0", + "blake3": "048c6334880c47cc91dbb50bc4ed8d3acb17e501ca36473f37302f652dd116c1" + } +} diff --git a/simready_assets/991/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/991/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7b3a68714a5d799205afa556b599947b6d2d0d28 --- /dev/null +++ b/simready_assets/991/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-31T13:34:21", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/991/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/991/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..8f6d1c68941fda6dae8feda190b041b2d28bcac6 --- /dev/null +++ b/simready_assets/991/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/output/.packages/electric_pallet_truck/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/electric_pallet_truck.usd.png", + "size": 15037, + "hash": { + "sha256-flat-1mb": "d40547443ca76c6131cca7ae47465ba871aedcbd7853ec4a88336d657a3e3c26", + "sha256": "48ac40420d87615bf3368832e429c3825d96e2b6bd95e0dc49fe682a0c4199ed", + "blake3": "a68cba9a559674a2bf6eb26989311c85a06cced9c7e4fd9c1f8be4e75bb3bc12" + } + }, + { + "relative_path": "electric_pallet_truck.usd", + "size": 16097706, + "hash": { + "sha256-flat-1mb": "40fbfcc5ad96e1a4ba2c536c2d5456c28ef61d9bcfeb845be7ae87d020eecab1", + "sha256": "2e435743b4802090f2e72430f9051561aabe140624d6d612f2b96f1c8a8bf238", + "blake3": "394429246c1f81e34f64e885bb0a6b667ef6f486cc42aaf236248d9a1e2a0cfc", + "sha256-first1m": "4c075c7ace7165f90e8d55cf1bd46ee9721fe39b5ee3ac5b2b5121ffa4ef9efd" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/991/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/991/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..d5ba02a2937f3094feca08eccd52c3b4dd730dcd --- /dev/null +++ b/simready_assets/991/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "electric_pallet_truck.usd" + ] +} diff --git a/simready_assets/991/gltf/pbr.mdl b/simready_assets/991/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/991/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/992/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/992/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..54d0e2fd04558028e58b8a747cc0ca858686c994 --- /dev/null +++ b/simready_assets/992/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-31T16:02:29", + "assets": [ + { + "asset": "cantilever_rack.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "ff1c64e56de83f503a400b1262fc4d31670a23f789cea48689f2b4657cb5df8a", + "blake3": "5595a20261ac9e64a74ddf021d4654fff03588cad78e18a8cca3ee2d4c7124b3" + } +} diff --git a/simready_assets/992/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/992/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..95e761037f09d980af1ed98b8862c9cd56b53739 --- /dev/null +++ b/simready_assets/992/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-31T16:02:29", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/992/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/992/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..dc57232e6f256403214775b3bfd253b34ec342d6 --- /dev/null +++ b/simready_assets/992/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/cantilever_rack/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/cantilever_rack.usd.png", + "size": 13388, + "hash": { + "sha256-flat-1mb": "dfb2bd650f69f0c517eb321a01e04f8d0aefbea600834c9f344a8c9b1f05ebe9", + "sha256": "5d4b95013dc6568cf2806f91528733106810b55b8d3ee45bac7d201bbea7cda9", + "blake3": "5ed6058c4df23eb517427a68b9007f3df4442dc011996c51a692a9ed7bde2250" + } + }, + { + "relative_path": "cantilever_rack.usd", + "size": 3029032, + "hash": { + "sha256-flat-1mb": "b9fa7eaa2d1df32c40e83c07f7c685a1369577721ed542c6fd8dabb7a9509c32", + "sha256": "34e06c4cf1497b2cb855aa134de2db2c05fbe055a3813b71377c3e11e77a24a7", + "blake3": "53a545464d290a778540fc5dab7b74bf598893e269f799ac6df6294e84138927", + "sha256-first1m": "fd391b9c8759aedf01263b04ae42d71a2a20b978d147be28dbbcf6bcfc5c7f18" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/992/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/992/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..7b7b9c6cef71e47e2a4113c4a342a1493e0bf9d3 --- /dev/null +++ b/simready_assets/992/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "cantilever_rack.usd" + ] +} diff --git a/simready_assets/992/gltf/pbr.mdl b/simready_assets/992/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/992/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/993/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/993/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..67dd7b40ff4626688f7102096f9e0d1025beeab9 --- /dev/null +++ b/simready_assets/993/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-31T16:44:05", + "assets": [ + { + "asset": "cantilever_rack_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "65753592b65cfe378e2439fd84c15d8a8ce51e2ef402f17657849733818b2066", + "blake3": "3d0a7ba8eb5a4ff2681d6c46d6b0fb6141be94e47b2febf779bb9434d3d8d092" + } +} diff --git a/simready_assets/993/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/993/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..7d31de903aae604efa45423158fb992ac335c8e5 --- /dev/null +++ b/simready_assets/993/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-31T16:44:05", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/993/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/993/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..600667e14d718170feefb55856b4837d40cf724a --- /dev/null +++ b/simready_assets/993/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,34 @@ +{ + "format_version": "1.0", + "content_root": "file:///E:/validate/Output/.packages/cantilever_rack_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/cantilever_rack_2.usd.png", + "size": 17560, + "hash": { + "sha256-flat-1mb": "27bd722930c7d1decabc9a1739b66d73a5d24c4bc48dc6933cd0c5a137ee0abd", + "sha256": "2ab0ae764c5f79f51534bb27101c0b4d409396b89729b87101bf626f536a8d6e", + "blake3": "0cd1c517c2e0a504fb193b55f179c69c906a618319175ab73f884c9909e34139" + } + }, + { + "relative_path": "cantilever_rack_2.usd", + "size": 3037738, + "hash": { + "sha256-flat-1mb": "7dbbec467de6064cf54e3f46ea4f0bfe1c40f3976ac935d05dc8ecaa06e5e71e", + "sha256": "71a2d0d3968ab172cd32380b133babf82c2126c368e9274c0868654ed602e0da", + "blake3": "e85149fa1219ef33d9c5cac2e532b6d5edcd2bb075d37641e348d42580f3ff2a", + "sha256-first1m": "3bbe1d4cac87676af01b2411b186cbcf08edbbb94d8b6a9998d0debafbd0967f" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 43800, + "hash": { + "sha256-flat-1mb": "f7013dcb99f4ad5c79b3b53c2b379598d790170e11a0aef8891ceef8c9bfc51c", + "sha256": "2c7c14d7bbf7cacea990f90e8ecc92700d8a7fe9805e44970096796e2be88b78", + "blake3": "3f0cb5ffe7e319677743a74dba7fdb0b2b11c3e40cc4b2d69277db595f52cbec" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/993/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/993/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..f39cadfad7318e0d728a45dda9c2a14a34e2dd7b --- /dev/null +++ b/simready_assets/993/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "cantilever_rack_2.usd" + ] +} diff --git a/simready_assets/993/gltf/pbr.mdl b/simready_assets/993/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..644b9a56c4061e9108b2e4c1e107cb6a4526efaa --- /dev/null +++ b/simready_assets/993/gltf/pbr.mdl @@ -0,0 +1,1027 @@ +/****************************************************************************** + * Copyright 2024 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NVIDIA CORPORATION nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..ec1be4186a01720aca5f73086bd78b8bd0a08432 --- /dev/null +++ b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T22:50:24", + "assets": [ + { + "asset": "beam_column_connection_plate_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "077e2a247479904bfefd66a473d86a775e70b23754ed4a85714951ba1301181e", + "blake3": "80da525261e125b8445f6aa1a8166bbea25930536487791333e775b7b0402ef1" + } +} diff --git a/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..dc7aad5f7a14b9f4d493ac9e09f647d611d0118e --- /dev/null +++ b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T22:50:24", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..44dd0f3d2fbb6e9fec235e548459efb17eb4a73b --- /dev/null +++ b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,54 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/beam_column_connection_plate_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/beam_column_connection_plate_1.usd.png", + "size": 12104, + "hash": { + "sha256-flat-1mb": "364f7700e2a8edbb088918f010c1736b61b24f4178f22c91317e243d64d0bca2", + "sha256": "e39fa742f3fd7074ffe63b9649ca50cf153420d954438493eab1e97bcd26d3f3", + "blake3": "9f7a4c6a03573c8bf253d54f89754367805602951c4cfb0c2ce9e5a7b4049a82" + } + }, + { + "relative_path": "SubUSDs/textures/ceiling_support_beam_3_diffuse.jpg", + "size": 1331137, + "hash": { + "sha256-flat-1mb": "90a3843bec133cecd8f7f828fcecd7771b05ad3fcf46cc12a585e5d90a3b4754", + "sha256": "dd24021a4a10b75acbf28fe8d4bb9465306be0fce03758d9f88030c05e77b4dd", + "blake3": "4c46a72beffebba64cea255dd4023b2733c10739281f7b31dcf9e5a7b62a1718", + "sha256-first1m": "391da60b33c4efec8c698841b63eae33401366047c51ce04c74989e17ee137a8" + } + }, + { + "relative_path": "SubUSDs/textures/ceiling_support_beam_3_normal.jpg", + "size": 2516313, + "hash": { + "sha256-flat-1mb": "8636c6e73bf6909c1d5685c74f7fbd2d381c666af3d721c8fed6a2b217d5b7c6", + "sha256": "0f7f62924897bfe05ecb569d0ccd270f2f4459b66cc4d5a3ec05580b6596465c", + "blake3": "287dd269eb9d2b3011e397d5c85a815c1eac5492d9cf82e27b2a34411dd71272", + "sha256-first1m": "dd0f705266422e6abe3681488734c73956ede82d75aef9d3555e5114f228836b" + } + }, + { + "relative_path": "beam_column_connection_plate_1.usd", + "size": 1126616, + "hash": { + "sha256-flat-1mb": "083bbb14dcb203798efb1fbb53ec1e4105d7712ba31ebefc950faa3cc34567c9", + "sha256": "cc574992e71f95ad2ef1ccdac3d5bfa247494fa88f36f398c82da8c9df0f562e", + "blake3": "c8f2630f802072ccfea191b0af53190edf1670d75d0e55d4e8a10406d53304f2", + "sha256-first1m": "914e6ab41e16a5f50bf1470870b6e8d3110c88ab007a0169e4f831bb1ae4eda2" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..fb010b0360ad2e87dbfc846f1891c1b86dd04e7b --- /dev/null +++ b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "beam_column_connection_plate_1.usd" + ] +} diff --git a/simready_assets/beams_columns_plates/beam_column_connection_plate_1/gltf/pbr.mdl b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/beams_columns_plates/beam_column_connection_plate_1/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..dd5fa27d322334eb85e67999666dbaf31563fe9a --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T20:41:28", + "assets": [ + { + "asset": "building_beam_metal_column_1.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "5fa475f9224550600b2db5a1226a1121dee0f926bf57e0591e6349ee21a2758d", + "blake3": "e2d330702a18404afb19adfc88d4c8ddd090479ad35ceb5eae7662daf01b6c05" + } +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..22f65f8258ac4151bf1eace89eece42c4ea551ee --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T20:41:28", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..fcbd996db0f8f6f07c506bb020178aafc42acc83 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,53 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/building_beam_metal_column_1/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/building_beam_metal_column_1.usd.png", + "size": 4221, + "hash": { + "sha256-flat-1mb": "e28dcc2af039bed01c50e901a12dc73f15db1e035e70e50e1dd0efa7727d995d", + "sha256": "58f07286478acd776badb2a7643516e4859cea12eda8851f09570abeaafa3ec8", + "blake3": "1404b68ae1f8b59c2e209a1c224a14803999891b89d0f6014d950a4f3dc7931c" + } + }, + { + "relative_path": "SubUSDs/textures/building_beam_metal_column_diffuse.png", + "size": 3078946, + "hash": { + "sha256-flat-1mb": "5185ac34625a24fd9e5d4e78ae42f3978a4ca98c8ea847d1adcc4cf0ee37efec", + "sha256": "ec1a225c1156e0efd99ab3980ff9c0c107bfa80c6e3938736737ec2475cfdd14", + "blake3": "3d5c221e4ab4fe2ad4d0e9ec8fca181d8a82b7a26e0779ab8146c48f06f0fca9", + "sha256-first1m": "a9de1ac594cbc3271448ea64192799d1ecd3e5cda50084c913a276abd65790ee" + } + }, + { + "relative_path": "SubUSDs/textures/building_beam_metal_column_normal.jpg", + "size": 3932079, + "hash": { + "sha256-flat-1mb": "0d5d854953e464226fa093b8900712ab585fc406f8ca8729433e89a33bbff0c9", + "sha256": "071d8899c7e7eb00b76c65e3ae4e852a52b9cdd2a9cf1e2d608f4c3891fbe279", + "blake3": "8a0c9cb2490bdcbf1855a0a6e912dd62bbed09523ddf44dd8d804285a5f0e2fe", + "sha256-first1m": "b06a9c0748137a152f4c91a59d4c8ed813cfb139c50c38598e46469b6981286c" + } + }, + { + "relative_path": "building_beam_metal_column_1.usd", + "size": 56387, + "hash": { + "sha256-flat-1mb": "84ca4fd6d57b247e9b48a0b3a4fe79380fba7509052cc7add98e94abef342be2", + "sha256": "61a522fe1403afa260b03efe0d17d53a18a221c9e7d9204d884db69b44c595f1", + "blake3": "9eff9dc75fe5b22d30ece225d2e1550c85007d3d1ce4f4ba458983e6917984ad" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..445883859ae71acf69adf94eb67708fd745f082e --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_1/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "building_beam_metal_column_1.usd" + ] +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_1/gltf/pbr.mdl b/simready_assets/beams_columns_plates/building_beam_metal_column_1/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_1/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..a7a03c65c6db1cb486f2cd01849b0cae133d7328 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T20:42:48", + "assets": [ + { + "asset": "building_beam_metal_column_2.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "f4af97adb310893a91f38dd11ba84017419bcc4977c44910324ee908eb61e13d", + "blake3": "9d79f647062d42501c5930abb2affb10e27eb37b0e90720353a4b090c80e1657" + } +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..56b9b6d952e9fee70594ef7d0a200170e48708de --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T20:42:48", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..8ee9ce5b3a79edc1a18007c6ede49edfa39d0eb1 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,53 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/building_beam_metal_column_2/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/building_beam_metal_column_2.usd.png", + "size": 4403, + "hash": { + "sha256-flat-1mb": "c3b40d6925f06f1498bfa50a55fd4c9cc5eed7d2db1853ee66e3930b141365cf", + "sha256": "35d288c58de65a004e1310d65e3ed1f50c97f658f7fcad77b0732a35dfc67f82", + "blake3": "03a4d03d41b80c514ef99efbdc2db3ef63c1169930a823217b30868bd20e0eec" + } + }, + { + "relative_path": "SubUSDs/textures/building_beam_metal_column_diffuse.png", + "size": 3078946, + "hash": { + "sha256-flat-1mb": "5185ac34625a24fd9e5d4e78ae42f3978a4ca98c8ea847d1adcc4cf0ee37efec", + "sha256": "ec1a225c1156e0efd99ab3980ff9c0c107bfa80c6e3938736737ec2475cfdd14", + "blake3": "3d5c221e4ab4fe2ad4d0e9ec8fca181d8a82b7a26e0779ab8146c48f06f0fca9", + "sha256-first1m": "a9de1ac594cbc3271448ea64192799d1ecd3e5cda50084c913a276abd65790ee" + } + }, + { + "relative_path": "SubUSDs/textures/building_beam_metal_column_normal.jpg", + "size": 3932079, + "hash": { + "sha256-flat-1mb": "0d5d854953e464226fa093b8900712ab585fc406f8ca8729433e89a33bbff0c9", + "sha256": "071d8899c7e7eb00b76c65e3ae4e852a52b9cdd2a9cf1e2d608f4c3891fbe279", + "blake3": "8a0c9cb2490bdcbf1855a0a6e912dd62bbed09523ddf44dd8d804285a5f0e2fe", + "sha256-first1m": "b06a9c0748137a152f4c91a59d4c8ed813cfb139c50c38598e46469b6981286c" + } + }, + { + "relative_path": "building_beam_metal_column_2.usd", + "size": 311039, + "hash": { + "sha256-flat-1mb": "b2296df9bb673b84cbc17b3a7d2b478ecc75ecd75ac911162fbf2fdb9894fa5d", + "sha256": "79bfbbd2a65de0199ba8fa8a7246c95dc84c857cb98eb6e75218d15e87c08132", + "blake3": "bf6b10a720741f8dcf97e416e13c34f28f3c18a2e65ed83d7c40e2d4170a5c4e" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..b6241db0c9beb71c4b26140cf9d30c85b26a7cea --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_2/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "building_beam_metal_column_2.usd" + ] +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_2/gltf/pbr.mdl b/simready_assets/beams_columns_plates/building_beam_metal_column_2/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_2/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..9631c6555d058019fbcde15a825a96052cee8cb4 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.conformance.Package-Candidate@1.0.0.json @@ -0,0 +1,39 @@ +{ + "format_version": "1.0", + "profile": "Package-Candidate", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T20:44:22", + "assets": [ + { + "asset": "building_beam_metal_column_3.usd", + "features": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET033_SIMREADY_PACKAGING": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET031_PACKAGE_SELF_CONTAINED": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ], + "content_hash": { + "sha256": "11e512410c06f12a93a22aff37a2882b8168d87191cb103116f731ca0f6e7cab", + "blake3": "119e2322eecb10f364d1e5cd442e2b2e5996ca2375029ec32df384f77f94a0c4" + } +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json new file mode 100644 index 0000000000000000000000000000000000000000..3d973ee33a2a0b5597ebaebb508edeba14cb06f8 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.conformance.Package@1.0.0.json @@ -0,0 +1,35 @@ +{ + "format_version": "1.0", + "profile": "Package", + "profile_version": "1.0.0", + "timestamp": "2026-08-17T20:44:22", + "assets": [ + { + "asset": "com.nvidia.simready.packaging.json", + "features": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [] + } + }, + { + "FET032_PACKAGING_INTROSPECTION": { + "version": "0.1.0", + "passed": true, + "failing_requirements": [], + "dependencies": [ + { + "FET030_PACKAGING_CORE": { + "version": "0.1.0" + } + } + ] + } + } + ] + } + ] +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.packaging.bom.json b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.packaging.bom.json new file mode 100644 index 0000000000000000000000000000000000000000..622a1b03f3ef8fb90102063d922e7d0ab86daee7 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.packaging.bom.json @@ -0,0 +1,53 @@ +{ + "format_version": "1.0", + "content_root": "file:///D:/Validation/output/.packages/building_beam_metal_column_3/1.0.0", + "items": [ + { + "relative_path": ".thumbs/256x256/building_beam_metal_column_3.usd.png", + "size": 3810, + "hash": { + "sha256-flat-1mb": "eff3675a224e11bb58872056751cacac73e70ad7b1c94b2499579014de15f887", + "sha256": "b4648f0604f3ae91a90961c26c5c0e0bb5d34baa02372dff1df9de68721983da", + "blake3": "ec478161cbb67a4d5bbe60e2033fd6914ad24f6cc0c22ecff26fe34181f28d1e" + } + }, + { + "relative_path": "SubUSDs/textures/building_beam_metal_column_diffuse.png", + "size": 3078946, + "hash": { + "sha256-flat-1mb": "5185ac34625a24fd9e5d4e78ae42f3978a4ca98c8ea847d1adcc4cf0ee37efec", + "sha256": "ec1a225c1156e0efd99ab3980ff9c0c107bfa80c6e3938736737ec2475cfdd14", + "blake3": "3d5c221e4ab4fe2ad4d0e9ec8fca181d8a82b7a26e0779ab8146c48f06f0fca9", + "sha256-first1m": "a9de1ac594cbc3271448ea64192799d1ecd3e5cda50084c913a276abd65790ee" + } + }, + { + "relative_path": "SubUSDs/textures/building_beam_metal_column_normal.jpg", + "size": 3932079, + "hash": { + "sha256-flat-1mb": "0d5d854953e464226fa093b8900712ab585fc406f8ca8729433e89a33bbff0c9", + "sha256": "071d8899c7e7eb00b76c65e3ae4e852a52b9cdd2a9cf1e2d608f4c3891fbe279", + "blake3": "8a0c9cb2490bdcbf1855a0a6e912dd62bbed09523ddf44dd8d804285a5f0e2fe", + "sha256-first1m": "b06a9c0748137a152f4c91a59d4c8ed813cfb139c50c38598e46469b6981286c" + } + }, + { + "relative_path": "building_beam_metal_column_3.usd", + "size": 110664, + "hash": { + "sha256-flat-1mb": "44c0ac5ece8807e44ac7fa2c9461d53d54aa7d923b20fdae2b3a8f87fbb32f71", + "sha256": "ebdfcda3d7c1e2200bab8454f722b9d4265152612be3e92b0bcd58a80f33370c", + "blake3": "2aafe003ba581fa3d3d06679ca479e4ab337ac7af8bce6f995f3fd44074a655c" + } + }, + { + "relative_path": "gltf/pbr.mdl", + "size": 42240, + "hash": { + "sha256-flat-1mb": "0ea567c192a18e6835ba556207f797ebe90850414ac832952c61c571cff22a0d", + "sha256": "eeed10b53c18d789f94a24a3a6b996c49668ae2d5b6a909bae3420f2beb16fc8", + "blake3": "9e577cb4dd7efe74b8418e38467a9e1c7056625fc127599c85a36596c6b62a59" + } + } + ] +} \ No newline at end of file diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.root_usds.json b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.root_usds.json new file mode 100644 index 0000000000000000000000000000000000000000..98ae5f30bae95cae3a24b1e2eba40b6a6f4ad61b --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_3/.metadata/com.nvidia.simready.root_usds.json @@ -0,0 +1,6 @@ +{ + "format_version": "1.0", + "entries": [ + "building_beam_metal_column_3.usd" + ] +} diff --git a/simready_assets/beams_columns_plates/building_beam_metal_column_3/gltf/pbr.mdl b/simready_assets/beams_columns_plates/building_beam_metal_column_3/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/beams_columns_plates/building_beam_metal_column_3/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); diff --git a/simready_assets/beams_columns_plates/ceiling_support_beam_1/gltf/pbr.mdl b/simready_assets/beams_columns_plates/ceiling_support_beam_1/gltf/pbr.mdl new file mode 100644 index 0000000000000000000000000000000000000000..6090ece0a16237b4063b56bfbcac09bee01bd092 --- /dev/null +++ b/simready_assets/beams_columns_plates/ceiling_support_beam_1/gltf/pbr.mdl @@ -0,0 +1,1004 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + +mdl 1.8; + +import ::anno::*; +import ::base::*; +import ::df::*; +import ::math::*; +import ::state::*; +import ::tex::*; +import ::scene::*; +import ::limits::*; + +export enum gltf_alpha_mode { + opaque, + mask, + blend +}; + +export enum gltf_wrapping_mode { + clamp_to_edge = 33071, + mirrored_repeat = 33648, + repeat = 10497 +}; + +export struct gltf_texture_lookup_value +{ + bool valid = false; + float4 value = float4(0.0, 0.0, 0.0, 1.0); +}; + +export struct gltf_normal_texture_lookup_value +{ + bool valid = false; + float3 value = float3(0.0); +}; + +float compute_opacity(gltf_alpha_mode mode, float alpha, float cutoff) { + switch (mode) { + case mask: + return alpha < cutoff ? 0.0 : 1.0; + case blend: + return alpha; + case opaque: + return 1.0; + } +} + +float4 gltf_prepare_tex_float4(gltf_texture_lookup_value sample, float4 default_value = float4(1.0)) { + return sample.valid ? sample.value : default_value; +} + +float3 gltf_prepare_tex_float3(gltf_texture_lookup_value sample, float3 default_value = float3(1.0)) { + return sample.valid ? float3(sample.value.x, sample.value.y, sample.value.z) : default_value; +} + +float3 gltf_prepare_normal(gltf_normal_texture_lookup_value sample) { + return sample.valid ? sample.value : state::normal(); +} + +float gltf_prepare_occlusion(gltf_texture_lookup_value sample, float occlusion_strength) { + float occulusion = sample.valid ? sample.value.x : 1.0; + return math::lerp(1.0, occulusion, occlusion_strength); +} + +color gltf_perpare_emission(gltf_texture_lookup_value sample, color emissive_factor) { + return emissive_factor * color(gltf_prepare_tex_float3(sample)); +} + +::tex::wrap_mode convert_wrap_mode(gltf_wrapping_mode mode) +{ + if (mode == clamp_to_edge) + return ::tex::wrap_clamp; + if (mode == mirrored_repeat) + return ::tex::wrap_mirrored_repeat; + + return ::tex::wrap_repeat; +} + +float2 khr_texture_transform_apply( + float2 coord, + float2 offset, + float rotation, + float2 scale +) +{ + // MDL expects the texture coordinate origin at the bottom left (gltf at top left) + // Assuming the renderer follows the MDL specification in which case the coordinates + // have been flipped either while loading the glTF geometry or while setting up the state. + + // Undo the flipping for the transformation to get into the original glTF texture space. + coord = float2(coord.x, 1.0f - coord.y); + + // first scale + coord = coord * scale; + // then rotate + float cos_rotation = ::math::cos(rotation); + float sin_rotation = ::math::sin(rotation); + coord = float2(cos_rotation * coord.x + sin_rotation * coord.y, cos_rotation * coord.y - sin_rotation * coord.x); + // then translate + coord = coord + offset; + + // flip back + coord = float2(coord.x, 1.0f - coord.y); + return coord; +} + +export gltf_texture_lookup_value gltf_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Texture Lookup"), + anno::description("Function to read a color or color with alpha channel texture.") +]] +{ + gltf_texture_lookup_value tex_ret; + if (!tex::texture_isvalid(texture)) + return tex_ret; + + float3 tex_coord3 = state::texture_coordinate(tex_coord_index); + float2 tex_coord = khr_texture_transform_apply( + coord: float2(tex_coord3.x, tex_coord3.y), + offset: offset, + rotation: rotation, + scale: scale); + + tex_ret.value = tex::lookup_float4( + tex: texture, + coord: tex_coord, + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export gltf_normal_texture_lookup_value gltf_normal_texture_lookup( + uniform texture_2d texture = texture_2d() + [[ + anno::in_group("Source"), + anno::display_name("Texture"), + anno::description("Texture File") + ]], + uniform float normal_scale_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Source"), + anno::display_name("Normal Scale Factor"), + anno::description("Strength of the base layer normal mapping."), + anno::enable_if("::tex::texture_isvalid(texture)") + ]], + uniform int tex_coord_index = 0 + [[ + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Texture coordinate set (UV-Set). KHR_texture_transform overrides the textureInfo texCoord value if supplied."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform int tex_tangent_index = 0 + [[ + anno::hidden(), + anno::in_group("Source"), + anno::display_name("Coordinate Set"), + anno::description("Tangent to be to construct the tangent frame."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform float2 offset = float2(0.0f, 0.0) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Offset"), + anno::description("The offset of the UV coordinate origin as a factor of the texture dimensions."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Texture Transform"), + anno::display_name("Rotation"), + anno::description("Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform float2 scale = float2(1.0f, 1.0f) + [[ + anno::in_group("Texture Transform"), + anno::display_name("Scale"), + anno::description("The scale factor applied to the components of the UV coordinates."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + + uniform gltf_wrapping_mode wrap_s = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap S"), + anno::description("S (U) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]], + uniform gltf_wrapping_mode wrap_t = repeat + [[ + anno::in_group("Sampler"), + anno::display_name("Wrap T"), + anno::description("T (V) wrapping mode."), + anno::enable_if("::tex::texture_isvalid(texture) && normal_scale_factor>0.0") + ]] +) +[[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Normal Texture Lookup"), + anno::description("Function to read a normal texture.") +]] +{ + gltf_normal_texture_lookup_value tex_ret; + if (!::tex::texture_isvalid(texture)) + return tex_ret; + + tex_ret.value = base::tangent_space_normal_texture( + texture: texture, + factor: normal_scale_factor, + uvw: base::transform_coordinate( + transform: base::rotation_translation_scale( + rotation: float3(0, 0, rotation), + translation: float3(offset.x, offset.y, 0), + scaling: float3(scale.x, scale.y, 1) + ), + coordinate: base::texture_coordinate_info( + position: state::texture_coordinate(tex_coord_index), + tangent_u: state::texture_tangent_u(tex_tangent_index), + tangent_v: state::texture_tangent_v(tex_tangent_index) + ) + ), + wrap_u: convert_wrap_mode(wrap_s), + wrap_v: convert_wrap_mode(wrap_t)); + tex_ret.valid = true; + return tex_ret; +} + +export material gltf_material( + // base color + uniform color base_color_factor = color(1.0) + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Factor"), + anno::description("The base color of the material. Multiplied to the 'Base Color Texture' if available.") + ]], + + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Base Color Texture"), + anno::description("The base color of the material. Influenced by the 'Base Color Factor'.") + ]], + + // KHR_materials_specular + uniform float specular_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Specular"), + anno::display_name("Specular Factor"), + anno::description("The strength of the specular reflection. Multiplied to the 'Specular Texture' if available.") + ]], + gltf_texture_lookup_value specular_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Texture"), + anno::description("A texture that defines the strength of the specular reflection, stored in the alpha (A) channel. This will be multiplied by the 'Specular Factor'.") + ]], + uniform color specular_color_factor = color(1.0) + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Factor"), + anno::description("The F0 color of the specular reflection (linear RGB). Multiplied to the 'Specular Color Texture' if available.") + ]], + gltf_texture_lookup_value specular_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Specular"), + anno::display_name("Specular Color Texture"), + anno::description("A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in sRGB. This texture will be multiplied by 'Specular Color Factor'.") + ]], + + // metallic roughness + uniform float metallic_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Metallic Factor"), + anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + + uniform float roughness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Metallic Roughness"), + anno::display_name("Roughness Factor"), + anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0). Multiplied to the 'Metal/Rough Texture' value if available.") + ]], + gltf_texture_lookup_value metallic_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Metallic Roughness"), + anno::display_name("Metal/Rough Texture"), + anno::description("Metallic in the red or blue component and roughness in the green component. Influenced by the 'Metallic Factor' and 'Roughness Factor'."), + anno::enable_if("metallic_factor>0.0 || roughness_factor>0.0") + ]], + + // KHR_materials_anisotropy + uniform float anisotropy_strength = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Strength"), + anno::description("The anisotropy strength. When the anisotropy texture is present, this value is multiplied by the texture's blue channel.") + ]], + uniform float anisotropy_rotation = 0.0 + [[ + anno::hard_range(0.0, 2.0 * ::math::PI), + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Rotation"), + anno::description("The rotation of the anisotropy in tangent, bitangent space, measured in radians counter-clockwise from the tangent. When the anisotropy texture is present, this value provides additional rotation to the vectors in the texture.") + ]], + gltf_texture_lookup_value anisotropy_texture = gltf_texture_lookup() + [[ + anno::in_group("Anisotropy"), + anno::display_name("Anisotropy Texture"), + anno::description("The anisotropy texture. Red and green channels represent the anisotropy direction in [− 1, 1] tangent, bitangent space to be rotated by the anisotropy rotation. The blue channel contains strength as [0, 1] to be multiplied by the anisotropy strength.") + ]], + + // KHR_materials_ior + uniform float ior = 1.5 + [[ + anno::hard_range(1.0, 5.0), + anno::in_group("Metallic Roughness"), + anno::display_name("IOR"), + anno::description("The index of refraction.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // KHR_materials_transmission + uniform float transmission_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Transmission"), + anno::display_name("Transmission Factor"), + anno::description("The base percentage of light that is transmitted through the surface. Multiplied to the 'Transmission Texture' if available.") + ]], + gltf_texture_lookup_value transmission_texture = gltf_texture_lookup() + [[ + anno::in_group("Transmission"), + anno::display_name("Transmission Texture"), + anno::description("A texture that defines the transmission percentage of the surface, stored in the R channel. Influenced by the 'Transmission Factor'."), + anno::enable_if("transmission_factor>0") + ]], + + // KHR_materials_sheen + uniform color sheen_color_factor = color(0.0) + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Factor"), + anno::description("The sheen color in linear space. Multiplied to the 'Sheen Color Texture' if available.") + ]], + gltf_texture_lookup_value sheen_color_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Color Texture"), + anno::description("The sheen color (RGB). The sheen color is in sRGB transfer function. Influenced by the 'Sheen Color Factor'.") + ]], + uniform float sheen_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Factor"), + anno::description("The sheen roughness. Multiplied to the 'Sheen Roughness Texture' if available.") + ]], + gltf_texture_lookup_value sheen_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Sheen"), + anno::display_name("Sheen Roughness Texture"), + anno::description("The sheen roughness (Alpha) texture. Influenced by the 'Sheen Roughness Factor'.") + ]], + + // KHR_materials_clearcoat + uniform float clearcoat_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Factor"), + anno::description("Strength of the clearcoat. Multiplied to the 'Clearcoat Texture' if available.") + ]], + gltf_texture_lookup_value clearcoat_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Texture"), + anno::description("Strength of the clearcoat. Influenced by the 'Clearcoat Factor'."), + anno::enable_if("clearcoat_factor>0") + ]], + uniform float clearcoat_roughness_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Factor"), + anno::description("The clearcoat layer roughness. Multiplied to the 'Clearcoat Roughness Texture' if available."), + anno::enable_if("clearcoat_factor>0.0") + ]], + gltf_texture_lookup_value clearcoat_roughness_texture = gltf_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Roughness Texture"), + anno::description("The clearcoat layer roughness texture. Influenced by the 'Clearcoat Roughness Texture'."), + anno::enable_if("clearcoat_factor>0.0 && clearcoat_roughness_factor>0.0") + ]], + gltf_normal_texture_lookup_value clearcoat_normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Clearcoat"), + anno::display_name("Clearcoat Normal"), + anno::description("The clearcoat normal map texture."), + anno::enable_if("clearcoat_factor>0.0") + ]], + + // KHR_materials_iridescence + uniform float iridescence_factor = 0.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Factor"), + anno::description("Strength of the iridescence. Multiplied to the 'Iridescence Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Texture"), + anno::description("Strength of the iridescence. Uses only the red channel, assuming linear space. Influenced by the 'Iridescence Factor'."), + anno::enable_if("iridescence_factor>0") + ]], + uniform float iridescence_ior = 1.3 + [[ + anno::soft_range(1.0, 5.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence IOR"), + anno::description("The index of refraction of the dielectric thin-film layer.") + ]], + uniform float iridescence_thickness_minimum = 100 + [[ + anno::soft_range(0.0, 600.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Minimum"), + anno::description("The minimum thickness of the thin-film layer given in nanometers.") + ]], + uniform float iridescence_thickness_maximum = 400 + [[ + anno::soft_range(0.0, 1000.0), + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Maximum"), + anno::description("The maximum thickness of the thin-film layer given in nanometers. Used as thickness if no 'Iridescence Thickness Texture' if available.") + ]], + gltf_texture_lookup_value iridescence_thickness_texture = gltf_texture_lookup() + [[ + anno::in_group("Iridescence"), + anno::display_name("Iridescence Thickness Texture"), + anno::description("The thickness texture of the thin-film layer. Uses only the red channel, assuming linear space. Used to blend between 'Iridescence Thickness Minimum' and 'Iridescence Thickness Maximum'."), + anno::enable_if("iridescence_factor>0") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // KHR_materials_volume + uniform bool thin_walled = true + [[ + anno::in_group("Volume"), + anno::display_name("Thin-walled"), + anno::description("If true the material is thin-walled. Otherwise the material is a volume boundary. The doubleSided property has no effect on volume boundaries. Note, the thickness parameters are ignored since ray-tracing is used to compute the traveled distance within the volume.") + ]], + uniform float attenuation_distance = 0.0 + [[ + anno::soft_range(0.0, ::limits::FLOAT_MAX), + anno::in_group("Volume"), + anno::display_name("Attenuation Distance"), + anno::description("Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. A value 0.0 disables it") + ]], + uniform color attenuation_color = color(1.0) + [[ + anno::in_group("Volume"), + anno::display_name("Attenuation Color"), + anno::description("The color that white light turns into due to absorption when reaching the attenuation distance.") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0(gltf), or displayColor(usd)") + ]], + + uniform bool use_vertex_color_alpha = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multipy the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex opacity primvar usually the fourth component of COLOR_0(gltf), or displayOpacity(usd)") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Metallic-Roughness"), + anno::description("Metallic-Roughness Material that takes the GLTF PBR model and KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + + float4 base_float4 = gltf_prepare_tex_float4(base_color_texture) * ::scene::data_lookup_float4(vertex_color_name, float4(1.0)); // apply vertex color + color base_color = base_color_factor * color(base_float4.x, base_float4.y, base_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha == 1 ? base_float4.w : 1.0) * ((vertex_color_name != vertex_opacity_name) ? ::scene::data_lookup_float(vertex_opacity_name, float(1.0)) : 1.0); + + float3 metallic_roughness = gltf_prepare_tex_float3(metallic_roughness_texture); + float metallic = metallic_factor * metallic_roughness.z; + float roughness = roughness_factor * metallic_roughness.y; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // KHR_materials_specular + // ------------------------------------------------------------------------ + color specular_color = color(gltf_prepare_tex_float3(specular_color_texture)) * specular_color_factor; + float specular = gltf_prepare_tex_float4(specular_texture).w * specular_factor; + + // KHR_materials_transmission + // ------------------------------------------------------------------------ + float transmission = gltf_prepare_tex_float4(transmission_texture).x * transmission_factor; + + // KHR_materials_sheen + // ------------------------------------------------------------------------ + color sheen_color = color(gltf_prepare_tex_float3(sheen_color_texture)) * sheen_color_factor; + float sheen_roughness = gltf_prepare_tex_float4(sheen_roughness_texture).w * sheen_roughness_factor; + + // KHR_materials_clearcoat + // ------------------------------------------------------------------------ + float clearcoat_blend = gltf_prepare_tex_float3(clearcoat_texture).x * clearcoat_factor; + float clearcoat_roughness = gltf_prepare_tex_float3(clearcoat_roughness_texture).y * clearcoat_roughness_factor; + float clearcoat_roughness2 = clearcoat_roughness * clearcoat_roughness; + float3 clearcoat_normal = gltf_prepare_normal(clearcoat_normal_texture); + float grazing_refl_coat = math::max((1.0 - clearcoat_roughness), 0.0); + + // KHR_materials_iridescence + // ------------------------------------------------------------------------ + float iridescence_strength = gltf_prepare_tex_float3(iridescence_texture).x * iridescence_factor; + float iridescence_thickness = math::lerp(iridescence_thickness_minimum, iridescence_thickness_maximum, gltf_prepare_tex_float3(iridescence_thickness_texture).x); + + // KHR_materials_anisotropy + // ------------------------------------------------------------------------ + float3 anisotropy_tex = gltf_prepare_tex_float3(anisotropy_texture, float3(1.0, 0.5, 1.0)); + float2 anisotropy_tex_dir = float2(anisotropy_tex.x * 2.0 - 1.0, anisotropy_tex.y * 2.0 - 1.0); + float2 anisotropy_rot = float2(math::cos(anisotropy_rotation), math::sin(anisotropy_rotation)); + float2 anisotropy_dir = float2x2(anisotropy_rot.x, anisotropy_rot.y, -anisotropy_rot.y, anisotropy_rot.x) * math::normalize(anisotropy_tex_dir); + float3 anisotropy_tangent_u = state::texture_tangent_u(0) * anisotropy_dir.x + state::texture_tangent_v(0) * anisotropy_dir.y; + float anisotropy = anisotropy_strength * anisotropy_tex.z; + + // metallic roughness model + // ------------------------------------------------------------------------ + + // compute final roughness by squaring the "roughness" parameter + float roughness2 = roughness * roughness; + + float anisotropy_roughness_u = math::lerp(roughness2, 1.0, anisotropy * anisotropy); + float anisotropy_roughness_v = roughness2; + + // reduce the reflectivity at grazing angles to avoid "dark edges" + // for high roughness due to the layering + float grazing_refl = math::max((1.0 - roughness), 0.0); + + // fresnel term based on ior + float f0 = math::pow((ior - 1.0)/(ior + 1.0), 2.0); + + // for the dielectric component we layer the glossy component on top of the diffuse one, + // the glossy layer has no color tint + bsdf dielectric_component = df::color_custom_curve_layer( + weight: color(1.0), // roughness is used to weight between diffuse and glossy + normal_reflectivity: math::min(f0 * specular_color, color(1.0)) * specular, + grazing_reflectivity: color(grazing_refl * specular), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u), + base: df::weighted_layer( + weight: transmission, + base: df::diffuse_reflection_bsdf(tint: base_color * occlusion), + layer: df::microfacet_ggx_vcavities_bsdf( + roughness_u: roughness2, + tint: base_color * occlusion, + mode: df::scatter_transmit)), + normal: normal + ); + + // apply iridescence and make the strength adjustable using a weighted layer + bsdf dielectric_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: dielectric_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: dielectric_component + ) + ); + + // the metallic component doesn't have a diffuse component, + // its only glossy base_color is applied to tint it + bsdf metallic_component = df::microfacet_ggx_vcavities_bsdf( + tint: base_color * occlusion, + roughness_u: anisotropy_roughness_u, + roughness_v: anisotropy_roughness_v, + tangent_u: anisotropy_tangent_u); + + // apply iridescence and make the strength adjustable using a weighted layer + // according to KHR_materials_iridescence spec: using dielectric thin film fresnel for metals, too + color base_color_sqrt = math::min(math::sqrt(math::saturate(base_color * occlusion)), color(0.99f)); + color dielectric_ior = (color(1.0f) + base_color_sqrt) / (color(1.0f) - base_color_sqrt); + bsdf metallic_component_with_thin_film = df::weighted_layer( + weight: iridescence_strength, + base: metallic_component, + layer: df::thin_film( + thickness: iridescence_thickness, + ior: color(iridescence_ior), + base: df::fresnel_factor( + ior: dielectric_ior, + extinction_coefficient: color(0.0f), + base: df::microfacet_ggx_vcavities_bsdf(roughness_u: roughness2)) + ) + ); + + // apply sheen to the dielectric component + // add the sheen_color as weight in an outer layer to be able to blend and disable on default + // otherwise, sheen would be applied and tinted black + bsdf dielectric_sheen_component = df::color_weighted_layer( + weight: sheen_color, + layer: df::sheen_bsdf( + roughness: sheen_roughness * sheen_roughness, + tint: color(1.0), + multiscatter_tint: color(1.0), + multiscatter: dielectric_component // don't apply thin_film + ), + base: dielectric_component_with_thin_film); + + // final BSDF is a linear blend between dielectric and metallic component + bsdf dielectric_metal_mix = df::weighted_layer( + weight: metallic, + base: dielectric_sheen_component, + layer: metallic_component_with_thin_film, + normal: normal); + + bsdf clearcoated = df::custom_curve_layer( + weight: clearcoat_blend, + normal_reflectivity: 0.04, + grazing_reflectivity: grazing_refl_coat, + layer: df::microfacet_ggx_vcavities_bsdf( + mode: df::scatter_reflect, + roughness_u: clearcoat_roughness2, + tint: color(1.0)), + base: df::weighted_layer( + weight: 1.0, + layer: dielectric_metal_mix, + normal: normal), + normal: clearcoat_normal); + +} in material( + thin_walled: thin_walled, + surface: material_surface( + scattering: clearcoated, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + volume: material_volume( + absorption_coefficient: thin_walled ? color(0.0) : (attenuation_distance == 0) ? color(0.0) : -math::log(attenuation_color) / attenuation_distance + ), + ior: color(ior), + geometry: material_geometry( + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +); + + +export material gltf_material_khr_specular_glossiness( + // diffuse color + uniform color diffuse_factor = color(1.0) + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Factor"), + anno::description("The diffuse color of the material. Multiplied to the 'Diffuse Texture' if available.") + ]], + gltf_texture_lookup_value diffuse_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Diffuse Texture"), + anno::description("The diffuse color of the material. Influenced by the 'Diffuse Factor'.") + ]], + + // specular glossiness + uniform color specular_factor = 1.0 + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular Factor"), + anno::description("The specular color of the material. Multiplied to the rgb values of the 'Specular/Glossy Texture' if available.") + ]], + uniform float glossiness_factor = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Glossiness Factor"), + anno::description("The glossiness of the material. Select between diffuse (0.0) and nearly specular (1.0). Multiplied to the alpha value of the 'Specular/Glossy Texture' if available.") + ]], + gltf_texture_lookup_value specular_glossiness_texture = gltf_texture_lookup() + [[ + anno::in_group("PBR Specular Glossiness"), + anno::display_name("Specular/Glossy Texture"), + anno::description("The specular-glossiness texture. Influenced by the 'Specular Factor' and 'Glossiness Factor'.") + ]], + + // normal map + gltf_normal_texture_lookup_value normal_texture = gltf_normal_texture_lookup() + [[ + anno::in_group("Normal Mapping"), + anno::display_name("Normal Texture"), + anno::description("Base layer normal map.") + ]], + + // emission + uniform color emissive_factor = color(0.0) + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Factor"), + anno::description("The emissive color of the material. Multiplied to the 'Emissive Texture' if available.") + ]], + gltf_texture_lookup_value emissive_texture = gltf_texture_lookup() + [[ + anno::in_group("Emission"), + anno::display_name("Emissive Texture"), + anno::description("The emissive map texture. Influenced by the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + // KHR_materials_emissive_strength + uniform float emissive_strength = 1.0 + [[ + anno::soft_range(0.0, 10000), + anno::in_group("Emission"), + anno::display_name("Emissive Strength"), + anno::description("The maximum strength of the emissive texture. Multiplied to the 'Emissive Factor'."), + anno::enable_if("::math::average(emissive_factor)>0.0") + ]], + + // ambient occlusion + gltf_texture_lookup_value occlusion_texture = gltf_texture_lookup() + [[ + anno::in_group("Occlusion"), + anno::display_name("Occlusion Texture"), + anno::description("The occlusion map texture. Influenced by the 'Occlusion Strength'.") + ]], + uniform float occlusion_strength = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Occlusion"), + anno::display_name("Occlusion Strength"), + anno::description("A scalar multiplier controlling the amount of occlusion applied. Multiplied to the 'Occlusion Texture'.") + ]], + + // alpha + uniform gltf_alpha_mode alpha_mode = opaque + [[ + anno::in_group("Opacity"), + anno::display_name("Alpha Mode"), + anno::description("Select how to interpret the alpha value.") + ]], + uniform float base_alpha = 1.0 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Base Alpha"), + anno::description("Select between transparent (0.0) and opaque (1.0). Multiplied to the base color texture alpha channel if available."), + anno::enable_if("alpha_mode!=opaque") + ]], + + // alpha for gltf_alpha_mode::mask + uniform float alpha_cutoff = 0.5 + [[ + anno::hard_range(0.0, 1.0), + anno::in_group("Opacity"), + anno::display_name("Alpha Cutoff"), + anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."), + anno::enable_if("alpha_mode==mask") + ]], + + uniform string vertex_color_name_spec = string("displayColor") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Color Name"), + anno::description("Name of the vertex color primvar usually COLOR_0 'gltf', or displayColor 'usd'.") + ]], + + uniform bool use_vertex_color_alpha_spec = false + [[ + anno::in_group("Primvar"), + anno::display_name("Use Opacity Channel From Vertex Color"), + anno::description("Multiply the Alpha or .w channel from the vertex color with the base alpha value.") + ]], + + uniform string vertex_opacity_name_spec = string("displayOpacity") + [[ + anno::in_group("Primvar"), + anno::display_name("Vertex Opacity Name"), + anno::description("Name of the vertex color primvar usually the .w component of COLOR_0 'gltf', or displayOpacity 'usd'.") + ]] + +) [[ + anno::author("NVIDIA Corporation"), + anno::display_name("GLTF Material - Specular-Glossiness"), + anno::description("Specular-Glossiness Material that takes the GLTF KHR extension parameters as input.") +]] = let { + + // handling GLTF parameters + // ------------------------------------------------------------------------ + float4 diffuse_float4 = gltf_prepare_tex_float4(diffuse_texture) * ::scene::data_lookup_float4(vertex_color_name_spec, float4(1.0)); // apply vertex color + color diffuse = diffuse_factor * color(diffuse_float4.x, diffuse_float4.y, diffuse_float4.z); + + float alpha = base_alpha * (use_vertex_color_alpha_spec == 1 ? diffuse_float4.w : 1.0) * ((vertex_color_name_spec != vertex_opacity_name_spec) ? ::scene::data_lookup_float(vertex_opacity_name_spec, float(1.0)) : 1.0); + //float alpha = base_alpha; + float4 specular_glossiness = gltf_prepare_tex_float4(specular_glossiness_texture); + color specular = specular_factor * color(specular_glossiness.x, specular_glossiness.y, specular_glossiness.z); + float glossiness = glossiness_factor * specular_glossiness.w; + + float3 normal = gltf_prepare_normal(normal_texture); + float occlusion = gltf_prepare_occlusion(occlusion_texture, occlusion_strength); + color emissive_color = gltf_perpare_emission(emissive_texture, emissive_factor * math::max(0.0f, emissive_strength)); + + // specular glossiness model + // ------------------------------------------------------------------------ + + //color c_diff = diffuse * (1.0 - math::maxvalue(specular)); + float F_0 = math::max_value(specular); + color F_0_tint = F_0==0.0? color(0.0) : (specular/F_0); + + float a = (1.0 - glossiness) * (1.0 - glossiness); + + // diffuse BRDF + bsdf diffuse_brdf = df::diffuse_reflection_bsdf( + tint: diffuse * occlusion, + roughness: 0.0); + + // specular BRDF + bsdf specular_brdf = df::microfacet_ggx_smith_bsdf( + tint: color(occlusion), + roughness_u: a, + roughness_v: a, + tangent_u: state::texture_tangent_u(0)); + bsdf tinted_specular = df::directional_factor(normal_tint: F_0_tint, grazing_tint: color(1.0), exponent: 5.0, base: specular_brdf); + //- Custom curve for specular/diffuse angular mix + bsdf diffuse_specular_mix = df::custom_curve_layer( + normal_reflectivity: F_0, + grazing_reflectivity: 1.0, + exponent: 5.0, + weight: 1.0, + layer: tinted_specular, + base: diffuse_brdf, + normal: normal); + +} in material( + surface: material_surface( + scattering: diffuse_specular_mix, + emission: material_emission ( + emission: df::diffuse_edf(), + intensity: emissive_color * ::math::PI + ) + ), + geometry: material_geometry( + normal: normal, + cutout_opacity: compute_opacity(alpha_mode, alpha, alpha_cutoff) + ) +);