init commit

This commit is contained in:
zyhe
2026-03-16 11:44:10 +00:00
commit 94384a93c9
552 changed files with 363038 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -0,0 +1,284 @@
mdl 1.6;
import ::math::*;
import ::state::*;
import ::tex::*;
import ::anno::*;
using .::OmniUe4Function import *;
using .::OmniUe4Base import *;
export annotation sampler_color();
export annotation sampler_normal();
export annotation sampler_grayscale();
export annotation sampler_alpha();
export annotation sampler_masks();
export annotation sampler_distancefield();
export annotation dither_masked_off();
export annotation world_space_normal();
export material Num5a5da57fa25e6b62e706446c(
uniform texture_2d Normal_Tex = texture_2d("./Textures/normal.png",::tex::gamma_linear)
[[
anno::display_name("Normal_Tex"),
anno::ui_order(32),
anno::in_group("Normal"),
sampler_normal()
]],
float4 Normal_UVA = float4(1.0,1.0,0.0,0.0)
[[
anno::display_name("Normal_UVA"),
anno::ui_order(32),
anno::in_group("Normal")
]],
float EmissiveIntensity = 0.0
[[
anno::display_name("EmissiveIntensity"),
anno::ui_order(32),
anno::in_group("EmissiveColor")
]],
float IsEmissiveTex = 0.0
[[
anno::display_name("IsEmissiveTex"),
anno::in_group("EmissiveColor")
]],
float4 Emissive_Color = float4(1.0,1.0,1.0,1.0)
[[
anno::display_name("Emissive_Color"),
anno::ui_order(32),
anno::in_group("EmissiveColor")
]],
uniform texture_2d Emissive_Tex = texture_2d("./Textures/white.png",::tex::gamma_srgb)
[[
anno::display_name("Emissive_Tex"),
anno::ui_order(32),
anno::in_group("EmissiveColor"),
sampler_color()
]],
float4 Emissive_UVA = float4(1.0,1.0,0.0,0.0)
[[
anno::display_name("Emissive_UVA"),
anno::ui_order(32),
anno::in_group("EmissiveColor")
]],
float IsBaseColorTex = 0.0
[[
anno::display_name("IsBaseColorTex"),
anno::in_group("BaseColor")
]],
float4 BaseColor_Color = float4(1.0,1.0,1.0,1.0)
[[
anno::display_name("BaseColor_Color"),
anno::ui_order(32),
anno::in_group("BaseColor")
]],
uniform texture_2d BaseColor_Tex = texture_2d("./Textures/white.png",::tex::gamma_srgb)
[[
anno::display_name("BaseColor_Tex"),
anno::ui_order(32),
anno::in_group("BaseColor"),
sampler_color()
]],
float4 BaseColor_UVA = float4(1.0,1.0,0.0,0.0)
[[
anno::display_name("BaseColor_UVA"),
anno::ui_order(32),
anno::in_group("BaseColor")
]],
float IsMetallicTex = 0.0
[[
anno::display_name("IsMetallicTex"),
anno::in_group("Metallic")
]],
float4 Metallic_Color = float4(0.0,0.0,0.0,1.0)
[[
anno::display_name("Metallic_Color"),
anno::ui_order(32),
anno::in_group("Metallic")
]],
uniform texture_2d Metallic_Tex = texture_2d("./Textures/black.png",::tex::gamma_srgb)
[[
anno::display_name("Metallic_Tex"),
anno::ui_order(32),
anno::in_group("Metallic"),
sampler_color()
]],
float4 Metallic_UVA = float4(1.0,1.0,0.0,0.0)
[[
anno::display_name("Metallic_UVA"),
anno::ui_order(32),
anno::in_group("Metallic")
]],
float IsSpecularTex = 0.0
[[
anno::display_name("IsSpecularTex"),
anno::in_group("Specular")
]],
float4 Specular_Color = float4(1.0,1.0,1.0,1.0)
[[
anno::display_name("Specular_Color"),
anno::ui_order(32),
anno::in_group("Specular")
]],
uniform texture_2d Specular_Tex = texture_2d("./Textures/white.png",::tex::gamma_srgb)
[[
anno::display_name("Specular_Tex"),
anno::ui_order(32),
anno::in_group("Specular"),
sampler_color()
]],
float4 Specular_UVA = float4(1.0,1.0,0.0,0.0)
[[
anno::display_name("Specular_UVA"),
anno::ui_order(32),
anno::in_group("Specular")
]],
float IsGlossTex = 0.0
[[
anno::display_name("IsGlossTex"),
anno::in_group("Roughness")
]],
float4 Gloss_Color = float4(0.1,0.1,0.1,1.0)
[[
anno::display_name("Gloss_Color"),
anno::ui_order(32),
anno::in_group("Roughness")
]],
uniform texture_2d Gloss_Tex = texture_2d("./Textures/white.png",::tex::gamma_srgb)
[[
anno::display_name("Gloss_Tex"),
anno::ui_order(32),
anno::in_group("Roughness"),
sampler_color()
]],
float4 Gloss_UVA = float4(1.0,1.0,0.0,0.0)
[[
anno::display_name("Gloss_UVA"),
anno::ui_order(32),
anno::in_group("Roughness")
]],
float PolygonOffset = 0.0
[[
anno::display_name("PolygonOffset"),
anno::ui_order(32),
anno::in_group("WorldPosition")
]],
int MaxTexCoordIndex = 3
[[
anno::hidden()
]])
=
let {
float3 Local82 = ::camera_position();
float3 Local83 = (Local82 - (::convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), true)*state::meters_per_scene_unit()*100.0));
float Local84 = math::dot(Local83, Local83);
float Local85 = math::sqrt(Local84);
float3 Local86 = (Local83 / Local85);
float3 Local87 = (Local86 * PolygonOffset);
float3 WorldPositionOffset_mdl = Local87;
float2 CustomizedUV0_mdl = float2(state::texture_coordinate(math::min(0,MaxTexCoordIndex)).x,1.0-state::texture_coordinate(math::min(0,MaxTexCoordIndex)).y);
float2 Local0 = (float2(0.5,0.5) * -1.0);
float Local1 = (CustomizedUV0_mdl.x * float3(Normal_UVA.x,Normal_UVA.y,Normal_UVA.z).x);
float Local2 = (CustomizedUV0_mdl.y * float3(Normal_UVA.x,Normal_UVA.y,Normal_UVA.z).y);
float2 Local3 = (Local0 + float2(Local1,Local2));
float Local4 = (3.141592 * -2.0);
float Local5 = (float3(Normal_UVA.x,Normal_UVA.y,Normal_UVA.z).z / Local4);
float Local6 = (Local5 * 6.283185);
float Local7 = math::cos(Local6);
float Local8 = math::sin(Local6);
float Local9 = (Local8 * -1.0);
float Local10 = math::dot(Local3, float2(Local7,Local9));
float Local11 = math::dot(Local3, float2(Local8,Local7));
float2 Local12 = (float2(0.5,0.5) + float2(Local10,Local11));
float4 Local13 = ::unpack_normal_map(tex::lookup_float4(Normal_Tex,float2(Local12.x,1.0-Local12.y),tex::wrap_repeat,tex::wrap_repeat));
float3 Local14 = ((math::abs(1.0 - 1.0) > 0.00001) ? (float3(0.0,0.0,0.0)) : float3(Local13.x,Local13.y,Local13.z));
float3 Normal_mdl = Local14;
float Local15 = (CustomizedUV0_mdl.x * float3(Emissive_UVA.x,Emissive_UVA.y,Emissive_UVA.z).x);
float Local16 = (CustomizedUV0_mdl.y * float3(Emissive_UVA.x,Emissive_UVA.y,Emissive_UVA.z).y);
float2 Local17 = (Local0 + float2(Local15,Local16));
float Local18 = (float3(Emissive_UVA.x,Emissive_UVA.y,Emissive_UVA.z).z / Local4);
float Local19 = (Local18 * 6.283185);
float Local20 = math::cos(Local19);
float Local21 = math::sin(Local19);
float Local22 = (Local21 * -1.0);
float Local23 = math::dot(Local17, float2(Local20,Local22));
float Local24 = math::dot(Local17, float2(Local21,Local20));
float2 Local25 = (float2(0.5,0.5) + float2(Local23,Local24));
float4 Local26 = tex::lookup_float4(Emissive_Tex,float2(Local25.x,1.0-Local25.y),tex::wrap_repeat,tex::wrap_repeat);
float3 Local27 = ((math::abs(IsEmissiveTex - 1.0) > 0.00001) ? (float3(Emissive_Color.x,Emissive_Color.y,Emissive_Color.z)) : float3(Local26.x,Local26.y,Local26.z));
float3 Local28 = (EmissiveIntensity * Local27);
float Local29 = (CustomizedUV0_mdl.x * float3(BaseColor_UVA.x,BaseColor_UVA.y,BaseColor_UVA.z).x);
float Local30 = (CustomizedUV0_mdl.y * float3(BaseColor_UVA.x,BaseColor_UVA.y,BaseColor_UVA.z).y);
float2 Local31 = (Local0 + float2(Local29,Local30));
float Local32 = (float3(BaseColor_UVA.x,BaseColor_UVA.y,BaseColor_UVA.z).z / Local4);
float Local33 = (Local32 * 6.283185);
float Local34 = math::cos(Local33);
float Local35 = math::sin(Local33);
float Local36 = (Local35 * -1.0);
float Local37 = math::dot(Local31, float2(Local34,Local36));
float Local38 = math::dot(Local31, float2(Local35,Local34));
float2 Local39 = (float2(0.5,0.5) + float2(Local37,Local38));
float4 Local40 = tex::lookup_float4(BaseColor_Tex,float2(Local39.x,1.0-Local39.y),tex::wrap_repeat,tex::wrap_repeat);
float3 Local41 = ((math::abs(IsBaseColorTex - 1.0) > 0.00001) ? (float3(BaseColor_Color.x,BaseColor_Color.y,BaseColor_Color.z)) : float3(Local40.x,Local40.y,Local40.z));
float Local42 = (CustomizedUV0_mdl.x * float3(Metallic_UVA.x,Metallic_UVA.y,Metallic_UVA.z).x);
float Local43 = (CustomizedUV0_mdl.y * float3(Metallic_UVA.x,Metallic_UVA.y,Metallic_UVA.z).y);
float2 Local44 = (Local0 + float2(Local42,Local43));
float Local45 = (float3(Metallic_UVA.x,Metallic_UVA.y,Metallic_UVA.z).z / Local4);
float Local46 = (Local45 * 6.283185);
float Local47 = math::cos(Local46);
float Local48 = math::sin(Local46);
float Local49 = (Local48 * -1.0);
float Local50 = math::dot(Local44, float2(Local47,Local49));
float Local51 = math::dot(Local44, float2(Local48,Local47));
float2 Local52 = (float2(0.5,0.5) + float2(Local50,Local51));
float4 Local53 = tex::lookup_float4(Metallic_Tex,float2(Local52.x,1.0-Local52.y),tex::wrap_repeat,tex::wrap_repeat);
float3 Local54 = ((math::abs(IsMetallicTex - 1.0) > 0.00001) ? (float3(Metallic_Color.x,Metallic_Color.y,Metallic_Color.z)) : float3(Local53.x,Local53.y,Local53.z));
float Local55 = (CustomizedUV0_mdl.x * float3(Specular_UVA.x,Specular_UVA.y,Specular_UVA.z).x);
float Local56 = (CustomizedUV0_mdl.y * float3(Specular_UVA.x,Specular_UVA.y,Specular_UVA.z).y);
float2 Local57 = (Local0 + float2(Local55,Local56));
float Local58 = (float3(Specular_UVA.x,Specular_UVA.y,Specular_UVA.z).z / Local4);
float Local59 = (Local58 * 6.283185);
float Local60 = math::cos(Local59);
float Local61 = math::sin(Local59);
float Local62 = (Local61 * -1.0);
float Local63 = math::dot(Local57, float2(Local60,Local62));
float Local64 = math::dot(Local57, float2(Local61,Local60));
float2 Local65 = (float2(0.5,0.5) + float2(Local63,Local64));
float4 Local66 = tex::lookup_float4(Specular_Tex,float2(Local65.x,1.0-Local65.y),tex::wrap_repeat,tex::wrap_repeat);
float3 Local67 = ((math::abs(IsSpecularTex - 1.0) > 0.00001) ? (float3(Specular_Color.x,Specular_Color.y,Specular_Color.z)) : float3(Local66.x,Local66.y,Local66.z));
float Local68 = (CustomizedUV0_mdl.x * float3(Gloss_UVA.x,Gloss_UVA.y,Gloss_UVA.z).x);
float Local69 = (CustomizedUV0_mdl.y * float3(Gloss_UVA.x,Gloss_UVA.y,Gloss_UVA.z).y);
float2 Local70 = (Local0 + float2(Local68,Local69));
float Local71 = (float3(Gloss_UVA.x,Gloss_UVA.y,Gloss_UVA.z).z / Local4);
float Local72 = (Local71 * 6.283185);
float Local73 = math::cos(Local72);
float Local74 = math::sin(Local72);
float Local75 = (Local74 * -1.0);
float Local76 = math::dot(Local70, float2(Local73,Local75));
float Local77 = math::dot(Local70, float2(Local74,Local73));
float2 Local78 = (float2(0.5,0.5) + float2(Local76,Local77));
float4 Local79 = tex::lookup_float4(Gloss_Tex,float2(Local78.x,1.0-Local78.y),tex::wrap_repeat,tex::wrap_repeat);
float3 Local80 = ((math::abs(IsGlossTex - 1.0) > 0.00001) ? (float3(Gloss_Color.x,Gloss_Color.y,Gloss_Color.z)) : float3(Local79.x,Local79.y,Local79.z));
float3 Local81 = (1.0 - Local80);
float3 EmissiveColor_mdl = Local28;
float OpacityMask_mdl = 1.0;
float3 BaseColor_mdl = Local41;
float Metallic_mdl = Local54.x;
float Specular_mdl = Local67.x;
float Roughness_mdl = Local81.x;
} in
::OmniUe4Base(
base_color: BaseColor_mdl,
metallic: Metallic_mdl,
roughness: Roughness_mdl,
specular: Specular_mdl,
normal: Normal_mdl,
opacity: OpacityMask_mdl,
emissive_color: EmissiveColor_mdl,
displacement: WorldPositionOffset_mdl,
two_sided: false);

