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