Team Ai
Datasetpublic

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.

sourceHugging Faceotherupdated 29d agoView on Hugging Face
0likes3.7kdownloads
SimPBR.mdl563 linesDownload Raw Back to materials
1/*****************************************************************************2*     Copyright 1986-2020 NVIDIA Corporation. All rights reserved.3******************************************************************************4 5 MDL MATERIALS ARE PROVIDED PURSUANT TO AN END USER LICENSE  AGREEMENT,6 WHICH WAS ACCEPTED IN ORDER TO GAIN ACCESS TO THIS FILE.  IN PARTICULAR,7 THE MDL MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,8 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF9 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF10 COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL NVIDIA11 CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING12 ANY GENERAL, SPECIAL,  INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,13 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF14 THE USE OR INABILITY TO USE THE MDL MATERIALS OR FROM OTHER DEALINGS IN15 THE MDL MATERIALS.16*/17 18mdl 1.4;19 20import ::df::*;21import ::state::*;22import ::math::*;23import ::base::*;24import ::tex::*;25import ::anno::*;26 27import ::nvidia::core_definitions::file_texture;28import ::nvidia::core_definitions::normalmap_texture;29 30using .::SimPBR_Model import *;31using .::baking_annotations import *;32 33export material SimPBR(34    // -------------------- DIFFUSE REFLECTION ----------------------35    color diffuse_color_constant = color(0.2f)36    [[37        anno::display_name("Albedo Base Color"),38        anno::description("The base albedo color to use if no texture is specified"),39        anno::in_group("Diffuse")40    ]],41    uniform texture_2d diffuse_texture = texture_2d()42    [[43        anno::display_name("Albedo Map"),44        anno::description("The texture specifying the albedo value to use"),45        anno::in_group("Diffuse")46    ]],47    uniform color diffuse_tint = color(1.0f)48    [[49        anno::display_name("Albedo Tint"),50        anno::description("This tints the albedo color or texture contant"),51        anno::in_group("Diffuse")52    ]],53    uniform bool enable_transmission = false54    [[55        anno::display_name("Enable Diffuse Transmission"),56        anno::description("Enables the diffuse transmission of light through thin diffuse scattering layer"),57        anno::in_group("Diffuse")58    ]],59    uniform float opacity_ratio = 1.f60    [[61        anno::enable_if("enable_transmission == true"),62        anno::display_name("Opacity Ratio"),63        anno::description("Amount of opacity"),64        anno::in_group("Diffuse")65    ]],66    uniform color opacity_tint = color(1.0f)67    [[68        anno::enable_if("enable_transmission == true"),69        anno::display_name("Diffuse transmission tint"),70        anno::description("Base diffuse transmission color"),71        anno::in_group("Diffuse")72    ]],73    uniform float opacity_multiplier = 1.f74    [[75        anno::enable_if("enable_transmission == true"),76        anno::display_name("Diffuse transmission multiplier"),77        anno::description("Base diffuse transmission multiplier"),78        anno::in_group("Diffuse")79    ]],80 81    // -------------------- SPECULAR REFLECTION ----------------------82    float reflection_roughness_constant = 0.5f83    [[84        anno::display_name("Roughness Amount"),85        anno::hard_range(0.0,1.),86        anno::description("Higher roughness values lead to more blurry reflections"),87        anno::in_group("Specular")88    ]],89    uniform float reflection_roughness_texture_influence = 0.0f90    [[91        anno::display_name("Roughness Map Influence"),92        anno::hard_range(0.0, 1.),93        anno::description("Blends between the constant value and the lookup of the roughness texture"),94        anno::in_group("Specular")95    ]],96    uniform texture_2d reflectionroughness_texture = texture_2d()97    [[98        anno::display_name("Roughness Map"),99        anno::in_group("Specular")100    ]],101 102    float anisotropy_constant = 0.0f103    [[104        anno::display_name("Anisotropy Amount"),105        anno::hard_range(-1.,1.),106        anno::description("0 for isotropic, extents of -1 to 1 for anisotropy"),107        anno::in_group("Specular")108    ]],109    uniform float anisotropy_texture_influence = 0.0f110    [[111        anno::display_name("Anisotropy Map Influence"),112        anno::hard_range(0.0, 1.),113        anno::description("Blends between the constant value and the lookup of the anisotropy texture"),114        anno::in_group("Specular")115    ]],116    uniform texture_2d anisotropy_texture = texture_2d()117    [[118        anno::display_name("Anisotropy Map"),119        anno::in_group("Specular")120    ]],121 122    float metallic_constant = 0.f123    [[124        anno::display_name("Metallic Amount"),125        anno::hard_range(0.0,1.),126        anno::description("Metallic Material"),127        anno::in_group("Specular")128    ]],129    uniform float metallic_texture_influence = 0.0f130    [[131        anno::display_name("Metallic Map Influence"),132        anno::hard_range(0.0, 1.),133        anno::description("Blends between the constant value and the lookup of the metallic texture"),134        anno::in_group("Specular")135    ]],136    uniform texture_2d metallic_texture = texture_2d()137    [[138        anno::display_name("Metallic Map"),139        anno::in_group("Specular")140    ]],141 142    float specular_constant = 1.f143    [[144        anno::display_name("Specular amount"),145        anno::hard_range(0.0, 1.0),146        anno::description("Scale of the specular component"),147        anno::in_group("Specular")148    ]],149    uniform texture_2d specular_texture = texture_2d()150    [[151        anno::display_name("Specular Map"),152        anno::in_group("Specular")153    ]],154 155    // -------------------- ORM ----------------------156    uniform bool enable_ORM_texture = true157    [[158        anno::display_name("Enable ORM Texture"),159        anno::description("When True the ORM texture will be used to extract the Occlusion, Roughness and Metallic Map"),160        anno::in_group("Reflectivity")161    ]],162    uniform texture_2d ORM_texture = texture_2d()163    [[164        anno::display_name("ORM Map"),165        anno::description("Texture that hae Occlusion, Roughness and Metallic map stored in the respective r, g and b channels"),166        anno::in_group("Reflectivity")167    ]],168 169    // -------------------- Clearcoat ----------------------170    uniform bool enable_clearcoat = false171    [[172        anno::display_name("Enable Clearcoat Layer"),173        anno::description("Adds a  clearcoat layer on top of the material when enabled"),174        anno::in_group("Clearcoat")175    ]],176    color clearcoat_tint = color(1.0f)177    [[178        anno::display_name("Clearcoat Tint"),179        anno::description("Clearcoat is tinted and affects the underlying material"),180        anno::in_group("Clearcoat")181    ]],182    float clearcoat_transparency = 1.0f183    [[184        anno::display_name("Clearcoat Transparency"),185        anno::description("Adjusts the transparency of the clearcoat. Can be turned into a fully opaque clearcoat "186        "covering the underlying layer"),187        anno::in_group("Clearcoat")188    ]],189    float clearcoat_reflection_roughness = 0.0f190    [[191        anno::display_name("Clearcoat Roughness"),192        anno::description("Higher roughness values lead to more blurry reflections"),193        anno::hard_range(0.0f, 1.0f),194        anno::in_group("Clearcoat")195    ]],196    float clearcoat_weight = 1.0f197    [[198        anno::display_name("Clearcoat Weight"),199        anno::description("Sets the weight for clearcoat layer"),200        anno::hard_range(0.0f, 1.0f),201        anno::in_group("Clearcoat")202    ]],203    float clearcoat_flatten = 1.0f204    [[205        anno::display_name("Clearcoat Flatten"),206        anno::description("Flattens the clearcoat to even out the underlying bump maps"),207        anno::hard_range(0.0f, 1.0f),208        anno::in_group("Clearcoat")209    ]],210    float clearcoat_ior = 1.56f211    [[212        anno::display_name("Clearcoat IOR"),213        anno::description("Sets the Index of refraction for the clearcoat layer"),214        anno::soft_range(1.0f, 4.0f),215        anno::in_group("Clearcoat")216    ]],217    uniform float clearcoat_bump_factor = 1.f218    [[219        anno::display_name("Clearcoat Normal Map Strength"),220        anno::description("Strength of normal map."),221        anno::in_group("Clearcoat")222    ]],223 224    float3 clearcoat_normal_input = float3(0.0, 0.0, 0.0),225    uniform texture_2d clearcoat_normalmap_texture = texture_2d()226    [[227        anno::display_name("Clearcoat Normal Map"),228        anno::description("Enables the usage of the normalmap texture"),229        anno::in_group("Clearcoat")230    ]],231 232    uniform bool clearcoat_flip_tangent_u = false233    [[234        anno::display_name("Clearcoat Normal Map Flip U Tangent"),235        anno::in_group("Clearcoat")236    ]],237    uniform bool clearcoat_flip_tangent_v = true238    [[239        anno::display_name("Clearcoat Normal Map Flip V Tangent"),240        anno::in_group("Clearcoat")241    ]],242 243 244    // -------------------- REFLECTIVITY ----------------------245    uniform bool enable_retroreflection = false246    [[247        anno::display_name("Enable Retroreflection"),248        anno::in_group("Reflectivity")249    ]],250    color retroreflection_tint = color(.182,.800,.000)251    [[252        anno::display_name("Retro-reflection tint"),253        anno::description("The tint of the retroreflection"),254        anno::in_group("Reflectivity")255    ]],256    uniform float normal_reflectivity = 0.5257    [[258        anno::display_name("Retro-reflection weight facing"),259        anno::hard_range(0.0,1.),260        anno::description("Reflectivity control for geometry facing the viewer"),261        anno::in_group("Reflectivity")262    ]],263    uniform float grazing_reflectivity = 1.0264    [[265        anno::display_name("Retro-reflection weight edge"),266        anno::hard_range(0.0,1.),267        anno::description("Reflectivity control for the reflectivity at geometry edges"),268        anno::in_group("Reflectivity")269    ]],270 271    // -------------------- AMBIENT OCCLUSION ----------------------272    float ao_to_diffuse = 0.0273    [[274        anno::display_name("AO to Diffuse"),275        anno::description("Controls the amount of ambient occlusion multiplied into the diffuse color channel"),276        anno::in_group("AO")277    ]],278    float ao_input = float(1.0),279    uniform texture_2d ao_texture = texture_2d()280    [[281        anno::display_name("Ambient Occlusion Map"),282        anno::description("The Ambient Occlusion texture for the material"),283        anno::in_group("AO")284    ]],285 286    // -------------------- EMISSIVE ----------------------287    uniform bool enable_emission = false288    [[289        anno::display_name("Enable Emission"),290        anno::description("Enables the emission of light from the material"),291        anno::in_group("Emissive")292    ]],293    uniform color emissive_color = color(1.0, 0.1, 0.1)294    [[295        anno::enable_if("enable_emission == true"),296        anno::display_name("Emissive Color"),297        anno::description("The emission color"),298        anno::in_group("Emissive")299    ]],300 301    color emissive_mask_input = color(1.0),302    uniform texture_2d emissive_mask_texture = texture_2d()303    [[304        anno::enable_if("enable_emission == true"),305        anno::display_name("Emissive Mask Map"),306        anno::description("The texture masking the emissive color"),307        anno::in_group("Emissive")308    ]],309    uniform float emissive_intensity = 40.f310    [[311        anno::enable_if("enable_emission == true"),312        anno::display_name("Emissive Intensity"),313        anno::description("Intensity of the emission"),314        anno::in_group("Emissive")315    ]],316    uniform bool enable_emissive_flipbook = false317    [[318        anno::display_name("Enable Flipbook for emission"),319        anno::description("Allows the use of animated emissive textures (e.g. video screens)"),320        anno::in_group("Emissive")321    ]],322    uniform int2 flipbook_dim = int2(1,1)323    [[324        anno::enable_if("enable_emissive_flipbook == true"),325        anno::display_name("Flipbook Rows/Columns"),326        anno::description("How many rows and columns are in the flipbook?"),327        anno::in_group("Emissive")328    ]],329    uniform int target_fps = 1330    [[331        anno::enable_if("enable_emissive_flipbook == true"),332        anno::display_name("Flipbook Target FPS"),333        anno::description("Playback speed in frames per second"),334        anno::in_group("Emissive")335    ]],336 337    // -------------------- ALPHA  ----------------------338    uniform bool enable_opacity = false339    [[340        anno::display_name("Enable Opacity"),341        anno::description("Enables or disables alpha functionality"),342        anno::in_group("Alpha")343    ]],344    float alpha_constant = 1.0345    [[346        anno::enable_if("enable_opacity == true"),347        anno::display_name("Opacity Fallback Constant"),348        anno::hard_range(0.0, 1.0),349        anno::description("The base alpha constant to use if no texture is specified"),350        anno::in_group("Alpha")351    ]],352    uniform texture_2d opacity_texture = texture_2d()353    [[354        anno::enable_if("enable_opacity == true"),355        anno::display_name("Opacity Map"),356        anno::description("The texture specifying the opacity value to use"),357        anno::in_group("Alpha")358    ]],359    uniform bool enable_opacity_cutout = false360    [[361        anno::enable_if("enable_opacity == true"),362        anno::display_name("Enable Alpha Cutout"),363        anno::description("Enables or disables alpha cutout functionality"),364        anno::in_group("Alpha")365    ]],366    uniform float alpha_cutout_cutoff = 1.f367    [[368        anno::enable_if("enable_opacity == true"),369        anno::enable_if("enable_opacity_cutout == true"),370        anno::hard_range(0.0, 1.0),371        anno::display_name("Alpha Cutout Cutoff"),372        anno::description("The cutoff value to to render as transparent up to and opaque past"),373        anno::in_group("Alpha")374    ]],375 376    // -------------------- NORMAL ----------------------377    uniform float bump_factor = 1.f378    [[379        anno::display_name("Normal Map Strength"),380        anno::description("Strength of normal map."),381        anno::in_group("Normal")382    ]],383 384    float3 normal_input = state::normal(),385    uniform texture_2d normalmap_texture = texture_2d()386    [[387        anno::display_name("Normal Map"),388        anno::in_group("Normal")389    ]],390    uniform bool flip_tangent_u = false391    [[392        anno::display_name("Normal Map Flip U Tangent"),393        anno::in_group("Normal")394    ]],395    uniform bool flip_tangent_v = true396    [[397        anno::display_name("Normal Map Flip V Tangent"),398        anno::in_group("Normal")399    ]],400 401    // -------------------- UV ADJUSTMENTS ----------------------402    uniform bool project_uvw = false403    [[404        anno::display_name("Enable Project UVW Coordinates"),405        anno::description("When enabled, UV coordinates will be generated by projecting them from a coordinate system"),406        anno::in_group("UV")407    ]],408    uniform bool world_or_object = false409    [[410        anno::enable_if("project_uvw == true"),411        anno::display_name("Enable World Space"),412        anno::description("When set to 'true' uses world space for projection, when 'false' object space is used"),413        anno::in_group("UV")414    ]],415    uniform float2 texture_translate =  float2(0.0f)416    [[417        anno::display_name("Texture Translate"),418        anno::description("Controls position of texture."),419        anno::in_group("UV")420    ]],421    uniform float2 texture_scale =  float2(1.0f)422    [[423        anno::display_name("Texture Tiling"),424        anno::description("Controls repetition of the texture."),425        anno::in_group("UV")426    ]],427    uniform float2 texture_speed =  float2(0.0f)428    [[429        anno::display_name("Texture Speed"),430        anno::description("Scrolling texture animation speed in UVs per sec."),431        anno::in_group("UV")432    ]]433)434[[435    anno::display_name("Sim PBR"),436    anno::description("Supports the opaque alpha cutout material model of the Sim Renderer"),437    anno::in_group("SimReady"),438    anno::version( 1, 0, 0),439    anno::author("NVIDIA CORPORATION"),440    anno::key_words(string[]("Sim", "PBR", "opaque", "alpha", "cutout", "omniverse", "generic"))441]]442 = let {443    base::texture_coordinate_system the_system = world_or_object ? base::texture_coordinate_world : base::texture_coordinate_object;444 445    base::texture_coordinate_info uvw = project_uvw ?446        base::coordinate_projection(447            coordinate_system: the_system,448            texture_space: 0,449            projection_type: base::projection_cubic450        ) : base::coordinate_source(451            coordinate_system: base::texture_coordinate_uvw,452            texture_space: 0453        );454 455    // Need to use a small value so the compiler doesnt optimize out this var...456    float t = 0.00000001;//state::animation_time();457    base::texture_coordinate_info transformed_uvw =  base::transform_coordinate(458        transform: base::rotation_translation_scale(459        scaling: float3(texture_scale.x, texture_scale.y, 1.0),460        rotation: float3(0.0, 0.0, 0.0 ),461        translation: float3(texture_translate.x + t * texture_speed.x, texture_translate.y + t * texture_speed.y, 0.0)),462        coordinate: uvw463    );464    float2 uv = float2(transformed_uvw.position.x, transformed_uvw.position.y);465 466    // Diffuse Color Lookup and AO467    float4 base_lookup = tex::texture_isvalid(diffuse_texture) ? tex::lookup_float4(tex: diffuse_texture, coord: uv) : float4(1, 1, 1, 1);468 469    float opacityValue = tex::texture_isvalid(opacity_texture) ? tex::lookup_float4(tex: opacity_texture, coord: uv).w : alpha_constant;470 471    // Normal calculations472    float3 normal_lookup =  tex::texture_isvalid(normalmap_texture) ?473        base::tangent_space_normal_texture(474            texture: normalmap_texture,475            factor: bump_factor,476            uvw: transformed_uvw,477            flip_tangent_u: flip_tangent_u,478            flip_tangent_v: flip_tangent_v479        ) : normal_input;480 481    float3 clearcoat_normal = tex::texture_isvalid(clearcoat_normalmap_texture) ?482    base::tangent_space_normal_texture(483        texture: clearcoat_normalmap_texture,484        factor: clearcoat_bump_factor,485        uvw: uvw,486        flip_tangent_u: clearcoat_flip_tangent_u,487        flip_tangent_v: clearcoat_flip_tangent_v488    ) : clearcoat_normal_input;489 490    float3 flattened_clearcoat_normal = ::math::lerp(normal_lookup, ::state::normal(), clearcoat_flatten);491    float3 final_clearcoat_normal = tex::texture_isvalid(clearcoat_normalmap_texture) ? clearcoat_normal : flattened_clearcoat_normal;492 493    float ao_lookup = tex::texture_isvalid(ao_texture) ? tex::lookup_float4(tex: ao_texture, coord: uv).x : ao_input;494 495    color diffuse_color = tex::texture_isvalid(diffuse_texture) ? color(base_lookup.x, base_lookup.y, base_lookup.z) : diffuse_color_constant;496 497    float3 ORM_lookup = tex::lookup_float3(498        tex: ORM_texture,499        coord: float2(transformed_uvw.position.x, transformed_uvw.position.y)500    );501 502    float roughness_lookup = tex::texture_isvalid(reflectionroughness_texture) ?503        tex::lookup_float4(tex: reflectionroughness_texture, coord: uv).x : reflection_roughness_constant;504    float anisotropy_lookup = tex::texture_isvalid(anisotropy_texture) ?505        (tex::lookup_float4(tex: anisotropy_texture, coord: uv).x * 2.0f - 1.0f) : anisotropy_constant;506    float metallic_lookup = tex::texture_isvalid(metallic_texture) ?507        tex::lookup_float4(tex: metallic_texture, coord: uv).x : metallic_constant;508    float specular_lookup = tex::texture_isvalid(specular_texture) ?509        tex::lookup_float4(tex: specular_texture, coord: uv).x : specular_constant;510 511    float roughness_selection = enable_ORM_texture ? ORM_lookup.y : roughness_lookup;512    float metallic_selection = enable_ORM_texture ? ORM_lookup.z : metallic_lookup;513    float ao = enable_ORM_texture ? ORM_lookup.x : ao_lookup;514 515    float reflection_roughness =  math::lerp(reflection_roughness_constant, roughness_selection, reflection_roughness_texture_influence);516    float anisotropy =  math::lerp(anisotropy_constant, anisotropy_lookup, anisotropy_texture_influence);517    float metallic = math::lerp(metallic_constant, metallic_selection, metallic_texture_influence);518 519    int rows = flipbook_dim.x;520    int columns = flipbook_dim.y;521    int numFrames = rows * columns;522    varying int frameIdx = int(state::animation_time() * target_fps) % numFrames;523    varying float2 baseUV = float2(transformed_uvw.position.x, transformed_uvw.position.y);524    varying float2 emissiveUV = enable_emissive_flipbook ?525        ((baseUV + float2(frameIdx % rows, frameIdx / rows)) / float2(rows, columns)) : baseUV;526 527    color emissive_mask = tex::texture_isvalid(emissive_mask_texture) ?528        tex::lookup_color(emissive_mask_texture, emissiveUV, tex::wrap_repeat, tex::wrap_repeat) : emissive_mask_input;529 530} in SimPBR_Model(531    diffuse_color: diffuse_color,532    diffuse_tint: diffuse_tint,533    roughness: reflection_roughness,534    anisotropy: anisotropy,535    metallic: metallic,536    specular: specular_lookup,537    normal: normal_lookup,538    enable_clearcoat: enable_clearcoat,539    clearcoat_tint: clearcoat_tint,540    clearcoat_transparency: clearcoat_transparency,541    clearcoat_reflection_roughness: clearcoat_reflection_roughness,542    clearcoat_weight: clearcoat_weight,543    clearcoat_ior: clearcoat_ior,544    clearcoat_normal: final_clearcoat_normal,545    enable_retroreflection: enable_retroreflection,546    retroreflection_tint: retroreflection_tint,547    normal_reflectivity: normal_reflectivity,548    grazing_reflectivity: grazing_reflectivity,549    ao_to_diffuse: ao_to_diffuse,550    ao: ao,551    enable_emission: enable_emission,552    emissive_color: emissive_color,553    emissive_mask: emissive_mask,554    emissive_intensity: emissive_intensity,555    enable_opacity: enable_opacity,556    alpha: opacityValue,557    enable_opacity_cutout: enable_opacity_cutout,558    alpha_cutout_cutoff: alpha_cutout_cutoff,559    opacity_ratio: enable_transmission ? opacity_ratio : 1.0,560    opacity_tint : opacity_tint,561    opacity_multiplier : opacity_multiplier562);563 
AVSim/simulation-package · Team Ai