File size: 11,319 Bytes
4f4dced | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | /*****************************************************************************
* Copyright 1986-2020 NVIDIA Corporation. All rights reserved.
******************************************************************************
MDL MATERIALS ARE PROVIDED PURSUANT TO AN END USER LICENSE AGREEMENT,
WHICH WAS ACCEPTED IN ORDER TO GAIN ACCESS TO THIS FILE. IN PARTICULAR,
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.6;
import ::df::*;
import ::state::*;
import ::math::*;
import ::base::*;
import ::tex::*;
import ::anno::*;
import ::nvidia::core_definitions::file_texture;
import ::nvidia::core_definitions::normalmap_texture;
export material SimPBR_Translucent(
// -------------------- SPECULAR REFLECTION/TRANSMISSION ----------------------
uniform float ior_constant = 1.1f
[[
anno::display_name("Index of Refraction"),
anno::hard_range(0.0,5.),
anno::description("Index of Refraction of the material"),
anno::in_group("Specular")
]],
uniform float reflection_roughness_constant = 0.5f
[[
anno::display_name("Roughness Amount"),
anno::hard_range(0.0,1.),
anno::description("Higher roughness values lead to more blurry reflections"),
anno::in_group("Specular")
]],
uniform float reflection_roughness_texture_influence = 0.0f
[[
anno::display_name("Roughness Map Influence"),
anno::hard_range(0.0, 1.),
anno::description("Blends between the constant value and the lookup of the roughness texture"),
anno::in_group("Specular")
]],
uniform texture_2d reflectionroughness_texture = texture_2d()
[[
anno::display_name("Roughness Map"),
anno::in_group("Specular")
]],
// -------------------- VOLUME ----------------------
color transmittance_color = color(1.0, 1.0f, 1.0f)
[[
anno::display_name("Transmittance Color"),
anno::description("Expected transmittance after the specified transmittance distance through the volume."),
anno::in_group("Volume")
]],
float transmittance_measurement_distance = 1.0f
[[
anno::display_name("Transmittance Measurement Distance"),
anno::description("Distance to match the transmittance through the volume at."),
anno::in_group("Volume")
]],
// -------------------- EMISSIVE ----------------------
uniform bool enable_thin_walled = false
[[
anno::display_name("Enable Thin Walled"),
anno::description("Enables thin walled logic"),
anno::in_group("Geometry")
]],
// -------------------- EMISSIVE ----------------------
uniform bool enable_emission = false
[[
anno::display_name("Enable Emission"),
anno::description("Enables the emission of light from the material"),
anno::in_group("Emissive")
]],
color emissive_color = color(1.0, 0.1, 0.1)
[[
anno::enable_if("enable_emission == true"),
anno::display_name("Emissive Color"),
anno::description("The emission color"),
anno::in_group("Emissive")
]],
uniform texture_2d emissive_mask_texture = texture_2d()
[[
anno::enable_if("enable_emission == true"),
anno::display_name("Emissive Mask Map"),
anno::description("The texture masking the emissive color"),
anno::in_group("Emissive")
]],
uniform float emissive_intensity = 40.f
[[
anno::enable_if("enable_emission == true"),
anno::display_name("Emissive Intensity"),
anno::description("Intensity of the emission"),
anno::in_group("Emissive")
]],
uniform bool enable_emissive_flipbook = false
[[
anno::display_name("Enable Flipbook for emission"),
anno::description("Allows the use of animated emissive textures (e.g. video screens)"),
anno::in_group("Emissive")
]],
uniform int2 flipbook_dim = int2(1,1)
[[
anno::enable_if("enable_emissive_flipbook == true"),
anno::display_name("Flipbook Rows/Columns"),
anno::description("How many rows and columns are in the flipbook?"),
anno::in_group("Emissive")
]],
uniform int target_fps = 1
[[
anno::enable_if("enable_emissive_flipbook == true"),
anno::display_name("Flipbook Target FPS"),
anno::description("Playback speed in frames per second"),
anno::in_group("Emissive")
]],
// -------------------- NORMAL ----------------------
uniform float bump_factor = 1.f
[[
anno::display_name("Normal Map Strength"),
anno::description("Strength of normal map."),
anno::in_group("Normal")
]],
uniform texture_2d normalmap_texture = texture_2d()
[[
anno::display_name("Normal Map"),
anno::in_group("Normal")
]],
uniform bool flip_tangent_u = false
[[
anno::display_name("Normal Map Flip U Tangent"),
anno::in_group("Normal")
]],
uniform bool flip_tangent_v = true
[[
anno::display_name("Normal Map Flip V Tangent"),
anno::in_group("Normal")
]],
// -------------------- UV ADJUSTMENTS ----------------------
uniform bool project_uvw = false
[[
anno::display_name("Enable Project UVW Coordinates"),
anno::description("When enabled, UV coordinates will be generated by projecting them from a coordinate system"),
anno::in_group("UV")
]],
uniform bool world_or_object = false
[[
anno::enable_if("project_uvw == true"),
anno::display_name("Enable World Space"),
anno::description("When set to 'true' uses world space for projection, when 'false' object space is used"),
anno::in_group("UV")
]],
uniform float2 texture_translate = float2(0.0f)
[[
anno::display_name("Texture Translate"),
anno::description("Controls position of texture."),
anno::in_group("UV")
]],
uniform float2 texture_scale = float2(1.0f)
[[
anno::display_name("Texture Tiling"),
anno::description("Controls the repetition of the texture."),
anno::in_group("UV")
]],
uniform float2 texture_speed = float2(0.0f)
[[
anno::display_name("Texture Speed"),
anno::description("Scrolling texture animation speed in UVs per sec."),
anno::in_group("UV")
]]
)
[[ anno::display_name("Sim PBR Translucent"), anno::description("Supports the translucent material model of the Sim Renderer"), anno::in_group("SimReady"), anno::version( 1, 0, 0), anno::author("NVIDIA CORPORATION"), anno::key_words(string[]("Sim", "PBR", "translucent", "omniverse", "generic"))
]]
= let {
base::texture_coordinate_system the_system = world_or_object ? base::texture_coordinate_world : base::texture_coordinate_object;
base::texture_coordinate_info uvw = project_uvw ?
base::coordinate_projection(
coordinate_system: the_system,
texture_space: 0,
projection_type: base::projection_cubic
) : base::coordinate_source(
coordinate_system: base::texture_coordinate_uvw,
texture_space: 0
);
// Need to use a small value so the compiler doesnt optimize out this var...
float t = 0.00000001;//state::animation_time();
base::texture_coordinate_info transformed_uvw = base::transform_coordinate(
transform: base::rotation_translation_scale(
scaling: float3(texture_scale.x, texture_scale.y, 1.0),
rotation: float3(0.0, 0.0, 0.0 ),
translation: float3(texture_translate.x + t * texture_speed.x, texture_translate.y + t * texture_speed.y, 0.0)),
coordinate: uvw
);
float2 uv = float2(transformed_uvw.position.x, transformed_uvw.position.y);
color volume_absorption_coefficient = -math::log(transmittance_color) / (transmittance_measurement_distance*0.01);
float roughness_lookup = tex::texture_isvalid(reflectionroughness_texture) ?
tex::lookup_float4(tex: reflectionroughness_texture, coord: uv).x : reflection_roughness_constant;
float reflection_roughness = math::lerp(reflection_roughness_constant, roughness_lookup, reflection_roughness_texture_influence);
float roughness_squared = reflection_roughness * reflection_roughness;
bsdf final_bsdf(enable_thin_walled ?
::df::fresnel_layer(
ior_constant,
1.f,
::df::microfacet_ggx_smith_bsdf(
roughness_squared,
roughness_squared,
color(1.f, 1.f, 1.f),
color(0.f, 0.f, 0.f),
::state::texture_tangent_u(0),
::df::scatter_reflect,
""
),
::df::specular_bsdf(
transmittance_color,
::df::scatter_transmit,
""
), ::state::normal())
: ::df::microfacet_ggx_smith_bsdf(
roughness_squared,
roughness_squared,
color(1.f, 1.f, 1.f),
color(0.f, 0.f, 0.f),
::state::texture_tangent_u(0),
::df::scatter_reflect_transmit,
""
));
int rows = flipbook_dim.x;
int columns = flipbook_dim.y;
int numFrames = rows * columns;
varying int frameIdx = int(state::animation_time() * target_fps) % numFrames;
varying float2 baseUV = float2(transformed_uvw.position.x, transformed_uvw.position.y);
varying float2 emissiveUV = enable_emissive_flipbook ?
((baseUV + float2(frameIdx % rows, frameIdx / rows)) / float2(rows, columns)) : baseUV;
color emissive_mask = tex::texture_isvalid(emissive_mask_texture) ?
tex::lookup_color(emissive_mask_texture, emissiveUV, tex::wrap_repeat, tex::wrap_repeat) : color(1.0);
// Normal calculations
float3 normal_lookup = tex::texture_isvalid(normalmap_texture) ?
base::tangent_space_normal_texture(
texture: normalmap_texture,
factor: bump_factor,
uvw: transformed_uvw,
flip_tangent_u: flip_tangent_u,
flip_tangent_v: flip_tangent_v
) : state::normal();
} in material(
thin_walled: enable_thin_walled,
surface: material_surface(
scattering: final_bsdf,
emission: material_emission (
df::diffuse_edf(),
intensity: enable_emission ? emissive_color * emissive_mask * color(emissive_intensity) : color(0)
)
),
ior: color(ior_constant),
volume: material_volume(
scattering: df::anisotropic_vdf(),
absorption_coefficient: volume_absorption_coefficient,
scattering_coefficient: color(0.0f, 0.0f, 0.0f)
),
geometry: material_geometry(
normal: normal_lookup
)
);
|