| /****************************************************************************** |
| * Copyright 2024 NVIDIA Corporation. All rights reserved. |
| ****************************************************************************** |
| |
| Permission is hereby granted by NVIDIA Corporation ("NVIDIA"), free of charge, |
| to any person obtaining a copy of the sample definition code that uses our |
| Material Definition Language (the "MDL Materials"), to reproduce and distribute |
| the MDL Materials, including without limitation the rights to use, copy, merge, |
| publish, distribute, and sell modified and unmodified copies of the MDL |
| Materials, and to permit persons to whom the MDL Materials is furnished to do |
| so, in all cases solely for use with NVIDIA's Material Definition Language, |
| subject to the following further conditions: |
|
|
| 1. The above copyright notices, this list of conditions, and the disclaimer |
| that follows shall be retained in all copies of one or more of the MDL |
| Materials, including in any software with which the MDL Materials are bundled, |
| redistributed, and/or sold, and included either as stand-alone text files, |
| human-readable headers or in the appropriate machine-readable metadata fields |
| within text or binary files as long as those fields can be easily viewed by the |
| user, as applicable. |
| 2. The name of NVIDIA shall not be used to promote, endorse or advertise any |
| Modified Version without specific prior written permission, except a) to comply |
| with the notice requirements otherwise contained herein; or b) to acknowledge |
| the contribution(s) of NVIDIA. |
|
|
| THE MDL MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, |
| TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR |
| ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, |
| INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF |
| CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE |
| THE MDL MATERIALS OR FROM OTHER DEALINGS IN THE MDL MATERIALS. |
| */ |
| |
| mdl 1.4; |
| import ::df::*; |
| import ::base::*; |
| import ::math::*; |
| import ::anno::*; |
| import ::tex::*; |
| import ::nvidia::core_definitions::dimension; |
| |
| |
| const string COPYRIGHT = |
| " Copyright 2024 NVIDIA Corporation. All rights reserved.\n" |
| " MDL MATERIALS ARE PROVIDED PURSUANT TO AN END USER LICENSE AGREEMENT,\n" |
| " WHICH WAS ACCEPTED IN ORDER TO GAIN ACCESS TO THIS FILE. IN PARTICULAR,\n" |
| " THE MDL MATERIALS ARE PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n" |
| " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF\n" |
| " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF\n" |
| " COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL NVIDIA\n" |
| " CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY\n" |
| " GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN\n" |
| " AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR\n" |
| " INABILITY TO USE THE MDL MATERIALS OR FROM OTHER DEALINGS IN THE MDL MATERIALS.\n"; |
| |
| |
| uniform float4x4 rotation_translation_scale( |
| uniform float3 rotation = float3(0.) |
| [[ ::anno::description("Rotation applied to every UVW coordinate.") ]], |
| uniform float3 translation = float3(0.) |
| [[ ::anno::description("Offset applied to every UVW coordinate.") ]], |
| uniform float3 scaling = float3(1.) |
| [[ ::anno::description("Scale applied to every UVW coordinate.") ]] |
| ) |
| [[ |
| ::anno::description("Construct transformation matrix from Euler rotation, translation and scale."), |
| ::anno::hidden() |
| ]] |
| { |
| float4x4 scale = |
| float4x4(scaling.x , 0. , 0. , 0., |
| 0. , scaling.y , 0. , 0., |
| 0. , 0. , scaling.z , 0., |
| translation.x, translation.y, translation.z, 1.); |
| |
| float3 s = ::math::sin(rotation); |
| float3 c = ::math::cos(rotation); |
| float4x4 rotate = |
| float4x4( c.y*c.z , -c.x*s.z + s.x*s.y*c.z , s.x*s.z + c.x*s.y*c.z , 0.0, |
| c.y*s.z , c.x*c.z + s.x*s.y*s.z , -s.x*c.z + c.x*s.y*s.z , 0.0, |
| -s.y , s.x*c.y , c.x*c.y , 0.0, |
| 0. , 0 , 0 , 1.); |
| |
| return scale*rotate; |
| } |
| |
| |
| export material Cardboard( |
| // Appearance Group |
| float brightness = .6f |
| [[ |
| ::anno::display_name("Cardboard Brightness"), |
| ::anno::description("Brightness of the cardboard."), |
| ::anno::hard_range(0.0f,1.f), |
| ::anno::in_group("Appearance") |
| ]], |
| float reflectivity = .35f |
| [[ |
| ::anno::display_name("Reflection weight"), |
| ::anno::description("Strength of cardboard reflectivity."), |
| ::anno::hard_range(0.0f,1.f), |
| ::anno::in_group("Appearance") |
| ]], |
| uniform float bump_amount = 0.3f |
| [[ |
| ::anno::display_name("Bumps"), |
| ::anno::description("Attach bump or normal maps here."), |
| ::anno::hard_range(0.0f,1.f), |
| ::anno::in_group("Appearance") |
| ]], |
| |
| // Adjustments Group |
| uniform float2 texture_translate = float2(0.0f) |
| [[ |
| ::anno::display_name("Translate"), |
| ::anno::description("Controls the position of the texture."), |
| ::anno::in_group("Adjustments") |
| ]], |
| uniform float texture_rotate = 0.f |
| [[ |
| ::anno::display_name("Rotate"), |
| ::anno::description("Rotates angle of the texture in degrees."), |
| ::anno::in_group("Adjustments") |
| ]], |
| uniform float2 texture_scale = float2(1.0f) |
| [[ |
| ::anno::display_name("Scale"), |
| ::anno::description("Larger numbers increase the size."), |
| ::nvidia::core_definitions::dimension(float2(1.0f, 1.0f)), |
| ::anno::in_group("Adjustments") |
| ]], |
| |
| //-----------------------Advanced---------------------------------- |
| uniform int uv_space_index = 0 |
| [[ |
| ::anno::display_name("UV Space Index"), |
| ::anno::description("UV Space Index."), |
| ::anno::in_group("Advanced"), |
| ::anno::hard_range(0, 3) |
| ]] |
| ) |
| [[ |
| ::anno::author("NVIDIA vMaterials"), |
| ::anno::display_name("Cardboard New"), |
| ::anno::description("A cardboard material."), |
| ::anno::created(2019, 5, 5, ""), |
| ::anno::key_words(string[]("paper", "cardboard", "box", "mailbox", "carton", "card", "new")), |
| ::anno::thumbnail("./.thumbs/Cardboard.Cardboard.png"), |
| ::anno::copyright_notice(COPYRIGHT) |
| ]] |
| = let{ |
| uniform texture_2d diffuse_texture = texture_2d("./textures/cardboard_new_01_diff.jpg", ::tex::gamma_srgb); |
| uniform texture_2d roughness_texture = texture_2d("./textures/cardboard_new_01_rough.jpg", ::tex::gamma_srgb); |
| uniform texture_2d normal_texture = texture_2d("./textures/cardboard_new_01_norm.jpg", ::tex::gamma_linear); |
| |
| ::base::texture_coordinate_info uvw = ::base::coordinate_source( |
| coordinate_system: ::base::texture_coordinate_uvw, |
| texture_space: uv_space_index |
| ); |
| |
| ::base::texture_coordinate_info transformed_uvw = ::base::transform_coordinate( |
| transform: rotation_translation_scale( |
| scaling: float3(2.5f/texture_scale.x, 2.5f/texture_scale.y, 1.0), |
| rotation: float3(0.0, 0.0, texture_rotate/180.*::math::PI ), |
| translation: float3(texture_translate.x, texture_translate.y, 0.0) |
| ), |
| coordinate: uvw |
| ); |
| |
| float roughness_lookup = ::base::file_texture( |
| texture: roughness_texture, |
| color_offset: color(0.0, 0.0, 0.0), |
| color_scale: color(1.0, 1.0, 1.0), |
| mono_source: ::base::mono_average, |
| uvw: transformed_uvw, |
| clip: false |
| ).mono; |
| |
| color diffuse_lookup = ::base::file_texture( |
| texture: diffuse_texture, |
| color_offset: color(0.0, 0.0, 0.0), |
| color_scale: color(brightness), |
| mono_source: ::base::mono_average, |
| uvw: transformed_uvw, |
| clip: false |
| ).tint; |
| |
| // Normal lookup |
| float3 the_normal = ::base::tangent_space_normal_texture( |
| texture: normal_texture, |
| factor: bump_amount, |
| uvw: transformed_uvw, |
| flip_tangent_u: false, |
| flip_tangent_v: false |
| ); |
| |
| bsdf diffuse_bsdf = ::df::diffuse_reflection_bsdf( |
| roughness: 0.0, |
| tint: diffuse_lookup |
| ); |
| |
| bsdf glossy_bsdf = ::df::microfacet_ggx_smith_bsdf( |
| mode: ::df::scatter_reflect, |
| tint: color(1.), |
| roughness_u: roughness_lookup, |
| roughness_v: roughness_lookup |
| ); |
| |
| bsdf custom_curve_layer_bsdf = ::df::custom_curve_layer( |
| normal_reflectivity: 0.08 * reflectivity, |
| grazing_reflectivity: 1.0, |
| exponent: 5.0, |
| weight: 1.0, |
| layer: glossy_bsdf, |
| base: diffuse_bsdf |
| ); |
| |
| } |
| in material( |
| thin_walled: true, |
| surface: material_surface( |
| scattering: custom_curve_layer_bsdf |
| ), |
| geometry: material_geometry( |
| normal: the_normal |
| ) |
| ); |
| |
|
|
| export material Cardboard_Worn( |
| float brightness = .6 |
| [[ |
| ::anno::display_name("Cardboard Brightness"), |
| ::anno::hard_range(0.0,1.), |
| ::anno::description("Brightness of the cardboard.") |
| ]], |
| float reflectivity = 0.6 |
| [[ |
| ::anno::display_name("Cardboard Reflectivity"), |
| ::anno::hard_range(0.0, 1.0), |
| ::anno::description("Strength of cardboard reflectivity.") |
| ]], |
| uniform float bump_amount = 0.3 |
| [[ |
| ::anno::display_name("Bump Amount"), |
| ::anno::description("The intensity of the cardboard bumpmap.") |
| ]], |
| |
| // Adjustments Group |
| uniform float2 texture_translate = float2(0.0f) |
| [[ |
| ::anno::display_name("Translate"), |
| ::anno::description("Controls the position of the texture."), |
| ::anno::in_group("Adjustments") |
| ]], |
| uniform float texture_rotate = 0.f |
| [[ |
| ::anno::display_name("Rotate"), |
| ::anno::description("Rotates angle of the texture in degrees."), |
| ::anno::in_group("Adjustments") |
| ]], |
| uniform float2 texture_scale = float2(1.0f) |
| [[ |
| ::anno::display_name("Scale"), |
| ::anno::description("Larger numbers increase the size."), |
| ::anno::in_group("Adjustments"), |
| ::nvidia::core_definitions::dimension(float3(1.0f, 1.0f, 1.0f)) |
| ]], |
| |
| //-----------------------Advanced---------------------------------- |
| uniform int uv_space_index = 0 |
| [[ |
| ::anno::display_name("UV Space Index"), |
| ::anno::description("UV Space Index."), |
| ::anno::in_group("Advanced"), |
| ::anno::soft_range(0, 3) |
| ]] |
| ) |
| [[ |
| ::anno::author("NVIDIA vMaterials"), |
| ::anno::display_name("Cardboard Worn"), |
| ::anno::description("A worn cardboard material."), |
| ::anno::created(2019, 5, 5, ""), |
| ::anno::key_words(string[]("paper", "cardboard", "box", "mailbox", "carton", "card", "used", "worn", "dirty")), |
| ::anno::thumbnail("./.thumbs/Cardboard.Cardboard_Worn.png"), |
| ::anno::copyright_notice(COPYRIGHT) |
| ]] |
| = let{ |
| uniform float ior = 1.4; |
| |
| uniform texture_2d diffuse_texture = texture_2d("./textures/cardboard_worn_01_diff.jpg", ::tex::gamma_srgb); |
| uniform texture_2d roughness_texture = texture_2d("./textures/cardboard_worn_01_rough.jpg", ::tex::gamma_srgb); |
| uniform texture_2d normal_texture = texture_2d("./textures/cardboard_worn_01_norm.jpg", ::tex::gamma_linear); |
| |
| ::base::texture_coordinate_info uvw = ::base::coordinate_source( |
| coordinate_system: ::base::texture_coordinate_uvw, |
| texture_space: uv_space_index |
| ); |
| |
| ::base::texture_coordinate_info transformed_uvw = ::base::transform_coordinate( |
| transform: rotation_translation_scale( |
| scaling: float3(2.5f/texture_scale.x, 2.5f/texture_scale.y, 1.0), |
| rotation: float3(0.0, 0.0, texture_rotate/180.*::math::PI ), |
| translation: float3(texture_translate.x, texture_translate.y, 0.0) |
| ), |
| coordinate: uvw |
| ); |
| |
| float roughness_lookup = ::base::file_texture( |
| texture: roughness_texture, |
| color_offset: color(0.0, 0.0, 0.0), |
| color_scale: color(1.0, 1.0, 1.0), |
| mono_source: ::base::mono_average, |
| uvw: transformed_uvw, |
| clip: false |
| ).mono; |
| |
| color diffuse_lookup = ::base::file_texture( |
| texture: diffuse_texture, |
| color_offset: color(0.0, 0.0, 0.0), |
| color_scale: color(brightness), |
| mono_source: ::base::mono_average, |
| uvw: transformed_uvw, |
| clip: false |
| ).tint; |
| |
| // Normal lookup |
| float3 the_normal = ::base::tangent_space_normal_texture( |
| texture: normal_texture, |
| factor: bump_amount, |
| uvw: transformed_uvw, |
| flip_tangent_u: false, |
| flip_tangent_v: false |
| ); |
| |
| |
| bsdf glossy_bsdf = ::df::simple_glossy_bsdf( |
| mode: ::df::scatter_reflect, |
| tint: color(1.), |
| roughness_u: roughness_lookup, |
| roughness_v: roughness_lookup |
| ); |
| |
| } |
| in material( |
| thin_walled: true, |
| surface: material_surface( |
| scattering: ::df::weighted_layer( |
| weight: 1., |
| normal: the_normal, |
| layer: ::df::fresnel_layer( |
| ior: ior, |
| weight: reflectivity, |
| layer: glossy_bsdf, |
| base: ::df::diffuse_reflection_bsdf( |
| roughness: 0.0, |
| tint: diffuse_lookup |
| ), |
| normal: the_normal |
| ) |
| ) |
| ) |
| ); |