View File

@@ -0,0 +1,224 @@
/***************************************************************************************************
* Copyright 2020 NVIDIA Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**************************************************************************************************/
//* 1.0.0 - first version
//* 1.0.1 - merge unlit template
//* 1.0.2 - Fix EDF in the back side: the EDF contained in surface is only used for the front side and not for the back side
//* 1.0.3 - UE4 normal mapping: Geometry normal shouldn't be changed
//* 1.0.4 - using absolute import paths when importing standard modules
mdl 1.3;
import ::df::*;
import ::state::*;
import ::math::*;
import ::tex::*;
import ::anno::*;
float emissive_multiplier()
[[
anno::description("the multiplier to convert UE4 emissive to raw data"),
anno::noinline()
]]
{
return 20.0f * 128.0f;
}
float3 tangent_space_normal(
float3 normal = float3(0.0,0.0,1.0),
float3 tangent_u = state::texture_tangent_u(0),
float3 tangent_v = state::texture_tangent_v(0)
)
[[
anno::description("Interprets the vector in tangent space"),
anno::noinline()
]]
{
return math::normalize(
tangent_u * normal.x - /* flip_tangent_v */
tangent_v * normal.y +
state::normal() * (normal.z));
}
float3 world_space_normal(
float3 normal = float3(0.0,0.0,1.0),
float3 tangent_u = state::texture_tangent_u(0),
float3 tangent_v = state::texture_tangent_v(0)
)
[[
anno::description("Interprets the vector in world space"),
anno::noinline()
]]
{
return tangent_space_normal(
math::normalize(
normal.x * float3(tangent_u.x, tangent_v.x, state::normal().x) -
normal.y * float3(tangent_u.y, tangent_v.y, state::normal().y) +
normal.z * float3(tangent_u.z, tangent_v.z, state::normal().z)),
tangent_u,
tangent_v
);
}
export material OmniUe4Base(
float3 base_color = float3(0.0, 0.0, 0.0),
float metallic = 0.0,
float roughness = 0.5,
float specular = 0.5,
float3 normal = float3(0.0,0.0,1.0),
float clearcoat_weight = 0.0,
float clearcoat_roughness = 0.0,
float3 clearcoat_normal = float3(0.0,0.0,1.0),
uniform bool enable_opacity = true,
float opacity = 1.0,
float3 emissive_color = float3(0.0, 0.0, 0.0),
float3 displacement = float3(0.0),
uniform bool is_tangent_space_normal = true,
uniform bool two_sided = false,
uniform bool is_unlit = false
)
[[
anno::display_name("Omni UE4 Base"),
anno::description("Omni UE4 Base, supports UE4 default lit and clearcoat shading model"),
anno::version( 1, 0, 0),
anno::author("NVIDIA CORPORATION"),
anno::key_words(string[]("omni", "UE4", "omniverse", "lit", "clearcoat", "generic"))
]]
= let {
color final_base_color = math::saturate(base_color);
float final_metallic = math::saturate(metallic);
float final_roughness = math::saturate(roughness);
float final_specular = math::saturate(specular);
color final_emissive_color = math::max(emissive_color, 0.0f) * emissive_multiplier(); /*factor for converting ue4 emissive to raw value*/
float final_clearcoat_weight = math::saturate(clearcoat_weight);
float final_clearcoat_roughness = math::saturate(clearcoat_roughness);
float3 final_normal = math::normalize(normal);
float3 final_clearcoat_normal = math::normalize(clearcoat_normal);
// - compute final roughness by squaring the "roughness" parameter
float alpha = final_roughness * final_roughness;
// reduce the reflectivity at grazing angles to avoid "dark edges" for high roughness due to the layering
float grazing_refl = math::max((1.0 - final_roughness), 0.0);
float3 the_normal = is_unlit ? state::normal() :
(is_tangent_space_normal ?
tangent_space_normal(
normal: final_normal,
tangent_u: state::texture_tangent_u(0),
tangent_v: state::texture_tangent_v(0)
) : world_space_normal(
normal: final_normal,
tangent_u: state::texture_tangent_u(0),
tangent_v: state::texture_tangent_v(0)
));
// for the dielectric component we layer the glossy component on top of the diffuse one,
// the glossy layer has no color tint
bsdf dielectric_component = df::custom_curve_layer(
weight: final_specular,
normal_reflectivity: 0.08,
grazing_reflectivity: grazing_refl,
layer: df::microfacet_ggx_smith_bsdf(roughness_u: alpha),
base: df::diffuse_reflection_bsdf(tint: final_base_color),
normal: the_normal);
// the metallic component doesn't have a diffuse component, it's only glossy
// base_color is applied to tint it
bsdf metallic_component = df::microfacet_ggx_smith_bsdf(tint: final_base_color, roughness_u: alpha);
// final BSDF is a linear blend between dielectric and metallic component
bsdf dielectric_metal_mix =
df::normalized_mix(
components:
df::bsdf_component[](
df::bsdf_component(
component: metallic_component,
weight: final_metallic),
df::bsdf_component(
component: dielectric_component,
weight: 1.0-final_metallic)
)
);
// clearcoat layer
float clearcoat_grazing_refl = math::max((1.0 - final_clearcoat_roughness), 0.0);
float clearcoat_alpha = final_clearcoat_roughness * final_clearcoat_roughness;
float3 the_clearcoat_normal = is_tangent_space_normal ? tangent_space_normal(
normal: final_clearcoat_normal,
tangent_u: state::texture_tangent_u(0),
tangent_v: state::texture_tangent_v(0)
) : world_space_normal(
normal: final_clearcoat_normal,
tangent_u: state::texture_tangent_u(0),
tangent_v: state::texture_tangent_v(0)
);
bsdf clearcoat =
df::custom_curve_layer(
base: df::weighted_layer(
layer: dielectric_metal_mix,
weight: 1.0,
normal: final_clearcoat_weight == 0.0 ? state::normal() : the_normal
),
layer: df::microfacet_ggx_smith_bsdf(
roughness_u: clearcoat_alpha,
tint: color(1.0)
),
normal_reflectivity: 0.04,
grazing_reflectivity: clearcoat_grazing_refl,
normal: the_clearcoat_normal,
weight: final_clearcoat_weight
);
bsdf surface = is_unlit ? bsdf() : clearcoat;
}
in material(
thin_walled: two_sided, // Graphene?
surface: material_surface(
scattering: surface,
emission:
material_emission (
emission: df::diffuse_edf (),
intensity: final_emissive_color
)
),
backface: material_surface(
emission:
material_emission (
emission: df::diffuse_edf (),
intensity: final_emissive_color
)
),
geometry: material_geometry(
displacement: displacement,
normal: final_clearcoat_weight == 0.0 ? the_normal : state::normal(),
cutout_opacity: enable_opacity ? opacity : 1.0
)
);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,233 @@
/***************************************************************************************************
* Copyright 2020 NVIDIA Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**************************************************************************************************/
//* 1.0.0 - first version
//* 1.0.1 - Emissive color affected by opacity
// - Support opacity mask
//* 1.0.2 - Unlit translucent
//* 1.0.3 - specular bsdf instead of microfacet ggx smith bsdf
//* 1.0.4 - using absolute import paths when importing standard modules
mdl 1.3;
import ::df::*;
import ::state::*;
import ::math::*;
import ::tex::*;
import ::anno::*;
float emissive_multiplier()
[[
anno::description("the multiplier to convert UE4 emissive to raw data"),
anno::noinline()
]]
{
return 20.0f * 128.0f;
}
color get_translucent_tint(color base_color, float opacity)
[[
anno::description("base color of UE4 translucent"),
anno::noinline()
]]
{
return math::lerp(color(1.0), base_color, opacity);
}
// Just for UE4 distilling
float get_translucent_opacity(float opacity)
[[
anno::noinline()
]]
{
return opacity;
}
color get_emissive_intensity(color emissive, float opacity)
[[
anno::description("emissive color of UE4 translucent"),
anno::noinline()
]]
{
return emissive * opacity;
}
float3 tangent_space_normal(
float3 normal = float3(0.0,0.0,1.0),
float3 tangent_u = state::texture_tangent_u(0),
float3 tangent_v = state::texture_tangent_v(0)
)
[[
anno::description("Interprets the vector in tangent space"),
anno::noinline()
]]
{
return math::normalize(
tangent_u * normal.x -
tangent_v * normal.y + /* flip_tangent_v */
state::normal() * (normal.z));
}
float3 world_space_normal(
float3 normal = float3(0.0,0.0,1.0),
float3 tangent_u = state::texture_tangent_u(0),
float3 tangent_v = state::texture_tangent_v(0)
)
[[
anno::description("Interprets the vector in world space"),
anno::noinline()
]]
{
return tangent_space_normal(
math::normalize(
normal.x * float3(tangent_u.x, tangent_v.x, state::normal().x) -
normal.y * float3(tangent_u.y, tangent_v.y, state::normal().y) +
normal.z * float3(tangent_u.z, tangent_v.z, state::normal().z)),
tangent_u,
tangent_v
);
}
export material OmniUe4Translucent(
float3 base_color = float3(0.0, 0.0, 0.0),
float metallic = 0.0,
float roughness = 0.5,
float specular = 0.5,
float3 normal = float3(0.0,0.0,1.0),
uniform bool enable_opacity = true,
float opacity = 1.0,
float opacity_mask = 1.0,
float3 emissive_color = float3(0.0, 0.0, 0.0),
float3 displacement = float3(0.0),
uniform float refraction = 1.0,
uniform bool two_sided = false,
uniform bool is_tangent_space_normal = true,
uniform bool is_unlit = false
)
[[
anno::display_name("Omni UE4 Translucent"),
anno::description("Omni UE4 Translucent, supports UE4 Translucent shading model"),
anno::version( 1, 0, 0),
anno::author("NVIDIA CORPORATION"),
anno::key_words(string[]("omni", "UE4", "omniverse", "translucent"))
]]
= let {
color final_base_color = math::saturate(base_color);
float final_metallic = math::min(math::max(metallic, 0.0f), 0.99f);
float final_roughness = math::saturate(roughness);
float final_specular = math::saturate(specular);
color final_emissive_color = math::max(emissive_color, 0.0f) * emissive_multiplier(); /*factor for converting ue4 emissive to raw value*/
float final_opacity = math::saturate(opacity);
float3 final_normal = math::normalize(normal);
// - compute final roughness by squaring the "roughness" parameter
float alpha = final_roughness * final_roughness;
// reduce the reflectivity at grazing angles to avoid "dark edges" for high roughness due to the layering
float grazing_refl = math::max((1.0 - final_roughness), 0.0);
float3 the_normal = is_unlit ? state::normal() :
(is_tangent_space_normal ?
tangent_space_normal(
normal: final_normal,
tangent_u: state::texture_tangent_u(0),
tangent_v: state::texture_tangent_v(0)
) : world_space_normal(
normal: final_normal,
tangent_u: state::texture_tangent_u(0),
tangent_v: state::texture_tangent_v(0)
));
// for the dielectric component we layer the glossy component on top of the diffuse one,
// the glossy layer has no color tint
bsdf dielectric_component = df::custom_curve_layer(
weight: final_specular,
normal_reflectivity: 0.08,
grazing_reflectivity: grazing_refl,
layer: df::microfacet_ggx_smith_bsdf(roughness_u: alpha),
base: df::diffuse_reflection_bsdf(tint: final_base_color));
// the metallic component doesn't have a diffuse component, it's only glossy
// base_color is applied to tint it
bsdf metallic_component = df::microfacet_ggx_smith_bsdf(tint: final_base_color, roughness_u: alpha);
// final BSDF is a linear blend between dielectric and metallic component
bsdf dielectric_metal_mix =
df::normalized_mix(
components:
df::bsdf_component[](
df::bsdf_component(
component: metallic_component,
weight: final_metallic),
df::bsdf_component(
component: dielectric_component,
weight: 1.0-final_metallic)
)
);
bsdf frosted_bsdf = df::specular_bsdf(
tint: color(1),
mode: df::scatter_reflect_transmit
);
bsdf final_mix_bsdf =
is_unlit ? df::specular_bsdf(
tint: get_translucent_tint(base_color: final_base_color, opacity: final_opacity),
mode: df::scatter_reflect_transmit
)
: df::normalized_mix(
components:
df::bsdf_component[](
df::bsdf_component(
component: dielectric_metal_mix,
weight: get_translucent_opacity(final_opacity)),
df::bsdf_component(
component: frosted_bsdf,
weight: 1.0-get_translucent_opacity(final_opacity))
)
);
}
in material(
thin_walled: two_sided, // Graphene?
ior: color(refraction), //refraction
surface: material_surface(
scattering: final_mix_bsdf,
emission:
material_emission (
emission: df::diffuse_edf (),
intensity: get_emissive_intensity(emissive: final_emissive_color, opacity: final_opacity)
)
),
geometry: material_geometry(
displacement: displacement,
normal: the_normal,
cutout_opacity: enable_opacity ? opacity_mask : 1.0
)
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

View File

@@ -0,0 +1,75 @@
mdl 1.6;
import ::math::*;
import ::state::*;
import ::tex::*;
import ::anno::*;
using .::OmniUe4Function import *;
using .::OmniUe4Base import *;
export annotation sampler_color();
export annotation sampler_normal();
export annotation sampler_grayscale();
export annotation sampler_alpha();
export annotation sampler_masks();
export annotation sampler_distancefield();
export annotation dither_masked_off();
export annotation world_space_normal();
export material WorldGridMaterial(
int MaxTexCoordIndex = 3
[[
anno::hidden()
]])
=
let {
float3 WorldPositionOffset_mdl = float3(0.0,0.0,0.0);
float2 CustomizedUV0_mdl = float2(state::texture_coordinate(math::min(0,MaxTexCoordIndex)).x,1.0-state::texture_coordinate(math::min(0,MaxTexCoordIndex)).y);
float2 Local0 = (CustomizedUV0_mdl / 2.0);
float2 Local1 = (Local0 / 0.05);
float4 Local2 = ::unpack_normal_map(tex::lookup_float4(texture_2d("./Textures/T_Default_Material_Grid_N.png",::tex::gamma_linear),float2(Local1.x,1.0-Local1.y),tex::wrap_repeat,tex::wrap_repeat));
float3 Local3 = (float3(Local2.x,Local2.y,Local2.z) * float3(0.3,0.3,1.0));
float3 Normal_mdl = Local3;
float2 Local4 = (CustomizedUV0_mdl * 20.0);
float4 Local5 = tex::lookup_float4(texture_2d("./Textures/T_Default_Material_Grid_M.png",::tex::gamma_linear),float2(Local4.x,1.0-Local4.y),tex::wrap_repeat,tex::wrap_repeat);
float Local6 = math::lerp(0.4,1.0,Local5.x);
float Local7 = (1.0 - Local6);
float2 Local8 = (Local0 / 0.1);
float4 Local9 = tex::lookup_float4(texture_2d("./Textures/T_Default_Material_Grid_M.png",::tex::gamma_linear),float2(Local8.x,1.0-Local8.y),tex::wrap_repeat,tex::wrap_repeat);
float Local10 = math::lerp(Local9.y,1.0,0.0);
float Local11 = math::lerp(Local6,Local7,Local10);
float4 Local12 = tex::lookup_float4(texture_2d("./Textures/T_Default_Material_Grid_M.png",::tex::gamma_linear),float2(Local0.x,1.0-Local0.y),tex::wrap_repeat,tex::wrap_repeat);
float Local13 = math::lerp(Local9.y,0.0,0.0);
float Local14 = (Local12.y + Local13);
float Local15 = math::lerp(Local14,0.5,0.5);
float Local16 = math::lerp(0.295,0.66,Local15);
float Local17 = (Local16 * 0.5);
float Local18 = (Local11 * Local17);
float Local19 = math::lerp(0.0,0.5,Local12.y);
float Local20 = math::lerp(0.7,1.0,Local9.y);
float Local21 = math::lerp(Local20,1.0,0.0);
float Local22 = (Local21 * 1.0);
float Local23 = (Local19 + Local22);
float Local24 = math::min(math::max(Local23,0.0),1.0);
float3 EmissiveColor_mdl = float3(0.0,0.0,0.0);
float OpacityMask_mdl = 1.0;
float3 BaseColor_mdl = float3(Local18,Local18,Local18);
float Metallic_mdl = 0.0;
float Specular_mdl = 0.5;
float Roughness_mdl = Local24;
} in
::OmniUe4Base(
base_color: BaseColor_mdl,
metallic: Metallic_mdl,
roughness: Roughness_mdl,
specular: Specular_mdl,
normal: Normal_mdl,
opacity: OpacityMask_mdl,
emissive_color: EmissiveColor_mdl,
displacement: WorldPositionOffset_mdl,
two_sided: false);

Binary file not shown.