AVSim/simulation-package
Simulation runtime: the third-party half of the AVSim data generation package This repository holds the third-party runtime of the Simulation data generation package, version 3: the pieces the pipeline needs that were not written by the authors. It contains no code and no data of the authors. It is not usable on its own: the private half of the package, AVSim/simulation, downloads this repository into the same directory at a pinned revision with its fetch_runtime.sh script and… See the full description on the dataset page: https://huggingface.co/datasets/AVSim/simulation-package.
03.7k
1/******************************************************************************2 * Copyright 2024 NVIDIA Corporation. All rights reserved.3 ******************************************************************************4 5Permission is hereby granted by NVIDIA Corporation ("NVIDIA"), free of charge,6to any person obtaining a copy of the sample definition code that uses our 7Material Definition Language (the "MDL Materials"), to reproduce and distribute8the MDL Materials, including without limitation the rights to use, copy, merge,9publish, distribute, and sell modified and unmodified copies of the MDL 10Materials, and to permit persons to whom the MDL Materials is furnished to do11so, in all cases solely for use with NVIDIA's Material Definition Language,12subject to the following further conditions:13 141. The above copyright notices, this list of conditions, and the disclaimer15that follows shall be retained in all copies of one or more of the MDL16Materials, including in any software with which the MDL Materials are bundled,17redistributed, and/or sold, and included either as stand-alone text files,18human-readable headers or in the appropriate machine-readable metadata fields19within text or binary files as long as those fields can be easily viewed by the20user, as applicable.212. The name of NVIDIA shall not be used to promote, endorse or advertise any 22Modified Version without specific prior written permission, except a) to comply23 with the notice requirements otherwise contained herein; or b) to acknowledge24the contribution(s) of NVIDIA.25 26THE MDL MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS27OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,28FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,29TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR 30ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, 31INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF 32CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE33THE MDL MATERIALS OR FROM OTHER DEALINGS IN THE MDL MATERIALS.34*/35 36 37mdl 1.7;38 39import ::anno::*;40import ::base::*;41import ::df::*;42import ::math::*;43import ::state::*;44import ::tex::*;45import ::nvidia::core_definitions::blend_colors;46import ::nvidia::core_definitions::dimension;47 48 49const string COPYRIGHT = 50" Copyright 2024 NVIDIA Corporation. All rights reserved.\n"51" MDL MATERIALS ARE PROVIDED PURSUANT TO AN END USER LICENSE AGREEMENT,\n"52" WHICH WAS ACCEPTED IN ORDER TO GAIN ACCESS TO THIS FILE. IN PARTICULAR,\n" 53" THE MDL MATERIALS ARE PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n"54" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF\n"55" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF\n" 56" COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL NVIDIA\n"57" CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY\n"58" GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN\n"59" AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR\n"60" INABILITY TO USE THE MDL MATERIALS OR FROM OTHER DEALINGS IN THE MDL MATERIALS.\n";61 62annotation preview_scale( float f);63 64color vmat_file_texture(65 uniform texture_2d texture,66 ::base::texture_coordinate_info uvw = ::base::texture_coordinate_info(),67 uniform float2 crop_u = float2(0.0, 1.0),68 uniform float2 crop_v = float2(0.0, 1.0),69 uniform tex::wrap_mode wrap_u = tex::wrap_repeat,70 uniform tex::wrap_mode wrap_v = tex::wrap_repeat71)72{73 return color(tex::lookup_float3(texture, float2(uvw.position.x,uvw.position.y), wrap_u, wrap_v, crop_u, crop_v));74}75 76// Returns the normal n in tangent space, given n is in internal space.77float3 transform_internal_to_tangent(float3 n)78[[ 79 ::anno::hidden() 80]]81{82 return83 n.x* float3(state::texture_tangent_u(0).x,state::texture_tangent_v(0).x,state::normal().x)+84 n.y* float3(state::texture_tangent_u(0).y,state::texture_tangent_v(0).y,state::normal().y)+85 n.z* float3(state::texture_tangent_u(0).z,state::texture_tangent_v(0).z,state::normal().z);86}87 88// Returns the normal n in internal space, given n is in tangent space.89float3 transform_tangent_to_internal(float3 n)90[[ 91 ::anno::hidden() 92]]93{94 return state::texture_tangent_u(0) * n.x +95 state::texture_tangent_v(0) * n.y +96 state::normal() * n.z ;97}98 99 100 101// Returns a normal by adding a detail normal to a global normal.102// If detail blending of two normal maps gives visual artifacts, check if texture_2d are loaded103// correctly with tex::gamma_linear104 float3 add_detail_normal(float3 nd = state::normal(), float3 n = state::normal())105{106 // http://blog.selfshadow.com/publications/blending-in-detail/107 float3 n_t = transform_internal_to_tangent(n);108 float3 nd_t = transform_internal_to_tangent(nd);109 110 n_t=n_t + float3(0.,0.,1.);111 nd_t = nd_t * float3(-1.,-1.,1.);112 n = n_t*math::dot(n_t, nd_t)/n_t.z - nd_t;113 return ::math::normalize(transform_tangent_to_internal(n));114}115 116float histogram_range(float input, float range = 1.0f, float position = 0.5f)117{ 118 float low = ::math::clamp(1.0 - ::math::min(((1.0 - position) + range * 0.5), (1.0 - position) * 2), 0.0, 1.0);119 float high = ::math::clamp(math::min((position + range * 0.5 ), position * 2.0), 0.0, 1.0);120 return ::math::lerp(low, high, input);121}122 123 124 125float3 normalmap_normal(126 uniform texture_2d texture,127 float factor = 1.0,128 ::base::texture_coordinate_info uvw = ::base::texture_coordinate_info()129)130{131 float3 lookup = (::tex::lookup_float3(texture, float2(uvw.position.x, uvw.position.y)) - float3(0.5)) * (factor * 2.0);132 return ::math::normalize(uvw.tangent_u * lookup.x + uvw.tangent_v * lookup.y + state::normal() * (lookup.z + (1.0 - factor)));133}134 135 136::base::texture_coordinate_info transform_coordinate_2(137 float4x4 transform 138 [[ ::anno::description("A transformation to be applied to the source coordinates. rotation_translation_scale() is a suggested means to compute the transformation matrix.") ]],139 ::base::texture_coordinate_info coordinate = ::base::texture_coordinate_info()140 [[ ::anno::description("Coordinate, typically sourced from coordinate_source or coordinate_projection.") ]]141) [[ 142 ::anno::description("Transform a texture coordinate by a matrix.") ,143 ::anno::noinline()144 ]]145{146 // Version 2147 float4 r_position = transform * float4(coordinate.position.x,coordinate.position.y,coordinate.position.z,1);148 float4 u = transform[0];149 float3 ru = ::math::normalize(float3(u.x,u.y,u.z));150 float cos = ru.x; 151 float sin = -ru.y;152 153 return ::base::texture_coordinate_info(154 float3(r_position.x,r_position.y,r_position.z),155 math::normalize(cos * coordinate.tangent_u - sin * coordinate.tangent_v),156 math::normalize(cos * coordinate.tangent_v + sin * coordinate.tangent_u));157}158 159 160// Takes the standard input that every material has. It combines a couple of161// functions in one convenience function.162::base::texture_coordinate_info vmat_transform(163 float2 translation = float2(0.0, 0.0),164 float rotation = 0.0, // rotation in degrees165 float2 scaling = float2(1.0, 1.0),166 uniform ::base::texture_coordinate_system system = ::base::texture_coordinate_uvw,167 uniform int uv_space = 0168)169{170 float rotation_rad = (rotation * 3.1415926535897932384626433832f) / 180.f;171 float4x4 scale =172 float4x4(1.0 /scaling.x, 0. , 0. , 0.,173 0. , 1.0 /scaling.y , 0. , 0.,174 0. , 0. , 1.0, 0.,175 translation.x , translation.y , 0.0, 1.);176 177 float s = ::math::sin(rotation_rad);178 float c = ::math::cos(rotation_rad);179 float4x4 rotate =180 float4x4( c , -s , 0.0 , 0.0,181 s , c , 0.0 , 0.0,182 0.0, 0.0 , 1.0 , 0.0,183 0. , 0.0 , 0.0 , 1.);184 185 return transform_coordinate_2(scale*rotate, ::base::coordinate_source(system, uv_space));186}187 188::base::texture_coordinate_info vmat_transform_post_scale(189 ::base::texture_coordinate_info uvw,190 float2 scale = float2(1.0f)191)192{193 return ::base::texture_coordinate_info(194 position: float3(uvw.position.x / scale.x,195 uvw.position.y / scale.y,196 uvw.position.z / scale.x),197 tangent_u: uvw.tangent_u,198 tangent_v: uvw.tangent_v199 );200}201 202 203float3 rgb2hsl(float3 c)204[[205 ::anno::description("Converts a color value to HSL. The function outputs the hue to \n"206 "lie in the range from 0.0-1.0."),207 ::anno::author("NVIDIA vMaterials")208]]209{210 float3 hsl;211 float cMax = ::math::max(::math::max(c.x, c.y), c.z);212 float cMin = ::math::min(::math::min(c.x, c.y), c.z);213 float delta = cMax - cMin;214 215 hsl.z = (cMax + cMin) / 2.0; 216 hsl.x = ((cMax == cMin) ? 0 :217 (cMax == c.x) ? (c.y - c.z) / delta + ((c.z > c.y) ? 6.0f : 0.0f):218 (cMax == c.y) ? (c.z - c.x) / delta + 2.0 : (c.x - c.y) / delta + 4.0) / 6.0f;219 hsl.y = (hsl.z == 0.0 || hsl.z == 1.0) ? 0.0 : delta / (1.0 - ::math::abs(2.0 * hsl.z - 1.0));220 return hsl;221}222 223float f_n(float n, float a, float h, float l) {224 float k = ::math::fmod(n + h * 12.f, 12.f);225 226 return l - a * ::math::max(-1.0f, ::math::min(::math::min(k-3.0f, 9.0f-k), 1.0f));227}228 229color hsl2rgb(float3 hsl)230[[231 ::anno::description("Converts a HSL value back to a color. Note that the hue is expected to \n"232 "lie in the range from 0.0-1.0."),233 ::anno::author("NVIDIA vMaterials")234]]235{236 float h = hsl.x, s = hsl.y, l = hsl.z;237 float a = s * ::math::min(l, 1.0f - l);238 return color(f_n(0.0, a, h, l),239 f_n(8.0, a, h, l),240 f_n(4.0, a, h, l)); 241}242 243 244 245//246// flake noise utilities247//248// constants for numerical fitted curve to observed flake noise density behavior249// 1. no jitter, maximum flake diameter250const float4 ABCD = float4(-26.19771808f, 26.39663835f, 85.53857017f, -102.35069432f);251const float2 EF = float2(-101.42634862f, 118.45082288f);252// 2. jitter scale of 0.5f, maximum flake diameter253const float4 ABCD_J = float4(-0.87962159f, 0.91006603f, 0.76088203f, -0.24953308f);254const float2 EF_J = float2(-3.11456809f, 2.63430594f);255 256float density_to_probability(257 float4 abcd,258 float2 ef,259 float x)260{261 float xx = x * x;262 return (abcd.x * xx + abcd.y * x) / (abcd.z * xx * x + abcd.w * xx + ef.x * x + ef.y);263}264 265 266int hash(int seed, int i)267{268 return (i ^ seed) * 1075385539;269}270int rnd_init(int3 pos)271{272 return hash(hash(hash(0, pos.x), pos.y), pos.z);273}274 275int rnd_next(int seed) {276 // xorshift32 using signed int277 seed ^= seed << 13;278 seed ^= seed >>> 17;279 seed ^= seed << 5;280 return seed;281}282 283float rnd_value(int seed)284{285 return ::math::abs(float(seed) * 4.6566e-10f);286}287 288// apply random rotation (using "Fast Random Rotation Matrices" by James Arvo)289float3 rotate_pos(float3 pos, float3 xi)290{291 float theta = ::math::PI * 2.0f * xi.x;292 float phi = ::math::PI * 2.0f * xi.y;293 float z = xi.z * 2.0f;294 295 float r = ::math::sqrt(z);296 float[2] sp_cp = ::math::sincos(phi);297 float Vx = sp_cp[0] * r;298 float Vy = sp_cp[1] * r;299 float Vz = ::math::sqrt(2.0f - z);300 301 float[2] st_ct = ::math::sincos(theta);302 float Sx = Vx * st_ct[1] - Vy * st_ct[0];303 float Sy = Vx * st_ct[0] + Vy * st_ct[1];304 305 float3x3 M(306 Vx * Sx - st_ct[1], Vx * Sy - st_ct[0], Vx * Vz,307 Vy * Sx + st_ct[0], Vy * Sy - st_ct[1], Vy * Vz,308 Vz * Sx, Vz * Sy, 1.0f - z);309 310 return M * pos;311}312 313struct flake_noise_value { 314 // flake priority (in [0..1], 0: no flake, flakes with higher priority shadow flakes "below" them)315 float priority;316 // Stores values from the functions (once normal, another time the color)317 // current pseudo random number generator seed318 int rnd_seed;319 float4 carrier; 320};321 322// flake noise function with controllable regularity, flake size, and probability323flake_noise_value flake_noise(324 float3 pos,325 float jitter_scale = 1.0f,326 float flake_diameter = 0.75f,327 float flake_probability = 1.0f)328{329 float3 base_pos = ::math::floor(pos);330 int3 base_pos_i = int3(base_pos);331 332 // limit the flake size to the allowed maximum (such that looking at all neighbors is sufficient)333 flake_diameter = ::math::min(flake_diameter, (1.5f - 0.5f * jitter_scale) / ::math::sqrt(3.0f));334 335 flake_noise_value val(0.0f, 0, float4(0.0));336 337 for (int i = -1; i < 2; ++i) {338 for (int j = -1; j < 2; ++j) {339 for (int k = -1; k < 2; ++k) {340 341 int seed = rnd_init(base_pos_i + int3(i, j, k));342 343 seed = rnd_next(seed);344 if (rnd_value(seed) > flake_probability)345 continue;346 347 seed = rnd_next(seed);348 float priority = rnd_value(seed);349 if (priority < val.priority)350 continue; 351 352 float3 flake_pos = base_pos + float3(i, j, k) + float3(0.5f);353 354 if (jitter_scale > 0.0f) {355 seed = rnd_next(seed);356 flake_pos.x += (rnd_value(seed) - 0.5f) * jitter_scale;357 seed = rnd_next(seed);358 flake_pos.y += (rnd_value(seed) - 0.5f) * jitter_scale;359 seed = rnd_next(seed);360 flake_pos.z += (rnd_value(seed) - 0.5f) * jitter_scale;361 }362 363 float3 p = pos - flake_pos;364 if (math::dot(p, p) >= flake_diameter * flake_diameter * 4.0f)365 continue;366 367 float3 xi_rot;368 seed = rnd_next(seed);369 xi_rot.x = rnd_value(seed);370 seed = rnd_next(seed);371 xi_rot.y = rnd_value(seed);372 seed = rnd_next(seed);373 xi_rot.z = rnd_value(seed);374 p = rotate_pos(p, xi_rot);375 376 if (math::abs(p.x) <= flake_diameter &&377 ::math::abs(p.y) <= flake_diameter &&378 ::math::abs(p.z) <= flake_diameter)379 {380 val.priority = priority;381 val.rnd_seed = seed;382 }383 }384 }385 }386 387 return val;388}389 390flake_noise_value flake_noise(391 float3 position,392 float density = 0.5f,393 bool jittered = false) // jittered: slightly slower and slightly less uniform394{395 float probability = density_to_probability(jittered ? ABCD_J : ABCD, jittered ? EF_J : EF, ::math::saturate(density));396 397 return flake_noise(pos: position, jitter_scale: jittered ? 0.5f : 0.0f, flake_diameter: (jittered ? 1.25f : 1.5f) / ::math::sqrt(3.0f), flake_probability: probability);398}399 400// create a flake normal by importance sampling the Beckmann distribution with given roughness401flake_noise_value flake_normal(402 flake_noise_value val,403 float spread)404{405 if (val.priority <= 0.0f)406 {407 val.carrier = float4(::state::normal().x, ::state::normal().y, ::state::normal().z, 1.0);408 return val;409 }410 411 int seed = rnd_next(val.rnd_seed);412 float xi0 = rnd_value(seed);413 seed = rnd_next(seed);414 float xi1 = rnd_value(seed);415 416 float phi = ::math::PI * 2.0f * xi0;417 418 float roughness = spread * spread;419 420 float tantheta = ::math::sqrt(-roughness * roughness * ::math::log(1.0f - xi1));421 float sintheta = tantheta / ::math::sqrt(1.0f + tantheta * tantheta);422 float costheta = ::math::sqrt(1.0f - sintheta * sintheta);423 424 float[2] scphi = ::math::sincos(phi);425 426 val.rnd_seed = seed;427 428 float3 normal = ::state::texture_tangent_u(0) * scphi[1] * sintheta +429 ::state::texture_tangent_v(0) * scphi[0] * sintheta +430 ::state::normal() * costheta;431 432 val.carrier = float4(normal.x, normal.y, normal.z, 1.0);433 434 435 return val; 436}437 438 439 440 441 442export material Silk_Crepe_de_Chine(443 color fabric_color = color(0.982251f, 0.982251f, 0.982251f) [[444 ::anno::description("Choose the color of the fabric."),445 ::anno::display_name("Fabric Color"),446 ::anno::in_group("Appearance"),447 ::anno::ui_order(0)448 ]],449 float color_deviation = 0.f [[450 ::anno::description("Adds a variation to the reflection colors of the fabric. Higher values lead to more drastical color changes."),451 ::anno::display_name("Color Deviation"),452 ::anno::in_group("Appearance"),453 ::anno::hard_range(0.f, 1.f),454 ::anno::ui_order(1)455 ]],456 float highlight_saturation = 0.79f [[457 ::anno::description("Higher values cause reflected light to be tinted in the color of the material."),458 ::anno::display_name("Highlight Saturation"),459 ::anno::in_group("Appearance"),460 ::anno::hard_range(0.f, 1.f),461 ::anno::ui_order(2)462 ]],463 float diffuse_weight = 0.19f [[464 ::anno::description("Increasing the diffuse contribution make the material appear more flat and takes away some of its shininess."),465 ::anno::display_name("Diffuse Amount"),466 ::anno::in_group("Appearance"),467 ::anno::hard_range(0.f, 1.f),468 ::anno::ui_order(3)469 ]],470 float transmissive_weight = 0.24f [[471 ::anno::description("Lets light pass through the material and illuminate it from the other side."),472 ::anno::display_name("Translucency"),473 ::anno::in_group("Appearance"),474 ::anno::hard_range(0.f, 1.f),475 ::anno::ui_order(4)476 ]],477 float bump_strength = 0.70f [[478 ::anno::description("Specifies the strength of the bump."),479 ::anno::display_name("Bump Strength"),480 ::anno::in_group("Appearance"),481 ::anno::hard_range(0.f, 1.f),482 ::anno::ui_order(5)483 ]],484 float2 texture_translate = float2(0.f) [[485 ::anno::description("Controls the position of the texture."),486 ::anno::display_name("Texture Translate"),487 ::anno::in_group("Transform"),488 ::anno::ui_order(6)489 ]],490 float texture_rotate = 0.f [[491 ::anno::description("Rotates angle of the texture in degrees."),492 ::anno::display_name("Texture Rotate"),493 ::anno::in_group("Transform"),494 ::anno::soft_range(0.f, 360.f),495 ::anno::ui_order(7)496 ]],497 float2 texture_scale = float2(1.f) [[498 ::anno::description("Larger numbers increase the size."),499 ::anno::display_name("Texture Scale"),500 ::anno::in_group("Transform"),501 ::nvidia::core_definitions::dimension(float2(1.0f, 1.0f)),502 ::preview_scale(4.0f),503 ::anno::ui_order(8)504 ]],505 uniform int uv_space_index = 0 [[506 ::anno::description("Uses selected UV space for material."),507 ::anno::display_name("UV Space Index"),508 ::anno::in_group("Transform"),509 ::anno::ui_order(9)510 ]]511 512 513)514[[515 ::anno::author("NVIDIA vMaterials"),516 ::anno::contributor("Rüdiger Raab"),517 ::anno::display_name("Silk Crepe de Chine - White"),518 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),519 ::anno::copyright_notice(COPYRIGHT),520 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine.png"),521 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "white", "light", "neutral"))522]]523 = 524 let {525 // These parameters could be exposed globally, however, they are set as constants in the material 526 float weft_deviation = 0.41f; // note that a stronger deviation will lead to clipping behavior of the527 // bsdfs when viewing them at grazing angles528 float warp_to_weft = 0.22f;529 float warp_weft_power = 2.7f; // controls the contrast of the mixing of the warp and weft with the AO texture530 531 532 // The next parameters control the width of the highlight533 float warp_roughness = 0.2f; // Width of the warp roughness534 float weft_roughness = 0.14f; // Width of the weft roughness535 float warpweft_noise_amount = 1.0f; // we use noise to introduce irregularities in the appearance of the536 // BDSF across the material surface537 538 texture_2d weave_normal_texture = texture_2d("./textures/crepe_de_chine_norm.jpg", ::tex::gamma_linear);539 texture_2d weave_var_texture = texture_2d("./textures/crepe_de_chine_var.jpg", ::tex::gamma_linear);540 texture_2d glizz_texture = texture_2d("./textures/fabric_noise_multi_R_noise1_G_noise_2.png", ::tex::gamma_linear);541 542 // preparing fabric colors543 // We will be deriving all colors of the fabric from a single color which requires some amount of remapping544 // the values in HSL space and then converting them back to RGB545 float3 fabric_hsl_color = rgb2hsl(float3(fabric_color));546 547 color diffuse_transmission_color = hsl2rgb(548 float3( fabric_hsl_color.x,549 fabric_hsl_color.y * ::math::pow(fabric_hsl_color.z, 0.26f),550 0.76f551 )552 );553 554 float remap_thread_brightness = fabric_hsl_color.z * 0.85 + 0.15;555 556 color warp_color = hsl2rgb(557 float3( fabric_hsl_color.x - (color_deviation * 0.3), // - Shifting color by color deviation558 ::math::lerp(0.0f, highlight_saturation, fabric_hsl_color.y * 0.85f), //scaling the max saturation down by 15%559 remap_thread_brightness) // remapping brightness for weft highlight560 );561 562 color weft_color = hsl2rgb(563 float3( fabric_hsl_color.x + (color_deviation * 0.3), // + Shifting color by color deviation564 ::math::lerp(0.0f, highlight_saturation, fabric_hsl_color.y * 0.85f),565 remap_thread_brightness566 )567 );568 569 // Prepare UV coordinates for texture and noise lookups570 ::base::texture_coordinate_info uvw = vmat_transform(571 translation: texture_translate,572 rotation: texture_rotate,573 scaling: texture_scale * 0.4f, // scale to fit default size of 1m for UV 0...1,574 system: ::base::texture_coordinate_uvw,575 uv_space: uv_space_index576 );577 578 ::base::texture_coordinate_info uvw_post = vmat_transform_post_scale(uvw: uvw, scale: float2(0.2f));579 580 // Flake normal581 flake_noise_value flake_noise_val = flake_noise(582 position: float3(uvw.position * 2500.0f),583 density: 0.72f,584 jittered: true585 );586 587 flake_noise_value flake_noise_val2 = flake_normal(588 val: flake_noise_val,589 spread: 0.38f // controllable from outside590 );591 592 float3 flake_normal = float3(flake_noise_val2.carrier.x, flake_noise_val2.carrier.y, flake_noise_val2.carrier.z);593 594 // TEXTURES595 // Glizz noise textures596 float3 glizz_lookup = tex::lookup_float3(597 glizz_texture, 598 float2(uvw.position.x,uvw.position.y)599 );600 601 602 // Weave AO/brightness variation603 float var_val = float3(vmat_file_texture(604 texture: weave_var_texture,605 uvw: uvw_post606 )).x;607 608 float var_val_pow = ::math::pow(var_val, warp_weft_power); // the power values controls the contrast of the lookup609 // and later in the code the mixing of the warp and weft lobe610 611 float3 weave_normal = normalmap_normal(612 texture: weave_normal_texture,613 factor: bump_strength, 614 uvw: uvw_post // we use the downscaled small UV cordinates here615 );616 617 // BSDFs618 // (single) Warp BSDF619 bsdf warp_bsdf = ::df::simple_glossy_bsdf(620 roughness_u: 0.88f,621 roughness_v: histogram_range(glizz_lookup.x, warpweft_noise_amount, warp_roughness), // adjusting noise texture to show some glizzening effect622 tint: warp_color,623 tangent_u: uvw.tangent_u, // required to rotate the anisotropic highlight correctly624 mode: ::df::scatter_reflect625 );626 627 // (double) Weft BSDF628 bsdf weft_bsdf = ::df::microfacet_ggx_smith_bsdf(629 roughness_u: histogram_range(glizz_lookup.y, warpweft_noise_amount, weft_roughness), // adjusting noise texture to show some glizzening effect630 roughness_v: 0.58f,631 tint: weft_color,632 multiscatter_tint: weft_color,633 tangent_u: uvw.tangent_u // required to rotate the anisotropic highlight correctly634 );635 636 float3 weft_left_normal = ::math::normalize(::state::normal() - uvw.tangent_u * weft_deviation);637 float3 weft_right_normal = ::math::normalize(::state::normal() + uvw.tangent_u * weft_deviation);638 639 //adding flake detail normals640 float3 weft_left_detail_normal = add_detail_normal(641 n: weft_left_normal, // left-shifted normal642 nd: flake_normal643 );644 645 float3 weft_right_detail_normal = add_detail_normal(646 n: weft_right_normal, // right-shifted normal647 nd: flake_normal648 );649 650 651 // Left lobe with detail normal652 bsdf left_lobe_bsdf = ::df::weighted_layer(653 weight: 1.0f,654 layer: weft_bsdf,655 base: bsdf(),656 normal: weft_left_detail_normal 657 );658 659 // Right lobe with detail normal660 bsdf right_lobe_bsdf = ::df::weighted_layer(661 weight: 1.0f,662 layer: weft_bsdf,663 base: bsdf(),664 normal: weft_right_detail_normal 665 );666 667 668 bsdf left_right_lobe_bsdf = ::df::weighted_layer(669 base: left_lobe_bsdf,670 layer: right_lobe_bsdf,671 weight: 0.5f672 );673 674 // Warp and Weft BSDF combined and weighted via custom curve layer675 bsdf warp_weft_combined_bsdf = ::df::custom_curve_layer(676 base: df::weighted_layer(677 layer: warp_bsdf,678 base: left_right_lobe_bsdf,679 weight: var_val_pow * (warp_to_weft > 1.0f ? 1.0 - 1.0f / warp_to_weft : warp_to_weft)680 ),681 layer: bsdf(),682 normal_reflectivity: 0.11f,683 grazing_reflectivity: 1.0f,684 exponent: 3.63f,685 weight: 1.0f686 );687 688 689 // Diffuse Transmission BSDF690 bsdf diff_transmission_bsdf = ::df::diffuse_transmission_bsdf(691 tint: diffuse_transmission_color692 );693 694 // Diffuse Reflection BSDF695 bsdf diff_reflection_bsdf = ::df::diffuse_reflection_bsdf(696 tint: fabric_color697 );698 699 700 // Computing weight contributions for the BSDF components for final mix701 702 // Diffuse Transmission Component703 ::df::bsdf_component diffuse_transmission_component(704 weight: transmissive_weight * 0.68f,705 component: diff_transmission_bsdf706 );707 708 // Diffuse Reflection Component709 ::df::bsdf_component diffuse_reflection_component(710 weight: diffuse_weight * 0.68f,711 component: diff_reflection_bsdf712 );713 714 // Mixed Glossy Lobes Component715 ::df::bsdf_component warp_weft_combine_component(716 weight: 2.0f - 0.68 * (transmissive_weight + diffuse_weight),717 component: warp_weft_combined_bsdf718 );719 720 // Final Mix721 bsdf final_bsdf = ::df::normalized_mix(722 components: df::bsdf_component[](723 diffuse_transmission_component,724 diffuse_reflection_component,725 warp_weft_combine_component726 ));727 728 /*729 bsdf transmission_warp_weft_mix = ::df::weighted_layer(730 base: warp_weft_combined_bsdf,731 layer: diff_transmission_bsdf,732 weight: transmissive_weight * 0.68f733 );734 735 bsdf diffuse_warp_weft_mix = ::df::weighted_layer(736 base: warp_weft_combined_bsdf,737 layer: diff_reflection_bsdf,738 weight: diffuse_weight * 0.68f739 );740 741 bsdf final_bsdf = ::df::weighted_layer(742 base: transmission_warp_weft_mix,743 layer: diffuse_warp_weft_mix,744 weight: 0.5f745 );746 */747 748 } in749 material(750 thin_walled: true,751 surface: material_surface(752 scattering: final_bsdf753 ),754 ior: color(1.0f),755 geometry: material_geometry(756 normal: weave_normal757 )758);759 760 761// 2762export material Silk_Crepe_de_Chine_Natural(*)763[[764 ::anno::author("NVIDIA vMaterials"),765 ::anno::contributor("Rüdiger Raab"),766 ::anno::display_name("Silk Crepe de Chine - Natural"),767 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),768 ::anno::copyright_notice(COPYRIGHT),769 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Natural.png"),770 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "natural", "light", "warm", "white"))771]] = Silk_Crepe_de_Chine(772 fabric_color: color(1.000000f, 0.921582f, 0.644480f),773 color_deviation: 0.0f,774 highlight_saturation: 0.79f,775 diffuse_weight: 0.19f,776 transmissive_weight: 0.24f,777 bump_strength: 0.70f,778 texture_translate: float2(0.0f),779 texture_rotate: 0.0f,780 texture_scale: float2(1.0f),781 uv_space_index: 0782);783 784 785 786// 3787export material Silk_Crepe_de_Chine_Champagne(*)788[[789 ::anno::author("NVIDIA vMaterials"),790 ::anno::contributor("Rüdiger Raab"),791 ::anno::display_name("Silk Crepe de Chine - Champagne"),792 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),793 ::anno::copyright_notice(COPYRIGHT),794 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Champagne.png"),795 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "light", "white", "champagne", "pastel", "warm"))796]] = Silk_Crepe_de_Chine(797 fabric_color: color(0.871367f, 0.672443f, 0.450786f),798 color_deviation: 0.08f,799 highlight_saturation: 0.79f,800 diffuse_weight: 0.19f,801 transmissive_weight: 0.24f,802 bump_strength: 0.70f,803 texture_translate: float2(0.0f),804 texture_rotate: 0.0f,805 texture_scale: float2(1.0f),806 uv_space_index: 0807);808 809 810 811// 4812export material Silk_Crepe_de_Chine_Rose(*)813[[814 ::anno::author("NVIDIA vMaterials"),815 ::anno::contributor("Rüdiger Raab"),816 ::anno::display_name("Silk Crepe de Chine - Rose"),817 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),818 ::anno::copyright_notice(COPYRIGHT),819 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Rose.png"),820 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "rose", "light", "warm", "pastel"))821]] = Silk_Crepe_de_Chine(822 fabric_color: color(1.000000f, 0.491021f, 0.332452f),823 color_deviation: 0.08f,824 highlight_saturation: 0.95f,825 diffuse_weight: 0.1f,826 transmissive_weight: 0.24f,827 bump_strength: 0.70f,828 texture_translate: float2(0.0f),829 texture_rotate: 0.0f,830 texture_scale: float2(1.0f),831 uv_space_index: 0832);833 834 835 836// 5837export material Silk_Crepe_de_Chine_Pink(*)838[[839 ::anno::author("NVIDIA vMaterials"),840 ::anno::contributor("Rüdiger Raab"),841 ::anno::display_name("Silk Crepe de Chine - Pink"),842 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),843 ::anno::copyright_notice(COPYRIGHT),844 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Pink.png"),845 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "pink", "warm", "red"))846]] = Silk_Crepe_de_Chine(847 fabric_color: color(0.822786f, 0.102242f, 0.144128f),848 color_deviation: 0.0f,849 highlight_saturation: 0.79f,850 diffuse_weight: 0.19f,851 transmissive_weight: 0.24f,852 bump_strength: 0.70f,853 texture_translate: float2(0.0f),854 texture_rotate: 0.0f,855 texture_scale: float2(1.0f),856 uv_space_index: 0857);858 859 860 861// 6862export material Silk_Crepe_de_Chine_Moss(*)863[[864 ::anno::author("NVIDIA vMaterials"),865 ::anno::contributor("Rüdiger Raab"),866 ::anno::display_name("Silk Crepe de Chine - Moss"),867 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),868 ::anno::copyright_notice(COPYRIGHT),869 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Moss.png"),870 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "green", "moss", "light"))871]] = Silk_Crepe_de_Chine(872 fabric_color: color(0.158961f, 0.318547f, 0.045186f),873 color_deviation: 0.0f,874 highlight_saturation: 0.92f,875 diffuse_weight: 0.0f,876 transmissive_weight: 0.34f,877 bump_strength: 0.70f,878 texture_translate: float2(0.0f),879 texture_rotate: 0.0f,880 texture_scale: float2(1.0f),881 uv_space_index: 0882);883 884 885 886// 7887export material Silk_Crepe_de_Chine_Purple(*)888[[889 ::anno::author("NVIDIA vMaterials"),890 ::anno::contributor("Rüdiger Raab"),891 ::anno::display_name("Silk Crepe de Chine - Purple"),892 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),893 ::anno::copyright_notice(COPYRIGHT),894 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Purple.png"),895 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "purple", "saturated"))896]] = Silk_Crepe_de_Chine(897 fabric_color: color(0.287441f, 0.006995f, 0.584078f),898 color_deviation: 0.0f,899 highlight_saturation: 0.79f,900 diffuse_weight: 0.19f,901 transmissive_weight: 0.24f,902 bump_strength: 0.70f,903 texture_translate: float2(0.0f),904 texture_rotate: 0.0f,905 texture_scale: float2(1.0f),906 uv_space_index: 0907);908 909 910 911// 8912export material Silk_Crepe_de_Chine_Sky_Blue(*)913[[914 ::anno::author("NVIDIA vMaterials"),915 ::anno::contributor("Rüdiger Raab"),916 ::anno::display_name("Silk Crepe de Chine - Sky Blue"),917 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),918 ::anno::copyright_notice(COPYRIGHT),919 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Sky_Blue.png"),920 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "blue", "sky", "cool"))921]] = Silk_Crepe_de_Chine(922 fabric_color: color(0.000911f, 0.238398f, 0.708376f),923 color_deviation: 0.0f,924 highlight_saturation: 0.79f,925 diffuse_weight: 0.19f,926 transmissive_weight: 0.24f,927 bump_strength: 0.70f,928 texture_translate: float2(0.0f),929 texture_rotate: 0.0f,930 texture_scale: float2(1.0f),931 uv_space_index: 0932);933 934 935 936// 9937export material Silk_Crepe_de_Chine_Royal_Blue(*)938[[939 ::anno::author("NVIDIA vMaterials"),940 ::anno::contributor("Rüdiger Raab"),941 ::anno::display_name("Silk Crepe de Chine - Royal Blue"),942 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),943 ::anno::copyright_notice(COPYRIGHT),944 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Royal_Blue.png"),945 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "blue", "royal", "saturated", "cool"))946]] = Silk_Crepe_de_Chine(947 fabric_color: color(0.004777f, 0.004777f, 0.381326f),948 color_deviation: 0.0f,949 highlight_saturation: 0.95f,950 diffuse_weight: 0.06f,951 transmissive_weight: 0.11f,952 bump_strength: 0.70f,953 texture_translate: float2(0.0f),954 texture_rotate: 0.0f,955 texture_scale: float2(1.0f),956 uv_space_index: 0957);958 959 960 961// 10962export material Silk_Crepe_de_Chine_Red(*)963[[964 ::anno::author("NVIDIA vMaterials"),965 ::anno::contributor("Rüdiger Raab"),966 ::anno::display_name("Silk Crepe de Chine - Red"),967 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),968 ::anno::copyright_notice(COPYRIGHT),969 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Red.png"),970 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "red", "saturated", "warm"))971]] = Silk_Crepe_de_Chine(972 fabric_color: color(0.496933f, 0.005182f, 0.000000f),973 color_deviation: 0.0f,974 highlight_saturation: 0.95f,975 diffuse_weight: 0.06f,976 transmissive_weight: 0.11f,977 bump_strength: 0.70f,978 texture_translate: float2(0.0f),979 texture_rotate: 0.0f,980 texture_scale: float2(1.0f),981 uv_space_index: 0982);983 984 985 986// 11987export material Silk_Crepe_de_Chine_Yellow(*)988[[989 ::anno::author("NVIDIA vMaterials"),990 ::anno::contributor("Rüdiger Raab"),991 ::anno::display_name("Silk Crepe de Chine - Yellow"),992 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),993 ::anno::copyright_notice(COPYRIGHT),994 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Yellow.png"),995 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "yellow", "light", "warm", "saturated"))996]] = Silk_Crepe_de_Chine(997 fabric_color: color(0.708376f, 0.456411f, 0.003035f),998 color_deviation: 0.0f,999 highlight_saturation: 0.99f,1000 diffuse_weight: 0.19f,1001 transmissive_weight: 0.24f,1002 bump_strength: 0.70f,1003 texture_translate: float2(0.0f),1004 texture_rotate: 0.0f,1005 texture_scale: float2(1.0f),1006 uv_space_index: 01007);1008 1009 1010 1011// 121012export material Silk_Crepe_de_Chine_Forest_Green(*)1013[[1014 ::anno::author("NVIDIA vMaterials"),1015 ::anno::contributor("Rüdiger Raab"),1016 ::anno::display_name("Silk Crepe de Chine - Forest Green"),1017 ::anno::description("A silk material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),1018 ::anno::copyright_notice(COPYRIGHT),1019 ::anno::thumbnail("./.thumbs/Silk_Crepe_de_Chine.Silk_Crepe_de_Chine_Forest_Green.png"),1020 ::anno::key_words(string[]("fabric", "translucent", "silk", "woven", "crepe", "chine", "iridescent", "fashion", "design", "forest", "green", "saturated", "dark"))1021]] = Silk_Crepe_de_Chine(1022 fabric_color: color(0.001214f, 0.063010f, 0.025187f),1023 color_deviation: 0.0f,1024 highlight_saturation: 0.79f,1025 diffuse_weight: 0.19f,1026 transmissive_weight: 0.24f,1027 bump_strength: 0.70f,1028 texture_translate: float2(0.0f),1029 texture_rotate: 0.0f,1030 texture_scale: float2(1.0f),1031 uv_space_index: 01032);