File size: 22,119 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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | /*****************************************************************************
* 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.4;
import ::df::*;
import ::state::*;
import ::math::*;
import ::base::*;
import ::tex::*;
import ::anno::*;
import ::nvidia::core_definitions::file_texture;
import ::nvidia::core_definitions::normalmap_texture;
using .::SimPBR_Model import *;
using .::baking_annotations import *;
export material SimPBR(
// -------------------- DIFFUSE REFLECTION ----------------------
color diffuse_color_constant = color(0.2f)
[[
anno::display_name("Albedo Base Color"),
anno::description("The base albedo color to use if no texture is specified"),
anno::in_group("Diffuse")
]],
uniform texture_2d diffuse_texture = texture_2d()
[[
anno::display_name("Albedo Map"),
anno::description("The texture specifying the albedo value to use"),
anno::in_group("Diffuse")
]],
uniform color diffuse_tint = color(1.0f)
[[
anno::display_name("Albedo Tint"),
anno::description("This tints the albedo color or texture contant"),
anno::in_group("Diffuse")
]],
uniform bool enable_transmission = false
[[
anno::display_name("Enable Diffuse Transmission"),
anno::description("Enables the diffuse transmission of light through thin diffuse scattering layer"),
anno::in_group("Diffuse")
]],
uniform float opacity_ratio = 1.f
[[
anno::enable_if("enable_transmission == true"),
anno::display_name("Opacity Ratio"),
anno::description("Amount of opacity"),
anno::in_group("Diffuse")
]],
uniform color opacity_tint = color(1.0f)
[[
anno::enable_if("enable_transmission == true"),
anno::display_name("Diffuse transmission tint"),
anno::description("Base diffuse transmission color"),
anno::in_group("Diffuse")
]],
uniform float opacity_multiplier = 1.f
[[
anno::enable_if("enable_transmission == true"),
anno::display_name("Diffuse transmission multiplier"),
anno::description("Base diffuse transmission multiplier"),
anno::in_group("Diffuse")
]],
// -------------------- SPECULAR REFLECTION ----------------------
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")
]],
float anisotropy_constant = 0.0f
[[
anno::display_name("Anisotropy Amount"),
anno::hard_range(-1.,1.),
anno::description("0 for isotropic, extents of -1 to 1 for anisotropy"),
anno::in_group("Specular")
]],
uniform float anisotropy_texture_influence = 0.0f
[[
anno::display_name("Anisotropy Map Influence"),
anno::hard_range(0.0, 1.),
anno::description("Blends between the constant value and the lookup of the anisotropy texture"),
anno::in_group("Specular")
]],
uniform texture_2d anisotropy_texture = texture_2d()
[[
anno::display_name("Anisotropy Map"),
anno::in_group("Specular")
]],
float metallic_constant = 0.f
[[
anno::display_name("Metallic Amount"),
anno::hard_range(0.0,1.),
anno::description("Metallic Material"),
anno::in_group("Specular")
]],
uniform float metallic_texture_influence = 0.0f
[[
anno::display_name("Metallic Map Influence"),
anno::hard_range(0.0, 1.),
anno::description("Blends between the constant value and the lookup of the metallic texture"),
anno::in_group("Specular")
]],
uniform texture_2d metallic_texture = texture_2d()
[[
anno::display_name("Metallic Map"),
anno::in_group("Specular")
]],
float specular_constant = 1.f
[[
anno::display_name("Specular amount"),
anno::hard_range(0.0, 1.0),
anno::description("Scale of the specular component"),
anno::in_group("Specular")
]],
uniform texture_2d specular_texture = texture_2d()
[[
anno::display_name("Specular Map"),
anno::in_group("Specular")
]],
// -------------------- ORM ----------------------
uniform bool enable_ORM_texture = true
[[
anno::display_name("Enable ORM Texture"),
anno::description("When True the ORM texture will be used to extract the Occlusion, Roughness and Metallic Map"),
anno::in_group("Reflectivity")
]],
uniform texture_2d ORM_texture = texture_2d()
[[
anno::display_name("ORM Map"),
anno::description("Texture that hae Occlusion, Roughness and Metallic map stored in the respective r, g and b channels"),
anno::in_group("Reflectivity")
]],
// -------------------- Clearcoat ----------------------
uniform bool enable_clearcoat = false
[[
anno::display_name("Enable Clearcoat Layer"),
anno::description("Adds a clearcoat layer on top of the material when enabled"),
anno::in_group("Clearcoat")
]],
color clearcoat_tint = color(1.0f)
[[
anno::display_name("Clearcoat Tint"),
anno::description("Clearcoat is tinted and affects the underlying material"),
anno::in_group("Clearcoat")
]],
float clearcoat_transparency = 1.0f
[[
anno::display_name("Clearcoat Transparency"),
anno::description("Adjusts the transparency of the clearcoat. Can be turned into a fully opaque clearcoat "
"covering the underlying layer"),
anno::in_group("Clearcoat")
]],
float clearcoat_reflection_roughness = 0.0f
[[
anno::display_name("Clearcoat Roughness"),
anno::description("Higher roughness values lead to more blurry reflections"),
anno::hard_range(0.0f, 1.0f),
anno::in_group("Clearcoat")
]],
float clearcoat_weight = 1.0f
[[
anno::display_name("Clearcoat Weight"),
anno::description("Sets the weight for clearcoat layer"),
anno::hard_range(0.0f, 1.0f),
anno::in_group("Clearcoat")
]],
float clearcoat_flatten = 1.0f
[[
anno::display_name("Clearcoat Flatten"),
anno::description("Flattens the clearcoat to even out the underlying bump maps"),
anno::hard_range(0.0f, 1.0f),
anno::in_group("Clearcoat")
]],
float clearcoat_ior = 1.56f
[[
anno::display_name("Clearcoat IOR"),
anno::description("Sets the Index of refraction for the clearcoat layer"),
anno::soft_range(1.0f, 4.0f),
anno::in_group("Clearcoat")
]],
uniform float clearcoat_bump_factor = 1.f
[[
anno::display_name("Clearcoat Normal Map Strength"),
anno::description("Strength of normal map."),
anno::in_group("Clearcoat")
]],
float3 clearcoat_normal_input = float3(0.0, 0.0, 0.0),
uniform texture_2d clearcoat_normalmap_texture = texture_2d()
[[
anno::display_name("Clearcoat Normal Map"),
anno::description("Enables the usage of the normalmap texture"),
anno::in_group("Clearcoat")
]],
uniform bool clearcoat_flip_tangent_u = false
[[
anno::display_name("Clearcoat Normal Map Flip U Tangent"),
anno::in_group("Clearcoat")
]],
uniform bool clearcoat_flip_tangent_v = true
[[
anno::display_name("Clearcoat Normal Map Flip V Tangent"),
anno::in_group("Clearcoat")
]],
// -------------------- REFLECTIVITY ----------------------
uniform bool enable_retroreflection = false
[[
anno::display_name("Enable Retroreflection"),
anno::in_group("Reflectivity")
]],
color retroreflection_tint = color(.182,.800,.000)
[[
anno::display_name("Retro-reflection tint"),
anno::description("The tint of the retroreflection"),
anno::in_group("Reflectivity")
]],
uniform float normal_reflectivity = 0.5
[[
anno::display_name("Retro-reflection weight facing"),
anno::hard_range(0.0,1.),
anno::description("Reflectivity control for geometry facing the viewer"),
anno::in_group("Reflectivity")
]],
uniform float grazing_reflectivity = 1.0
[[
anno::display_name("Retro-reflection weight edge"),
anno::hard_range(0.0,1.),
anno::description("Reflectivity control for the reflectivity at geometry edges"),
anno::in_group("Reflectivity")
]],
// -------------------- AMBIENT OCCLUSION ----------------------
float ao_to_diffuse = 0.0
[[
anno::display_name("AO to Diffuse"),
anno::description("Controls the amount of ambient occlusion multiplied into the diffuse color channel"),
anno::in_group("AO")
]],
float ao_input = float(1.0),
uniform texture_2d ao_texture = texture_2d()
[[
anno::display_name("Ambient Occlusion Map"),
anno::description("The Ambient Occlusion texture for the material"),
anno::in_group("AO")
]],
// -------------------- 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")
]],
uniform 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")
]],
color emissive_mask_input = color(1.0),
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")
]],
// -------------------- ALPHA ----------------------
uniform bool enable_opacity = false
[[
anno::display_name("Enable Opacity"),
anno::description("Enables or disables alpha functionality"),
anno::in_group("Alpha")
]],
float alpha_constant = 1.0
[[
anno::enable_if("enable_opacity == true"),
anno::display_name("Opacity Fallback Constant"),
anno::hard_range(0.0, 1.0),
anno::description("The base alpha constant to use if no texture is specified"),
anno::in_group("Alpha")
]],
uniform texture_2d opacity_texture = texture_2d()
[[
anno::enable_if("enable_opacity == true"),
anno::display_name("Opacity Map"),
anno::description("The texture specifying the opacity value to use"),
anno::in_group("Alpha")
]],
uniform bool enable_opacity_cutout = false
[[
anno::enable_if("enable_opacity == true"),
anno::display_name("Enable Alpha Cutout"),
anno::description("Enables or disables alpha cutout functionality"),
anno::in_group("Alpha")
]],
uniform float alpha_cutout_cutoff = 1.f
[[
anno::enable_if("enable_opacity == true"),
anno::enable_if("enable_opacity_cutout == true"),
anno::hard_range(0.0, 1.0),
anno::display_name("Alpha Cutout Cutoff"),
anno::description("The cutoff value to to render as transparent up to and opaque past"),
anno::in_group("Alpha")
]],
// -------------------- NORMAL ----------------------
uniform float bump_factor = 1.f
[[
anno::display_name("Normal Map Strength"),
anno::description("Strength of normal map."),
anno::in_group("Normal")
]],
float3 normal_input = state::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 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"),
anno::description("Supports the opaque alpha cutout 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", "opaque", "alpha", "cutout", "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);
// Diffuse Color Lookup and AO
float4 base_lookup = tex::texture_isvalid(diffuse_texture) ? tex::lookup_float4(tex: diffuse_texture, coord: uv) : float4(1, 1, 1, 1);
float opacityValue = tex::texture_isvalid(opacity_texture) ? tex::lookup_float4(tex: opacity_texture, coord: uv).w : alpha_constant;
// 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
) : normal_input;
float3 clearcoat_normal = tex::texture_isvalid(clearcoat_normalmap_texture) ?
base::tangent_space_normal_texture(
texture: clearcoat_normalmap_texture,
factor: clearcoat_bump_factor,
uvw: uvw,
flip_tangent_u: clearcoat_flip_tangent_u,
flip_tangent_v: clearcoat_flip_tangent_v
) : clearcoat_normal_input;
float3 flattened_clearcoat_normal = ::math::lerp(normal_lookup, ::state::normal(), clearcoat_flatten);
float3 final_clearcoat_normal = tex::texture_isvalid(clearcoat_normalmap_texture) ? clearcoat_normal : flattened_clearcoat_normal;
float ao_lookup = tex::texture_isvalid(ao_texture) ? tex::lookup_float4(tex: ao_texture, coord: uv).x : ao_input;
color diffuse_color = tex::texture_isvalid(diffuse_texture) ? color(base_lookup.x, base_lookup.y, base_lookup.z) : diffuse_color_constant;
float3 ORM_lookup = tex::lookup_float3(
tex: ORM_texture,
coord: float2(transformed_uvw.position.x, transformed_uvw.position.y)
);
float roughness_lookup = tex::texture_isvalid(reflectionroughness_texture) ?
tex::lookup_float4(tex: reflectionroughness_texture, coord: uv).x : reflection_roughness_constant;
float anisotropy_lookup = tex::texture_isvalid(anisotropy_texture) ?
(tex::lookup_float4(tex: anisotropy_texture, coord: uv).x * 2.0f - 1.0f) : anisotropy_constant;
float metallic_lookup = tex::texture_isvalid(metallic_texture) ?
tex::lookup_float4(tex: metallic_texture, coord: uv).x : metallic_constant;
float specular_lookup = tex::texture_isvalid(specular_texture) ?
tex::lookup_float4(tex: specular_texture, coord: uv).x : specular_constant;
float roughness_selection = enable_ORM_texture ? ORM_lookup.y : roughness_lookup;
float metallic_selection = enable_ORM_texture ? ORM_lookup.z : metallic_lookup;
float ao = enable_ORM_texture ? ORM_lookup.x : ao_lookup;
float reflection_roughness = math::lerp(reflection_roughness_constant, roughness_selection, reflection_roughness_texture_influence);
float anisotropy = math::lerp(anisotropy_constant, anisotropy_lookup, anisotropy_texture_influence);
float metallic = math::lerp(metallic_constant, metallic_selection, metallic_texture_influence);
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) : emissive_mask_input;
} in SimPBR_Model(
diffuse_color: diffuse_color,
diffuse_tint: diffuse_tint,
roughness: reflection_roughness,
anisotropy: anisotropy,
metallic: metallic,
specular: specular_lookup,
normal: normal_lookup,
enable_clearcoat: enable_clearcoat,
clearcoat_tint: clearcoat_tint,
clearcoat_transparency: clearcoat_transparency,
clearcoat_reflection_roughness: clearcoat_reflection_roughness,
clearcoat_weight: clearcoat_weight,
clearcoat_ior: clearcoat_ior,
clearcoat_normal: final_clearcoat_normal,
enable_retroreflection: enable_retroreflection,
retroreflection_tint: retroreflection_tint,
normal_reflectivity: normal_reflectivity,
grazing_reflectivity: grazing_reflectivity,
ao_to_diffuse: ao_to_diffuse,
ao: ao,
enable_emission: enable_emission,
emissive_color: emissive_color,
emissive_mask: emissive_mask,
emissive_intensity: emissive_intensity,
enable_opacity: enable_opacity,
alpha: opacityValue,
enable_opacity_cutout: enable_opacity_cutout,
alpha_cutout_cutoff: alpha_cutout_cutoff,
opacity_ratio: enable_transmission ? opacity_ratio : 1.0,
opacity_tint : opacity_tint,
opacity_multiplier : opacity_multiplier
);
|