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 Polyester_Crepe_de_Chine(443 color fabric_color = color(0.799103f, 0.799103f, 0.799103f) [[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.9f [[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.21f [[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.16f [[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(2.5f),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("Polyester Crepe de Chine - White"),518 ::anno::description("A polyester 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/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine.png"),521 ::anno::key_words(string[]("fabric", "translucent", "polyester", "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 // Computing weight contributions for the BSDF components dc_3, dc_2 and dc_1 for final mix700 ::df::bsdf_component dc_3(701 weight: (2.0f - transmissive_weight * 0.68f - diffuse_weight * 0.68f),702 component: warp_weft_combined_bsdf703 );704 705 ::df::bsdf_component dc_2(706 weight: transmissive_weight * 0.68f,707 component: diff_transmission_bsdf708 );709 710 ::df::bsdf_component dc_1(711 weight: diffuse_weight * 0.68f,712 component: diff_reflection_bsdf713 );714 715 // Final Mix716 bsdf final_bsdf = ::df::normalized_mix(717 components: ::df::bsdf_component[](dc_3, dc_2, dc_1)718 );719 720 /*721 bsdf transmission_warp_weft_mix = ::df::weighted_layer(722 base: warp_weft_combined_bsdf,723 layer: diff_transmission_bsdf,724 weight: transmissive_weight * 0.68f725 );726 727 bsdf diffuse_warp_weft_mix = ::df::weighted_layer(728 base: warp_weft_combined_bsdf,729 layer: diff_reflection_bsdf,730 weight: diffuse_weight * 0.68f731 );732 733 bsdf final_bsdf = ::df::weighted_layer(734 base: transmission_warp_weft_mix,735 layer: diffuse_warp_weft_mix,736 weight: 0.5f737 );738 */739 740 } in741 material(742 thin_walled: true,743 surface: material_surface(744 scattering: final_bsdf745 ),746 ior: color(1.0f),747 geometry: material_geometry(748 normal: weave_normal749 )750);751 752 753// 2754export material Polyester_Crepe_de_Chine_Red(*)755[[756 ::anno::author("NVIDIA vMaterials"),757 ::anno::contributor("Rüdiger Raab"),758 ::anno::display_name("Polyester Crepe de Chine - Red"),759 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),760 ::anno::copyright_notice(COPYRIGHT),761 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Red.png"),762 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "red", "warm", "saturated"))763]] = Polyester_Crepe_de_Chine(764 fabric_color: color(0.361307f, 0.004777f, 0.004777f),765 color_deviation: 0.0f,766 highlight_saturation: 0.93f,767 diffuse_weight: 0.3f,768 transmissive_weight: 0.16f,769 bump_strength: 0.70f,770 texture_translate: float2(0.0f),771 texture_rotate: 0.0f,772 texture_scale: float2(1.0f),773 uv_space_index: 0774);775 776 777// 3778export material Polyester_Crepe_de_Chine_Orange(*)779[[780 ::anno::author("NVIDIA vMaterials"),781 ::anno::contributor("Rüdiger Raab"),782 ::anno::display_name("Polyester Crepe de Chine - Orange"),783 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),784 ::anno::copyright_notice(COPYRIGHT),785 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Orange.png"),786 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "orange", "warm", "saturated"))787]] = Polyester_Crepe_de_Chine(788 fabric_color: color(0.830770f, 0.132868f, 0.003035f),789 color_deviation: 0.0f,790 highlight_saturation: 0.93f,791 diffuse_weight: 0.21f,792 transmissive_weight: 0.16f,793 bump_strength: 0.70f,794 texture_translate: float2(0.0f),795 texture_rotate: 0.0f,796 texture_scale: float2(1.0f),797 uv_space_index: 0798);799 800 801// 4802export material Polyester_Crepe_de_Chine_Pink(*)803[[804 ::anno::author("NVIDIA vMaterials"),805 ::anno::contributor("Rüdiger Raab"),806 ::anno::display_name("Polyester Crepe de Chine - Pink"),807 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),808 ::anno::copyright_notice(COPYRIGHT),809 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Pink.png"),810 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "pink", "saturated"))811]] = Polyester_Crepe_de_Chine(812 fabric_color: color(0.838799f, 0.027321f, 0.147027f),813 color_deviation: 0.0f,814 highlight_saturation: 0.93f,815 diffuse_weight: 0.21f,816 transmissive_weight: 0.16,817 bump_strength: 0.70f,818 texture_translate: float2(0.0f),819 texture_rotate: 0.0f,820 texture_scale: float2(1.0f),821 uv_space_index: 0822);823 824 825// 5826export material Polyester_Crepe_de_Chine_Rose(*)827[[828 ::anno::author("NVIDIA vMaterials"),829 ::anno::contributor("Rüdiger Raab"),830 ::anno::display_name("Polyester Crepe de Chine - Rose"),831 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),832 ::anno::copyright_notice(COPYRIGHT),833 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Rose.png"),834 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "rose", "warm"))835]] = Polyester_Crepe_de_Chine(836 fabric_color: color(0.686685f, 0.168269f, 0.278894f),837 color_deviation: 0.0f,838 highlight_saturation: 0.93f,839 diffuse_weight: 0.21f,840 transmissive_weight: 0.16f,841 bump_strength: 0.70f,842 texture_translate: float2(0.0f),843 texture_rotate: 0.0f,844 texture_scale: float2(1.0f),845 uv_space_index: 0846);847 848 849// 6850export material Polyester_Crepe_de_Chine_Purple(*)851[[852 ::anno::author("NVIDIA vMaterials"),853 ::anno::contributor("Rüdiger Raab"),854 ::anno::display_name("Polyester Crepe de Chine - Purple"),855 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),856 ::anno::copyright_notice(COPYRIGHT),857 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Purple.png"),858 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "purple", "saturated"))859]] = Polyester_Crepe_de_Chine(860 fabric_color: color(0.246201f, 0.025187f, 0.177888f),861 color_deviation: 0.05f,862 highlight_saturation: 0.93f,863 diffuse_weight: 0.21f,864 transmissive_weight: 0.16f,865 bump_strength: 0.70f,866 texture_translate: float2(0.0f),867 texture_rotate: 0.0f,868 texture_scale: float2(1.0f),869 uv_space_index: 0870);871 872 873// 7874export material Polyester_Crepe_de_Chine_Sky_Blue(*)875[[876 ::anno::author("NVIDIA vMaterials"),877 ::anno::contributor("Rüdiger Raab"),878 ::anno::display_name("Polyester Crepe de Chine - Sky Blue"),879 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),880 ::anno::copyright_notice(COPYRIGHT),881 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Sky_Blue.png"),882 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "sky", "blue", "cool"))883]] = Polyester_Crepe_de_Chine(884 fabric_color: color(0.080220f, 0.230740f, 0.558340f),885 color_deviation: 0.0f,886 highlight_saturation: 0.93f,887 diffuse_weight: 0.21f,888 transmissive_weight: 0.16f,889 bump_strength: 0.70f,890 texture_translate: float2(0.0f),891 texture_rotate: 0.0f,892 texture_scale: float2(1.0f),893 uv_space_index: 0894);895 896 897// 8898export material Polyester_Crepe_de_Chine_Anthracite(*)899[[900 ::anno::author("NVIDIA vMaterials"),901 ::anno::contributor("Rüdiger Raab"),902 ::anno::display_name("Polyester Crepe de Chine - Anthracite"),903 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),904 ::anno::copyright_notice(COPYRIGHT),905 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Anthracite.png"),906 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "anthracite", "gray", "dark", "neutral"))907]] = Polyester_Crepe_de_Chine(908 fabric_color: color(0.034340f, 0.049707f, 0.052861f),909 color_deviation: 0.0f,910 highlight_saturation: 0.93f,911 diffuse_weight: 0.21f,912 transmissive_weight: 0.16f,913 bump_strength: 0.70f,914 texture_translate: float2(0.0f),915 texture_rotate: 0.0f,916 texture_scale: float2(1.0f),917 uv_space_index: 0918);919 920 921// 9922export material Polyester_Crepe_de_Chine_Petrol(*)923[[924 ::anno::author("NVIDIA vMaterials"),925 ::anno::contributor("Rüdiger Raab"),926 ::anno::display_name("Polyester Crepe de Chine - Petrol"),927 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),928 ::anno::copyright_notice(COPYRIGHT),929 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Petrol.png"),930 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "petrol", "cool", "saturated"))931]] = Polyester_Crepe_de_Chine(932 fabric_color: color(0.003035f, 0.130136f, 0.152926f),933 color_deviation: 0.0f,934 highlight_saturation: 0.93f,935 diffuse_weight: 0.21f,936 transmissive_weight: 0.16f,937 bump_strength: 0.70f,938 texture_translate: float2(0.0f),939 texture_rotate: 0.0f,940 texture_scale: float2(1.0f),941 uv_space_index: 0942);943 944 945// 10946export material Polyester_Crepe_de_Chine_Black(*)947[[948 ::anno::author("NVIDIA vMaterials"),949 ::anno::contributor("Rüdiger Raab"),950 ::anno::display_name("Polyester Crepe de Chine - Black"),951 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),952 ::anno::copyright_notice(COPYRIGHT),953 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Black.png"),954 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "black", "dark", "neutral"))955]] = Polyester_Crepe_de_Chine(956 fabric_color: color(0.003035f, 0.003035f, 0.003035f),957 color_deviation: 0.0f,958 highlight_saturation: 0.93f,959 diffuse_weight: 0.21f,960 transmissive_weight: 0.16f,961 bump_strength: 0.70f,962 texture_translate: float2(0.0f),963 texture_rotate: 0.0f,964 texture_scale: float2(1.0f),965 uv_space_index: 0966);967 968 969// 11970export material Polyester_Crepe_de_Chine_Dark_Green(*)971[[972 ::anno::author("NVIDIA vMaterials"),973 ::anno::contributor("Rüdiger Raab"),974 ::anno::display_name("Polyester Crepe de Chine - Dark Green"),975 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),976 ::anno::copyright_notice(COPYRIGHT),977 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Dark_Green.png"),978 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "dark", "green", "saturated"))979]] = Polyester_Crepe_de_Chine(980 fabric_color: color(0.015996f, 0.109462f, 0.015996f),981 color_deviation: 0.0f,982 highlight_saturation: 0.93f,983 diffuse_weight: 0.21f,984 transmissive_weight: 0.16f,985 bump_strength: 0.70f,986 texture_translate: float2(0.0f),987 texture_rotate: 0.0f,988 texture_scale: float2(1.0f),989 uv_space_index: 0990);991 992 993// 12994export material Polyester_Crepe_de_Chine_Lime_Green(*)995[[996 ::anno::author("NVIDIA vMaterials"),997 ::anno::contributor("Rüdiger Raab"),998 ::anno::display_name("Polyester Crepe de Chine - Lime Green"),999 ::anno::description("A polyester material woven in a Crepe de Chine fashion. It features color deviation to simulate color shifting in the material."),1000 ::anno::copyright_notice(COPYRIGHT),1001 ::anno::thumbnail("./.thumbs/Polyester_Crepe_de_Chine.Polyester_Crepe_de_Chine_Lime_Green.png"),1002 ::anno::key_words(string[]("fabric", "translucent", "polyester", "woven", "crepe", "chine", "iridescent", "fashion", "design", "synthetic", "lime", "green", "saturated"))1003]] = Polyester_Crepe_de_Chine(1004 fabric_color: color(0.184475f, 0.597202f, 0.031896f),1005 color_deviation: 0.0f,1006 highlight_saturation: 0.93f,1007 diffuse_weight: 0.21f,1008 transmissive_weight: 0.16f,1009 bump_strength: 0.70f,1010 texture_translate: float2(0.0f),1011 texture_rotate: 0.0f,1012 texture_scale: float2(1.0f),1013 uv_space_index: 01014);