diff --git a/.gitattributes b/.gitattributes index 87907b5f542a2f38fab36944252e0e2afeb74947..e5b1f9e98db8c5929b8d4179f5537c653ba195b5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -109,3 +109,9 @@ IROS_C_V3_Aloha_seen/make_sandwich/004/scene.usd filter=lfs diff=lfs merge=lfs - IROS_C_V3_Aloha_seen/make_sandwich/SubUSDs/textures/brown_photostudio_02_4k.exr filter=lfs diff=lfs merge=lfs -text IROS_C_V3_Aloha_seen/make_sandwich/005/scene.usd filter=lfs diff=lfs merge=lfs -text IROS_C_V3_Aloha_seen/make_sandwich/003/scene.usd filter=lfs diff=lfs merge=lfs -text +validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/brown_photostudio_02_4k.exr filter=lfs diff=lfs merge=lfs -text +validation/IROS_C_V3_Aloha_unseen/sort_waste/000/scene.usd filter=lfs diff=lfs merge=lfs -text +validation/IROS_C_V3_Aloha_unseen/sort_waste/005/scene.usd filter=lfs diff=lfs merge=lfs -text +validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/brown_photostudio_02_4k.exr filter=lfs diff=lfs merge=lfs -text +validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/004/scene.usd filter=lfs diff=lfs merge=lfs -text +validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/brown_photostudio_02_4k.exr filter=lfs diff=lfs merge=lfs -text diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/004/scene.usd b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/004/scene.usd new file mode 100644 index 0000000000000000000000000000000000000000..54313d7c3fe53a260ba358e1ec5652d3a207de89 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/004/scene.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d81d0e861c8b9d5ffb12719353ee7109ad4c5817686c2c2008455d8190057708 +size 65275690 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture0.jpg b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b772a5dd5e41dcddfa6d2ce46f7f1e8a4f33906f --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture0.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3e3bd79f5cf33d38412e428c417c3487cddb9044b059bd4276df2c44b0c5227 +size 17012 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture2.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture2.png new file mode 100644 index 0000000000000000000000000000000000000000..438a0f15a4897676705c3c3f70cb6b3c122b3eb8 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed315506b4c41ecdf8d9f8f273eedadb2ab5d9a5c71a02d235fab23137f8f499 +size 610044 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture3.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture3.png new file mode 100644 index 0000000000000000000000000000000000000000..438a0f15a4897676705c3c3f70cb6b3c122b3eb8 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/398c1b3b8114409a89eb02f9b42f8064_texture3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed315506b4c41ecdf8d9f8f273eedadb2ab5d9a5c71a02d235fab23137f8f499 +size 610044 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/5d3f935344b61600019162e4_color.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/5d3f935344b61600019162e4_color.png new file mode 100644 index 0000000000000000000000000000000000000000..046daec267d77181089a14e42d7548fbcc420d21 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/5d3f935344b61600019162e4_color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:464579158e457fa6a162bda93aa5d3ea39a866a8c03fcbabea8dd5ddd08098bf +size 1084008 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/black.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/black.png new file mode 100644 index 0000000000000000000000000000000000000000..fe25e679621fef83e0b6e7a2a37e761c0f1fb016 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/black.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1737b9d208dc78e4638c6c2e98a46f222c5aa8bbe3dfa7812b869c0351c9d509 +size 197 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/black_1.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/black_1.png new file mode 100644 index 0000000000000000000000000000000000000000..fe25e679621fef83e0b6e7a2a37e761c0f1fb016 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/black_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1737b9d208dc78e4638c6c2e98a46f222c5aa8bbe3dfa7812b869c0351c9d509 +size 197 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/brown_photostudio_02_4k.exr b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/brown_photostudio_02_4k.exr new file mode 100644 index 0000000000000000000000000000000000000000..f2712e277f960d20e233e19cb675a2902691b4d1 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/brown_photostudio_02_4k.exr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:580a912e23d2298f59e983496fd9b4a4646a0659877e0f0391fcddb8813f2034 +size 20159867 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/normal.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/normal.png new file mode 100644 index 0000000000000000000000000000000000000000..bcd2cbe633402945b9863951d24f055ae6be3bfd --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffa19106ab1ef542307afa48e779c169d23d534bb0acd7c99d986889a19f002c +size 196 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/normal_1.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/normal_1.png new file mode 100644 index 0000000000000000000000000000000000000000..bcd2cbe633402945b9863951d24f055ae6be3bfd --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/normal_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffa19106ab1ef542307afa48e779c169d23d534bb0acd7c99d986889a19f002c +size 196 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..3d763ff213aa8fcfb490f54b2302071a36e624e5 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf7348ad4150c67621b3936012f2616616b8f336a5ad2f87788064282044e010 +size 3889168 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_1.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_1.png new file mode 100644 index 0000000000000000000000000000000000000000..97d0f01a799b204d70ba0c6727347b3205f5ea72 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac5952c927202c3468da5cb65aef58ef2e20dc8afdc03a95b966b87f8b507f05 +size 2169566 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_2.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_2.png new file mode 100644 index 0000000000000000000000000000000000000000..3962e4da34fef4ae96f2358a594ca49078372d00 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:223c7173f0ac631cfc79688cc32db84f7eff606edd85b4630eb2e6832c1d1634 +size 3902931 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_3.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_3.png new file mode 100644 index 0000000000000000000000000000000000000000..b6dde05ea11c0be07c93639e81994894723a0135 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_diffuse_3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18778365fbf191473fe26e6050d56862e653e2b23fdb702fe073540dc8fe32e7 +size 2608821 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_metallic-texture_roughness.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_metallic-texture_roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..f9d0f7056f37d583b742de0dcd9e9bff48eed40f --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_metallic-texture_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa0c13adcbc8f06b46e32d36d30f5b084482c134e66169985db22f258b5b6ca5 +size 3034388 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_metallic-texture_roughness_2.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_metallic-texture_roughness_2.png new file mode 100644 index 0000000000000000000000000000000000000000..4c59ed99bbb2b0944d13486abaef221c7f6bdcb2 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_metallic-texture_roughness_2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b364bb45c659ec4b84bfd1e0d99e40710394247e0fa0d2e9a3b49443ca945bf +size 2878868 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..5652a18dca41155abd156890bd356001fc31a36e --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ef0b814853ec0aa0e782cf3ae570a7cf187f545e39a56a894f4e53a26f3f599 +size 4433210 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal_1.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal_1.png new file mode 100644 index 0000000000000000000000000000000000000000..8ba4ad75f7b2c7cb468dd1ca565fc3b74cf57322 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9c045595270fdbf27a46ab4c5d715062f91ad441c74ce609d54718a5b384d0d +size 2690848 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal_2.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal_2.png new file mode 100644 index 0000000000000000000000000000000000000000..0698ee1b1399457effc57ff465d9758183b75ae0 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/texture_normal_2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b52b04374f01326124a3a65f38134840fb9e6fc707235d699bb983c4d9c790e5 +size 3773003 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/white.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/white.png new file mode 100644 index 0000000000000000000000000000000000000000..8e7c9ddfd5b159635f2775c4487099834432f834 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/white.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3953e0be8bde97630eb7e1ee94a34f08cc408895ddd1244a29958ef5da3ea40 +size 195 diff --git a/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/white_1.png b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/white_1.png new file mode 100644 index 0000000000000000000000000000000000000000..8e7c9ddfd5b159635f2775c4487099834432f834 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_seen/gather_three_teaboxes/SubUSDs/textures/white_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3953e0be8bde97630eb7e1ee94a34f08cc408895ddd1244a29958ef5da3ea40 +size 195 diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl new file mode 100644 index 0000000000000000000000000000000000000000..9aad34bcd7bd5f29f99549120f776102febec45d --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl @@ -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 Num608bbc47c6ff5a0001d607d8( + uniform texture_2d Normal_Tex = texture_2d("../textures/normal_1.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_1.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_1.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_1.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_1.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_1.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); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/OmniUe4Base.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/OmniUe4Base.mdl new file mode 100644 index 0000000000000000000000000000000000000000..a441fbaf28040302c7aaabfbcf14b24a85bdf643 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/OmniUe4Base.mdl @@ -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 + ) +); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/OmniUe4Function.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/OmniUe4Function.mdl new file mode 100644 index 0000000000000000000000000000000000000000..f0801afff6f0870ea2574c9e9b6e2043e79e9a79 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/002/SubUSDs/materials/OmniUe4Function.mdl @@ -0,0 +1,1413 @@ +/*************************************************************************************************** + * 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.1 - using absolute import paths when importing standard modules + +mdl 1.6; + +import ::df::*; +import ::state::*; +import ::math::*; +import ::tex::*; +import ::anno::*; + + +export float3 convert_to_left_hand(float3 vec3, uniform bool up_z = true, uniform bool is_position = true) +[[ + anno::description("convert from RH to LH"), + anno::noinline() +]] +{ + float4x4 ZupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4x4 YupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4 vec4 = float4(vec3.x, vec3.y, vec3.z, is_position ? 1.0f : 0.0f); + + vec4 = vec4 * (up_z ? ZupConversion : YupConversion); + + return float3(vec4.x, vec4.y, vec4.z); +} + +export float3 transform_vector_from_tangent_to_world(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from tangent space to world space"), + anno::noinline() +]] +{ + /* flip_tangent_v */ + return convert_to_left_hand( + tangent_u * vector.x - tangent_v * vector.y + state::normal() * vector.z, + up_z, false); +} + +export float3 transform_vector_from_world_to_tangent(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from world space to tangent space"), + anno::noinline() +]] +{ + float3 vecRH = convert_to_left_hand(vector, up_z, false); + /* flip_tangent_v */ + return vecRH.x * float3(tangent_u.x, -tangent_v.x, state::normal().x) + + vecRH.y * float3(tangent_u.y, -tangent_v.y, state::normal().y) + + vecRH.z * float3(tangent_u.z, -tangent_v.z, state::normal().z); +} + +export float4 unpack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Unpack a normal stored in a normal map"), + anno::noinline() +]] +{ + float2 normal_xy = float2(texture_sample.x, texture_sample.y); + + normal_xy = normal_xy * float2(2.0,2.0) - float2(1.0,1.0); + float normal_z = math::sqrt( math::saturate( 1.0 - math::dot( normal_xy, normal_xy ) ) ); + return float4( normal_xy.x, normal_xy.y, normal_z, 1.0 ); +} + +// for get color value from normal. +export float4 pack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Pack to color from a normal") +]] +{ + float2 return_xy = float2(texture_sample.x, texture_sample.y); + + return_xy = (return_xy + float2(1.0,1.0)) / float2(2.0,2.0); + + return float4( return_xy.x, return_xy.y, 0.0, 1.0 ); +} + +export float4 greyscale_texture_lookup( + float4 texture_sample = float4(0.0, 0.0, 0.0, 1.0) + ) +[[ + anno::description("Sampling a greyscale texture"), + anno::noinline() +]] +{ + return float4(texture_sample.x, texture_sample.x, texture_sample.x, texture_sample.x); +} + +export float3 pixel_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Pixel normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 vertex_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Vertex normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 landscape_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Landscape normal in world space") +]] +{ + float3 normalFromNormalmap = math::floor((::vertex_normal_world_space(up_z) * 0.5 + 0.5) * 255.0) / 255.0 * 2.0 - 1.0; + + float2 normalXY = float2(normalFromNormalmap.x, normalFromNormalmap.y); + return float3(normalXY.x, normalXY.y, math::sqrt(math::saturate(1.0 - math::dot(normalXY, normalXY)))); +} + +// Different implementation specific between mdl and hlsl for smoothstep +export float smoothstep(float a, float b, float l) +{ + if (a < b) + { + return math::smoothstep(a, b, l); + } + else if (a > b) + { + return 1.0 - math::smoothstep(b, a, l); + } + else + { + return l <= a ? 0.0 : 1.0; + } +} + +export float2 smoothstep(float2 a, float2 b, float2 l) +{ + return float2(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y)); +} + +export float3 smoothstep(float3 a, float3 b, float3 l) +{ + return float3(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z)); +} + +export float4 smoothstep(float4 a, float4 b, float4 l) +{ + return float4(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z), smoothstep(a.w, b.w, l.w)); +} + +export float2 smoothstep(float2 a, float2 b, float l) +{ + return float2(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l)); +} + +export float3 smoothstep(float3 a, float3 b, float l) +{ + return float3(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l)); +} + +export float4 smoothstep(float4 a, float4 b, float l) +{ + return float4(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l), smoothstep(a.w, b.w, l)); +} + +export float2 smoothstep(float a, float b, float2 l) +{ + return float2(smoothstep(a, b, l.x), smoothstep(a, b, l.y)); +} + +export float3 smoothstep(float a, float b, float3 l) +{ + return float3(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z)); +} + +export float4 smoothstep(float a, float b, float4 l) +{ + return float4(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z), smoothstep(a, b, l.w)); +} + +//------------------ Random from UE4 ----------------------- +float length2(float3 v) +{ + return math::dot(v, v); +} + +float3 GetPerlinNoiseGradientTextureAt(uniform texture_2d PerlinNoiseGradientTexture, float3 v) +{ + const float2 ZShear = float2(17.0f, 89.0f); + + float2 OffsetA = v.z * ZShear; + float2 TexA = (float2(v.x, v.y) + OffsetA + 0.5f) / 128.0f; + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA.x,1.0-TexA.y),tex::wrap_repeat,tex::wrap_repeat); + return float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z) * 2.0 - 1.0; +} + +float3 SkewSimplex(float3 In) +{ + return In + math::dot(In, float3(1.0 / 3.0f) ); +} +float3 UnSkewSimplex(float3 In) +{ + return In - math::dot(In, float3(1.0 / 6.0f) ); +} + +// 3D random number generator inspired by PCGs (permuted congruential generator) +// Using a **simple** Feistel cipher in place of the usual xor shift permutation step +// @param v = 3D integer coordinate +// @return three elements w/ 16 random bits each (0-0xffff). +// ~8 ALU operations for result.x (7 mad, 1 >>) +// ~10 ALU operations for result.xy (8 mad, 2 >>) +// ~12 ALU operations for result.xyz (9 mad, 3 >>) + +//TODO: uint3 +int3 Rand3DPCG16(int3 p) +{ + // taking a signed int then reinterpreting as unsigned gives good behavior for negatives + //TODO: uint3 + int3 v = int3(p); + + // Linear congruential step. These LCG constants are from Numerical Recipies + // For additional #'s, PCG would do multiple LCG steps and scramble each on output + // So v here is the RNG state + v = v * 1664525 + 1013904223; + + // PCG uses xorshift for the final shuffle, but it is expensive (and cheap + // versions of xorshift have visible artifacts). Instead, use simple MAD Feistel steps + // + // Feistel ciphers divide the state into separate parts (usually by bits) + // then apply a series of permutation steps one part at a time. The permutations + // use a reversible operation (usually ^) to part being updated with the result of + // a permutation function on the other parts and the key. + // + // In this case, I'm using v.x, v.y and v.z as the parts, using + instead of ^ for + // the combination function, and just multiplying the other two parts (no key) for + // the permutation function. + // + // That gives a simple mad per round. + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + + // only top 16 bits are well shuffled + return v >> 16; +} + +// Wraps noise for tiling texture creation +// @param v = unwrapped texture parameter +// @param bTiling = true to tile, false to not tile +// @param RepeatSize = number of units before repeating +// @return either original or wrapped coord +float3 NoiseTileWrap(float3 v, bool bTiling, float RepeatSize) +{ + return bTiling ? (math::frac(v / RepeatSize) * RepeatSize) : v; +} + +// Evaluate polynomial to get smooth transitions for Perlin noise +// only needed by Perlin functions in this file +// scalar(per component): 2 add, 5 mul +float4 PerlinRamp(float4 t) +{ + return t * t * t * (t * (t * 6 - 15) + 10); +} + +// Blum-Blum-Shub-inspired pseudo random number generator +// http://www.umbc.edu/~olano/papers/mNoise.pdf +// real BBS uses ((s*s) mod M) with bignums and M as the product of two huge Blum primes +// instead, we use a single prime M just small enough not to overflow +// note that the above paper used 61, which fits in a half, but is unusably bad +// @param Integer valued floating point seed +// @return random number in range [0,1) +// ~8 ALU operations (5 *, 3 frac) +float RandBBSfloat(float seed) +{ + float BBS_PRIME24 = 4093.0; + float s = math::frac(seed / BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + return s; +} + +// Modified noise gradient term +// @param seed - random seed for integer lattice position +// @param offset - [-1,1] offset of evaluation point from lattice point +// @return gradient direction (xyz) and contribution (w) from this lattice point +float4 MGradient(int seed, float3 offset) +{ + //TODO uint + int rand = Rand3DPCG16(int3(seed,0,0)).x; + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1.0 / 0x4000, 1.0 / 0x2000, 1.0 / 0x1000); + float3 direction = float3(int3(rand, rand, rand) & MGradientMask) * MGradientScale - 1; + return float4(direction.x, direction.y, direction.z, math::dot(direction, offset)); +} + +// compute Perlin and related noise corner seed values +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = true to return seed values for a repeating noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @param seed000-seed111 = hash function seeds for the eight corners +// @return fractional part of v +struct SeedValue +{ + float3 fv = float3(0); + float seed000 = 0; + float seed001 = 0; + float seed010 = 0; + float seed011 = 0; + float seed100 = 0; + float seed101 = 0; + float seed110 = 0; + float seed111 = 0; +}; + +SeedValue NoiseSeeds(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds; + seeds.fv = math::frac(v); + float3 iv = math::floor(v); + + const float3 primes = float3(19, 47, 101); + + if (bTiling) + { // can't algebraically combine with primes + seeds.seed000 = math::dot(primes, NoiseTileWrap(iv, true, RepeatSize)); + seeds.seed100 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 0), true, RepeatSize)); + seeds.seed010 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 0), true, RepeatSize)); + seeds.seed110 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 0), true, RepeatSize)); + seeds.seed001 = math::dot(primes, NoiseTileWrap(iv + float3(0, 0, 1), true, RepeatSize)); + seeds.seed101 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 1), true, RepeatSize)); + seeds.seed011 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 1), true, RepeatSize)); + seeds.seed111 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 1), true, RepeatSize)); + } + else + { // get to combine offsets with multiplication by primes in this case + seeds.seed000 = math::dot(iv, primes); + seeds.seed100 = seeds.seed000 + primes.x; + seeds.seed010 = seeds.seed000 + primes.y; + seeds.seed110 = seeds.seed100 + primes.y; + seeds.seed001 = seeds.seed000 + primes.z; + seeds.seed101 = seeds.seed100 + primes.z; + seeds.seed011 = seeds.seed010 + primes.z; + seeds.seed111 = seeds.seed110 + primes.z; + } + + return seeds; +} + +struct SimplexWeights +{ + float4 Result = float4(0); + float3 PosA = float3(0); + float3 PosB = float3(0); + float3 PosC = float3(0); + float3 PosD = float3(0); +}; + +// Computed weights and sample positions for simplex interpolation +// @return float4(a,b,c, d) Barycentric coordinate defined as Filtered = Tex(PosA) * a + Tex(PosB) * b + Tex(PosC) * c + Tex(PosD) * d +SimplexWeights ComputeSimplexWeights3D(float3 OrthogonalPos) +{ + SimplexWeights weights; + float3 OrthogonalPosFloor = math::floor(OrthogonalPos); + + weights.PosA = OrthogonalPosFloor; + weights.PosB = weights.PosA + float3(1, 1, 1); + + OrthogonalPos -= OrthogonalPosFloor; + + float Largest = math::max(OrthogonalPos.x, math::max(OrthogonalPos.y, OrthogonalPos.z)); + float Smallest = math::min(OrthogonalPos.x, math::min(OrthogonalPos.y, OrthogonalPos.z)); + + weights.PosC = weights.PosA + float3(Largest == OrthogonalPos.x, Largest == OrthogonalPos.y, Largest == OrthogonalPos.z); + weights.PosD = weights.PosA + float3(Smallest != OrthogonalPos.x, Smallest != OrthogonalPos.y, Smallest != OrthogonalPos.z); + + float RG = OrthogonalPos.x - OrthogonalPos.y; + float RB = OrthogonalPos.x - OrthogonalPos.z; + float GB = OrthogonalPos.y - OrthogonalPos.z; + + weights.Result.z = + math::min(math::max(0, RG), math::max(0, RB)) // X + + math::min(math::max(0, -RG), math::max(0, GB)) // Y + + math::min(math::max(0, -RB), math::max(0, -GB)); // Z + + weights.Result.w = + math::min(math::max(0, -RG), math::max(0, -RB)) // X + + math::min(math::max(0, RG), math::max(0, -GB)) // Y + + math::min(math::max(0, RB), math::max(0, GB)); // Z + + weights.Result.y = Smallest; + weights.Result.x = 1.0f - weights.Result.y - weights.Result.z - weights.Result.w; + + return weights; +} + +// filtered 3D gradient simple noise (few texture lookups, high quality) +// @param v >0 +// @return random number in the range -1 .. 1 +float SimplexNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 EvalPos) +{ + float3 OrthogonalPos = SkewSimplex(EvalPos); + + SimplexWeights Weights = ComputeSimplexWeights3D(OrthogonalPos); + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 32 bit) + float3 A = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosA); + float3 B = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosB); + float3 C = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosC); + float3 D = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosD); + + Weights.PosA = UnSkewSimplex(Weights.PosA); + Weights.PosB = UnSkewSimplex(Weights.PosB); + Weights.PosC = UnSkewSimplex(Weights.PosC); + Weights.PosD = UnSkewSimplex(Weights.PosD); + + float DistanceWeight; + + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosA)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float a = math::dot(A, EvalPos - Weights.PosA) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosB)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float b = math::dot(B, EvalPos - Weights.PosB) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosC)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float c = math::dot(C, EvalPos - Weights.PosC) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosD)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float d = math::dot(D, EvalPos - Weights.PosD) * DistanceWeight; + + return 32 * (a + b + c + d); +} + +// filtered 3D noise, can be optimized +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 v, bool bTiling, float RepeatSize) +{ + bTiling = true; + float3 fv = math::frac(v); + float3 iv0 = NoiseTileWrap(math::floor(v), bTiling, RepeatSize); + float3 iv1 = NoiseTileWrap(iv0 + 1, bTiling, RepeatSize); + + const int2 ZShear = int2(17, 89); + + float2 OffsetA = iv0.z * ZShear; + float2 OffsetB = OffsetA + ZShear; // non-tiling, use relative offset + if (bTiling) // tiling, have to compute from wrapped coordinates + { + OffsetB = iv1.z * ZShear; + } + + // Texture size scale factor + float ts = 1 / 128.0f; + + // texture coordinates for iv0.xy, as offset for both z slices + float2 TexA0 = (float2(iv0.x, iv0.y) + OffsetA + 0.5f) * ts; + float2 TexB0 = (float2(iv0.x, iv0.y) + OffsetB + 0.5f) * ts; + + // texture coordinates for iv1.xy, as offset for both z slices + float2 TexA1 = TexA0 + ts; // for non-tiling, can compute relative to existing coordinates + float2 TexB1 = TexB0 + ts; + if (bTiling) // for tiling, need to compute from wrapped coordinates + { + TexA1 = (float2(iv1.x, iv1.y) + OffsetA + 0.5f) * ts; + TexB1 = (float2(iv1.x, iv1.y) + OffsetB + 0.5f) * ts; + } + + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 8, 16 or 32 bit) + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + float3 PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 A = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 B = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 C = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 D = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 E = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 F = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 G = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 H = PerlinNoiseColor * 2 - 1; + + float a = math::dot(A, fv - float3(0, 0, 0)); + float b = math::dot(B, fv - float3(1, 0, 0)); + float c = math::dot(C, fv - float3(0, 1, 0)); + float d = math::dot(D, fv - float3(1, 1, 0)); + float e = math::dot(E, fv - float3(0, 0, 1)); + float f = math::dot(F, fv - float3(1, 0, 1)); + float g = math::dot(G, fv - float3(0, 1, 1)); + float h = math::dot(H, fv - float3(1, 1, 1)); + + float4 Weights = PerlinRamp(math::frac(float4(fv.x, fv.y, fv.z, 0))); + + float i = math::lerp(math::lerp(a, b, Weights.x), math::lerp(c, d, Weights.x), Weights.y); + float j = math::lerp(math::lerp(e, f, Weights.x), math::lerp(g, h, Weights.x), Weights.y); + + return math::lerp(i, j, Weights.z); +} + +// @return random number in the range -1 .. 1 +// scalar: 6 frac, 31 mul/mad, 15 add, +float FastGradientPerlinNoise3D_TEX(uniform texture_3d PerlinNoise3DTexture, float3 xyz) +{ + // needs to be the same value when creating the PerlinNoise3D texture + float Extent = 16; + + // last texel replicated and needed for filtering + // scalar: 3 frac, 6 mul + xyz = math::frac(xyz / (Extent - 1)) * (Extent - 1); + + // scalar: 3 frac + float3 uvw = math::frac(xyz); + // = floor(xyz); + // scalar: 3 add + float3 p0 = xyz - uvw; +// float3 f = math::pow(uvw, 2) * 3.0f - math::pow(uvw, 3) * 2.0f; // original perlin hermite (ok when used without bump mapping) + // scalar: 2*3 add 5*3 mul + float4 pr = PerlinRamp(float4(uvw.x, uvw.y, uvw.z, 0)); + float3 f = float3(pr.x, pr.y, pr.z); // new, better with continues second derivative for bump mapping + // scalar: 3 add + float3 p = p0 + f; + // scalar: 3 mad + // TODO: need reverse??? + float4 NoiseSample = tex::lookup_float4(PerlinNoise3DTexture, p / Extent + 0.5f / Extent); // +0.5f to get rid of bilinear offset + + // reconstruct from 8bit (using mad with 2 constants and dot4 was same instruction count) + // scalar: 4 mad, 3 mul, 3 add + float3 n = float3(NoiseSample.x, NoiseSample.y, NoiseSample.z) * 255.0f / 127.0f - 1.0f; + float d = NoiseSample.w * 255.f - 127; + return math::dot(xyz, n) - d; +} + +// Perlin-style "Modified Noise" +// http://www.umbc.edu/~olano/papers/index.html#mNoise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = MGradient(int(seeds.seed000), seeds.fv - float3(0, 0, 0)).w; + float rand100 = MGradient(int(seeds.seed100), seeds.fv - float3(1, 0, 0)).w; + float rand010 = MGradient(int(seeds.seed010), seeds.fv - float3(0, 1, 0)).w; + float rand110 = MGradient(int(seeds.seed110), seeds.fv - float3(1, 1, 0)).w; + float rand001 = MGradient(int(seeds.seed001), seeds.fv - float3(0, 0, 1)).w; + float rand101 = MGradient(int(seeds.seed101), seeds.fv - float3(1, 0, 1)).w; + float rand011 = MGradient(int(seeds.seed011), seeds.fv - float3(0, 1, 1)).w; + float rand111 = MGradient(int(seeds.seed111), seeds.fv - float3(1, 1, 1)).w; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D value noise - used to be incorrectly called Perlin noise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float ValueNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = RandBBSfloat(seeds.seed000) * 2 - 1; + float rand100 = RandBBSfloat(seeds.seed100) * 2 - 1; + float rand010 = RandBBSfloat(seeds.seed010) * 2 - 1; + float rand110 = RandBBSfloat(seeds.seed110) * 2 - 1; + float rand001 = RandBBSfloat(seeds.seed001) * 2 - 1; + float rand101 = RandBBSfloat(seeds.seed101) * 2 - 1; + float rand011 = RandBBSfloat(seeds.seed011) * 2 - 1; + float rand111 = RandBBSfloat(seeds.seed111) * 2 - 1; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D jitter offset within a voronoi noise cell +// @param pos - integer lattice corner +// @return random offsets vector +float3 VoronoiCornerSample(float3 pos, int Quality) +{ + // random values in [-0.5, 0.5] + float3 noise = float3(Rand3DPCG16(int3(pos))) / 0xffff - 0.5; + + // quality level 1 or 2: searches a 2x2x2 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 2x2x2 search + if (Quality <= 2) + { + return math::normalize(noise) * 0.2588; + } + + // quality level 3: searches a 3x3x3 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 3x3x3 search + if (Quality == 3) + { + return math::normalize(noise) * 0.3090; + } + + // quality level 4: jitter to anywhere in the cell, needs 4x4x4 search + return noise; +} + +// compare previous best with a new candidate +// not producing point locations makes it easier for compiler to eliminate calculations when they're not needed +// @param minval = location and distance of best candidate seed point before the new one +// @param candidate = candidate seed point +// @param offset = 3D offset to new candidate seed point +// @param bDistanceOnly = if true, only set maxval.w with distance, otherwise maxval.w is distance and maxval.xyz is position +// @return position (if bDistanceOnly is false) and distance to closest seed point so far +float4 VoronoiCompare(float4 minval, float3 candidate, float3 offset, bool bDistanceOnly) +{ + if (bDistanceOnly) + { + return float4(0, 0, 0, math::min(minval.w, math::dot(offset, offset))); + } + else + { + float newdist = math::dot(offset, offset); + return newdist > minval.w ? minval : float4(candidate.x, candidate.y, candidate.z, newdist); + } +} + +// 220 instruction Worley noise +float4 VoronoiNoise3D_ALU(float3 v, int Quality, bool bTiling, float RepeatSize, bool bDistanceOnly) +{ + float3 fv = math::frac(v), fv2 = math::frac(v + 0.5); + float3 iv = math::floor(v), iv2 = math::floor(v + 0.5); + + // with initial minimum distance = infinity (or at least bigger than 4), first min is optimized away + float4 mindist = float4(0,0,0,100); + float3 p, offset; + + // quality level 3: do a 3x3x3 search + if (Quality == 3) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 1; ++offset_x) + { + for (offset_y = -1; offset_y <= 1; ++offset_y) + { + for (offset_z = -1; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + + // everybody else searches a base 2x2x2 neighborhood + else + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = 0; offset_x <= 1; ++offset_x) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // quality level 2, do extra set of points, offset by half a cell + if (Quality == 2) + { + // 467 is just an offset to a different area in the random number field to avoid similar neighbor artifacts + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize) + 467, Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + } + + // quality level 4: add extra sets of four cells in each direction + if (Quality >= 4) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 2; offset_x += 3) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + // along x axis + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along y axis + p = float3(offset.y, offset.z, offset.x) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.y, offset.z, offset.x), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along z axis + p = float3(offset.z, offset.x, offset.y) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.z, offset.x, offset.y), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + } + } + } + } + + // transform squared distance to real distance + return float4(mindist.x, mindist.y, mindist.z, math::sqrt(mindist.w)); +} + +// Coordinates for corners of a Simplex tetrahedron +// Based on McEwan et al., Efficient computation of noise in GLSL, JGT 2011 +// @param v = 3D noise argument +// @return 4 corner locations +float4x3 SimplexCorners(float3 v) +{ + // find base corner by skewing to tetrahedral space and back + float3 tet = math::floor(v + v.x/3 + v.y/3 + v.z/3); + float3 base = tet - tet.x/6 - tet.y/6 - tet.z/6; + float3 f = v - base; + + // Find offsets to other corners (McEwan did this in tetrahedral space, + // but since skew is along x=y=z axis, this works in Euclidean space too.) + float3 g = math::step(float3(f.y,f.z,f.x), float3(f.x,f.y,f.z)), h = 1 - float3(g.z, g.x, g.y); + float3 a1 = math::min(g, h) - 1.0 / 6.0, a2 = math::max(g, h) - 1.0 / 3.0; + + // four corners + return float4x3(base, base + a1, base + a2, base + 0.5); +} + +// Improved smoothing function for simplex noise +// @param f = fractional distance to four tetrahedral corners +// @return weight for each corner +float4 SimplexSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + return (1 * scale + s*(-3 * scale + s*(3 * scale - s*scale))); +} + +// Derivative of simplex noise smoothing function +// @param f = fractional distanc eto four tetrahedral corners +// @return derivative of smoothing function for each corner by x, y and z +float3x4 SimplexDSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + s = -12 * scale + s*(24 * scale - s * 12 * scale); + + return float3x4( + s * float4(f[0][0], f[1][0], f[2][0], f[3][0]), + s * float4(f[0][1], f[1][1], f[2][1], f[3][1]), + s * float4(f[0][2], f[1][2], f[2][2], f[3][2])); +} + +// Simplex noise and its Jacobian derivative +// @param v = 3D noise argument +// @param bTiling = whether to repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension, must be a multiple of 3 +// @return float3x3 Jacobian in J[*].xyz, vector noise in J[*].w +// J[0].w, J[1].w, J[2].w is a Perlin-style simplex noise with vector output, e.g. (Nx, Ny, Nz) +// J[i].x is X derivative of the i'th component of the noise so J[2].x is dNz/dx +// You can use this to compute the noise, gradient, curl, or divergence: +// float3x4 J = JacobianSimplex_ALU(...); +// float3 VNoise = float3(J[0].w, J[1].w, J[2].w); // 3D noise +// float3 Grad = J[0].xyz; // gradient of J[0].w +// float3 Curl = float3(J[1][2]-J[2][1], J[2][0]-J[0][2], J[0][1]-J[1][2]); +// float Div = J[0][0]+J[1][1]+J[2][2]; +// All of these are confirmed to compile out all unneeded terms. +// So Grad of X doesn't compute Y or Z components, and VNoise doesn't do any of the derivative computation. +float3x4 JacobianSimplex_ALU(float3 v, bool bTiling, float RepeatSize) +{ + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1. / 0x4000, 1. / 0x2000, 1. / 0x1000); + + // corners of tetrahedron + float4x3 T = SimplexCorners(v); + // TODO: uint3 + int3 rand = int3(0); + float4x3 gvec0 = float4x3(1.0); + float4x3 gvec1 = float4x3(1.0); + float4x3 gvec2 = float4x3(1.0); + float4x3 fv = float4x3(1.0); + float3x4 grad = float3x4(1.0); + + // processing of tetrahedral vertices, unrolled + // to compute gradient at each corner + fv[0] = v - T[0]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[0] + 0.5, bTiling, RepeatSize)))); + gvec0[0] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[0] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[0] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][0] = math::dot(gvec0[0], fv[0]); + grad[1][0] = math::dot(gvec1[0], fv[0]); + grad[2][0] = math::dot(gvec2[0], fv[0]); + + fv[1] = v - T[1]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[1] + 0.5, bTiling, RepeatSize)))); + gvec0[1] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][1] = math::dot(gvec0[1], fv[1]); + grad[1][1] = math::dot(gvec1[1], fv[1]); + grad[2][1] = math::dot(gvec2[1], fv[1]); + + fv[2] = v - T[2]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[2] + 0.5, bTiling, RepeatSize)))); + gvec0[2] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[2] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[2] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][2] = math::dot(gvec0[2], fv[2]); + grad[1][2] = math::dot(gvec1[2], fv[2]); + grad[2][2] = math::dot(gvec2[2], fv[2]); + + fv[3] = v - T[3]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[3] + 0.5, bTiling, RepeatSize)))); + gvec0[3] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[3] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[3] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][3] = math::dot(gvec0[3], fv[3]); + grad[1][3] = math::dot(gvec1[3], fv[3]); + grad[2][3] = math::dot(gvec2[3], fv[3]); + + // blend gradients + float4 sv = SimplexSmooth(fv); + float3x4 ds = SimplexDSmooth(fv); + + float3x4 jacobian = float3x4(1.0); + float3 vec0 = gvec0*sv + grad[0]*ds; // NOTE: mdl is column major, convert from UE4 (row major) + jacobian[0] = float4(vec0.x, vec0.y, vec0.z, math::dot(sv, grad[0])); + float3 vec1 = gvec1*sv + grad[1]*ds; + jacobian[1] = float4(vec1.x, vec1.y, vec1.z, math::dot(sv, grad[1])); + float3 vec2 = gvec2*sv + grad[2]*ds; + jacobian[2] = float4(vec2.x, vec2.y, vec2.z, math::dot(sv, grad[2])); + + return jacobian; +} + +// While RepeatSize is a float here, the expectation is that it would be largely integer values coming in from the UI. The downstream logic assumes +// floats for all called functions (NoiseTileWrap) and this prevents any float-to-int conversion errors from automatic type conversion. +float Noise3D_Multiplexer(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, int Function, float3 Position, int Quality, bool bTiling, float RepeatSize) +{ + // verified, HLSL compiled out the switch if Function is a constant + switch(Function) + { + case 0: + return SimplexNoise3D_TEX(PerlinNoiseGradientTexture, Position); + case 1: + return GradientNoise3D_TEX(PerlinNoiseGradientTexture, Position, bTiling, RepeatSize); + case 2: + return FastGradientPerlinNoise3D_TEX(PerlinNoise3DTexture, Position); + case 3: + return GradientNoise3D_ALU(Position, bTiling, RepeatSize); + case 4: + return ValueNoise3D_ALU(Position, bTiling, RepeatSize); + case 5: + return VoronoiNoise3D_ALU(Position, Quality, bTiling, RepeatSize, true).w * 2.0 - 1.0; + } + return 0; +} +//---------------------------------------------------------- + +export float noise(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, float3 Position, float Scale, float Quality, float Function, float Turbulence, float Levels, float OutputMin, float OutputMax, float LevelScale, float FilterWidth, float Tiling, float RepeatSize) +[[ + anno::description("Noise"), + anno::noinline() +]] +{ + Position *= Scale; + FilterWidth *= Scale; + + float Out = 0.0f; + float OutScale = 1.0f; + float InvLevelScale = 1.0f / LevelScale; + + int iFunction(Function); + int iQuality(Quality); + int iLevels(Levels); + bool bTurbulence(Turbulence); + bool bTiling(Tiling); + + for(int i = 0; i < iLevels; ++i) + { + // fade out noise level that are too high frequent (not done through dynamic branching as it usually requires gradient instructions) + OutScale *= math::saturate(1.0 - FilterWidth); + + if(bTurbulence) + { + Out += math::abs(Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize)) * OutScale; + } + else + { + Out += Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize) * OutScale; + } + + Position *= LevelScale; + RepeatSize *= LevelScale; + OutScale *= InvLevelScale; + FilterWidth *= LevelScale; + } + + if(!bTurbulence) + { + // bring -1..1 to 0..1 range + Out = Out * 0.5f + 0.5f; + } + + // Out is in 0..1 range + return math::lerp(OutputMin, OutputMax, Out); +} + +// Material node for noise functions returning a vector value +// @param LevelScale usually 2 but higher values allow efficient use of few levels +// @return in user defined range (OutputMin..OutputMax) +export float4 vector4_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise"), + anno::noinline() +]] +{ + float4 result = float4(0,0,0,1); + float3 ret = float3(0); + int iQuality = int(Quality); + int iFunction = int(Function); + bool bTiling = Tiling > 0.0; + + float3x4 Jacobian = JacobianSimplex_ALU(Position, bTiling, TileSize); // compiled out if not used + + // verified, HLSL compiled out the switch if Function is a constant + switch (iFunction) + { + case 0: // Cellnoise + ret = float3(Rand3DPCG16(int3(math::floor(NoiseTileWrap(Position, bTiling, TileSize))))) / 0xffff; + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 1: // Color noise + ret = float3(Jacobian[0].w, Jacobian[1].w, Jacobian[2].w); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 2: // Gradient + result = Jacobian[0]; + break; + case 3: // Curl + ret = float3(Jacobian[2][1] - Jacobian[1][2], Jacobian[0][2] - Jacobian[2][0], Jacobian[1][0] - Jacobian[0][1]); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 4: // Voronoi + result = VoronoiNoise3D_ALU(Position, iQuality, bTiling, TileSize, false); + break; + } + return result; +} + +export float3 vector3_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise float3 version"), + anno::noinline() +]] +{ + float4 noise = vector4_noise(Position, Quality, Function, Tiling, TileSize); + return float3(noise.x, noise.y, noise.z); +} + + +// workaround for ue4 fresnel (without supporting for camera vector) : replacing it with 0.0, means facing to the view +export float fresnel(float exponent [[anno::unused()]], float base_reflect_fraction [[anno::unused()]], float3 normal [[anno::unused()]]) +[[ + anno::description("Fresnel"), + anno::noinline() +]] +{ + return 0.0; +} + +export float fresnel_function(float3 normal_vector [[anno::unused()]], float3 camera_vector [[anno::unused()]], + bool invert_fresnel [[anno::unused()]], float power [[anno::unused()]], + bool use_cheap_contrast [[anno::unused()]], float cheap_contrast_dark [[anno::unused()]], float cheap_contrast_bright [[anno::unused()]], + bool clamp_fresnel_dot_product [[anno::unused()]]) +[[ + anno::description("Fresnel Function"), + anno::noinline() +]] +{ + return 0.0; +} + +export float3 camera_vector(uniform bool up_z = true) +[[ + anno::description("Camera Vector"), + anno::noinline() +]] +{ + // assume camera postion is 0,0,0 + return math::normalize(float3(0) - convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)); +} + +export float pixel_depth() +[[ + anno::description("Pixel Depth"), + anno::noinline() +]] +{ + return 256.0f; +} + +export float scene_depth() +[[ + anno::description("Scene Depth") +]] +{ + return 65500.0f; +} + +export float3 scene_color() +[[ + anno::description("Scene Color") +]] +{ + return float3(1.0f); +} + +export float4 vertex_color() +[[ + anno::description("Vertex Color"), + anno::noinline() +]] +{ + return float4(1.0f); +} + +export float4 vertex_color_from_coordinate(int VertexColorCoordinateIndex) +[[ + anno::description("Vertex Color for float2 PrimVar"), + anno::noinline() +]] +{ + // Kit only supports 4 uv sets, 2 uvs are available to vertex color. if vertex color index is invalid, output the constant WHITE color intead + return (VertexColorCoordinateIndex > 2) ? float4(1.0f) : float4(state::texture_coordinate(VertexColorCoordinateIndex).x, state::texture_coordinate(VertexColorCoordinateIndex).y, state::texture_coordinate(VertexColorCoordinateIndex+1).x, state::texture_coordinate(VertexColorCoordinateIndex+1).y); +} + +export float3 camera_position() +[[ + anno::description("Camera Position"), + anno::noinline() +]] +{ + return float3(1000.0f, 0, 0); +} + +export float3 rotate_about_axis(float4 NormalizedRotationAxisAndAngle, float3 PositionOnAxis, float3 Position) +[[ + anno::description("Rotates Position about the given axis by the given angle") +]] +{ + // Project Position onto the rotation axis and find the closest point on the axis to Position + float3 NormalizedRotationAxis = float3(NormalizedRotationAxisAndAngle.x,NormalizedRotationAxisAndAngle.y,NormalizedRotationAxisAndAngle.z); + float3 ClosestPointOnAxis = PositionOnAxis + NormalizedRotationAxis * math::dot(NormalizedRotationAxis, Position - PositionOnAxis); + // Construct orthogonal axes in the plane of the rotation + float3 UAxis = Position - ClosestPointOnAxis; + float3 VAxis = math::cross(NormalizedRotationAxis, UAxis); + float[2] SinCosAngle = math::sincos(NormalizedRotationAxisAndAngle.w); + // Rotate using the orthogonal axes + float3 R = UAxis * SinCosAngle[1] + VAxis * SinCosAngle[0]; + // Reconstruct the rotated world space position + float3 RotatedPosition = ClosestPointOnAxis + R; + // Convert from position to a position offset + return RotatedPosition - Position; +} + +export float2 rotate_scale_offset_texcoords(float2 InTexCoords, float4 InRotationScale, float2 InOffset) +[[ + anno::description("Returns a float2 texture coordinate after 2x2 transform and offset applied") +]] +{ + return float2(math::dot(InTexCoords, float2(InRotationScale.x, InRotationScale.y)), math::dot(InTexCoords, float2(InRotationScale.z, InRotationScale.w))) + InOffset; +} + +export float3 reflection_custom_world_normal(float3 WorldNormal, bool bNormalizeInputNormal, uniform bool up_z = true) +[[ + anno::description("Reflection vector about the specified world space normal") +]] +{ + if (bNormalizeInputNormal) + { + WorldNormal = math::normalize(WorldNormal); + } + + return -camera_vector(up_z) + WorldNormal * math::dot(WorldNormal, camera_vector(up_z)) * 2.0; +} + +export float3 reflection_vector(uniform bool up_z = true) +[[ + anno::description("Reflection Vector"), + anno::noinline() +]] +{ + float3 normal = convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); + return reflection_custom_world_normal(normal, false, up_z); +} + +export float dither_temporalAA(float AlphaThreshold = 0.5f, float Random = 1.0f [[anno::unused()]]) +[[ + anno::description("Dither TemporalAA"), + anno::noinline() +]] +{ + return AlphaThreshold; +} + +export float3 black_body( float Temp ) +[[ + anno::description("Black Body"), + anno::noinline() +]] +{ + float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp ); + float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp ); + + float x = 3*u / ( 2*u - 8*v + 4 ); + float y = 2*v / ( 2*u - 8*v + 4 ); + float z = 1 - x - y; + + float Y = 1; + float X = Y/y * x; + float Z = Y/y * z; + + float3x3 XYZtoRGB = float3x3( + float3(3.2404542, -1.5371385, -0.4985314), + float3(-0.9692660, 1.8760108, 0.0415560), + float3(0.0556434, -0.2040259, 1.0572252) + ); + + return XYZtoRGB * float3( X, Y, Z ) * math::pow( 0.0004 * Temp, 4 ); +} + +export float per_instance_random(uniform texture_2d PerlinNoiseGradientTexture, int NumberInstances) +[[ + anno::description("Per Instance Random"), + anno::noinline() +]] +{ + float weight = state::object_id() / float(NumberInstances); + return NumberInstances == 0 ? 0.0 : tex::lookup_float4(PerlinNoiseGradientTexture, float2(weight, 1.0 - weight), tex::wrap_repeat, tex::wrap_repeat).x; +} + +//------------------ Hair from UE4 ----------------------- +float3 hair_absorption_to_color(float3 A) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::exp(-math::sqrt(A) * D); +} + +float3 hair_color_to_absorption(float3 C) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::pow(math::log(C) / D, 2.0f); +} + +export float3 get_hair_color_from_melanin(float InMelanin, float InRedness, float3 InDyeColor) +[[ + anno::description("Hair Color") +]] +{ + InMelanin = math::saturate(InMelanin); + InRedness = math::saturate(InRedness); + float Melanin = -math::log(math::max(1 - InMelanin, 0.0001f)); + float Eumelanin = Melanin * (1 - InRedness); + float Pheomelanin = Melanin * InRedness; + + float3 DyeAbsorption = hair_color_to_absorption(math::saturate(InDyeColor)); + float3 Absorption = Eumelanin * float3(0.506f, 0.841f, 1.653f) + Pheomelanin * float3(0.343f, 0.733f, 1.924f); + + return hair_absorption_to_color(Absorption + DyeAbsorption); +} + +export float3 local_object_bounds_min() +[[ + anno::description("Local Object Bounds Min"), + anno::noinline() +]] +{ + return float3(0.0); +} + +export float3 local_object_bounds_max() +[[ + anno::description("Local Object Bounds Max"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float3 object_bounds() +[[ + anno::description("Object Bounds"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float object_radius() +[[ + anno::description("Object Radius"), + anno::noinline() +]] +{ + return 100.0f; +} + +export float3 object_world_position(uniform bool up_z = true) +[[ + anno::description("Object World Position"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)*state::meters_per_scene_unit()*100.0; +} + +export float3 object_orientation() +[[ + anno::description("Object Orientation"), + anno::noinline() +]] +{ + return float3(0); +} + +export float rcp(float x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float2 rcp(float2 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float3 rcp(float3 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float4 rcp(float4 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export int BitFieldExtractI32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractI32 int"), + anno::noinline() +]] +{ + Size &= 3; + Offset &= 3; + + if (Size == 0) + return 0; + else if (Offset + Size < 32) + return (Data << (32 - Size - Offset)) >> (32 - Size); + else + return Data >> Offset; +} + +export int BitFieldExtractI32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractI32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(int(Data), int(Size), int(Offset)); +} + +export int BitFieldExtractU32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractU32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export int BitFieldExtractU32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractU32 int"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export float3 EyeAdaptationInverseLookup(float3 LightValue, float Alpha) +[[ + anno::description("EyeAdaptationInverseLookup"), + anno::noinline() +]] +{ + float Adaptation = 1.0f; + + // When Alpha=0.0, we want to multiply by 1.0. when Alpha = 1.0, we want to multiply by 1/Adaptation. + // So the lerped value is: + // LerpLogScale = Lerp(log(1),log(1/Adaptaiton),T) + // Which is simplified as: + // LerpLogScale = Lerp(0,-log(Adaptation),T) + // LerpLogScale = -T * logAdaptation; + + float LerpLogScale = -Alpha * math::log(Adaptation); + float Scale = math::exp(LerpLogScale); + return LightValue * Scale; +} diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl new file mode 100644 index 0000000000000000000000000000000000000000..9aad34bcd7bd5f29f99549120f776102febec45d --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl @@ -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 Num608bbc47c6ff5a0001d607d8( + uniform texture_2d Normal_Tex = texture_2d("../textures/normal_1.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_1.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_1.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_1.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_1.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_1.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); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/OmniUe4Base.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/OmniUe4Base.mdl new file mode 100644 index 0000000000000000000000000000000000000000..a441fbaf28040302c7aaabfbcf14b24a85bdf643 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/OmniUe4Base.mdl @@ -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 + ) +); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/OmniUe4Function.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/OmniUe4Function.mdl new file mode 100644 index 0000000000000000000000000000000000000000..f0801afff6f0870ea2574c9e9b6e2043e79e9a79 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/004/SubUSDs/materials/OmniUe4Function.mdl @@ -0,0 +1,1413 @@ +/*************************************************************************************************** + * 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.1 - using absolute import paths when importing standard modules + +mdl 1.6; + +import ::df::*; +import ::state::*; +import ::math::*; +import ::tex::*; +import ::anno::*; + + +export float3 convert_to_left_hand(float3 vec3, uniform bool up_z = true, uniform bool is_position = true) +[[ + anno::description("convert from RH to LH"), + anno::noinline() +]] +{ + float4x4 ZupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4x4 YupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4 vec4 = float4(vec3.x, vec3.y, vec3.z, is_position ? 1.0f : 0.0f); + + vec4 = vec4 * (up_z ? ZupConversion : YupConversion); + + return float3(vec4.x, vec4.y, vec4.z); +} + +export float3 transform_vector_from_tangent_to_world(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from tangent space to world space"), + anno::noinline() +]] +{ + /* flip_tangent_v */ + return convert_to_left_hand( + tangent_u * vector.x - tangent_v * vector.y + state::normal() * vector.z, + up_z, false); +} + +export float3 transform_vector_from_world_to_tangent(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from world space to tangent space"), + anno::noinline() +]] +{ + float3 vecRH = convert_to_left_hand(vector, up_z, false); + /* flip_tangent_v */ + return vecRH.x * float3(tangent_u.x, -tangent_v.x, state::normal().x) + + vecRH.y * float3(tangent_u.y, -tangent_v.y, state::normal().y) + + vecRH.z * float3(tangent_u.z, -tangent_v.z, state::normal().z); +} + +export float4 unpack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Unpack a normal stored in a normal map"), + anno::noinline() +]] +{ + float2 normal_xy = float2(texture_sample.x, texture_sample.y); + + normal_xy = normal_xy * float2(2.0,2.0) - float2(1.0,1.0); + float normal_z = math::sqrt( math::saturate( 1.0 - math::dot( normal_xy, normal_xy ) ) ); + return float4( normal_xy.x, normal_xy.y, normal_z, 1.0 ); +} + +// for get color value from normal. +export float4 pack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Pack to color from a normal") +]] +{ + float2 return_xy = float2(texture_sample.x, texture_sample.y); + + return_xy = (return_xy + float2(1.0,1.0)) / float2(2.0,2.0); + + return float4( return_xy.x, return_xy.y, 0.0, 1.0 ); +} + +export float4 greyscale_texture_lookup( + float4 texture_sample = float4(0.0, 0.0, 0.0, 1.0) + ) +[[ + anno::description("Sampling a greyscale texture"), + anno::noinline() +]] +{ + return float4(texture_sample.x, texture_sample.x, texture_sample.x, texture_sample.x); +} + +export float3 pixel_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Pixel normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 vertex_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Vertex normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 landscape_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Landscape normal in world space") +]] +{ + float3 normalFromNormalmap = math::floor((::vertex_normal_world_space(up_z) * 0.5 + 0.5) * 255.0) / 255.0 * 2.0 - 1.0; + + float2 normalXY = float2(normalFromNormalmap.x, normalFromNormalmap.y); + return float3(normalXY.x, normalXY.y, math::sqrt(math::saturate(1.0 - math::dot(normalXY, normalXY)))); +} + +// Different implementation specific between mdl and hlsl for smoothstep +export float smoothstep(float a, float b, float l) +{ + if (a < b) + { + return math::smoothstep(a, b, l); + } + else if (a > b) + { + return 1.0 - math::smoothstep(b, a, l); + } + else + { + return l <= a ? 0.0 : 1.0; + } +} + +export float2 smoothstep(float2 a, float2 b, float2 l) +{ + return float2(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y)); +} + +export float3 smoothstep(float3 a, float3 b, float3 l) +{ + return float3(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z)); +} + +export float4 smoothstep(float4 a, float4 b, float4 l) +{ + return float4(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z), smoothstep(a.w, b.w, l.w)); +} + +export float2 smoothstep(float2 a, float2 b, float l) +{ + return float2(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l)); +} + +export float3 smoothstep(float3 a, float3 b, float l) +{ + return float3(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l)); +} + +export float4 smoothstep(float4 a, float4 b, float l) +{ + return float4(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l), smoothstep(a.w, b.w, l)); +} + +export float2 smoothstep(float a, float b, float2 l) +{ + return float2(smoothstep(a, b, l.x), smoothstep(a, b, l.y)); +} + +export float3 smoothstep(float a, float b, float3 l) +{ + return float3(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z)); +} + +export float4 smoothstep(float a, float b, float4 l) +{ + return float4(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z), smoothstep(a, b, l.w)); +} + +//------------------ Random from UE4 ----------------------- +float length2(float3 v) +{ + return math::dot(v, v); +} + +float3 GetPerlinNoiseGradientTextureAt(uniform texture_2d PerlinNoiseGradientTexture, float3 v) +{ + const float2 ZShear = float2(17.0f, 89.0f); + + float2 OffsetA = v.z * ZShear; + float2 TexA = (float2(v.x, v.y) + OffsetA + 0.5f) / 128.0f; + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA.x,1.0-TexA.y),tex::wrap_repeat,tex::wrap_repeat); + return float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z) * 2.0 - 1.0; +} + +float3 SkewSimplex(float3 In) +{ + return In + math::dot(In, float3(1.0 / 3.0f) ); +} +float3 UnSkewSimplex(float3 In) +{ + return In - math::dot(In, float3(1.0 / 6.0f) ); +} + +// 3D random number generator inspired by PCGs (permuted congruential generator) +// Using a **simple** Feistel cipher in place of the usual xor shift permutation step +// @param v = 3D integer coordinate +// @return three elements w/ 16 random bits each (0-0xffff). +// ~8 ALU operations for result.x (7 mad, 1 >>) +// ~10 ALU operations for result.xy (8 mad, 2 >>) +// ~12 ALU operations for result.xyz (9 mad, 3 >>) + +//TODO: uint3 +int3 Rand3DPCG16(int3 p) +{ + // taking a signed int then reinterpreting as unsigned gives good behavior for negatives + //TODO: uint3 + int3 v = int3(p); + + // Linear congruential step. These LCG constants are from Numerical Recipies + // For additional #'s, PCG would do multiple LCG steps and scramble each on output + // So v here is the RNG state + v = v * 1664525 + 1013904223; + + // PCG uses xorshift for the final shuffle, but it is expensive (and cheap + // versions of xorshift have visible artifacts). Instead, use simple MAD Feistel steps + // + // Feistel ciphers divide the state into separate parts (usually by bits) + // then apply a series of permutation steps one part at a time. The permutations + // use a reversible operation (usually ^) to part being updated with the result of + // a permutation function on the other parts and the key. + // + // In this case, I'm using v.x, v.y and v.z as the parts, using + instead of ^ for + // the combination function, and just multiplying the other two parts (no key) for + // the permutation function. + // + // That gives a simple mad per round. + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + + // only top 16 bits are well shuffled + return v >> 16; +} + +// Wraps noise for tiling texture creation +// @param v = unwrapped texture parameter +// @param bTiling = true to tile, false to not tile +// @param RepeatSize = number of units before repeating +// @return either original or wrapped coord +float3 NoiseTileWrap(float3 v, bool bTiling, float RepeatSize) +{ + return bTiling ? (math::frac(v / RepeatSize) * RepeatSize) : v; +} + +// Evaluate polynomial to get smooth transitions for Perlin noise +// only needed by Perlin functions in this file +// scalar(per component): 2 add, 5 mul +float4 PerlinRamp(float4 t) +{ + return t * t * t * (t * (t * 6 - 15) + 10); +} + +// Blum-Blum-Shub-inspired pseudo random number generator +// http://www.umbc.edu/~olano/papers/mNoise.pdf +// real BBS uses ((s*s) mod M) with bignums and M as the product of two huge Blum primes +// instead, we use a single prime M just small enough not to overflow +// note that the above paper used 61, which fits in a half, but is unusably bad +// @param Integer valued floating point seed +// @return random number in range [0,1) +// ~8 ALU operations (5 *, 3 frac) +float RandBBSfloat(float seed) +{ + float BBS_PRIME24 = 4093.0; + float s = math::frac(seed / BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + return s; +} + +// Modified noise gradient term +// @param seed - random seed for integer lattice position +// @param offset - [-1,1] offset of evaluation point from lattice point +// @return gradient direction (xyz) and contribution (w) from this lattice point +float4 MGradient(int seed, float3 offset) +{ + //TODO uint + int rand = Rand3DPCG16(int3(seed,0,0)).x; + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1.0 / 0x4000, 1.0 / 0x2000, 1.0 / 0x1000); + float3 direction = float3(int3(rand, rand, rand) & MGradientMask) * MGradientScale - 1; + return float4(direction.x, direction.y, direction.z, math::dot(direction, offset)); +} + +// compute Perlin and related noise corner seed values +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = true to return seed values for a repeating noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @param seed000-seed111 = hash function seeds for the eight corners +// @return fractional part of v +struct SeedValue +{ + float3 fv = float3(0); + float seed000 = 0; + float seed001 = 0; + float seed010 = 0; + float seed011 = 0; + float seed100 = 0; + float seed101 = 0; + float seed110 = 0; + float seed111 = 0; +}; + +SeedValue NoiseSeeds(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds; + seeds.fv = math::frac(v); + float3 iv = math::floor(v); + + const float3 primes = float3(19, 47, 101); + + if (bTiling) + { // can't algebraically combine with primes + seeds.seed000 = math::dot(primes, NoiseTileWrap(iv, true, RepeatSize)); + seeds.seed100 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 0), true, RepeatSize)); + seeds.seed010 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 0), true, RepeatSize)); + seeds.seed110 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 0), true, RepeatSize)); + seeds.seed001 = math::dot(primes, NoiseTileWrap(iv + float3(0, 0, 1), true, RepeatSize)); + seeds.seed101 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 1), true, RepeatSize)); + seeds.seed011 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 1), true, RepeatSize)); + seeds.seed111 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 1), true, RepeatSize)); + } + else + { // get to combine offsets with multiplication by primes in this case + seeds.seed000 = math::dot(iv, primes); + seeds.seed100 = seeds.seed000 + primes.x; + seeds.seed010 = seeds.seed000 + primes.y; + seeds.seed110 = seeds.seed100 + primes.y; + seeds.seed001 = seeds.seed000 + primes.z; + seeds.seed101 = seeds.seed100 + primes.z; + seeds.seed011 = seeds.seed010 + primes.z; + seeds.seed111 = seeds.seed110 + primes.z; + } + + return seeds; +} + +struct SimplexWeights +{ + float4 Result = float4(0); + float3 PosA = float3(0); + float3 PosB = float3(0); + float3 PosC = float3(0); + float3 PosD = float3(0); +}; + +// Computed weights and sample positions for simplex interpolation +// @return float4(a,b,c, d) Barycentric coordinate defined as Filtered = Tex(PosA) * a + Tex(PosB) * b + Tex(PosC) * c + Tex(PosD) * d +SimplexWeights ComputeSimplexWeights3D(float3 OrthogonalPos) +{ + SimplexWeights weights; + float3 OrthogonalPosFloor = math::floor(OrthogonalPos); + + weights.PosA = OrthogonalPosFloor; + weights.PosB = weights.PosA + float3(1, 1, 1); + + OrthogonalPos -= OrthogonalPosFloor; + + float Largest = math::max(OrthogonalPos.x, math::max(OrthogonalPos.y, OrthogonalPos.z)); + float Smallest = math::min(OrthogonalPos.x, math::min(OrthogonalPos.y, OrthogonalPos.z)); + + weights.PosC = weights.PosA + float3(Largest == OrthogonalPos.x, Largest == OrthogonalPos.y, Largest == OrthogonalPos.z); + weights.PosD = weights.PosA + float3(Smallest != OrthogonalPos.x, Smallest != OrthogonalPos.y, Smallest != OrthogonalPos.z); + + float RG = OrthogonalPos.x - OrthogonalPos.y; + float RB = OrthogonalPos.x - OrthogonalPos.z; + float GB = OrthogonalPos.y - OrthogonalPos.z; + + weights.Result.z = + math::min(math::max(0, RG), math::max(0, RB)) // X + + math::min(math::max(0, -RG), math::max(0, GB)) // Y + + math::min(math::max(0, -RB), math::max(0, -GB)); // Z + + weights.Result.w = + math::min(math::max(0, -RG), math::max(0, -RB)) // X + + math::min(math::max(0, RG), math::max(0, -GB)) // Y + + math::min(math::max(0, RB), math::max(0, GB)); // Z + + weights.Result.y = Smallest; + weights.Result.x = 1.0f - weights.Result.y - weights.Result.z - weights.Result.w; + + return weights; +} + +// filtered 3D gradient simple noise (few texture lookups, high quality) +// @param v >0 +// @return random number in the range -1 .. 1 +float SimplexNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 EvalPos) +{ + float3 OrthogonalPos = SkewSimplex(EvalPos); + + SimplexWeights Weights = ComputeSimplexWeights3D(OrthogonalPos); + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 32 bit) + float3 A = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosA); + float3 B = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosB); + float3 C = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosC); + float3 D = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosD); + + Weights.PosA = UnSkewSimplex(Weights.PosA); + Weights.PosB = UnSkewSimplex(Weights.PosB); + Weights.PosC = UnSkewSimplex(Weights.PosC); + Weights.PosD = UnSkewSimplex(Weights.PosD); + + float DistanceWeight; + + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosA)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float a = math::dot(A, EvalPos - Weights.PosA) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosB)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float b = math::dot(B, EvalPos - Weights.PosB) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosC)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float c = math::dot(C, EvalPos - Weights.PosC) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosD)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float d = math::dot(D, EvalPos - Weights.PosD) * DistanceWeight; + + return 32 * (a + b + c + d); +} + +// filtered 3D noise, can be optimized +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 v, bool bTiling, float RepeatSize) +{ + bTiling = true; + float3 fv = math::frac(v); + float3 iv0 = NoiseTileWrap(math::floor(v), bTiling, RepeatSize); + float3 iv1 = NoiseTileWrap(iv0 + 1, bTiling, RepeatSize); + + const int2 ZShear = int2(17, 89); + + float2 OffsetA = iv0.z * ZShear; + float2 OffsetB = OffsetA + ZShear; // non-tiling, use relative offset + if (bTiling) // tiling, have to compute from wrapped coordinates + { + OffsetB = iv1.z * ZShear; + } + + // Texture size scale factor + float ts = 1 / 128.0f; + + // texture coordinates for iv0.xy, as offset for both z slices + float2 TexA0 = (float2(iv0.x, iv0.y) + OffsetA + 0.5f) * ts; + float2 TexB0 = (float2(iv0.x, iv0.y) + OffsetB + 0.5f) * ts; + + // texture coordinates for iv1.xy, as offset for both z slices + float2 TexA1 = TexA0 + ts; // for non-tiling, can compute relative to existing coordinates + float2 TexB1 = TexB0 + ts; + if (bTiling) // for tiling, need to compute from wrapped coordinates + { + TexA1 = (float2(iv1.x, iv1.y) + OffsetA + 0.5f) * ts; + TexB1 = (float2(iv1.x, iv1.y) + OffsetB + 0.5f) * ts; + } + + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 8, 16 or 32 bit) + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + float3 PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 A = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 B = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 C = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 D = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 E = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 F = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 G = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 H = PerlinNoiseColor * 2 - 1; + + float a = math::dot(A, fv - float3(0, 0, 0)); + float b = math::dot(B, fv - float3(1, 0, 0)); + float c = math::dot(C, fv - float3(0, 1, 0)); + float d = math::dot(D, fv - float3(1, 1, 0)); + float e = math::dot(E, fv - float3(0, 0, 1)); + float f = math::dot(F, fv - float3(1, 0, 1)); + float g = math::dot(G, fv - float3(0, 1, 1)); + float h = math::dot(H, fv - float3(1, 1, 1)); + + float4 Weights = PerlinRamp(math::frac(float4(fv.x, fv.y, fv.z, 0))); + + float i = math::lerp(math::lerp(a, b, Weights.x), math::lerp(c, d, Weights.x), Weights.y); + float j = math::lerp(math::lerp(e, f, Weights.x), math::lerp(g, h, Weights.x), Weights.y); + + return math::lerp(i, j, Weights.z); +} + +// @return random number in the range -1 .. 1 +// scalar: 6 frac, 31 mul/mad, 15 add, +float FastGradientPerlinNoise3D_TEX(uniform texture_3d PerlinNoise3DTexture, float3 xyz) +{ + // needs to be the same value when creating the PerlinNoise3D texture + float Extent = 16; + + // last texel replicated and needed for filtering + // scalar: 3 frac, 6 mul + xyz = math::frac(xyz / (Extent - 1)) * (Extent - 1); + + // scalar: 3 frac + float3 uvw = math::frac(xyz); + // = floor(xyz); + // scalar: 3 add + float3 p0 = xyz - uvw; +// float3 f = math::pow(uvw, 2) * 3.0f - math::pow(uvw, 3) * 2.0f; // original perlin hermite (ok when used without bump mapping) + // scalar: 2*3 add 5*3 mul + float4 pr = PerlinRamp(float4(uvw.x, uvw.y, uvw.z, 0)); + float3 f = float3(pr.x, pr.y, pr.z); // new, better with continues second derivative for bump mapping + // scalar: 3 add + float3 p = p0 + f; + // scalar: 3 mad + // TODO: need reverse??? + float4 NoiseSample = tex::lookup_float4(PerlinNoise3DTexture, p / Extent + 0.5f / Extent); // +0.5f to get rid of bilinear offset + + // reconstruct from 8bit (using mad with 2 constants and dot4 was same instruction count) + // scalar: 4 mad, 3 mul, 3 add + float3 n = float3(NoiseSample.x, NoiseSample.y, NoiseSample.z) * 255.0f / 127.0f - 1.0f; + float d = NoiseSample.w * 255.f - 127; + return math::dot(xyz, n) - d; +} + +// Perlin-style "Modified Noise" +// http://www.umbc.edu/~olano/papers/index.html#mNoise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = MGradient(int(seeds.seed000), seeds.fv - float3(0, 0, 0)).w; + float rand100 = MGradient(int(seeds.seed100), seeds.fv - float3(1, 0, 0)).w; + float rand010 = MGradient(int(seeds.seed010), seeds.fv - float3(0, 1, 0)).w; + float rand110 = MGradient(int(seeds.seed110), seeds.fv - float3(1, 1, 0)).w; + float rand001 = MGradient(int(seeds.seed001), seeds.fv - float3(0, 0, 1)).w; + float rand101 = MGradient(int(seeds.seed101), seeds.fv - float3(1, 0, 1)).w; + float rand011 = MGradient(int(seeds.seed011), seeds.fv - float3(0, 1, 1)).w; + float rand111 = MGradient(int(seeds.seed111), seeds.fv - float3(1, 1, 1)).w; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D value noise - used to be incorrectly called Perlin noise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float ValueNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = RandBBSfloat(seeds.seed000) * 2 - 1; + float rand100 = RandBBSfloat(seeds.seed100) * 2 - 1; + float rand010 = RandBBSfloat(seeds.seed010) * 2 - 1; + float rand110 = RandBBSfloat(seeds.seed110) * 2 - 1; + float rand001 = RandBBSfloat(seeds.seed001) * 2 - 1; + float rand101 = RandBBSfloat(seeds.seed101) * 2 - 1; + float rand011 = RandBBSfloat(seeds.seed011) * 2 - 1; + float rand111 = RandBBSfloat(seeds.seed111) * 2 - 1; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D jitter offset within a voronoi noise cell +// @param pos - integer lattice corner +// @return random offsets vector +float3 VoronoiCornerSample(float3 pos, int Quality) +{ + // random values in [-0.5, 0.5] + float3 noise = float3(Rand3DPCG16(int3(pos))) / 0xffff - 0.5; + + // quality level 1 or 2: searches a 2x2x2 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 2x2x2 search + if (Quality <= 2) + { + return math::normalize(noise) * 0.2588; + } + + // quality level 3: searches a 3x3x3 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 3x3x3 search + if (Quality == 3) + { + return math::normalize(noise) * 0.3090; + } + + // quality level 4: jitter to anywhere in the cell, needs 4x4x4 search + return noise; +} + +// compare previous best with a new candidate +// not producing point locations makes it easier for compiler to eliminate calculations when they're not needed +// @param minval = location and distance of best candidate seed point before the new one +// @param candidate = candidate seed point +// @param offset = 3D offset to new candidate seed point +// @param bDistanceOnly = if true, only set maxval.w with distance, otherwise maxval.w is distance and maxval.xyz is position +// @return position (if bDistanceOnly is false) and distance to closest seed point so far +float4 VoronoiCompare(float4 minval, float3 candidate, float3 offset, bool bDistanceOnly) +{ + if (bDistanceOnly) + { + return float4(0, 0, 0, math::min(minval.w, math::dot(offset, offset))); + } + else + { + float newdist = math::dot(offset, offset); + return newdist > minval.w ? minval : float4(candidate.x, candidate.y, candidate.z, newdist); + } +} + +// 220 instruction Worley noise +float4 VoronoiNoise3D_ALU(float3 v, int Quality, bool bTiling, float RepeatSize, bool bDistanceOnly) +{ + float3 fv = math::frac(v), fv2 = math::frac(v + 0.5); + float3 iv = math::floor(v), iv2 = math::floor(v + 0.5); + + // with initial minimum distance = infinity (or at least bigger than 4), first min is optimized away + float4 mindist = float4(0,0,0,100); + float3 p, offset; + + // quality level 3: do a 3x3x3 search + if (Quality == 3) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 1; ++offset_x) + { + for (offset_y = -1; offset_y <= 1; ++offset_y) + { + for (offset_z = -1; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + + // everybody else searches a base 2x2x2 neighborhood + else + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = 0; offset_x <= 1; ++offset_x) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // quality level 2, do extra set of points, offset by half a cell + if (Quality == 2) + { + // 467 is just an offset to a different area in the random number field to avoid similar neighbor artifacts + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize) + 467, Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + } + + // quality level 4: add extra sets of four cells in each direction + if (Quality >= 4) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 2; offset_x += 3) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + // along x axis + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along y axis + p = float3(offset.y, offset.z, offset.x) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.y, offset.z, offset.x), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along z axis + p = float3(offset.z, offset.x, offset.y) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.z, offset.x, offset.y), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + } + } + } + } + + // transform squared distance to real distance + return float4(mindist.x, mindist.y, mindist.z, math::sqrt(mindist.w)); +} + +// Coordinates for corners of a Simplex tetrahedron +// Based on McEwan et al., Efficient computation of noise in GLSL, JGT 2011 +// @param v = 3D noise argument +// @return 4 corner locations +float4x3 SimplexCorners(float3 v) +{ + // find base corner by skewing to tetrahedral space and back + float3 tet = math::floor(v + v.x/3 + v.y/3 + v.z/3); + float3 base = tet - tet.x/6 - tet.y/6 - tet.z/6; + float3 f = v - base; + + // Find offsets to other corners (McEwan did this in tetrahedral space, + // but since skew is along x=y=z axis, this works in Euclidean space too.) + float3 g = math::step(float3(f.y,f.z,f.x), float3(f.x,f.y,f.z)), h = 1 - float3(g.z, g.x, g.y); + float3 a1 = math::min(g, h) - 1.0 / 6.0, a2 = math::max(g, h) - 1.0 / 3.0; + + // four corners + return float4x3(base, base + a1, base + a2, base + 0.5); +} + +// Improved smoothing function for simplex noise +// @param f = fractional distance to four tetrahedral corners +// @return weight for each corner +float4 SimplexSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + return (1 * scale + s*(-3 * scale + s*(3 * scale - s*scale))); +} + +// Derivative of simplex noise smoothing function +// @param f = fractional distanc eto four tetrahedral corners +// @return derivative of smoothing function for each corner by x, y and z +float3x4 SimplexDSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + s = -12 * scale + s*(24 * scale - s * 12 * scale); + + return float3x4( + s * float4(f[0][0], f[1][0], f[2][0], f[3][0]), + s * float4(f[0][1], f[1][1], f[2][1], f[3][1]), + s * float4(f[0][2], f[1][2], f[2][2], f[3][2])); +} + +// Simplex noise and its Jacobian derivative +// @param v = 3D noise argument +// @param bTiling = whether to repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension, must be a multiple of 3 +// @return float3x3 Jacobian in J[*].xyz, vector noise in J[*].w +// J[0].w, J[1].w, J[2].w is a Perlin-style simplex noise with vector output, e.g. (Nx, Ny, Nz) +// J[i].x is X derivative of the i'th component of the noise so J[2].x is dNz/dx +// You can use this to compute the noise, gradient, curl, or divergence: +// float3x4 J = JacobianSimplex_ALU(...); +// float3 VNoise = float3(J[0].w, J[1].w, J[2].w); // 3D noise +// float3 Grad = J[0].xyz; // gradient of J[0].w +// float3 Curl = float3(J[1][2]-J[2][1], J[2][0]-J[0][2], J[0][1]-J[1][2]); +// float Div = J[0][0]+J[1][1]+J[2][2]; +// All of these are confirmed to compile out all unneeded terms. +// So Grad of X doesn't compute Y or Z components, and VNoise doesn't do any of the derivative computation. +float3x4 JacobianSimplex_ALU(float3 v, bool bTiling, float RepeatSize) +{ + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1. / 0x4000, 1. / 0x2000, 1. / 0x1000); + + // corners of tetrahedron + float4x3 T = SimplexCorners(v); + // TODO: uint3 + int3 rand = int3(0); + float4x3 gvec0 = float4x3(1.0); + float4x3 gvec1 = float4x3(1.0); + float4x3 gvec2 = float4x3(1.0); + float4x3 fv = float4x3(1.0); + float3x4 grad = float3x4(1.0); + + // processing of tetrahedral vertices, unrolled + // to compute gradient at each corner + fv[0] = v - T[0]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[0] + 0.5, bTiling, RepeatSize)))); + gvec0[0] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[0] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[0] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][0] = math::dot(gvec0[0], fv[0]); + grad[1][0] = math::dot(gvec1[0], fv[0]); + grad[2][0] = math::dot(gvec2[0], fv[0]); + + fv[1] = v - T[1]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[1] + 0.5, bTiling, RepeatSize)))); + gvec0[1] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][1] = math::dot(gvec0[1], fv[1]); + grad[1][1] = math::dot(gvec1[1], fv[1]); + grad[2][1] = math::dot(gvec2[1], fv[1]); + + fv[2] = v - T[2]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[2] + 0.5, bTiling, RepeatSize)))); + gvec0[2] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[2] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[2] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][2] = math::dot(gvec0[2], fv[2]); + grad[1][2] = math::dot(gvec1[2], fv[2]); + grad[2][2] = math::dot(gvec2[2], fv[2]); + + fv[3] = v - T[3]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[3] + 0.5, bTiling, RepeatSize)))); + gvec0[3] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[3] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[3] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][3] = math::dot(gvec0[3], fv[3]); + grad[1][3] = math::dot(gvec1[3], fv[3]); + grad[2][3] = math::dot(gvec2[3], fv[3]); + + // blend gradients + float4 sv = SimplexSmooth(fv); + float3x4 ds = SimplexDSmooth(fv); + + float3x4 jacobian = float3x4(1.0); + float3 vec0 = gvec0*sv + grad[0]*ds; // NOTE: mdl is column major, convert from UE4 (row major) + jacobian[0] = float4(vec0.x, vec0.y, vec0.z, math::dot(sv, grad[0])); + float3 vec1 = gvec1*sv + grad[1]*ds; + jacobian[1] = float4(vec1.x, vec1.y, vec1.z, math::dot(sv, grad[1])); + float3 vec2 = gvec2*sv + grad[2]*ds; + jacobian[2] = float4(vec2.x, vec2.y, vec2.z, math::dot(sv, grad[2])); + + return jacobian; +} + +// While RepeatSize is a float here, the expectation is that it would be largely integer values coming in from the UI. The downstream logic assumes +// floats for all called functions (NoiseTileWrap) and this prevents any float-to-int conversion errors from automatic type conversion. +float Noise3D_Multiplexer(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, int Function, float3 Position, int Quality, bool bTiling, float RepeatSize) +{ + // verified, HLSL compiled out the switch if Function is a constant + switch(Function) + { + case 0: + return SimplexNoise3D_TEX(PerlinNoiseGradientTexture, Position); + case 1: + return GradientNoise3D_TEX(PerlinNoiseGradientTexture, Position, bTiling, RepeatSize); + case 2: + return FastGradientPerlinNoise3D_TEX(PerlinNoise3DTexture, Position); + case 3: + return GradientNoise3D_ALU(Position, bTiling, RepeatSize); + case 4: + return ValueNoise3D_ALU(Position, bTiling, RepeatSize); + case 5: + return VoronoiNoise3D_ALU(Position, Quality, bTiling, RepeatSize, true).w * 2.0 - 1.0; + } + return 0; +} +//---------------------------------------------------------- + +export float noise(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, float3 Position, float Scale, float Quality, float Function, float Turbulence, float Levels, float OutputMin, float OutputMax, float LevelScale, float FilterWidth, float Tiling, float RepeatSize) +[[ + anno::description("Noise"), + anno::noinline() +]] +{ + Position *= Scale; + FilterWidth *= Scale; + + float Out = 0.0f; + float OutScale = 1.0f; + float InvLevelScale = 1.0f / LevelScale; + + int iFunction(Function); + int iQuality(Quality); + int iLevels(Levels); + bool bTurbulence(Turbulence); + bool bTiling(Tiling); + + for(int i = 0; i < iLevels; ++i) + { + // fade out noise level that are too high frequent (not done through dynamic branching as it usually requires gradient instructions) + OutScale *= math::saturate(1.0 - FilterWidth); + + if(bTurbulence) + { + Out += math::abs(Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize)) * OutScale; + } + else + { + Out += Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize) * OutScale; + } + + Position *= LevelScale; + RepeatSize *= LevelScale; + OutScale *= InvLevelScale; + FilterWidth *= LevelScale; + } + + if(!bTurbulence) + { + // bring -1..1 to 0..1 range + Out = Out * 0.5f + 0.5f; + } + + // Out is in 0..1 range + return math::lerp(OutputMin, OutputMax, Out); +} + +// Material node for noise functions returning a vector value +// @param LevelScale usually 2 but higher values allow efficient use of few levels +// @return in user defined range (OutputMin..OutputMax) +export float4 vector4_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise"), + anno::noinline() +]] +{ + float4 result = float4(0,0,0,1); + float3 ret = float3(0); + int iQuality = int(Quality); + int iFunction = int(Function); + bool bTiling = Tiling > 0.0; + + float3x4 Jacobian = JacobianSimplex_ALU(Position, bTiling, TileSize); // compiled out if not used + + // verified, HLSL compiled out the switch if Function is a constant + switch (iFunction) + { + case 0: // Cellnoise + ret = float3(Rand3DPCG16(int3(math::floor(NoiseTileWrap(Position, bTiling, TileSize))))) / 0xffff; + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 1: // Color noise + ret = float3(Jacobian[0].w, Jacobian[1].w, Jacobian[2].w); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 2: // Gradient + result = Jacobian[0]; + break; + case 3: // Curl + ret = float3(Jacobian[2][1] - Jacobian[1][2], Jacobian[0][2] - Jacobian[2][0], Jacobian[1][0] - Jacobian[0][1]); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 4: // Voronoi + result = VoronoiNoise3D_ALU(Position, iQuality, bTiling, TileSize, false); + break; + } + return result; +} + +export float3 vector3_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise float3 version"), + anno::noinline() +]] +{ + float4 noise = vector4_noise(Position, Quality, Function, Tiling, TileSize); + return float3(noise.x, noise.y, noise.z); +} + + +// workaround for ue4 fresnel (without supporting for camera vector) : replacing it with 0.0, means facing to the view +export float fresnel(float exponent [[anno::unused()]], float base_reflect_fraction [[anno::unused()]], float3 normal [[anno::unused()]]) +[[ + anno::description("Fresnel"), + anno::noinline() +]] +{ + return 0.0; +} + +export float fresnel_function(float3 normal_vector [[anno::unused()]], float3 camera_vector [[anno::unused()]], + bool invert_fresnel [[anno::unused()]], float power [[anno::unused()]], + bool use_cheap_contrast [[anno::unused()]], float cheap_contrast_dark [[anno::unused()]], float cheap_contrast_bright [[anno::unused()]], + bool clamp_fresnel_dot_product [[anno::unused()]]) +[[ + anno::description("Fresnel Function"), + anno::noinline() +]] +{ + return 0.0; +} + +export float3 camera_vector(uniform bool up_z = true) +[[ + anno::description("Camera Vector"), + anno::noinline() +]] +{ + // assume camera postion is 0,0,0 + return math::normalize(float3(0) - convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)); +} + +export float pixel_depth() +[[ + anno::description("Pixel Depth"), + anno::noinline() +]] +{ + return 256.0f; +} + +export float scene_depth() +[[ + anno::description("Scene Depth") +]] +{ + return 65500.0f; +} + +export float3 scene_color() +[[ + anno::description("Scene Color") +]] +{ + return float3(1.0f); +} + +export float4 vertex_color() +[[ + anno::description("Vertex Color"), + anno::noinline() +]] +{ + return float4(1.0f); +} + +export float4 vertex_color_from_coordinate(int VertexColorCoordinateIndex) +[[ + anno::description("Vertex Color for float2 PrimVar"), + anno::noinline() +]] +{ + // Kit only supports 4 uv sets, 2 uvs are available to vertex color. if vertex color index is invalid, output the constant WHITE color intead + return (VertexColorCoordinateIndex > 2) ? float4(1.0f) : float4(state::texture_coordinate(VertexColorCoordinateIndex).x, state::texture_coordinate(VertexColorCoordinateIndex).y, state::texture_coordinate(VertexColorCoordinateIndex+1).x, state::texture_coordinate(VertexColorCoordinateIndex+1).y); +} + +export float3 camera_position() +[[ + anno::description("Camera Position"), + anno::noinline() +]] +{ + return float3(1000.0f, 0, 0); +} + +export float3 rotate_about_axis(float4 NormalizedRotationAxisAndAngle, float3 PositionOnAxis, float3 Position) +[[ + anno::description("Rotates Position about the given axis by the given angle") +]] +{ + // Project Position onto the rotation axis and find the closest point on the axis to Position + float3 NormalizedRotationAxis = float3(NormalizedRotationAxisAndAngle.x,NormalizedRotationAxisAndAngle.y,NormalizedRotationAxisAndAngle.z); + float3 ClosestPointOnAxis = PositionOnAxis + NormalizedRotationAxis * math::dot(NormalizedRotationAxis, Position - PositionOnAxis); + // Construct orthogonal axes in the plane of the rotation + float3 UAxis = Position - ClosestPointOnAxis; + float3 VAxis = math::cross(NormalizedRotationAxis, UAxis); + float[2] SinCosAngle = math::sincos(NormalizedRotationAxisAndAngle.w); + // Rotate using the orthogonal axes + float3 R = UAxis * SinCosAngle[1] + VAxis * SinCosAngle[0]; + // Reconstruct the rotated world space position + float3 RotatedPosition = ClosestPointOnAxis + R; + // Convert from position to a position offset + return RotatedPosition - Position; +} + +export float2 rotate_scale_offset_texcoords(float2 InTexCoords, float4 InRotationScale, float2 InOffset) +[[ + anno::description("Returns a float2 texture coordinate after 2x2 transform and offset applied") +]] +{ + return float2(math::dot(InTexCoords, float2(InRotationScale.x, InRotationScale.y)), math::dot(InTexCoords, float2(InRotationScale.z, InRotationScale.w))) + InOffset; +} + +export float3 reflection_custom_world_normal(float3 WorldNormal, bool bNormalizeInputNormal, uniform bool up_z = true) +[[ + anno::description("Reflection vector about the specified world space normal") +]] +{ + if (bNormalizeInputNormal) + { + WorldNormal = math::normalize(WorldNormal); + } + + return -camera_vector(up_z) + WorldNormal * math::dot(WorldNormal, camera_vector(up_z)) * 2.0; +} + +export float3 reflection_vector(uniform bool up_z = true) +[[ + anno::description("Reflection Vector"), + anno::noinline() +]] +{ + float3 normal = convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); + return reflection_custom_world_normal(normal, false, up_z); +} + +export float dither_temporalAA(float AlphaThreshold = 0.5f, float Random = 1.0f [[anno::unused()]]) +[[ + anno::description("Dither TemporalAA"), + anno::noinline() +]] +{ + return AlphaThreshold; +} + +export float3 black_body( float Temp ) +[[ + anno::description("Black Body"), + anno::noinline() +]] +{ + float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp ); + float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp ); + + float x = 3*u / ( 2*u - 8*v + 4 ); + float y = 2*v / ( 2*u - 8*v + 4 ); + float z = 1 - x - y; + + float Y = 1; + float X = Y/y * x; + float Z = Y/y * z; + + float3x3 XYZtoRGB = float3x3( + float3(3.2404542, -1.5371385, -0.4985314), + float3(-0.9692660, 1.8760108, 0.0415560), + float3(0.0556434, -0.2040259, 1.0572252) + ); + + return XYZtoRGB * float3( X, Y, Z ) * math::pow( 0.0004 * Temp, 4 ); +} + +export float per_instance_random(uniform texture_2d PerlinNoiseGradientTexture, int NumberInstances) +[[ + anno::description("Per Instance Random"), + anno::noinline() +]] +{ + float weight = state::object_id() / float(NumberInstances); + return NumberInstances == 0 ? 0.0 : tex::lookup_float4(PerlinNoiseGradientTexture, float2(weight, 1.0 - weight), tex::wrap_repeat, tex::wrap_repeat).x; +} + +//------------------ Hair from UE4 ----------------------- +float3 hair_absorption_to_color(float3 A) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::exp(-math::sqrt(A) * D); +} + +float3 hair_color_to_absorption(float3 C) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::pow(math::log(C) / D, 2.0f); +} + +export float3 get_hair_color_from_melanin(float InMelanin, float InRedness, float3 InDyeColor) +[[ + anno::description("Hair Color") +]] +{ + InMelanin = math::saturate(InMelanin); + InRedness = math::saturate(InRedness); + float Melanin = -math::log(math::max(1 - InMelanin, 0.0001f)); + float Eumelanin = Melanin * (1 - InRedness); + float Pheomelanin = Melanin * InRedness; + + float3 DyeAbsorption = hair_color_to_absorption(math::saturate(InDyeColor)); + float3 Absorption = Eumelanin * float3(0.506f, 0.841f, 1.653f) + Pheomelanin * float3(0.343f, 0.733f, 1.924f); + + return hair_absorption_to_color(Absorption + DyeAbsorption); +} + +export float3 local_object_bounds_min() +[[ + anno::description("Local Object Bounds Min"), + anno::noinline() +]] +{ + return float3(0.0); +} + +export float3 local_object_bounds_max() +[[ + anno::description("Local Object Bounds Max"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float3 object_bounds() +[[ + anno::description("Object Bounds"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float object_radius() +[[ + anno::description("Object Radius"), + anno::noinline() +]] +{ + return 100.0f; +} + +export float3 object_world_position(uniform bool up_z = true) +[[ + anno::description("Object World Position"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)*state::meters_per_scene_unit()*100.0; +} + +export float3 object_orientation() +[[ + anno::description("Object Orientation"), + anno::noinline() +]] +{ + return float3(0); +} + +export float rcp(float x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float2 rcp(float2 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float3 rcp(float3 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float4 rcp(float4 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export int BitFieldExtractI32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractI32 int"), + anno::noinline() +]] +{ + Size &= 3; + Offset &= 3; + + if (Size == 0) + return 0; + else if (Offset + Size < 32) + return (Data << (32 - Size - Offset)) >> (32 - Size); + else + return Data >> Offset; +} + +export int BitFieldExtractI32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractI32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(int(Data), int(Size), int(Offset)); +} + +export int BitFieldExtractU32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractU32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export int BitFieldExtractU32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractU32 int"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export float3 EyeAdaptationInverseLookup(float3 LightValue, float Alpha) +[[ + anno::description("EyeAdaptationInverseLookup"), + anno::noinline() +]] +{ + float Adaptation = 1.0f; + + // When Alpha=0.0, we want to multiply by 1.0. when Alpha = 1.0, we want to multiply by 1/Adaptation. + // So the lerped value is: + // LerpLogScale = Lerp(log(1),log(1/Adaptaiton),T) + // Which is simplified as: + // LerpLogScale = Lerp(0,-log(Adaptation),T) + // LerpLogScale = -T * logAdaptation; + + float LerpLogScale = -Alpha * math::log(Adaptation); + float Scale = math::exp(LerpLogScale); + return LightValue * Scale; +} diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl new file mode 100644 index 0000000000000000000000000000000000000000..9aad34bcd7bd5f29f99549120f776102febec45d --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl @@ -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 Num608bbc47c6ff5a0001d607d8( + uniform texture_2d Normal_Tex = texture_2d("../textures/normal_1.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_1.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_1.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_1.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_1.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_1.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); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/OmniUe4Base.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/OmniUe4Base.mdl new file mode 100644 index 0000000000000000000000000000000000000000..a441fbaf28040302c7aaabfbcf14b24a85bdf643 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/OmniUe4Base.mdl @@ -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 + ) +); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/OmniUe4Function.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/OmniUe4Function.mdl new file mode 100644 index 0000000000000000000000000000000000000000..f0801afff6f0870ea2574c9e9b6e2043e79e9a79 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/005/SubUSDs/materials/OmniUe4Function.mdl @@ -0,0 +1,1413 @@ +/*************************************************************************************************** + * 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.1 - using absolute import paths when importing standard modules + +mdl 1.6; + +import ::df::*; +import ::state::*; +import ::math::*; +import ::tex::*; +import ::anno::*; + + +export float3 convert_to_left_hand(float3 vec3, uniform bool up_z = true, uniform bool is_position = true) +[[ + anno::description("convert from RH to LH"), + anno::noinline() +]] +{ + float4x4 ZupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4x4 YupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4 vec4 = float4(vec3.x, vec3.y, vec3.z, is_position ? 1.0f : 0.0f); + + vec4 = vec4 * (up_z ? ZupConversion : YupConversion); + + return float3(vec4.x, vec4.y, vec4.z); +} + +export float3 transform_vector_from_tangent_to_world(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from tangent space to world space"), + anno::noinline() +]] +{ + /* flip_tangent_v */ + return convert_to_left_hand( + tangent_u * vector.x - tangent_v * vector.y + state::normal() * vector.z, + up_z, false); +} + +export float3 transform_vector_from_world_to_tangent(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from world space to tangent space"), + anno::noinline() +]] +{ + float3 vecRH = convert_to_left_hand(vector, up_z, false); + /* flip_tangent_v */ + return vecRH.x * float3(tangent_u.x, -tangent_v.x, state::normal().x) + + vecRH.y * float3(tangent_u.y, -tangent_v.y, state::normal().y) + + vecRH.z * float3(tangent_u.z, -tangent_v.z, state::normal().z); +} + +export float4 unpack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Unpack a normal stored in a normal map"), + anno::noinline() +]] +{ + float2 normal_xy = float2(texture_sample.x, texture_sample.y); + + normal_xy = normal_xy * float2(2.0,2.0) - float2(1.0,1.0); + float normal_z = math::sqrt( math::saturate( 1.0 - math::dot( normal_xy, normal_xy ) ) ); + return float4( normal_xy.x, normal_xy.y, normal_z, 1.0 ); +} + +// for get color value from normal. +export float4 pack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Pack to color from a normal") +]] +{ + float2 return_xy = float2(texture_sample.x, texture_sample.y); + + return_xy = (return_xy + float2(1.0,1.0)) / float2(2.0,2.0); + + return float4( return_xy.x, return_xy.y, 0.0, 1.0 ); +} + +export float4 greyscale_texture_lookup( + float4 texture_sample = float4(0.0, 0.0, 0.0, 1.0) + ) +[[ + anno::description("Sampling a greyscale texture"), + anno::noinline() +]] +{ + return float4(texture_sample.x, texture_sample.x, texture_sample.x, texture_sample.x); +} + +export float3 pixel_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Pixel normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 vertex_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Vertex normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 landscape_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Landscape normal in world space") +]] +{ + float3 normalFromNormalmap = math::floor((::vertex_normal_world_space(up_z) * 0.5 + 0.5) * 255.0) / 255.0 * 2.0 - 1.0; + + float2 normalXY = float2(normalFromNormalmap.x, normalFromNormalmap.y); + return float3(normalXY.x, normalXY.y, math::sqrt(math::saturate(1.0 - math::dot(normalXY, normalXY)))); +} + +// Different implementation specific between mdl and hlsl for smoothstep +export float smoothstep(float a, float b, float l) +{ + if (a < b) + { + return math::smoothstep(a, b, l); + } + else if (a > b) + { + return 1.0 - math::smoothstep(b, a, l); + } + else + { + return l <= a ? 0.0 : 1.0; + } +} + +export float2 smoothstep(float2 a, float2 b, float2 l) +{ + return float2(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y)); +} + +export float3 smoothstep(float3 a, float3 b, float3 l) +{ + return float3(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z)); +} + +export float4 smoothstep(float4 a, float4 b, float4 l) +{ + return float4(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z), smoothstep(a.w, b.w, l.w)); +} + +export float2 smoothstep(float2 a, float2 b, float l) +{ + return float2(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l)); +} + +export float3 smoothstep(float3 a, float3 b, float l) +{ + return float3(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l)); +} + +export float4 smoothstep(float4 a, float4 b, float l) +{ + return float4(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l), smoothstep(a.w, b.w, l)); +} + +export float2 smoothstep(float a, float b, float2 l) +{ + return float2(smoothstep(a, b, l.x), smoothstep(a, b, l.y)); +} + +export float3 smoothstep(float a, float b, float3 l) +{ + return float3(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z)); +} + +export float4 smoothstep(float a, float b, float4 l) +{ + return float4(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z), smoothstep(a, b, l.w)); +} + +//------------------ Random from UE4 ----------------------- +float length2(float3 v) +{ + return math::dot(v, v); +} + +float3 GetPerlinNoiseGradientTextureAt(uniform texture_2d PerlinNoiseGradientTexture, float3 v) +{ + const float2 ZShear = float2(17.0f, 89.0f); + + float2 OffsetA = v.z * ZShear; + float2 TexA = (float2(v.x, v.y) + OffsetA + 0.5f) / 128.0f; + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA.x,1.0-TexA.y),tex::wrap_repeat,tex::wrap_repeat); + return float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z) * 2.0 - 1.0; +} + +float3 SkewSimplex(float3 In) +{ + return In + math::dot(In, float3(1.0 / 3.0f) ); +} +float3 UnSkewSimplex(float3 In) +{ + return In - math::dot(In, float3(1.0 / 6.0f) ); +} + +// 3D random number generator inspired by PCGs (permuted congruential generator) +// Using a **simple** Feistel cipher in place of the usual xor shift permutation step +// @param v = 3D integer coordinate +// @return three elements w/ 16 random bits each (0-0xffff). +// ~8 ALU operations for result.x (7 mad, 1 >>) +// ~10 ALU operations for result.xy (8 mad, 2 >>) +// ~12 ALU operations for result.xyz (9 mad, 3 >>) + +//TODO: uint3 +int3 Rand3DPCG16(int3 p) +{ + // taking a signed int then reinterpreting as unsigned gives good behavior for negatives + //TODO: uint3 + int3 v = int3(p); + + // Linear congruential step. These LCG constants are from Numerical Recipies + // For additional #'s, PCG would do multiple LCG steps and scramble each on output + // So v here is the RNG state + v = v * 1664525 + 1013904223; + + // PCG uses xorshift for the final shuffle, but it is expensive (and cheap + // versions of xorshift have visible artifacts). Instead, use simple MAD Feistel steps + // + // Feistel ciphers divide the state into separate parts (usually by bits) + // then apply a series of permutation steps one part at a time. The permutations + // use a reversible operation (usually ^) to part being updated with the result of + // a permutation function on the other parts and the key. + // + // In this case, I'm using v.x, v.y and v.z as the parts, using + instead of ^ for + // the combination function, and just multiplying the other two parts (no key) for + // the permutation function. + // + // That gives a simple mad per round. + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + + // only top 16 bits are well shuffled + return v >> 16; +} + +// Wraps noise for tiling texture creation +// @param v = unwrapped texture parameter +// @param bTiling = true to tile, false to not tile +// @param RepeatSize = number of units before repeating +// @return either original or wrapped coord +float3 NoiseTileWrap(float3 v, bool bTiling, float RepeatSize) +{ + return bTiling ? (math::frac(v / RepeatSize) * RepeatSize) : v; +} + +// Evaluate polynomial to get smooth transitions for Perlin noise +// only needed by Perlin functions in this file +// scalar(per component): 2 add, 5 mul +float4 PerlinRamp(float4 t) +{ + return t * t * t * (t * (t * 6 - 15) + 10); +} + +// Blum-Blum-Shub-inspired pseudo random number generator +// http://www.umbc.edu/~olano/papers/mNoise.pdf +// real BBS uses ((s*s) mod M) with bignums and M as the product of two huge Blum primes +// instead, we use a single prime M just small enough not to overflow +// note that the above paper used 61, which fits in a half, but is unusably bad +// @param Integer valued floating point seed +// @return random number in range [0,1) +// ~8 ALU operations (5 *, 3 frac) +float RandBBSfloat(float seed) +{ + float BBS_PRIME24 = 4093.0; + float s = math::frac(seed / BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + return s; +} + +// Modified noise gradient term +// @param seed - random seed for integer lattice position +// @param offset - [-1,1] offset of evaluation point from lattice point +// @return gradient direction (xyz) and contribution (w) from this lattice point +float4 MGradient(int seed, float3 offset) +{ + //TODO uint + int rand = Rand3DPCG16(int3(seed,0,0)).x; + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1.0 / 0x4000, 1.0 / 0x2000, 1.0 / 0x1000); + float3 direction = float3(int3(rand, rand, rand) & MGradientMask) * MGradientScale - 1; + return float4(direction.x, direction.y, direction.z, math::dot(direction, offset)); +} + +// compute Perlin and related noise corner seed values +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = true to return seed values for a repeating noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @param seed000-seed111 = hash function seeds for the eight corners +// @return fractional part of v +struct SeedValue +{ + float3 fv = float3(0); + float seed000 = 0; + float seed001 = 0; + float seed010 = 0; + float seed011 = 0; + float seed100 = 0; + float seed101 = 0; + float seed110 = 0; + float seed111 = 0; +}; + +SeedValue NoiseSeeds(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds; + seeds.fv = math::frac(v); + float3 iv = math::floor(v); + + const float3 primes = float3(19, 47, 101); + + if (bTiling) + { // can't algebraically combine with primes + seeds.seed000 = math::dot(primes, NoiseTileWrap(iv, true, RepeatSize)); + seeds.seed100 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 0), true, RepeatSize)); + seeds.seed010 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 0), true, RepeatSize)); + seeds.seed110 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 0), true, RepeatSize)); + seeds.seed001 = math::dot(primes, NoiseTileWrap(iv + float3(0, 0, 1), true, RepeatSize)); + seeds.seed101 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 1), true, RepeatSize)); + seeds.seed011 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 1), true, RepeatSize)); + seeds.seed111 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 1), true, RepeatSize)); + } + else + { // get to combine offsets with multiplication by primes in this case + seeds.seed000 = math::dot(iv, primes); + seeds.seed100 = seeds.seed000 + primes.x; + seeds.seed010 = seeds.seed000 + primes.y; + seeds.seed110 = seeds.seed100 + primes.y; + seeds.seed001 = seeds.seed000 + primes.z; + seeds.seed101 = seeds.seed100 + primes.z; + seeds.seed011 = seeds.seed010 + primes.z; + seeds.seed111 = seeds.seed110 + primes.z; + } + + return seeds; +} + +struct SimplexWeights +{ + float4 Result = float4(0); + float3 PosA = float3(0); + float3 PosB = float3(0); + float3 PosC = float3(0); + float3 PosD = float3(0); +}; + +// Computed weights and sample positions for simplex interpolation +// @return float4(a,b,c, d) Barycentric coordinate defined as Filtered = Tex(PosA) * a + Tex(PosB) * b + Tex(PosC) * c + Tex(PosD) * d +SimplexWeights ComputeSimplexWeights3D(float3 OrthogonalPos) +{ + SimplexWeights weights; + float3 OrthogonalPosFloor = math::floor(OrthogonalPos); + + weights.PosA = OrthogonalPosFloor; + weights.PosB = weights.PosA + float3(1, 1, 1); + + OrthogonalPos -= OrthogonalPosFloor; + + float Largest = math::max(OrthogonalPos.x, math::max(OrthogonalPos.y, OrthogonalPos.z)); + float Smallest = math::min(OrthogonalPos.x, math::min(OrthogonalPos.y, OrthogonalPos.z)); + + weights.PosC = weights.PosA + float3(Largest == OrthogonalPos.x, Largest == OrthogonalPos.y, Largest == OrthogonalPos.z); + weights.PosD = weights.PosA + float3(Smallest != OrthogonalPos.x, Smallest != OrthogonalPos.y, Smallest != OrthogonalPos.z); + + float RG = OrthogonalPos.x - OrthogonalPos.y; + float RB = OrthogonalPos.x - OrthogonalPos.z; + float GB = OrthogonalPos.y - OrthogonalPos.z; + + weights.Result.z = + math::min(math::max(0, RG), math::max(0, RB)) // X + + math::min(math::max(0, -RG), math::max(0, GB)) // Y + + math::min(math::max(0, -RB), math::max(0, -GB)); // Z + + weights.Result.w = + math::min(math::max(0, -RG), math::max(0, -RB)) // X + + math::min(math::max(0, RG), math::max(0, -GB)) // Y + + math::min(math::max(0, RB), math::max(0, GB)); // Z + + weights.Result.y = Smallest; + weights.Result.x = 1.0f - weights.Result.y - weights.Result.z - weights.Result.w; + + return weights; +} + +// filtered 3D gradient simple noise (few texture lookups, high quality) +// @param v >0 +// @return random number in the range -1 .. 1 +float SimplexNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 EvalPos) +{ + float3 OrthogonalPos = SkewSimplex(EvalPos); + + SimplexWeights Weights = ComputeSimplexWeights3D(OrthogonalPos); + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 32 bit) + float3 A = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosA); + float3 B = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosB); + float3 C = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosC); + float3 D = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosD); + + Weights.PosA = UnSkewSimplex(Weights.PosA); + Weights.PosB = UnSkewSimplex(Weights.PosB); + Weights.PosC = UnSkewSimplex(Weights.PosC); + Weights.PosD = UnSkewSimplex(Weights.PosD); + + float DistanceWeight; + + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosA)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float a = math::dot(A, EvalPos - Weights.PosA) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosB)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float b = math::dot(B, EvalPos - Weights.PosB) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosC)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float c = math::dot(C, EvalPos - Weights.PosC) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosD)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float d = math::dot(D, EvalPos - Weights.PosD) * DistanceWeight; + + return 32 * (a + b + c + d); +} + +// filtered 3D noise, can be optimized +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 v, bool bTiling, float RepeatSize) +{ + bTiling = true; + float3 fv = math::frac(v); + float3 iv0 = NoiseTileWrap(math::floor(v), bTiling, RepeatSize); + float3 iv1 = NoiseTileWrap(iv0 + 1, bTiling, RepeatSize); + + const int2 ZShear = int2(17, 89); + + float2 OffsetA = iv0.z * ZShear; + float2 OffsetB = OffsetA + ZShear; // non-tiling, use relative offset + if (bTiling) // tiling, have to compute from wrapped coordinates + { + OffsetB = iv1.z * ZShear; + } + + // Texture size scale factor + float ts = 1 / 128.0f; + + // texture coordinates for iv0.xy, as offset for both z slices + float2 TexA0 = (float2(iv0.x, iv0.y) + OffsetA + 0.5f) * ts; + float2 TexB0 = (float2(iv0.x, iv0.y) + OffsetB + 0.5f) * ts; + + // texture coordinates for iv1.xy, as offset for both z slices + float2 TexA1 = TexA0 + ts; // for non-tiling, can compute relative to existing coordinates + float2 TexB1 = TexB0 + ts; + if (bTiling) // for tiling, need to compute from wrapped coordinates + { + TexA1 = (float2(iv1.x, iv1.y) + OffsetA + 0.5f) * ts; + TexB1 = (float2(iv1.x, iv1.y) + OffsetB + 0.5f) * ts; + } + + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 8, 16 or 32 bit) + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + float3 PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 A = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 B = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 C = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 D = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 E = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 F = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 G = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 H = PerlinNoiseColor * 2 - 1; + + float a = math::dot(A, fv - float3(0, 0, 0)); + float b = math::dot(B, fv - float3(1, 0, 0)); + float c = math::dot(C, fv - float3(0, 1, 0)); + float d = math::dot(D, fv - float3(1, 1, 0)); + float e = math::dot(E, fv - float3(0, 0, 1)); + float f = math::dot(F, fv - float3(1, 0, 1)); + float g = math::dot(G, fv - float3(0, 1, 1)); + float h = math::dot(H, fv - float3(1, 1, 1)); + + float4 Weights = PerlinRamp(math::frac(float4(fv.x, fv.y, fv.z, 0))); + + float i = math::lerp(math::lerp(a, b, Weights.x), math::lerp(c, d, Weights.x), Weights.y); + float j = math::lerp(math::lerp(e, f, Weights.x), math::lerp(g, h, Weights.x), Weights.y); + + return math::lerp(i, j, Weights.z); +} + +// @return random number in the range -1 .. 1 +// scalar: 6 frac, 31 mul/mad, 15 add, +float FastGradientPerlinNoise3D_TEX(uniform texture_3d PerlinNoise3DTexture, float3 xyz) +{ + // needs to be the same value when creating the PerlinNoise3D texture + float Extent = 16; + + // last texel replicated and needed for filtering + // scalar: 3 frac, 6 mul + xyz = math::frac(xyz / (Extent - 1)) * (Extent - 1); + + // scalar: 3 frac + float3 uvw = math::frac(xyz); + // = floor(xyz); + // scalar: 3 add + float3 p0 = xyz - uvw; +// float3 f = math::pow(uvw, 2) * 3.0f - math::pow(uvw, 3) * 2.0f; // original perlin hermite (ok when used without bump mapping) + // scalar: 2*3 add 5*3 mul + float4 pr = PerlinRamp(float4(uvw.x, uvw.y, uvw.z, 0)); + float3 f = float3(pr.x, pr.y, pr.z); // new, better with continues second derivative for bump mapping + // scalar: 3 add + float3 p = p0 + f; + // scalar: 3 mad + // TODO: need reverse??? + float4 NoiseSample = tex::lookup_float4(PerlinNoise3DTexture, p / Extent + 0.5f / Extent); // +0.5f to get rid of bilinear offset + + // reconstruct from 8bit (using mad with 2 constants and dot4 was same instruction count) + // scalar: 4 mad, 3 mul, 3 add + float3 n = float3(NoiseSample.x, NoiseSample.y, NoiseSample.z) * 255.0f / 127.0f - 1.0f; + float d = NoiseSample.w * 255.f - 127; + return math::dot(xyz, n) - d; +} + +// Perlin-style "Modified Noise" +// http://www.umbc.edu/~olano/papers/index.html#mNoise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = MGradient(int(seeds.seed000), seeds.fv - float3(0, 0, 0)).w; + float rand100 = MGradient(int(seeds.seed100), seeds.fv - float3(1, 0, 0)).w; + float rand010 = MGradient(int(seeds.seed010), seeds.fv - float3(0, 1, 0)).w; + float rand110 = MGradient(int(seeds.seed110), seeds.fv - float3(1, 1, 0)).w; + float rand001 = MGradient(int(seeds.seed001), seeds.fv - float3(0, 0, 1)).w; + float rand101 = MGradient(int(seeds.seed101), seeds.fv - float3(1, 0, 1)).w; + float rand011 = MGradient(int(seeds.seed011), seeds.fv - float3(0, 1, 1)).w; + float rand111 = MGradient(int(seeds.seed111), seeds.fv - float3(1, 1, 1)).w; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D value noise - used to be incorrectly called Perlin noise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float ValueNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = RandBBSfloat(seeds.seed000) * 2 - 1; + float rand100 = RandBBSfloat(seeds.seed100) * 2 - 1; + float rand010 = RandBBSfloat(seeds.seed010) * 2 - 1; + float rand110 = RandBBSfloat(seeds.seed110) * 2 - 1; + float rand001 = RandBBSfloat(seeds.seed001) * 2 - 1; + float rand101 = RandBBSfloat(seeds.seed101) * 2 - 1; + float rand011 = RandBBSfloat(seeds.seed011) * 2 - 1; + float rand111 = RandBBSfloat(seeds.seed111) * 2 - 1; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D jitter offset within a voronoi noise cell +// @param pos - integer lattice corner +// @return random offsets vector +float3 VoronoiCornerSample(float3 pos, int Quality) +{ + // random values in [-0.5, 0.5] + float3 noise = float3(Rand3DPCG16(int3(pos))) / 0xffff - 0.5; + + // quality level 1 or 2: searches a 2x2x2 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 2x2x2 search + if (Quality <= 2) + { + return math::normalize(noise) * 0.2588; + } + + // quality level 3: searches a 3x3x3 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 3x3x3 search + if (Quality == 3) + { + return math::normalize(noise) * 0.3090; + } + + // quality level 4: jitter to anywhere in the cell, needs 4x4x4 search + return noise; +} + +// compare previous best with a new candidate +// not producing point locations makes it easier for compiler to eliminate calculations when they're not needed +// @param minval = location and distance of best candidate seed point before the new one +// @param candidate = candidate seed point +// @param offset = 3D offset to new candidate seed point +// @param bDistanceOnly = if true, only set maxval.w with distance, otherwise maxval.w is distance and maxval.xyz is position +// @return position (if bDistanceOnly is false) and distance to closest seed point so far +float4 VoronoiCompare(float4 minval, float3 candidate, float3 offset, bool bDistanceOnly) +{ + if (bDistanceOnly) + { + return float4(0, 0, 0, math::min(minval.w, math::dot(offset, offset))); + } + else + { + float newdist = math::dot(offset, offset); + return newdist > minval.w ? minval : float4(candidate.x, candidate.y, candidate.z, newdist); + } +} + +// 220 instruction Worley noise +float4 VoronoiNoise3D_ALU(float3 v, int Quality, bool bTiling, float RepeatSize, bool bDistanceOnly) +{ + float3 fv = math::frac(v), fv2 = math::frac(v + 0.5); + float3 iv = math::floor(v), iv2 = math::floor(v + 0.5); + + // with initial minimum distance = infinity (or at least bigger than 4), first min is optimized away + float4 mindist = float4(0,0,0,100); + float3 p, offset; + + // quality level 3: do a 3x3x3 search + if (Quality == 3) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 1; ++offset_x) + { + for (offset_y = -1; offset_y <= 1; ++offset_y) + { + for (offset_z = -1; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + + // everybody else searches a base 2x2x2 neighborhood + else + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = 0; offset_x <= 1; ++offset_x) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // quality level 2, do extra set of points, offset by half a cell + if (Quality == 2) + { + // 467 is just an offset to a different area in the random number field to avoid similar neighbor artifacts + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize) + 467, Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + } + + // quality level 4: add extra sets of four cells in each direction + if (Quality >= 4) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 2; offset_x += 3) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + // along x axis + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along y axis + p = float3(offset.y, offset.z, offset.x) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.y, offset.z, offset.x), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along z axis + p = float3(offset.z, offset.x, offset.y) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.z, offset.x, offset.y), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + } + } + } + } + + // transform squared distance to real distance + return float4(mindist.x, mindist.y, mindist.z, math::sqrt(mindist.w)); +} + +// Coordinates for corners of a Simplex tetrahedron +// Based on McEwan et al., Efficient computation of noise in GLSL, JGT 2011 +// @param v = 3D noise argument +// @return 4 corner locations +float4x3 SimplexCorners(float3 v) +{ + // find base corner by skewing to tetrahedral space and back + float3 tet = math::floor(v + v.x/3 + v.y/3 + v.z/3); + float3 base = tet - tet.x/6 - tet.y/6 - tet.z/6; + float3 f = v - base; + + // Find offsets to other corners (McEwan did this in tetrahedral space, + // but since skew is along x=y=z axis, this works in Euclidean space too.) + float3 g = math::step(float3(f.y,f.z,f.x), float3(f.x,f.y,f.z)), h = 1 - float3(g.z, g.x, g.y); + float3 a1 = math::min(g, h) - 1.0 / 6.0, a2 = math::max(g, h) - 1.0 / 3.0; + + // four corners + return float4x3(base, base + a1, base + a2, base + 0.5); +} + +// Improved smoothing function for simplex noise +// @param f = fractional distance to four tetrahedral corners +// @return weight for each corner +float4 SimplexSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + return (1 * scale + s*(-3 * scale + s*(3 * scale - s*scale))); +} + +// Derivative of simplex noise smoothing function +// @param f = fractional distanc eto four tetrahedral corners +// @return derivative of smoothing function for each corner by x, y and z +float3x4 SimplexDSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + s = -12 * scale + s*(24 * scale - s * 12 * scale); + + return float3x4( + s * float4(f[0][0], f[1][0], f[2][0], f[3][0]), + s * float4(f[0][1], f[1][1], f[2][1], f[3][1]), + s * float4(f[0][2], f[1][2], f[2][2], f[3][2])); +} + +// Simplex noise and its Jacobian derivative +// @param v = 3D noise argument +// @param bTiling = whether to repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension, must be a multiple of 3 +// @return float3x3 Jacobian in J[*].xyz, vector noise in J[*].w +// J[0].w, J[1].w, J[2].w is a Perlin-style simplex noise with vector output, e.g. (Nx, Ny, Nz) +// J[i].x is X derivative of the i'th component of the noise so J[2].x is dNz/dx +// You can use this to compute the noise, gradient, curl, or divergence: +// float3x4 J = JacobianSimplex_ALU(...); +// float3 VNoise = float3(J[0].w, J[1].w, J[2].w); // 3D noise +// float3 Grad = J[0].xyz; // gradient of J[0].w +// float3 Curl = float3(J[1][2]-J[2][1], J[2][0]-J[0][2], J[0][1]-J[1][2]); +// float Div = J[0][0]+J[1][1]+J[2][2]; +// All of these are confirmed to compile out all unneeded terms. +// So Grad of X doesn't compute Y or Z components, and VNoise doesn't do any of the derivative computation. +float3x4 JacobianSimplex_ALU(float3 v, bool bTiling, float RepeatSize) +{ + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1. / 0x4000, 1. / 0x2000, 1. / 0x1000); + + // corners of tetrahedron + float4x3 T = SimplexCorners(v); + // TODO: uint3 + int3 rand = int3(0); + float4x3 gvec0 = float4x3(1.0); + float4x3 gvec1 = float4x3(1.0); + float4x3 gvec2 = float4x3(1.0); + float4x3 fv = float4x3(1.0); + float3x4 grad = float3x4(1.0); + + // processing of tetrahedral vertices, unrolled + // to compute gradient at each corner + fv[0] = v - T[0]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[0] + 0.5, bTiling, RepeatSize)))); + gvec0[0] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[0] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[0] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][0] = math::dot(gvec0[0], fv[0]); + grad[1][0] = math::dot(gvec1[0], fv[0]); + grad[2][0] = math::dot(gvec2[0], fv[0]); + + fv[1] = v - T[1]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[1] + 0.5, bTiling, RepeatSize)))); + gvec0[1] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][1] = math::dot(gvec0[1], fv[1]); + grad[1][1] = math::dot(gvec1[1], fv[1]); + grad[2][1] = math::dot(gvec2[1], fv[1]); + + fv[2] = v - T[2]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[2] + 0.5, bTiling, RepeatSize)))); + gvec0[2] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[2] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[2] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][2] = math::dot(gvec0[2], fv[2]); + grad[1][2] = math::dot(gvec1[2], fv[2]); + grad[2][2] = math::dot(gvec2[2], fv[2]); + + fv[3] = v - T[3]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[3] + 0.5, bTiling, RepeatSize)))); + gvec0[3] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[3] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[3] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][3] = math::dot(gvec0[3], fv[3]); + grad[1][3] = math::dot(gvec1[3], fv[3]); + grad[2][3] = math::dot(gvec2[3], fv[3]); + + // blend gradients + float4 sv = SimplexSmooth(fv); + float3x4 ds = SimplexDSmooth(fv); + + float3x4 jacobian = float3x4(1.0); + float3 vec0 = gvec0*sv + grad[0]*ds; // NOTE: mdl is column major, convert from UE4 (row major) + jacobian[0] = float4(vec0.x, vec0.y, vec0.z, math::dot(sv, grad[0])); + float3 vec1 = gvec1*sv + grad[1]*ds; + jacobian[1] = float4(vec1.x, vec1.y, vec1.z, math::dot(sv, grad[1])); + float3 vec2 = gvec2*sv + grad[2]*ds; + jacobian[2] = float4(vec2.x, vec2.y, vec2.z, math::dot(sv, grad[2])); + + return jacobian; +} + +// While RepeatSize is a float here, the expectation is that it would be largely integer values coming in from the UI. The downstream logic assumes +// floats for all called functions (NoiseTileWrap) and this prevents any float-to-int conversion errors from automatic type conversion. +float Noise3D_Multiplexer(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, int Function, float3 Position, int Quality, bool bTiling, float RepeatSize) +{ + // verified, HLSL compiled out the switch if Function is a constant + switch(Function) + { + case 0: + return SimplexNoise3D_TEX(PerlinNoiseGradientTexture, Position); + case 1: + return GradientNoise3D_TEX(PerlinNoiseGradientTexture, Position, bTiling, RepeatSize); + case 2: + return FastGradientPerlinNoise3D_TEX(PerlinNoise3DTexture, Position); + case 3: + return GradientNoise3D_ALU(Position, bTiling, RepeatSize); + case 4: + return ValueNoise3D_ALU(Position, bTiling, RepeatSize); + case 5: + return VoronoiNoise3D_ALU(Position, Quality, bTiling, RepeatSize, true).w * 2.0 - 1.0; + } + return 0; +} +//---------------------------------------------------------- + +export float noise(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, float3 Position, float Scale, float Quality, float Function, float Turbulence, float Levels, float OutputMin, float OutputMax, float LevelScale, float FilterWidth, float Tiling, float RepeatSize) +[[ + anno::description("Noise"), + anno::noinline() +]] +{ + Position *= Scale; + FilterWidth *= Scale; + + float Out = 0.0f; + float OutScale = 1.0f; + float InvLevelScale = 1.0f / LevelScale; + + int iFunction(Function); + int iQuality(Quality); + int iLevels(Levels); + bool bTurbulence(Turbulence); + bool bTiling(Tiling); + + for(int i = 0; i < iLevels; ++i) + { + // fade out noise level that are too high frequent (not done through dynamic branching as it usually requires gradient instructions) + OutScale *= math::saturate(1.0 - FilterWidth); + + if(bTurbulence) + { + Out += math::abs(Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize)) * OutScale; + } + else + { + Out += Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize) * OutScale; + } + + Position *= LevelScale; + RepeatSize *= LevelScale; + OutScale *= InvLevelScale; + FilterWidth *= LevelScale; + } + + if(!bTurbulence) + { + // bring -1..1 to 0..1 range + Out = Out * 0.5f + 0.5f; + } + + // Out is in 0..1 range + return math::lerp(OutputMin, OutputMax, Out); +} + +// Material node for noise functions returning a vector value +// @param LevelScale usually 2 but higher values allow efficient use of few levels +// @return in user defined range (OutputMin..OutputMax) +export float4 vector4_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise"), + anno::noinline() +]] +{ + float4 result = float4(0,0,0,1); + float3 ret = float3(0); + int iQuality = int(Quality); + int iFunction = int(Function); + bool bTiling = Tiling > 0.0; + + float3x4 Jacobian = JacobianSimplex_ALU(Position, bTiling, TileSize); // compiled out if not used + + // verified, HLSL compiled out the switch if Function is a constant + switch (iFunction) + { + case 0: // Cellnoise + ret = float3(Rand3DPCG16(int3(math::floor(NoiseTileWrap(Position, bTiling, TileSize))))) / 0xffff; + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 1: // Color noise + ret = float3(Jacobian[0].w, Jacobian[1].w, Jacobian[2].w); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 2: // Gradient + result = Jacobian[0]; + break; + case 3: // Curl + ret = float3(Jacobian[2][1] - Jacobian[1][2], Jacobian[0][2] - Jacobian[2][0], Jacobian[1][0] - Jacobian[0][1]); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 4: // Voronoi + result = VoronoiNoise3D_ALU(Position, iQuality, bTiling, TileSize, false); + break; + } + return result; +} + +export float3 vector3_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise float3 version"), + anno::noinline() +]] +{ + float4 noise = vector4_noise(Position, Quality, Function, Tiling, TileSize); + return float3(noise.x, noise.y, noise.z); +} + + +// workaround for ue4 fresnel (without supporting for camera vector) : replacing it with 0.0, means facing to the view +export float fresnel(float exponent [[anno::unused()]], float base_reflect_fraction [[anno::unused()]], float3 normal [[anno::unused()]]) +[[ + anno::description("Fresnel"), + anno::noinline() +]] +{ + return 0.0; +} + +export float fresnel_function(float3 normal_vector [[anno::unused()]], float3 camera_vector [[anno::unused()]], + bool invert_fresnel [[anno::unused()]], float power [[anno::unused()]], + bool use_cheap_contrast [[anno::unused()]], float cheap_contrast_dark [[anno::unused()]], float cheap_contrast_bright [[anno::unused()]], + bool clamp_fresnel_dot_product [[anno::unused()]]) +[[ + anno::description("Fresnel Function"), + anno::noinline() +]] +{ + return 0.0; +} + +export float3 camera_vector(uniform bool up_z = true) +[[ + anno::description("Camera Vector"), + anno::noinline() +]] +{ + // assume camera postion is 0,0,0 + return math::normalize(float3(0) - convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)); +} + +export float pixel_depth() +[[ + anno::description("Pixel Depth"), + anno::noinline() +]] +{ + return 256.0f; +} + +export float scene_depth() +[[ + anno::description("Scene Depth") +]] +{ + return 65500.0f; +} + +export float3 scene_color() +[[ + anno::description("Scene Color") +]] +{ + return float3(1.0f); +} + +export float4 vertex_color() +[[ + anno::description("Vertex Color"), + anno::noinline() +]] +{ + return float4(1.0f); +} + +export float4 vertex_color_from_coordinate(int VertexColorCoordinateIndex) +[[ + anno::description("Vertex Color for float2 PrimVar"), + anno::noinline() +]] +{ + // Kit only supports 4 uv sets, 2 uvs are available to vertex color. if vertex color index is invalid, output the constant WHITE color intead + return (VertexColorCoordinateIndex > 2) ? float4(1.0f) : float4(state::texture_coordinate(VertexColorCoordinateIndex).x, state::texture_coordinate(VertexColorCoordinateIndex).y, state::texture_coordinate(VertexColorCoordinateIndex+1).x, state::texture_coordinate(VertexColorCoordinateIndex+1).y); +} + +export float3 camera_position() +[[ + anno::description("Camera Position"), + anno::noinline() +]] +{ + return float3(1000.0f, 0, 0); +} + +export float3 rotate_about_axis(float4 NormalizedRotationAxisAndAngle, float3 PositionOnAxis, float3 Position) +[[ + anno::description("Rotates Position about the given axis by the given angle") +]] +{ + // Project Position onto the rotation axis and find the closest point on the axis to Position + float3 NormalizedRotationAxis = float3(NormalizedRotationAxisAndAngle.x,NormalizedRotationAxisAndAngle.y,NormalizedRotationAxisAndAngle.z); + float3 ClosestPointOnAxis = PositionOnAxis + NormalizedRotationAxis * math::dot(NormalizedRotationAxis, Position - PositionOnAxis); + // Construct orthogonal axes in the plane of the rotation + float3 UAxis = Position - ClosestPointOnAxis; + float3 VAxis = math::cross(NormalizedRotationAxis, UAxis); + float[2] SinCosAngle = math::sincos(NormalizedRotationAxisAndAngle.w); + // Rotate using the orthogonal axes + float3 R = UAxis * SinCosAngle[1] + VAxis * SinCosAngle[0]; + // Reconstruct the rotated world space position + float3 RotatedPosition = ClosestPointOnAxis + R; + // Convert from position to a position offset + return RotatedPosition - Position; +} + +export float2 rotate_scale_offset_texcoords(float2 InTexCoords, float4 InRotationScale, float2 InOffset) +[[ + anno::description("Returns a float2 texture coordinate after 2x2 transform and offset applied") +]] +{ + return float2(math::dot(InTexCoords, float2(InRotationScale.x, InRotationScale.y)), math::dot(InTexCoords, float2(InRotationScale.z, InRotationScale.w))) + InOffset; +} + +export float3 reflection_custom_world_normal(float3 WorldNormal, bool bNormalizeInputNormal, uniform bool up_z = true) +[[ + anno::description("Reflection vector about the specified world space normal") +]] +{ + if (bNormalizeInputNormal) + { + WorldNormal = math::normalize(WorldNormal); + } + + return -camera_vector(up_z) + WorldNormal * math::dot(WorldNormal, camera_vector(up_z)) * 2.0; +} + +export float3 reflection_vector(uniform bool up_z = true) +[[ + anno::description("Reflection Vector"), + anno::noinline() +]] +{ + float3 normal = convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); + return reflection_custom_world_normal(normal, false, up_z); +} + +export float dither_temporalAA(float AlphaThreshold = 0.5f, float Random = 1.0f [[anno::unused()]]) +[[ + anno::description("Dither TemporalAA"), + anno::noinline() +]] +{ + return AlphaThreshold; +} + +export float3 black_body( float Temp ) +[[ + anno::description("Black Body"), + anno::noinline() +]] +{ + float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp ); + float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp ); + + float x = 3*u / ( 2*u - 8*v + 4 ); + float y = 2*v / ( 2*u - 8*v + 4 ); + float z = 1 - x - y; + + float Y = 1; + float X = Y/y * x; + float Z = Y/y * z; + + float3x3 XYZtoRGB = float3x3( + float3(3.2404542, -1.5371385, -0.4985314), + float3(-0.9692660, 1.8760108, 0.0415560), + float3(0.0556434, -0.2040259, 1.0572252) + ); + + return XYZtoRGB * float3( X, Y, Z ) * math::pow( 0.0004 * Temp, 4 ); +} + +export float per_instance_random(uniform texture_2d PerlinNoiseGradientTexture, int NumberInstances) +[[ + anno::description("Per Instance Random"), + anno::noinline() +]] +{ + float weight = state::object_id() / float(NumberInstances); + return NumberInstances == 0 ? 0.0 : tex::lookup_float4(PerlinNoiseGradientTexture, float2(weight, 1.0 - weight), tex::wrap_repeat, tex::wrap_repeat).x; +} + +//------------------ Hair from UE4 ----------------------- +float3 hair_absorption_to_color(float3 A) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::exp(-math::sqrt(A) * D); +} + +float3 hair_color_to_absorption(float3 C) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::pow(math::log(C) / D, 2.0f); +} + +export float3 get_hair_color_from_melanin(float InMelanin, float InRedness, float3 InDyeColor) +[[ + anno::description("Hair Color") +]] +{ + InMelanin = math::saturate(InMelanin); + InRedness = math::saturate(InRedness); + float Melanin = -math::log(math::max(1 - InMelanin, 0.0001f)); + float Eumelanin = Melanin * (1 - InRedness); + float Pheomelanin = Melanin * InRedness; + + float3 DyeAbsorption = hair_color_to_absorption(math::saturate(InDyeColor)); + float3 Absorption = Eumelanin * float3(0.506f, 0.841f, 1.653f) + Pheomelanin * float3(0.343f, 0.733f, 1.924f); + + return hair_absorption_to_color(Absorption + DyeAbsorption); +} + +export float3 local_object_bounds_min() +[[ + anno::description("Local Object Bounds Min"), + anno::noinline() +]] +{ + return float3(0.0); +} + +export float3 local_object_bounds_max() +[[ + anno::description("Local Object Bounds Max"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float3 object_bounds() +[[ + anno::description("Object Bounds"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float object_radius() +[[ + anno::description("Object Radius"), + anno::noinline() +]] +{ + return 100.0f; +} + +export float3 object_world_position(uniform bool up_z = true) +[[ + anno::description("Object World Position"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)*state::meters_per_scene_unit()*100.0; +} + +export float3 object_orientation() +[[ + anno::description("Object Orientation"), + anno::noinline() +]] +{ + return float3(0); +} + +export float rcp(float x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float2 rcp(float2 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float3 rcp(float3 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float4 rcp(float4 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export int BitFieldExtractI32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractI32 int"), + anno::noinline() +]] +{ + Size &= 3; + Offset &= 3; + + if (Size == 0) + return 0; + else if (Offset + Size < 32) + return (Data << (32 - Size - Offset)) >> (32 - Size); + else + return Data >> Offset; +} + +export int BitFieldExtractI32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractI32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(int(Data), int(Size), int(Offset)); +} + +export int BitFieldExtractU32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractU32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export int BitFieldExtractU32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractU32 int"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export float3 EyeAdaptationInverseLookup(float3 LightValue, float Alpha) +[[ + anno::description("EyeAdaptationInverseLookup"), + anno::noinline() +]] +{ + float Adaptation = 1.0f; + + // When Alpha=0.0, we want to multiply by 1.0. when Alpha = 1.0, we want to multiply by 1/Adaptation. + // So the lerped value is: + // LerpLogScale = Lerp(log(1),log(1/Adaptaiton),T) + // Which is simplified as: + // LerpLogScale = Lerp(0,-log(Adaptation),T) + // LerpLogScale = -T * logAdaptation; + + float LerpLogScale = -Alpha * math::log(Adaptation); + float Scale = math::exp(LerpLogScale); + return LightValue * Scale; +} diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl new file mode 100644 index 0000000000000000000000000000000000000000..9aad34bcd7bd5f29f99549120f776102febec45d --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl @@ -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 Num608bbc47c6ff5a0001d607d8( + uniform texture_2d Normal_Tex = texture_2d("../textures/normal_1.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_1.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_1.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_1.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_1.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_1.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); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/OmniUe4Base.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/OmniUe4Base.mdl new file mode 100644 index 0000000000000000000000000000000000000000..a441fbaf28040302c7aaabfbcf14b24a85bdf643 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/OmniUe4Base.mdl @@ -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 + ) +); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/OmniUe4Function.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/OmniUe4Function.mdl new file mode 100644 index 0000000000000000000000000000000000000000..f0801afff6f0870ea2574c9e9b6e2043e79e9a79 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/006/SubUSDs/materials/OmniUe4Function.mdl @@ -0,0 +1,1413 @@ +/*************************************************************************************************** + * 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.1 - using absolute import paths when importing standard modules + +mdl 1.6; + +import ::df::*; +import ::state::*; +import ::math::*; +import ::tex::*; +import ::anno::*; + + +export float3 convert_to_left_hand(float3 vec3, uniform bool up_z = true, uniform bool is_position = true) +[[ + anno::description("convert from RH to LH"), + anno::noinline() +]] +{ + float4x4 ZupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4x4 YupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4 vec4 = float4(vec3.x, vec3.y, vec3.z, is_position ? 1.0f : 0.0f); + + vec4 = vec4 * (up_z ? ZupConversion : YupConversion); + + return float3(vec4.x, vec4.y, vec4.z); +} + +export float3 transform_vector_from_tangent_to_world(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from tangent space to world space"), + anno::noinline() +]] +{ + /* flip_tangent_v */ + return convert_to_left_hand( + tangent_u * vector.x - tangent_v * vector.y + state::normal() * vector.z, + up_z, false); +} + +export float3 transform_vector_from_world_to_tangent(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from world space to tangent space"), + anno::noinline() +]] +{ + float3 vecRH = convert_to_left_hand(vector, up_z, false); + /* flip_tangent_v */ + return vecRH.x * float3(tangent_u.x, -tangent_v.x, state::normal().x) + + vecRH.y * float3(tangent_u.y, -tangent_v.y, state::normal().y) + + vecRH.z * float3(tangent_u.z, -tangent_v.z, state::normal().z); +} + +export float4 unpack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Unpack a normal stored in a normal map"), + anno::noinline() +]] +{ + float2 normal_xy = float2(texture_sample.x, texture_sample.y); + + normal_xy = normal_xy * float2(2.0,2.0) - float2(1.0,1.0); + float normal_z = math::sqrt( math::saturate( 1.0 - math::dot( normal_xy, normal_xy ) ) ); + return float4( normal_xy.x, normal_xy.y, normal_z, 1.0 ); +} + +// for get color value from normal. +export float4 pack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Pack to color from a normal") +]] +{ + float2 return_xy = float2(texture_sample.x, texture_sample.y); + + return_xy = (return_xy + float2(1.0,1.0)) / float2(2.0,2.0); + + return float4( return_xy.x, return_xy.y, 0.0, 1.0 ); +} + +export float4 greyscale_texture_lookup( + float4 texture_sample = float4(0.0, 0.0, 0.0, 1.0) + ) +[[ + anno::description("Sampling a greyscale texture"), + anno::noinline() +]] +{ + return float4(texture_sample.x, texture_sample.x, texture_sample.x, texture_sample.x); +} + +export float3 pixel_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Pixel normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 vertex_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Vertex normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 landscape_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Landscape normal in world space") +]] +{ + float3 normalFromNormalmap = math::floor((::vertex_normal_world_space(up_z) * 0.5 + 0.5) * 255.0) / 255.0 * 2.0 - 1.0; + + float2 normalXY = float2(normalFromNormalmap.x, normalFromNormalmap.y); + return float3(normalXY.x, normalXY.y, math::sqrt(math::saturate(1.0 - math::dot(normalXY, normalXY)))); +} + +// Different implementation specific between mdl and hlsl for smoothstep +export float smoothstep(float a, float b, float l) +{ + if (a < b) + { + return math::smoothstep(a, b, l); + } + else if (a > b) + { + return 1.0 - math::smoothstep(b, a, l); + } + else + { + return l <= a ? 0.0 : 1.0; + } +} + +export float2 smoothstep(float2 a, float2 b, float2 l) +{ + return float2(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y)); +} + +export float3 smoothstep(float3 a, float3 b, float3 l) +{ + return float3(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z)); +} + +export float4 smoothstep(float4 a, float4 b, float4 l) +{ + return float4(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z), smoothstep(a.w, b.w, l.w)); +} + +export float2 smoothstep(float2 a, float2 b, float l) +{ + return float2(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l)); +} + +export float3 smoothstep(float3 a, float3 b, float l) +{ + return float3(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l)); +} + +export float4 smoothstep(float4 a, float4 b, float l) +{ + return float4(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l), smoothstep(a.w, b.w, l)); +} + +export float2 smoothstep(float a, float b, float2 l) +{ + return float2(smoothstep(a, b, l.x), smoothstep(a, b, l.y)); +} + +export float3 smoothstep(float a, float b, float3 l) +{ + return float3(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z)); +} + +export float4 smoothstep(float a, float b, float4 l) +{ + return float4(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z), smoothstep(a, b, l.w)); +} + +//------------------ Random from UE4 ----------------------- +float length2(float3 v) +{ + return math::dot(v, v); +} + +float3 GetPerlinNoiseGradientTextureAt(uniform texture_2d PerlinNoiseGradientTexture, float3 v) +{ + const float2 ZShear = float2(17.0f, 89.0f); + + float2 OffsetA = v.z * ZShear; + float2 TexA = (float2(v.x, v.y) + OffsetA + 0.5f) / 128.0f; + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA.x,1.0-TexA.y),tex::wrap_repeat,tex::wrap_repeat); + return float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z) * 2.0 - 1.0; +} + +float3 SkewSimplex(float3 In) +{ + return In + math::dot(In, float3(1.0 / 3.0f) ); +} +float3 UnSkewSimplex(float3 In) +{ + return In - math::dot(In, float3(1.0 / 6.0f) ); +} + +// 3D random number generator inspired by PCGs (permuted congruential generator) +// Using a **simple** Feistel cipher in place of the usual xor shift permutation step +// @param v = 3D integer coordinate +// @return three elements w/ 16 random bits each (0-0xffff). +// ~8 ALU operations for result.x (7 mad, 1 >>) +// ~10 ALU operations for result.xy (8 mad, 2 >>) +// ~12 ALU operations for result.xyz (9 mad, 3 >>) + +//TODO: uint3 +int3 Rand3DPCG16(int3 p) +{ + // taking a signed int then reinterpreting as unsigned gives good behavior for negatives + //TODO: uint3 + int3 v = int3(p); + + // Linear congruential step. These LCG constants are from Numerical Recipies + // For additional #'s, PCG would do multiple LCG steps and scramble each on output + // So v here is the RNG state + v = v * 1664525 + 1013904223; + + // PCG uses xorshift for the final shuffle, but it is expensive (and cheap + // versions of xorshift have visible artifacts). Instead, use simple MAD Feistel steps + // + // Feistel ciphers divide the state into separate parts (usually by bits) + // then apply a series of permutation steps one part at a time. The permutations + // use a reversible operation (usually ^) to part being updated with the result of + // a permutation function on the other parts and the key. + // + // In this case, I'm using v.x, v.y and v.z as the parts, using + instead of ^ for + // the combination function, and just multiplying the other two parts (no key) for + // the permutation function. + // + // That gives a simple mad per round. + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + + // only top 16 bits are well shuffled + return v >> 16; +} + +// Wraps noise for tiling texture creation +// @param v = unwrapped texture parameter +// @param bTiling = true to tile, false to not tile +// @param RepeatSize = number of units before repeating +// @return either original or wrapped coord +float3 NoiseTileWrap(float3 v, bool bTiling, float RepeatSize) +{ + return bTiling ? (math::frac(v / RepeatSize) * RepeatSize) : v; +} + +// Evaluate polynomial to get smooth transitions for Perlin noise +// only needed by Perlin functions in this file +// scalar(per component): 2 add, 5 mul +float4 PerlinRamp(float4 t) +{ + return t * t * t * (t * (t * 6 - 15) + 10); +} + +// Blum-Blum-Shub-inspired pseudo random number generator +// http://www.umbc.edu/~olano/papers/mNoise.pdf +// real BBS uses ((s*s) mod M) with bignums and M as the product of two huge Blum primes +// instead, we use a single prime M just small enough not to overflow +// note that the above paper used 61, which fits in a half, but is unusably bad +// @param Integer valued floating point seed +// @return random number in range [0,1) +// ~8 ALU operations (5 *, 3 frac) +float RandBBSfloat(float seed) +{ + float BBS_PRIME24 = 4093.0; + float s = math::frac(seed / BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + return s; +} + +// Modified noise gradient term +// @param seed - random seed for integer lattice position +// @param offset - [-1,1] offset of evaluation point from lattice point +// @return gradient direction (xyz) and contribution (w) from this lattice point +float4 MGradient(int seed, float3 offset) +{ + //TODO uint + int rand = Rand3DPCG16(int3(seed,0,0)).x; + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1.0 / 0x4000, 1.0 / 0x2000, 1.0 / 0x1000); + float3 direction = float3(int3(rand, rand, rand) & MGradientMask) * MGradientScale - 1; + return float4(direction.x, direction.y, direction.z, math::dot(direction, offset)); +} + +// compute Perlin and related noise corner seed values +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = true to return seed values for a repeating noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @param seed000-seed111 = hash function seeds for the eight corners +// @return fractional part of v +struct SeedValue +{ + float3 fv = float3(0); + float seed000 = 0; + float seed001 = 0; + float seed010 = 0; + float seed011 = 0; + float seed100 = 0; + float seed101 = 0; + float seed110 = 0; + float seed111 = 0; +}; + +SeedValue NoiseSeeds(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds; + seeds.fv = math::frac(v); + float3 iv = math::floor(v); + + const float3 primes = float3(19, 47, 101); + + if (bTiling) + { // can't algebraically combine with primes + seeds.seed000 = math::dot(primes, NoiseTileWrap(iv, true, RepeatSize)); + seeds.seed100 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 0), true, RepeatSize)); + seeds.seed010 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 0), true, RepeatSize)); + seeds.seed110 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 0), true, RepeatSize)); + seeds.seed001 = math::dot(primes, NoiseTileWrap(iv + float3(0, 0, 1), true, RepeatSize)); + seeds.seed101 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 1), true, RepeatSize)); + seeds.seed011 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 1), true, RepeatSize)); + seeds.seed111 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 1), true, RepeatSize)); + } + else + { // get to combine offsets with multiplication by primes in this case + seeds.seed000 = math::dot(iv, primes); + seeds.seed100 = seeds.seed000 + primes.x; + seeds.seed010 = seeds.seed000 + primes.y; + seeds.seed110 = seeds.seed100 + primes.y; + seeds.seed001 = seeds.seed000 + primes.z; + seeds.seed101 = seeds.seed100 + primes.z; + seeds.seed011 = seeds.seed010 + primes.z; + seeds.seed111 = seeds.seed110 + primes.z; + } + + return seeds; +} + +struct SimplexWeights +{ + float4 Result = float4(0); + float3 PosA = float3(0); + float3 PosB = float3(0); + float3 PosC = float3(0); + float3 PosD = float3(0); +}; + +// Computed weights and sample positions for simplex interpolation +// @return float4(a,b,c, d) Barycentric coordinate defined as Filtered = Tex(PosA) * a + Tex(PosB) * b + Tex(PosC) * c + Tex(PosD) * d +SimplexWeights ComputeSimplexWeights3D(float3 OrthogonalPos) +{ + SimplexWeights weights; + float3 OrthogonalPosFloor = math::floor(OrthogonalPos); + + weights.PosA = OrthogonalPosFloor; + weights.PosB = weights.PosA + float3(1, 1, 1); + + OrthogonalPos -= OrthogonalPosFloor; + + float Largest = math::max(OrthogonalPos.x, math::max(OrthogonalPos.y, OrthogonalPos.z)); + float Smallest = math::min(OrthogonalPos.x, math::min(OrthogonalPos.y, OrthogonalPos.z)); + + weights.PosC = weights.PosA + float3(Largest == OrthogonalPos.x, Largest == OrthogonalPos.y, Largest == OrthogonalPos.z); + weights.PosD = weights.PosA + float3(Smallest != OrthogonalPos.x, Smallest != OrthogonalPos.y, Smallest != OrthogonalPos.z); + + float RG = OrthogonalPos.x - OrthogonalPos.y; + float RB = OrthogonalPos.x - OrthogonalPos.z; + float GB = OrthogonalPos.y - OrthogonalPos.z; + + weights.Result.z = + math::min(math::max(0, RG), math::max(0, RB)) // X + + math::min(math::max(0, -RG), math::max(0, GB)) // Y + + math::min(math::max(0, -RB), math::max(0, -GB)); // Z + + weights.Result.w = + math::min(math::max(0, -RG), math::max(0, -RB)) // X + + math::min(math::max(0, RG), math::max(0, -GB)) // Y + + math::min(math::max(0, RB), math::max(0, GB)); // Z + + weights.Result.y = Smallest; + weights.Result.x = 1.0f - weights.Result.y - weights.Result.z - weights.Result.w; + + return weights; +} + +// filtered 3D gradient simple noise (few texture lookups, high quality) +// @param v >0 +// @return random number in the range -1 .. 1 +float SimplexNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 EvalPos) +{ + float3 OrthogonalPos = SkewSimplex(EvalPos); + + SimplexWeights Weights = ComputeSimplexWeights3D(OrthogonalPos); + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 32 bit) + float3 A = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosA); + float3 B = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosB); + float3 C = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosC); + float3 D = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosD); + + Weights.PosA = UnSkewSimplex(Weights.PosA); + Weights.PosB = UnSkewSimplex(Weights.PosB); + Weights.PosC = UnSkewSimplex(Weights.PosC); + Weights.PosD = UnSkewSimplex(Weights.PosD); + + float DistanceWeight; + + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosA)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float a = math::dot(A, EvalPos - Weights.PosA) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosB)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float b = math::dot(B, EvalPos - Weights.PosB) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosC)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float c = math::dot(C, EvalPos - Weights.PosC) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosD)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float d = math::dot(D, EvalPos - Weights.PosD) * DistanceWeight; + + return 32 * (a + b + c + d); +} + +// filtered 3D noise, can be optimized +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 v, bool bTiling, float RepeatSize) +{ + bTiling = true; + float3 fv = math::frac(v); + float3 iv0 = NoiseTileWrap(math::floor(v), bTiling, RepeatSize); + float3 iv1 = NoiseTileWrap(iv0 + 1, bTiling, RepeatSize); + + const int2 ZShear = int2(17, 89); + + float2 OffsetA = iv0.z * ZShear; + float2 OffsetB = OffsetA + ZShear; // non-tiling, use relative offset + if (bTiling) // tiling, have to compute from wrapped coordinates + { + OffsetB = iv1.z * ZShear; + } + + // Texture size scale factor + float ts = 1 / 128.0f; + + // texture coordinates for iv0.xy, as offset for both z slices + float2 TexA0 = (float2(iv0.x, iv0.y) + OffsetA + 0.5f) * ts; + float2 TexB0 = (float2(iv0.x, iv0.y) + OffsetB + 0.5f) * ts; + + // texture coordinates for iv1.xy, as offset for both z slices + float2 TexA1 = TexA0 + ts; // for non-tiling, can compute relative to existing coordinates + float2 TexB1 = TexB0 + ts; + if (bTiling) // for tiling, need to compute from wrapped coordinates + { + TexA1 = (float2(iv1.x, iv1.y) + OffsetA + 0.5f) * ts; + TexB1 = (float2(iv1.x, iv1.y) + OffsetB + 0.5f) * ts; + } + + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 8, 16 or 32 bit) + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + float3 PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 A = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 B = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 C = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 D = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 E = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 F = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 G = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 H = PerlinNoiseColor * 2 - 1; + + float a = math::dot(A, fv - float3(0, 0, 0)); + float b = math::dot(B, fv - float3(1, 0, 0)); + float c = math::dot(C, fv - float3(0, 1, 0)); + float d = math::dot(D, fv - float3(1, 1, 0)); + float e = math::dot(E, fv - float3(0, 0, 1)); + float f = math::dot(F, fv - float3(1, 0, 1)); + float g = math::dot(G, fv - float3(0, 1, 1)); + float h = math::dot(H, fv - float3(1, 1, 1)); + + float4 Weights = PerlinRamp(math::frac(float4(fv.x, fv.y, fv.z, 0))); + + float i = math::lerp(math::lerp(a, b, Weights.x), math::lerp(c, d, Weights.x), Weights.y); + float j = math::lerp(math::lerp(e, f, Weights.x), math::lerp(g, h, Weights.x), Weights.y); + + return math::lerp(i, j, Weights.z); +} + +// @return random number in the range -1 .. 1 +// scalar: 6 frac, 31 mul/mad, 15 add, +float FastGradientPerlinNoise3D_TEX(uniform texture_3d PerlinNoise3DTexture, float3 xyz) +{ + // needs to be the same value when creating the PerlinNoise3D texture + float Extent = 16; + + // last texel replicated and needed for filtering + // scalar: 3 frac, 6 mul + xyz = math::frac(xyz / (Extent - 1)) * (Extent - 1); + + // scalar: 3 frac + float3 uvw = math::frac(xyz); + // = floor(xyz); + // scalar: 3 add + float3 p0 = xyz - uvw; +// float3 f = math::pow(uvw, 2) * 3.0f - math::pow(uvw, 3) * 2.0f; // original perlin hermite (ok when used without bump mapping) + // scalar: 2*3 add 5*3 mul + float4 pr = PerlinRamp(float4(uvw.x, uvw.y, uvw.z, 0)); + float3 f = float3(pr.x, pr.y, pr.z); // new, better with continues second derivative for bump mapping + // scalar: 3 add + float3 p = p0 + f; + // scalar: 3 mad + // TODO: need reverse??? + float4 NoiseSample = tex::lookup_float4(PerlinNoise3DTexture, p / Extent + 0.5f / Extent); // +0.5f to get rid of bilinear offset + + // reconstruct from 8bit (using mad with 2 constants and dot4 was same instruction count) + // scalar: 4 mad, 3 mul, 3 add + float3 n = float3(NoiseSample.x, NoiseSample.y, NoiseSample.z) * 255.0f / 127.0f - 1.0f; + float d = NoiseSample.w * 255.f - 127; + return math::dot(xyz, n) - d; +} + +// Perlin-style "Modified Noise" +// http://www.umbc.edu/~olano/papers/index.html#mNoise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = MGradient(int(seeds.seed000), seeds.fv - float3(0, 0, 0)).w; + float rand100 = MGradient(int(seeds.seed100), seeds.fv - float3(1, 0, 0)).w; + float rand010 = MGradient(int(seeds.seed010), seeds.fv - float3(0, 1, 0)).w; + float rand110 = MGradient(int(seeds.seed110), seeds.fv - float3(1, 1, 0)).w; + float rand001 = MGradient(int(seeds.seed001), seeds.fv - float3(0, 0, 1)).w; + float rand101 = MGradient(int(seeds.seed101), seeds.fv - float3(1, 0, 1)).w; + float rand011 = MGradient(int(seeds.seed011), seeds.fv - float3(0, 1, 1)).w; + float rand111 = MGradient(int(seeds.seed111), seeds.fv - float3(1, 1, 1)).w; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D value noise - used to be incorrectly called Perlin noise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float ValueNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = RandBBSfloat(seeds.seed000) * 2 - 1; + float rand100 = RandBBSfloat(seeds.seed100) * 2 - 1; + float rand010 = RandBBSfloat(seeds.seed010) * 2 - 1; + float rand110 = RandBBSfloat(seeds.seed110) * 2 - 1; + float rand001 = RandBBSfloat(seeds.seed001) * 2 - 1; + float rand101 = RandBBSfloat(seeds.seed101) * 2 - 1; + float rand011 = RandBBSfloat(seeds.seed011) * 2 - 1; + float rand111 = RandBBSfloat(seeds.seed111) * 2 - 1; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D jitter offset within a voronoi noise cell +// @param pos - integer lattice corner +// @return random offsets vector +float3 VoronoiCornerSample(float3 pos, int Quality) +{ + // random values in [-0.5, 0.5] + float3 noise = float3(Rand3DPCG16(int3(pos))) / 0xffff - 0.5; + + // quality level 1 or 2: searches a 2x2x2 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 2x2x2 search + if (Quality <= 2) + { + return math::normalize(noise) * 0.2588; + } + + // quality level 3: searches a 3x3x3 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 3x3x3 search + if (Quality == 3) + { + return math::normalize(noise) * 0.3090; + } + + // quality level 4: jitter to anywhere in the cell, needs 4x4x4 search + return noise; +} + +// compare previous best with a new candidate +// not producing point locations makes it easier for compiler to eliminate calculations when they're not needed +// @param minval = location and distance of best candidate seed point before the new one +// @param candidate = candidate seed point +// @param offset = 3D offset to new candidate seed point +// @param bDistanceOnly = if true, only set maxval.w with distance, otherwise maxval.w is distance and maxval.xyz is position +// @return position (if bDistanceOnly is false) and distance to closest seed point so far +float4 VoronoiCompare(float4 minval, float3 candidate, float3 offset, bool bDistanceOnly) +{ + if (bDistanceOnly) + { + return float4(0, 0, 0, math::min(minval.w, math::dot(offset, offset))); + } + else + { + float newdist = math::dot(offset, offset); + return newdist > minval.w ? minval : float4(candidate.x, candidate.y, candidate.z, newdist); + } +} + +// 220 instruction Worley noise +float4 VoronoiNoise3D_ALU(float3 v, int Quality, bool bTiling, float RepeatSize, bool bDistanceOnly) +{ + float3 fv = math::frac(v), fv2 = math::frac(v + 0.5); + float3 iv = math::floor(v), iv2 = math::floor(v + 0.5); + + // with initial minimum distance = infinity (or at least bigger than 4), first min is optimized away + float4 mindist = float4(0,0,0,100); + float3 p, offset; + + // quality level 3: do a 3x3x3 search + if (Quality == 3) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 1; ++offset_x) + { + for (offset_y = -1; offset_y <= 1; ++offset_y) + { + for (offset_z = -1; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + + // everybody else searches a base 2x2x2 neighborhood + else + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = 0; offset_x <= 1; ++offset_x) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // quality level 2, do extra set of points, offset by half a cell + if (Quality == 2) + { + // 467 is just an offset to a different area in the random number field to avoid similar neighbor artifacts + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize) + 467, Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + } + + // quality level 4: add extra sets of four cells in each direction + if (Quality >= 4) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 2; offset_x += 3) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + // along x axis + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along y axis + p = float3(offset.y, offset.z, offset.x) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.y, offset.z, offset.x), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along z axis + p = float3(offset.z, offset.x, offset.y) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.z, offset.x, offset.y), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + } + } + } + } + + // transform squared distance to real distance + return float4(mindist.x, mindist.y, mindist.z, math::sqrt(mindist.w)); +} + +// Coordinates for corners of a Simplex tetrahedron +// Based on McEwan et al., Efficient computation of noise in GLSL, JGT 2011 +// @param v = 3D noise argument +// @return 4 corner locations +float4x3 SimplexCorners(float3 v) +{ + // find base corner by skewing to tetrahedral space and back + float3 tet = math::floor(v + v.x/3 + v.y/3 + v.z/3); + float3 base = tet - tet.x/6 - tet.y/6 - tet.z/6; + float3 f = v - base; + + // Find offsets to other corners (McEwan did this in tetrahedral space, + // but since skew is along x=y=z axis, this works in Euclidean space too.) + float3 g = math::step(float3(f.y,f.z,f.x), float3(f.x,f.y,f.z)), h = 1 - float3(g.z, g.x, g.y); + float3 a1 = math::min(g, h) - 1.0 / 6.0, a2 = math::max(g, h) - 1.0 / 3.0; + + // four corners + return float4x3(base, base + a1, base + a2, base + 0.5); +} + +// Improved smoothing function for simplex noise +// @param f = fractional distance to four tetrahedral corners +// @return weight for each corner +float4 SimplexSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + return (1 * scale + s*(-3 * scale + s*(3 * scale - s*scale))); +} + +// Derivative of simplex noise smoothing function +// @param f = fractional distanc eto four tetrahedral corners +// @return derivative of smoothing function for each corner by x, y and z +float3x4 SimplexDSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + s = -12 * scale + s*(24 * scale - s * 12 * scale); + + return float3x4( + s * float4(f[0][0], f[1][0], f[2][0], f[3][0]), + s * float4(f[0][1], f[1][1], f[2][1], f[3][1]), + s * float4(f[0][2], f[1][2], f[2][2], f[3][2])); +} + +// Simplex noise and its Jacobian derivative +// @param v = 3D noise argument +// @param bTiling = whether to repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension, must be a multiple of 3 +// @return float3x3 Jacobian in J[*].xyz, vector noise in J[*].w +// J[0].w, J[1].w, J[2].w is a Perlin-style simplex noise with vector output, e.g. (Nx, Ny, Nz) +// J[i].x is X derivative of the i'th component of the noise so J[2].x is dNz/dx +// You can use this to compute the noise, gradient, curl, or divergence: +// float3x4 J = JacobianSimplex_ALU(...); +// float3 VNoise = float3(J[0].w, J[1].w, J[2].w); // 3D noise +// float3 Grad = J[0].xyz; // gradient of J[0].w +// float3 Curl = float3(J[1][2]-J[2][1], J[2][0]-J[0][2], J[0][1]-J[1][2]); +// float Div = J[0][0]+J[1][1]+J[2][2]; +// All of these are confirmed to compile out all unneeded terms. +// So Grad of X doesn't compute Y or Z components, and VNoise doesn't do any of the derivative computation. +float3x4 JacobianSimplex_ALU(float3 v, bool bTiling, float RepeatSize) +{ + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1. / 0x4000, 1. / 0x2000, 1. / 0x1000); + + // corners of tetrahedron + float4x3 T = SimplexCorners(v); + // TODO: uint3 + int3 rand = int3(0); + float4x3 gvec0 = float4x3(1.0); + float4x3 gvec1 = float4x3(1.0); + float4x3 gvec2 = float4x3(1.0); + float4x3 fv = float4x3(1.0); + float3x4 grad = float3x4(1.0); + + // processing of tetrahedral vertices, unrolled + // to compute gradient at each corner + fv[0] = v - T[0]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[0] + 0.5, bTiling, RepeatSize)))); + gvec0[0] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[0] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[0] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][0] = math::dot(gvec0[0], fv[0]); + grad[1][0] = math::dot(gvec1[0], fv[0]); + grad[2][0] = math::dot(gvec2[0], fv[0]); + + fv[1] = v - T[1]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[1] + 0.5, bTiling, RepeatSize)))); + gvec0[1] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][1] = math::dot(gvec0[1], fv[1]); + grad[1][1] = math::dot(gvec1[1], fv[1]); + grad[2][1] = math::dot(gvec2[1], fv[1]); + + fv[2] = v - T[2]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[2] + 0.5, bTiling, RepeatSize)))); + gvec0[2] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[2] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[2] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][2] = math::dot(gvec0[2], fv[2]); + grad[1][2] = math::dot(gvec1[2], fv[2]); + grad[2][2] = math::dot(gvec2[2], fv[2]); + + fv[3] = v - T[3]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[3] + 0.5, bTiling, RepeatSize)))); + gvec0[3] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[3] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[3] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][3] = math::dot(gvec0[3], fv[3]); + grad[1][3] = math::dot(gvec1[3], fv[3]); + grad[2][3] = math::dot(gvec2[3], fv[3]); + + // blend gradients + float4 sv = SimplexSmooth(fv); + float3x4 ds = SimplexDSmooth(fv); + + float3x4 jacobian = float3x4(1.0); + float3 vec0 = gvec0*sv + grad[0]*ds; // NOTE: mdl is column major, convert from UE4 (row major) + jacobian[0] = float4(vec0.x, vec0.y, vec0.z, math::dot(sv, grad[0])); + float3 vec1 = gvec1*sv + grad[1]*ds; + jacobian[1] = float4(vec1.x, vec1.y, vec1.z, math::dot(sv, grad[1])); + float3 vec2 = gvec2*sv + grad[2]*ds; + jacobian[2] = float4(vec2.x, vec2.y, vec2.z, math::dot(sv, grad[2])); + + return jacobian; +} + +// While RepeatSize is a float here, the expectation is that it would be largely integer values coming in from the UI. The downstream logic assumes +// floats for all called functions (NoiseTileWrap) and this prevents any float-to-int conversion errors from automatic type conversion. +float Noise3D_Multiplexer(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, int Function, float3 Position, int Quality, bool bTiling, float RepeatSize) +{ + // verified, HLSL compiled out the switch if Function is a constant + switch(Function) + { + case 0: + return SimplexNoise3D_TEX(PerlinNoiseGradientTexture, Position); + case 1: + return GradientNoise3D_TEX(PerlinNoiseGradientTexture, Position, bTiling, RepeatSize); + case 2: + return FastGradientPerlinNoise3D_TEX(PerlinNoise3DTexture, Position); + case 3: + return GradientNoise3D_ALU(Position, bTiling, RepeatSize); + case 4: + return ValueNoise3D_ALU(Position, bTiling, RepeatSize); + case 5: + return VoronoiNoise3D_ALU(Position, Quality, bTiling, RepeatSize, true).w * 2.0 - 1.0; + } + return 0; +} +//---------------------------------------------------------- + +export float noise(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, float3 Position, float Scale, float Quality, float Function, float Turbulence, float Levels, float OutputMin, float OutputMax, float LevelScale, float FilterWidth, float Tiling, float RepeatSize) +[[ + anno::description("Noise"), + anno::noinline() +]] +{ + Position *= Scale; + FilterWidth *= Scale; + + float Out = 0.0f; + float OutScale = 1.0f; + float InvLevelScale = 1.0f / LevelScale; + + int iFunction(Function); + int iQuality(Quality); + int iLevels(Levels); + bool bTurbulence(Turbulence); + bool bTiling(Tiling); + + for(int i = 0; i < iLevels; ++i) + { + // fade out noise level that are too high frequent (not done through dynamic branching as it usually requires gradient instructions) + OutScale *= math::saturate(1.0 - FilterWidth); + + if(bTurbulence) + { + Out += math::abs(Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize)) * OutScale; + } + else + { + Out += Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize) * OutScale; + } + + Position *= LevelScale; + RepeatSize *= LevelScale; + OutScale *= InvLevelScale; + FilterWidth *= LevelScale; + } + + if(!bTurbulence) + { + // bring -1..1 to 0..1 range + Out = Out * 0.5f + 0.5f; + } + + // Out is in 0..1 range + return math::lerp(OutputMin, OutputMax, Out); +} + +// Material node for noise functions returning a vector value +// @param LevelScale usually 2 but higher values allow efficient use of few levels +// @return in user defined range (OutputMin..OutputMax) +export float4 vector4_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise"), + anno::noinline() +]] +{ + float4 result = float4(0,0,0,1); + float3 ret = float3(0); + int iQuality = int(Quality); + int iFunction = int(Function); + bool bTiling = Tiling > 0.0; + + float3x4 Jacobian = JacobianSimplex_ALU(Position, bTiling, TileSize); // compiled out if not used + + // verified, HLSL compiled out the switch if Function is a constant + switch (iFunction) + { + case 0: // Cellnoise + ret = float3(Rand3DPCG16(int3(math::floor(NoiseTileWrap(Position, bTiling, TileSize))))) / 0xffff; + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 1: // Color noise + ret = float3(Jacobian[0].w, Jacobian[1].w, Jacobian[2].w); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 2: // Gradient + result = Jacobian[0]; + break; + case 3: // Curl + ret = float3(Jacobian[2][1] - Jacobian[1][2], Jacobian[0][2] - Jacobian[2][0], Jacobian[1][0] - Jacobian[0][1]); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 4: // Voronoi + result = VoronoiNoise3D_ALU(Position, iQuality, bTiling, TileSize, false); + break; + } + return result; +} + +export float3 vector3_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise float3 version"), + anno::noinline() +]] +{ + float4 noise = vector4_noise(Position, Quality, Function, Tiling, TileSize); + return float3(noise.x, noise.y, noise.z); +} + + +// workaround for ue4 fresnel (without supporting for camera vector) : replacing it with 0.0, means facing to the view +export float fresnel(float exponent [[anno::unused()]], float base_reflect_fraction [[anno::unused()]], float3 normal [[anno::unused()]]) +[[ + anno::description("Fresnel"), + anno::noinline() +]] +{ + return 0.0; +} + +export float fresnel_function(float3 normal_vector [[anno::unused()]], float3 camera_vector [[anno::unused()]], + bool invert_fresnel [[anno::unused()]], float power [[anno::unused()]], + bool use_cheap_contrast [[anno::unused()]], float cheap_contrast_dark [[anno::unused()]], float cheap_contrast_bright [[anno::unused()]], + bool clamp_fresnel_dot_product [[anno::unused()]]) +[[ + anno::description("Fresnel Function"), + anno::noinline() +]] +{ + return 0.0; +} + +export float3 camera_vector(uniform bool up_z = true) +[[ + anno::description("Camera Vector"), + anno::noinline() +]] +{ + // assume camera postion is 0,0,0 + return math::normalize(float3(0) - convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)); +} + +export float pixel_depth() +[[ + anno::description("Pixel Depth"), + anno::noinline() +]] +{ + return 256.0f; +} + +export float scene_depth() +[[ + anno::description("Scene Depth") +]] +{ + return 65500.0f; +} + +export float3 scene_color() +[[ + anno::description("Scene Color") +]] +{ + return float3(1.0f); +} + +export float4 vertex_color() +[[ + anno::description("Vertex Color"), + anno::noinline() +]] +{ + return float4(1.0f); +} + +export float4 vertex_color_from_coordinate(int VertexColorCoordinateIndex) +[[ + anno::description("Vertex Color for float2 PrimVar"), + anno::noinline() +]] +{ + // Kit only supports 4 uv sets, 2 uvs are available to vertex color. if vertex color index is invalid, output the constant WHITE color intead + return (VertexColorCoordinateIndex > 2) ? float4(1.0f) : float4(state::texture_coordinate(VertexColorCoordinateIndex).x, state::texture_coordinate(VertexColorCoordinateIndex).y, state::texture_coordinate(VertexColorCoordinateIndex+1).x, state::texture_coordinate(VertexColorCoordinateIndex+1).y); +} + +export float3 camera_position() +[[ + anno::description("Camera Position"), + anno::noinline() +]] +{ + return float3(1000.0f, 0, 0); +} + +export float3 rotate_about_axis(float4 NormalizedRotationAxisAndAngle, float3 PositionOnAxis, float3 Position) +[[ + anno::description("Rotates Position about the given axis by the given angle") +]] +{ + // Project Position onto the rotation axis and find the closest point on the axis to Position + float3 NormalizedRotationAxis = float3(NormalizedRotationAxisAndAngle.x,NormalizedRotationAxisAndAngle.y,NormalizedRotationAxisAndAngle.z); + float3 ClosestPointOnAxis = PositionOnAxis + NormalizedRotationAxis * math::dot(NormalizedRotationAxis, Position - PositionOnAxis); + // Construct orthogonal axes in the plane of the rotation + float3 UAxis = Position - ClosestPointOnAxis; + float3 VAxis = math::cross(NormalizedRotationAxis, UAxis); + float[2] SinCosAngle = math::sincos(NormalizedRotationAxisAndAngle.w); + // Rotate using the orthogonal axes + float3 R = UAxis * SinCosAngle[1] + VAxis * SinCosAngle[0]; + // Reconstruct the rotated world space position + float3 RotatedPosition = ClosestPointOnAxis + R; + // Convert from position to a position offset + return RotatedPosition - Position; +} + +export float2 rotate_scale_offset_texcoords(float2 InTexCoords, float4 InRotationScale, float2 InOffset) +[[ + anno::description("Returns a float2 texture coordinate after 2x2 transform and offset applied") +]] +{ + return float2(math::dot(InTexCoords, float2(InRotationScale.x, InRotationScale.y)), math::dot(InTexCoords, float2(InRotationScale.z, InRotationScale.w))) + InOffset; +} + +export float3 reflection_custom_world_normal(float3 WorldNormal, bool bNormalizeInputNormal, uniform bool up_z = true) +[[ + anno::description("Reflection vector about the specified world space normal") +]] +{ + if (bNormalizeInputNormal) + { + WorldNormal = math::normalize(WorldNormal); + } + + return -camera_vector(up_z) + WorldNormal * math::dot(WorldNormal, camera_vector(up_z)) * 2.0; +} + +export float3 reflection_vector(uniform bool up_z = true) +[[ + anno::description("Reflection Vector"), + anno::noinline() +]] +{ + float3 normal = convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); + return reflection_custom_world_normal(normal, false, up_z); +} + +export float dither_temporalAA(float AlphaThreshold = 0.5f, float Random = 1.0f [[anno::unused()]]) +[[ + anno::description("Dither TemporalAA"), + anno::noinline() +]] +{ + return AlphaThreshold; +} + +export float3 black_body( float Temp ) +[[ + anno::description("Black Body"), + anno::noinline() +]] +{ + float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp ); + float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp ); + + float x = 3*u / ( 2*u - 8*v + 4 ); + float y = 2*v / ( 2*u - 8*v + 4 ); + float z = 1 - x - y; + + float Y = 1; + float X = Y/y * x; + float Z = Y/y * z; + + float3x3 XYZtoRGB = float3x3( + float3(3.2404542, -1.5371385, -0.4985314), + float3(-0.9692660, 1.8760108, 0.0415560), + float3(0.0556434, -0.2040259, 1.0572252) + ); + + return XYZtoRGB * float3( X, Y, Z ) * math::pow( 0.0004 * Temp, 4 ); +} + +export float per_instance_random(uniform texture_2d PerlinNoiseGradientTexture, int NumberInstances) +[[ + anno::description("Per Instance Random"), + anno::noinline() +]] +{ + float weight = state::object_id() / float(NumberInstances); + return NumberInstances == 0 ? 0.0 : tex::lookup_float4(PerlinNoiseGradientTexture, float2(weight, 1.0 - weight), tex::wrap_repeat, tex::wrap_repeat).x; +} + +//------------------ Hair from UE4 ----------------------- +float3 hair_absorption_to_color(float3 A) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::exp(-math::sqrt(A) * D); +} + +float3 hair_color_to_absorption(float3 C) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::pow(math::log(C) / D, 2.0f); +} + +export float3 get_hair_color_from_melanin(float InMelanin, float InRedness, float3 InDyeColor) +[[ + anno::description("Hair Color") +]] +{ + InMelanin = math::saturate(InMelanin); + InRedness = math::saturate(InRedness); + float Melanin = -math::log(math::max(1 - InMelanin, 0.0001f)); + float Eumelanin = Melanin * (1 - InRedness); + float Pheomelanin = Melanin * InRedness; + + float3 DyeAbsorption = hair_color_to_absorption(math::saturate(InDyeColor)); + float3 Absorption = Eumelanin * float3(0.506f, 0.841f, 1.653f) + Pheomelanin * float3(0.343f, 0.733f, 1.924f); + + return hair_absorption_to_color(Absorption + DyeAbsorption); +} + +export float3 local_object_bounds_min() +[[ + anno::description("Local Object Bounds Min"), + anno::noinline() +]] +{ + return float3(0.0); +} + +export float3 local_object_bounds_max() +[[ + anno::description("Local Object Bounds Max"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float3 object_bounds() +[[ + anno::description("Object Bounds"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float object_radius() +[[ + anno::description("Object Radius"), + anno::noinline() +]] +{ + return 100.0f; +} + +export float3 object_world_position(uniform bool up_z = true) +[[ + anno::description("Object World Position"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)*state::meters_per_scene_unit()*100.0; +} + +export float3 object_orientation() +[[ + anno::description("Object Orientation"), + anno::noinline() +]] +{ + return float3(0); +} + +export float rcp(float x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float2 rcp(float2 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float3 rcp(float3 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float4 rcp(float4 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export int BitFieldExtractI32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractI32 int"), + anno::noinline() +]] +{ + Size &= 3; + Offset &= 3; + + if (Size == 0) + return 0; + else if (Offset + Size < 32) + return (Data << (32 - Size - Offset)) >> (32 - Size); + else + return Data >> Offset; +} + +export int BitFieldExtractI32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractI32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(int(Data), int(Size), int(Offset)); +} + +export int BitFieldExtractU32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractU32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export int BitFieldExtractU32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractU32 int"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export float3 EyeAdaptationInverseLookup(float3 LightValue, float Alpha) +[[ + anno::description("EyeAdaptationInverseLookup"), + anno::noinline() +]] +{ + float Adaptation = 1.0f; + + // When Alpha=0.0, we want to multiply by 1.0. when Alpha = 1.0, we want to multiply by 1/Adaptation. + // So the lerped value is: + // LerpLogScale = Lerp(log(1),log(1/Adaptaiton),T) + // Which is simplified as: + // LerpLogScale = Lerp(0,-log(Adaptation),T) + // LerpLogScale = -T * logAdaptation; + + float LerpLogScale = -Alpha * math::log(Adaptation); + float Scale = math::exp(LerpLogScale); + return LightValue * Scale; +} diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl new file mode 100644 index 0000000000000000000000000000000000000000..9aad34bcd7bd5f29f99549120f776102febec45d --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl @@ -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 Num608bbc47c6ff5a0001d607d8( + uniform texture_2d Normal_Tex = texture_2d("../textures/normal_1.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_1.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_1.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_1.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_1.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_1.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); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/OmniUe4Base.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/OmniUe4Base.mdl new file mode 100644 index 0000000000000000000000000000000000000000..a441fbaf28040302c7aaabfbcf14b24a85bdf643 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/OmniUe4Base.mdl @@ -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 + ) +); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/OmniUe4Function.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/OmniUe4Function.mdl new file mode 100644 index 0000000000000000000000000000000000000000..f0801afff6f0870ea2574c9e9b6e2043e79e9a79 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/009/SubUSDs/materials/OmniUe4Function.mdl @@ -0,0 +1,1413 @@ +/*************************************************************************************************** + * 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.1 - using absolute import paths when importing standard modules + +mdl 1.6; + +import ::df::*; +import ::state::*; +import ::math::*; +import ::tex::*; +import ::anno::*; + + +export float3 convert_to_left_hand(float3 vec3, uniform bool up_z = true, uniform bool is_position = true) +[[ + anno::description("convert from RH to LH"), + anno::noinline() +]] +{ + float4x4 ZupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4x4 YupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4 vec4 = float4(vec3.x, vec3.y, vec3.z, is_position ? 1.0f : 0.0f); + + vec4 = vec4 * (up_z ? ZupConversion : YupConversion); + + return float3(vec4.x, vec4.y, vec4.z); +} + +export float3 transform_vector_from_tangent_to_world(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from tangent space to world space"), + anno::noinline() +]] +{ + /* flip_tangent_v */ + return convert_to_left_hand( + tangent_u * vector.x - tangent_v * vector.y + state::normal() * vector.z, + up_z, false); +} + +export float3 transform_vector_from_world_to_tangent(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from world space to tangent space"), + anno::noinline() +]] +{ + float3 vecRH = convert_to_left_hand(vector, up_z, false); + /* flip_tangent_v */ + return vecRH.x * float3(tangent_u.x, -tangent_v.x, state::normal().x) + + vecRH.y * float3(tangent_u.y, -tangent_v.y, state::normal().y) + + vecRH.z * float3(tangent_u.z, -tangent_v.z, state::normal().z); +} + +export float4 unpack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Unpack a normal stored in a normal map"), + anno::noinline() +]] +{ + float2 normal_xy = float2(texture_sample.x, texture_sample.y); + + normal_xy = normal_xy * float2(2.0,2.0) - float2(1.0,1.0); + float normal_z = math::sqrt( math::saturate( 1.0 - math::dot( normal_xy, normal_xy ) ) ); + return float4( normal_xy.x, normal_xy.y, normal_z, 1.0 ); +} + +// for get color value from normal. +export float4 pack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Pack to color from a normal") +]] +{ + float2 return_xy = float2(texture_sample.x, texture_sample.y); + + return_xy = (return_xy + float2(1.0,1.0)) / float2(2.0,2.0); + + return float4( return_xy.x, return_xy.y, 0.0, 1.0 ); +} + +export float4 greyscale_texture_lookup( + float4 texture_sample = float4(0.0, 0.0, 0.0, 1.0) + ) +[[ + anno::description("Sampling a greyscale texture"), + anno::noinline() +]] +{ + return float4(texture_sample.x, texture_sample.x, texture_sample.x, texture_sample.x); +} + +export float3 pixel_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Pixel normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 vertex_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Vertex normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 landscape_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Landscape normal in world space") +]] +{ + float3 normalFromNormalmap = math::floor((::vertex_normal_world_space(up_z) * 0.5 + 0.5) * 255.0) / 255.0 * 2.0 - 1.0; + + float2 normalXY = float2(normalFromNormalmap.x, normalFromNormalmap.y); + return float3(normalXY.x, normalXY.y, math::sqrt(math::saturate(1.0 - math::dot(normalXY, normalXY)))); +} + +// Different implementation specific between mdl and hlsl for smoothstep +export float smoothstep(float a, float b, float l) +{ + if (a < b) + { + return math::smoothstep(a, b, l); + } + else if (a > b) + { + return 1.0 - math::smoothstep(b, a, l); + } + else + { + return l <= a ? 0.0 : 1.0; + } +} + +export float2 smoothstep(float2 a, float2 b, float2 l) +{ + return float2(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y)); +} + +export float3 smoothstep(float3 a, float3 b, float3 l) +{ + return float3(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z)); +} + +export float4 smoothstep(float4 a, float4 b, float4 l) +{ + return float4(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z), smoothstep(a.w, b.w, l.w)); +} + +export float2 smoothstep(float2 a, float2 b, float l) +{ + return float2(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l)); +} + +export float3 smoothstep(float3 a, float3 b, float l) +{ + return float3(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l)); +} + +export float4 smoothstep(float4 a, float4 b, float l) +{ + return float4(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l), smoothstep(a.w, b.w, l)); +} + +export float2 smoothstep(float a, float b, float2 l) +{ + return float2(smoothstep(a, b, l.x), smoothstep(a, b, l.y)); +} + +export float3 smoothstep(float a, float b, float3 l) +{ + return float3(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z)); +} + +export float4 smoothstep(float a, float b, float4 l) +{ + return float4(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z), smoothstep(a, b, l.w)); +} + +//------------------ Random from UE4 ----------------------- +float length2(float3 v) +{ + return math::dot(v, v); +} + +float3 GetPerlinNoiseGradientTextureAt(uniform texture_2d PerlinNoiseGradientTexture, float3 v) +{ + const float2 ZShear = float2(17.0f, 89.0f); + + float2 OffsetA = v.z * ZShear; + float2 TexA = (float2(v.x, v.y) + OffsetA + 0.5f) / 128.0f; + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA.x,1.0-TexA.y),tex::wrap_repeat,tex::wrap_repeat); + return float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z) * 2.0 - 1.0; +} + +float3 SkewSimplex(float3 In) +{ + return In + math::dot(In, float3(1.0 / 3.0f) ); +} +float3 UnSkewSimplex(float3 In) +{ + return In - math::dot(In, float3(1.0 / 6.0f) ); +} + +// 3D random number generator inspired by PCGs (permuted congruential generator) +// Using a **simple** Feistel cipher in place of the usual xor shift permutation step +// @param v = 3D integer coordinate +// @return three elements w/ 16 random bits each (0-0xffff). +// ~8 ALU operations for result.x (7 mad, 1 >>) +// ~10 ALU operations for result.xy (8 mad, 2 >>) +// ~12 ALU operations for result.xyz (9 mad, 3 >>) + +//TODO: uint3 +int3 Rand3DPCG16(int3 p) +{ + // taking a signed int then reinterpreting as unsigned gives good behavior for negatives + //TODO: uint3 + int3 v = int3(p); + + // Linear congruential step. These LCG constants are from Numerical Recipies + // For additional #'s, PCG would do multiple LCG steps and scramble each on output + // So v here is the RNG state + v = v * 1664525 + 1013904223; + + // PCG uses xorshift for the final shuffle, but it is expensive (and cheap + // versions of xorshift have visible artifacts). Instead, use simple MAD Feistel steps + // + // Feistel ciphers divide the state into separate parts (usually by bits) + // then apply a series of permutation steps one part at a time. The permutations + // use a reversible operation (usually ^) to part being updated with the result of + // a permutation function on the other parts and the key. + // + // In this case, I'm using v.x, v.y and v.z as the parts, using + instead of ^ for + // the combination function, and just multiplying the other two parts (no key) for + // the permutation function. + // + // That gives a simple mad per round. + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + + // only top 16 bits are well shuffled + return v >> 16; +} + +// Wraps noise for tiling texture creation +// @param v = unwrapped texture parameter +// @param bTiling = true to tile, false to not tile +// @param RepeatSize = number of units before repeating +// @return either original or wrapped coord +float3 NoiseTileWrap(float3 v, bool bTiling, float RepeatSize) +{ + return bTiling ? (math::frac(v / RepeatSize) * RepeatSize) : v; +} + +// Evaluate polynomial to get smooth transitions for Perlin noise +// only needed by Perlin functions in this file +// scalar(per component): 2 add, 5 mul +float4 PerlinRamp(float4 t) +{ + return t * t * t * (t * (t * 6 - 15) + 10); +} + +// Blum-Blum-Shub-inspired pseudo random number generator +// http://www.umbc.edu/~olano/papers/mNoise.pdf +// real BBS uses ((s*s) mod M) with bignums and M as the product of two huge Blum primes +// instead, we use a single prime M just small enough not to overflow +// note that the above paper used 61, which fits in a half, but is unusably bad +// @param Integer valued floating point seed +// @return random number in range [0,1) +// ~8 ALU operations (5 *, 3 frac) +float RandBBSfloat(float seed) +{ + float BBS_PRIME24 = 4093.0; + float s = math::frac(seed / BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + return s; +} + +// Modified noise gradient term +// @param seed - random seed for integer lattice position +// @param offset - [-1,1] offset of evaluation point from lattice point +// @return gradient direction (xyz) and contribution (w) from this lattice point +float4 MGradient(int seed, float3 offset) +{ + //TODO uint + int rand = Rand3DPCG16(int3(seed,0,0)).x; + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1.0 / 0x4000, 1.0 / 0x2000, 1.0 / 0x1000); + float3 direction = float3(int3(rand, rand, rand) & MGradientMask) * MGradientScale - 1; + return float4(direction.x, direction.y, direction.z, math::dot(direction, offset)); +} + +// compute Perlin and related noise corner seed values +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = true to return seed values for a repeating noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @param seed000-seed111 = hash function seeds for the eight corners +// @return fractional part of v +struct SeedValue +{ + float3 fv = float3(0); + float seed000 = 0; + float seed001 = 0; + float seed010 = 0; + float seed011 = 0; + float seed100 = 0; + float seed101 = 0; + float seed110 = 0; + float seed111 = 0; +}; + +SeedValue NoiseSeeds(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds; + seeds.fv = math::frac(v); + float3 iv = math::floor(v); + + const float3 primes = float3(19, 47, 101); + + if (bTiling) + { // can't algebraically combine with primes + seeds.seed000 = math::dot(primes, NoiseTileWrap(iv, true, RepeatSize)); + seeds.seed100 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 0), true, RepeatSize)); + seeds.seed010 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 0), true, RepeatSize)); + seeds.seed110 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 0), true, RepeatSize)); + seeds.seed001 = math::dot(primes, NoiseTileWrap(iv + float3(0, 0, 1), true, RepeatSize)); + seeds.seed101 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 1), true, RepeatSize)); + seeds.seed011 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 1), true, RepeatSize)); + seeds.seed111 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 1), true, RepeatSize)); + } + else + { // get to combine offsets with multiplication by primes in this case + seeds.seed000 = math::dot(iv, primes); + seeds.seed100 = seeds.seed000 + primes.x; + seeds.seed010 = seeds.seed000 + primes.y; + seeds.seed110 = seeds.seed100 + primes.y; + seeds.seed001 = seeds.seed000 + primes.z; + seeds.seed101 = seeds.seed100 + primes.z; + seeds.seed011 = seeds.seed010 + primes.z; + seeds.seed111 = seeds.seed110 + primes.z; + } + + return seeds; +} + +struct SimplexWeights +{ + float4 Result = float4(0); + float3 PosA = float3(0); + float3 PosB = float3(0); + float3 PosC = float3(0); + float3 PosD = float3(0); +}; + +// Computed weights and sample positions for simplex interpolation +// @return float4(a,b,c, d) Barycentric coordinate defined as Filtered = Tex(PosA) * a + Tex(PosB) * b + Tex(PosC) * c + Tex(PosD) * d +SimplexWeights ComputeSimplexWeights3D(float3 OrthogonalPos) +{ + SimplexWeights weights; + float3 OrthogonalPosFloor = math::floor(OrthogonalPos); + + weights.PosA = OrthogonalPosFloor; + weights.PosB = weights.PosA + float3(1, 1, 1); + + OrthogonalPos -= OrthogonalPosFloor; + + float Largest = math::max(OrthogonalPos.x, math::max(OrthogonalPos.y, OrthogonalPos.z)); + float Smallest = math::min(OrthogonalPos.x, math::min(OrthogonalPos.y, OrthogonalPos.z)); + + weights.PosC = weights.PosA + float3(Largest == OrthogonalPos.x, Largest == OrthogonalPos.y, Largest == OrthogonalPos.z); + weights.PosD = weights.PosA + float3(Smallest != OrthogonalPos.x, Smallest != OrthogonalPos.y, Smallest != OrthogonalPos.z); + + float RG = OrthogonalPos.x - OrthogonalPos.y; + float RB = OrthogonalPos.x - OrthogonalPos.z; + float GB = OrthogonalPos.y - OrthogonalPos.z; + + weights.Result.z = + math::min(math::max(0, RG), math::max(0, RB)) // X + + math::min(math::max(0, -RG), math::max(0, GB)) // Y + + math::min(math::max(0, -RB), math::max(0, -GB)); // Z + + weights.Result.w = + math::min(math::max(0, -RG), math::max(0, -RB)) // X + + math::min(math::max(0, RG), math::max(0, -GB)) // Y + + math::min(math::max(0, RB), math::max(0, GB)); // Z + + weights.Result.y = Smallest; + weights.Result.x = 1.0f - weights.Result.y - weights.Result.z - weights.Result.w; + + return weights; +} + +// filtered 3D gradient simple noise (few texture lookups, high quality) +// @param v >0 +// @return random number in the range -1 .. 1 +float SimplexNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 EvalPos) +{ + float3 OrthogonalPos = SkewSimplex(EvalPos); + + SimplexWeights Weights = ComputeSimplexWeights3D(OrthogonalPos); + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 32 bit) + float3 A = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosA); + float3 B = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosB); + float3 C = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosC); + float3 D = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosD); + + Weights.PosA = UnSkewSimplex(Weights.PosA); + Weights.PosB = UnSkewSimplex(Weights.PosB); + Weights.PosC = UnSkewSimplex(Weights.PosC); + Weights.PosD = UnSkewSimplex(Weights.PosD); + + float DistanceWeight; + + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosA)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float a = math::dot(A, EvalPos - Weights.PosA) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosB)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float b = math::dot(B, EvalPos - Weights.PosB) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosC)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float c = math::dot(C, EvalPos - Weights.PosC) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosD)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float d = math::dot(D, EvalPos - Weights.PosD) * DistanceWeight; + + return 32 * (a + b + c + d); +} + +// filtered 3D noise, can be optimized +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 v, bool bTiling, float RepeatSize) +{ + bTiling = true; + float3 fv = math::frac(v); + float3 iv0 = NoiseTileWrap(math::floor(v), bTiling, RepeatSize); + float3 iv1 = NoiseTileWrap(iv0 + 1, bTiling, RepeatSize); + + const int2 ZShear = int2(17, 89); + + float2 OffsetA = iv0.z * ZShear; + float2 OffsetB = OffsetA + ZShear; // non-tiling, use relative offset + if (bTiling) // tiling, have to compute from wrapped coordinates + { + OffsetB = iv1.z * ZShear; + } + + // Texture size scale factor + float ts = 1 / 128.0f; + + // texture coordinates for iv0.xy, as offset for both z slices + float2 TexA0 = (float2(iv0.x, iv0.y) + OffsetA + 0.5f) * ts; + float2 TexB0 = (float2(iv0.x, iv0.y) + OffsetB + 0.5f) * ts; + + // texture coordinates for iv1.xy, as offset for both z slices + float2 TexA1 = TexA0 + ts; // for non-tiling, can compute relative to existing coordinates + float2 TexB1 = TexB0 + ts; + if (bTiling) // for tiling, need to compute from wrapped coordinates + { + TexA1 = (float2(iv1.x, iv1.y) + OffsetA + 0.5f) * ts; + TexB1 = (float2(iv1.x, iv1.y) + OffsetB + 0.5f) * ts; + } + + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 8, 16 or 32 bit) + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + float3 PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 A = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 B = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 C = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 D = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 E = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 F = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 G = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 H = PerlinNoiseColor * 2 - 1; + + float a = math::dot(A, fv - float3(0, 0, 0)); + float b = math::dot(B, fv - float3(1, 0, 0)); + float c = math::dot(C, fv - float3(0, 1, 0)); + float d = math::dot(D, fv - float3(1, 1, 0)); + float e = math::dot(E, fv - float3(0, 0, 1)); + float f = math::dot(F, fv - float3(1, 0, 1)); + float g = math::dot(G, fv - float3(0, 1, 1)); + float h = math::dot(H, fv - float3(1, 1, 1)); + + float4 Weights = PerlinRamp(math::frac(float4(fv.x, fv.y, fv.z, 0))); + + float i = math::lerp(math::lerp(a, b, Weights.x), math::lerp(c, d, Weights.x), Weights.y); + float j = math::lerp(math::lerp(e, f, Weights.x), math::lerp(g, h, Weights.x), Weights.y); + + return math::lerp(i, j, Weights.z); +} + +// @return random number in the range -1 .. 1 +// scalar: 6 frac, 31 mul/mad, 15 add, +float FastGradientPerlinNoise3D_TEX(uniform texture_3d PerlinNoise3DTexture, float3 xyz) +{ + // needs to be the same value when creating the PerlinNoise3D texture + float Extent = 16; + + // last texel replicated and needed for filtering + // scalar: 3 frac, 6 mul + xyz = math::frac(xyz / (Extent - 1)) * (Extent - 1); + + // scalar: 3 frac + float3 uvw = math::frac(xyz); + // = floor(xyz); + // scalar: 3 add + float3 p0 = xyz - uvw; +// float3 f = math::pow(uvw, 2) * 3.0f - math::pow(uvw, 3) * 2.0f; // original perlin hermite (ok when used without bump mapping) + // scalar: 2*3 add 5*3 mul + float4 pr = PerlinRamp(float4(uvw.x, uvw.y, uvw.z, 0)); + float3 f = float3(pr.x, pr.y, pr.z); // new, better with continues second derivative for bump mapping + // scalar: 3 add + float3 p = p0 + f; + // scalar: 3 mad + // TODO: need reverse??? + float4 NoiseSample = tex::lookup_float4(PerlinNoise3DTexture, p / Extent + 0.5f / Extent); // +0.5f to get rid of bilinear offset + + // reconstruct from 8bit (using mad with 2 constants and dot4 was same instruction count) + // scalar: 4 mad, 3 mul, 3 add + float3 n = float3(NoiseSample.x, NoiseSample.y, NoiseSample.z) * 255.0f / 127.0f - 1.0f; + float d = NoiseSample.w * 255.f - 127; + return math::dot(xyz, n) - d; +} + +// Perlin-style "Modified Noise" +// http://www.umbc.edu/~olano/papers/index.html#mNoise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = MGradient(int(seeds.seed000), seeds.fv - float3(0, 0, 0)).w; + float rand100 = MGradient(int(seeds.seed100), seeds.fv - float3(1, 0, 0)).w; + float rand010 = MGradient(int(seeds.seed010), seeds.fv - float3(0, 1, 0)).w; + float rand110 = MGradient(int(seeds.seed110), seeds.fv - float3(1, 1, 0)).w; + float rand001 = MGradient(int(seeds.seed001), seeds.fv - float3(0, 0, 1)).w; + float rand101 = MGradient(int(seeds.seed101), seeds.fv - float3(1, 0, 1)).w; + float rand011 = MGradient(int(seeds.seed011), seeds.fv - float3(0, 1, 1)).w; + float rand111 = MGradient(int(seeds.seed111), seeds.fv - float3(1, 1, 1)).w; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D value noise - used to be incorrectly called Perlin noise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float ValueNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = RandBBSfloat(seeds.seed000) * 2 - 1; + float rand100 = RandBBSfloat(seeds.seed100) * 2 - 1; + float rand010 = RandBBSfloat(seeds.seed010) * 2 - 1; + float rand110 = RandBBSfloat(seeds.seed110) * 2 - 1; + float rand001 = RandBBSfloat(seeds.seed001) * 2 - 1; + float rand101 = RandBBSfloat(seeds.seed101) * 2 - 1; + float rand011 = RandBBSfloat(seeds.seed011) * 2 - 1; + float rand111 = RandBBSfloat(seeds.seed111) * 2 - 1; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D jitter offset within a voronoi noise cell +// @param pos - integer lattice corner +// @return random offsets vector +float3 VoronoiCornerSample(float3 pos, int Quality) +{ + // random values in [-0.5, 0.5] + float3 noise = float3(Rand3DPCG16(int3(pos))) / 0xffff - 0.5; + + // quality level 1 or 2: searches a 2x2x2 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 2x2x2 search + if (Quality <= 2) + { + return math::normalize(noise) * 0.2588; + } + + // quality level 3: searches a 3x3x3 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 3x3x3 search + if (Quality == 3) + { + return math::normalize(noise) * 0.3090; + } + + // quality level 4: jitter to anywhere in the cell, needs 4x4x4 search + return noise; +} + +// compare previous best with a new candidate +// not producing point locations makes it easier for compiler to eliminate calculations when they're not needed +// @param minval = location and distance of best candidate seed point before the new one +// @param candidate = candidate seed point +// @param offset = 3D offset to new candidate seed point +// @param bDistanceOnly = if true, only set maxval.w with distance, otherwise maxval.w is distance and maxval.xyz is position +// @return position (if bDistanceOnly is false) and distance to closest seed point so far +float4 VoronoiCompare(float4 minval, float3 candidate, float3 offset, bool bDistanceOnly) +{ + if (bDistanceOnly) + { + return float4(0, 0, 0, math::min(minval.w, math::dot(offset, offset))); + } + else + { + float newdist = math::dot(offset, offset); + return newdist > minval.w ? minval : float4(candidate.x, candidate.y, candidate.z, newdist); + } +} + +// 220 instruction Worley noise +float4 VoronoiNoise3D_ALU(float3 v, int Quality, bool bTiling, float RepeatSize, bool bDistanceOnly) +{ + float3 fv = math::frac(v), fv2 = math::frac(v + 0.5); + float3 iv = math::floor(v), iv2 = math::floor(v + 0.5); + + // with initial minimum distance = infinity (or at least bigger than 4), first min is optimized away + float4 mindist = float4(0,0,0,100); + float3 p, offset; + + // quality level 3: do a 3x3x3 search + if (Quality == 3) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 1; ++offset_x) + { + for (offset_y = -1; offset_y <= 1; ++offset_y) + { + for (offset_z = -1; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + + // everybody else searches a base 2x2x2 neighborhood + else + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = 0; offset_x <= 1; ++offset_x) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // quality level 2, do extra set of points, offset by half a cell + if (Quality == 2) + { + // 467 is just an offset to a different area in the random number field to avoid similar neighbor artifacts + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize) + 467, Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + } + + // quality level 4: add extra sets of four cells in each direction + if (Quality >= 4) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 2; offset_x += 3) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + // along x axis + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along y axis + p = float3(offset.y, offset.z, offset.x) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.y, offset.z, offset.x), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along z axis + p = float3(offset.z, offset.x, offset.y) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.z, offset.x, offset.y), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + } + } + } + } + + // transform squared distance to real distance + return float4(mindist.x, mindist.y, mindist.z, math::sqrt(mindist.w)); +} + +// Coordinates for corners of a Simplex tetrahedron +// Based on McEwan et al., Efficient computation of noise in GLSL, JGT 2011 +// @param v = 3D noise argument +// @return 4 corner locations +float4x3 SimplexCorners(float3 v) +{ + // find base corner by skewing to tetrahedral space and back + float3 tet = math::floor(v + v.x/3 + v.y/3 + v.z/3); + float3 base = tet - tet.x/6 - tet.y/6 - tet.z/6; + float3 f = v - base; + + // Find offsets to other corners (McEwan did this in tetrahedral space, + // but since skew is along x=y=z axis, this works in Euclidean space too.) + float3 g = math::step(float3(f.y,f.z,f.x), float3(f.x,f.y,f.z)), h = 1 - float3(g.z, g.x, g.y); + float3 a1 = math::min(g, h) - 1.0 / 6.0, a2 = math::max(g, h) - 1.0 / 3.0; + + // four corners + return float4x3(base, base + a1, base + a2, base + 0.5); +} + +// Improved smoothing function for simplex noise +// @param f = fractional distance to four tetrahedral corners +// @return weight for each corner +float4 SimplexSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + return (1 * scale + s*(-3 * scale + s*(3 * scale - s*scale))); +} + +// Derivative of simplex noise smoothing function +// @param f = fractional distanc eto four tetrahedral corners +// @return derivative of smoothing function for each corner by x, y and z +float3x4 SimplexDSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + s = -12 * scale + s*(24 * scale - s * 12 * scale); + + return float3x4( + s * float4(f[0][0], f[1][0], f[2][0], f[3][0]), + s * float4(f[0][1], f[1][1], f[2][1], f[3][1]), + s * float4(f[0][2], f[1][2], f[2][2], f[3][2])); +} + +// Simplex noise and its Jacobian derivative +// @param v = 3D noise argument +// @param bTiling = whether to repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension, must be a multiple of 3 +// @return float3x3 Jacobian in J[*].xyz, vector noise in J[*].w +// J[0].w, J[1].w, J[2].w is a Perlin-style simplex noise with vector output, e.g. (Nx, Ny, Nz) +// J[i].x is X derivative of the i'th component of the noise so J[2].x is dNz/dx +// You can use this to compute the noise, gradient, curl, or divergence: +// float3x4 J = JacobianSimplex_ALU(...); +// float3 VNoise = float3(J[0].w, J[1].w, J[2].w); // 3D noise +// float3 Grad = J[0].xyz; // gradient of J[0].w +// float3 Curl = float3(J[1][2]-J[2][1], J[2][0]-J[0][2], J[0][1]-J[1][2]); +// float Div = J[0][0]+J[1][1]+J[2][2]; +// All of these are confirmed to compile out all unneeded terms. +// So Grad of X doesn't compute Y or Z components, and VNoise doesn't do any of the derivative computation. +float3x4 JacobianSimplex_ALU(float3 v, bool bTiling, float RepeatSize) +{ + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1. / 0x4000, 1. / 0x2000, 1. / 0x1000); + + // corners of tetrahedron + float4x3 T = SimplexCorners(v); + // TODO: uint3 + int3 rand = int3(0); + float4x3 gvec0 = float4x3(1.0); + float4x3 gvec1 = float4x3(1.0); + float4x3 gvec2 = float4x3(1.0); + float4x3 fv = float4x3(1.0); + float3x4 grad = float3x4(1.0); + + // processing of tetrahedral vertices, unrolled + // to compute gradient at each corner + fv[0] = v - T[0]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[0] + 0.5, bTiling, RepeatSize)))); + gvec0[0] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[0] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[0] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][0] = math::dot(gvec0[0], fv[0]); + grad[1][0] = math::dot(gvec1[0], fv[0]); + grad[2][0] = math::dot(gvec2[0], fv[0]); + + fv[1] = v - T[1]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[1] + 0.5, bTiling, RepeatSize)))); + gvec0[1] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][1] = math::dot(gvec0[1], fv[1]); + grad[1][1] = math::dot(gvec1[1], fv[1]); + grad[2][1] = math::dot(gvec2[1], fv[1]); + + fv[2] = v - T[2]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[2] + 0.5, bTiling, RepeatSize)))); + gvec0[2] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[2] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[2] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][2] = math::dot(gvec0[2], fv[2]); + grad[1][2] = math::dot(gvec1[2], fv[2]); + grad[2][2] = math::dot(gvec2[2], fv[2]); + + fv[3] = v - T[3]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[3] + 0.5, bTiling, RepeatSize)))); + gvec0[3] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[3] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[3] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][3] = math::dot(gvec0[3], fv[3]); + grad[1][3] = math::dot(gvec1[3], fv[3]); + grad[2][3] = math::dot(gvec2[3], fv[3]); + + // blend gradients + float4 sv = SimplexSmooth(fv); + float3x4 ds = SimplexDSmooth(fv); + + float3x4 jacobian = float3x4(1.0); + float3 vec0 = gvec0*sv + grad[0]*ds; // NOTE: mdl is column major, convert from UE4 (row major) + jacobian[0] = float4(vec0.x, vec0.y, vec0.z, math::dot(sv, grad[0])); + float3 vec1 = gvec1*sv + grad[1]*ds; + jacobian[1] = float4(vec1.x, vec1.y, vec1.z, math::dot(sv, grad[1])); + float3 vec2 = gvec2*sv + grad[2]*ds; + jacobian[2] = float4(vec2.x, vec2.y, vec2.z, math::dot(sv, grad[2])); + + return jacobian; +} + +// While RepeatSize is a float here, the expectation is that it would be largely integer values coming in from the UI. The downstream logic assumes +// floats for all called functions (NoiseTileWrap) and this prevents any float-to-int conversion errors from automatic type conversion. +float Noise3D_Multiplexer(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, int Function, float3 Position, int Quality, bool bTiling, float RepeatSize) +{ + // verified, HLSL compiled out the switch if Function is a constant + switch(Function) + { + case 0: + return SimplexNoise3D_TEX(PerlinNoiseGradientTexture, Position); + case 1: + return GradientNoise3D_TEX(PerlinNoiseGradientTexture, Position, bTiling, RepeatSize); + case 2: + return FastGradientPerlinNoise3D_TEX(PerlinNoise3DTexture, Position); + case 3: + return GradientNoise3D_ALU(Position, bTiling, RepeatSize); + case 4: + return ValueNoise3D_ALU(Position, bTiling, RepeatSize); + case 5: + return VoronoiNoise3D_ALU(Position, Quality, bTiling, RepeatSize, true).w * 2.0 - 1.0; + } + return 0; +} +//---------------------------------------------------------- + +export float noise(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, float3 Position, float Scale, float Quality, float Function, float Turbulence, float Levels, float OutputMin, float OutputMax, float LevelScale, float FilterWidth, float Tiling, float RepeatSize) +[[ + anno::description("Noise"), + anno::noinline() +]] +{ + Position *= Scale; + FilterWidth *= Scale; + + float Out = 0.0f; + float OutScale = 1.0f; + float InvLevelScale = 1.0f / LevelScale; + + int iFunction(Function); + int iQuality(Quality); + int iLevels(Levels); + bool bTurbulence(Turbulence); + bool bTiling(Tiling); + + for(int i = 0; i < iLevels; ++i) + { + // fade out noise level that are too high frequent (not done through dynamic branching as it usually requires gradient instructions) + OutScale *= math::saturate(1.0 - FilterWidth); + + if(bTurbulence) + { + Out += math::abs(Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize)) * OutScale; + } + else + { + Out += Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize) * OutScale; + } + + Position *= LevelScale; + RepeatSize *= LevelScale; + OutScale *= InvLevelScale; + FilterWidth *= LevelScale; + } + + if(!bTurbulence) + { + // bring -1..1 to 0..1 range + Out = Out * 0.5f + 0.5f; + } + + // Out is in 0..1 range + return math::lerp(OutputMin, OutputMax, Out); +} + +// Material node for noise functions returning a vector value +// @param LevelScale usually 2 but higher values allow efficient use of few levels +// @return in user defined range (OutputMin..OutputMax) +export float4 vector4_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise"), + anno::noinline() +]] +{ + float4 result = float4(0,0,0,1); + float3 ret = float3(0); + int iQuality = int(Quality); + int iFunction = int(Function); + bool bTiling = Tiling > 0.0; + + float3x4 Jacobian = JacobianSimplex_ALU(Position, bTiling, TileSize); // compiled out if not used + + // verified, HLSL compiled out the switch if Function is a constant + switch (iFunction) + { + case 0: // Cellnoise + ret = float3(Rand3DPCG16(int3(math::floor(NoiseTileWrap(Position, bTiling, TileSize))))) / 0xffff; + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 1: // Color noise + ret = float3(Jacobian[0].w, Jacobian[1].w, Jacobian[2].w); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 2: // Gradient + result = Jacobian[0]; + break; + case 3: // Curl + ret = float3(Jacobian[2][1] - Jacobian[1][2], Jacobian[0][2] - Jacobian[2][0], Jacobian[1][0] - Jacobian[0][1]); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 4: // Voronoi + result = VoronoiNoise3D_ALU(Position, iQuality, bTiling, TileSize, false); + break; + } + return result; +} + +export float3 vector3_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise float3 version"), + anno::noinline() +]] +{ + float4 noise = vector4_noise(Position, Quality, Function, Tiling, TileSize); + return float3(noise.x, noise.y, noise.z); +} + + +// workaround for ue4 fresnel (without supporting for camera vector) : replacing it with 0.0, means facing to the view +export float fresnel(float exponent [[anno::unused()]], float base_reflect_fraction [[anno::unused()]], float3 normal [[anno::unused()]]) +[[ + anno::description("Fresnel"), + anno::noinline() +]] +{ + return 0.0; +} + +export float fresnel_function(float3 normal_vector [[anno::unused()]], float3 camera_vector [[anno::unused()]], + bool invert_fresnel [[anno::unused()]], float power [[anno::unused()]], + bool use_cheap_contrast [[anno::unused()]], float cheap_contrast_dark [[anno::unused()]], float cheap_contrast_bright [[anno::unused()]], + bool clamp_fresnel_dot_product [[anno::unused()]]) +[[ + anno::description("Fresnel Function"), + anno::noinline() +]] +{ + return 0.0; +} + +export float3 camera_vector(uniform bool up_z = true) +[[ + anno::description("Camera Vector"), + anno::noinline() +]] +{ + // assume camera postion is 0,0,0 + return math::normalize(float3(0) - convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)); +} + +export float pixel_depth() +[[ + anno::description("Pixel Depth"), + anno::noinline() +]] +{ + return 256.0f; +} + +export float scene_depth() +[[ + anno::description("Scene Depth") +]] +{ + return 65500.0f; +} + +export float3 scene_color() +[[ + anno::description("Scene Color") +]] +{ + return float3(1.0f); +} + +export float4 vertex_color() +[[ + anno::description("Vertex Color"), + anno::noinline() +]] +{ + return float4(1.0f); +} + +export float4 vertex_color_from_coordinate(int VertexColorCoordinateIndex) +[[ + anno::description("Vertex Color for float2 PrimVar"), + anno::noinline() +]] +{ + // Kit only supports 4 uv sets, 2 uvs are available to vertex color. if vertex color index is invalid, output the constant WHITE color intead + return (VertexColorCoordinateIndex > 2) ? float4(1.0f) : float4(state::texture_coordinate(VertexColorCoordinateIndex).x, state::texture_coordinate(VertexColorCoordinateIndex).y, state::texture_coordinate(VertexColorCoordinateIndex+1).x, state::texture_coordinate(VertexColorCoordinateIndex+1).y); +} + +export float3 camera_position() +[[ + anno::description("Camera Position"), + anno::noinline() +]] +{ + return float3(1000.0f, 0, 0); +} + +export float3 rotate_about_axis(float4 NormalizedRotationAxisAndAngle, float3 PositionOnAxis, float3 Position) +[[ + anno::description("Rotates Position about the given axis by the given angle") +]] +{ + // Project Position onto the rotation axis and find the closest point on the axis to Position + float3 NormalizedRotationAxis = float3(NormalizedRotationAxisAndAngle.x,NormalizedRotationAxisAndAngle.y,NormalizedRotationAxisAndAngle.z); + float3 ClosestPointOnAxis = PositionOnAxis + NormalizedRotationAxis * math::dot(NormalizedRotationAxis, Position - PositionOnAxis); + // Construct orthogonal axes in the plane of the rotation + float3 UAxis = Position - ClosestPointOnAxis; + float3 VAxis = math::cross(NormalizedRotationAxis, UAxis); + float[2] SinCosAngle = math::sincos(NormalizedRotationAxisAndAngle.w); + // Rotate using the orthogonal axes + float3 R = UAxis * SinCosAngle[1] + VAxis * SinCosAngle[0]; + // Reconstruct the rotated world space position + float3 RotatedPosition = ClosestPointOnAxis + R; + // Convert from position to a position offset + return RotatedPosition - Position; +} + +export float2 rotate_scale_offset_texcoords(float2 InTexCoords, float4 InRotationScale, float2 InOffset) +[[ + anno::description("Returns a float2 texture coordinate after 2x2 transform and offset applied") +]] +{ + return float2(math::dot(InTexCoords, float2(InRotationScale.x, InRotationScale.y)), math::dot(InTexCoords, float2(InRotationScale.z, InRotationScale.w))) + InOffset; +} + +export float3 reflection_custom_world_normal(float3 WorldNormal, bool bNormalizeInputNormal, uniform bool up_z = true) +[[ + anno::description("Reflection vector about the specified world space normal") +]] +{ + if (bNormalizeInputNormal) + { + WorldNormal = math::normalize(WorldNormal); + } + + return -camera_vector(up_z) + WorldNormal * math::dot(WorldNormal, camera_vector(up_z)) * 2.0; +} + +export float3 reflection_vector(uniform bool up_z = true) +[[ + anno::description("Reflection Vector"), + anno::noinline() +]] +{ + float3 normal = convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); + return reflection_custom_world_normal(normal, false, up_z); +} + +export float dither_temporalAA(float AlphaThreshold = 0.5f, float Random = 1.0f [[anno::unused()]]) +[[ + anno::description("Dither TemporalAA"), + anno::noinline() +]] +{ + return AlphaThreshold; +} + +export float3 black_body( float Temp ) +[[ + anno::description("Black Body"), + anno::noinline() +]] +{ + float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp ); + float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp ); + + float x = 3*u / ( 2*u - 8*v + 4 ); + float y = 2*v / ( 2*u - 8*v + 4 ); + float z = 1 - x - y; + + float Y = 1; + float X = Y/y * x; + float Z = Y/y * z; + + float3x3 XYZtoRGB = float3x3( + float3(3.2404542, -1.5371385, -0.4985314), + float3(-0.9692660, 1.8760108, 0.0415560), + float3(0.0556434, -0.2040259, 1.0572252) + ); + + return XYZtoRGB * float3( X, Y, Z ) * math::pow( 0.0004 * Temp, 4 ); +} + +export float per_instance_random(uniform texture_2d PerlinNoiseGradientTexture, int NumberInstances) +[[ + anno::description("Per Instance Random"), + anno::noinline() +]] +{ + float weight = state::object_id() / float(NumberInstances); + return NumberInstances == 0 ? 0.0 : tex::lookup_float4(PerlinNoiseGradientTexture, float2(weight, 1.0 - weight), tex::wrap_repeat, tex::wrap_repeat).x; +} + +//------------------ Hair from UE4 ----------------------- +float3 hair_absorption_to_color(float3 A) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::exp(-math::sqrt(A) * D); +} + +float3 hair_color_to_absorption(float3 C) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::pow(math::log(C) / D, 2.0f); +} + +export float3 get_hair_color_from_melanin(float InMelanin, float InRedness, float3 InDyeColor) +[[ + anno::description("Hair Color") +]] +{ + InMelanin = math::saturate(InMelanin); + InRedness = math::saturate(InRedness); + float Melanin = -math::log(math::max(1 - InMelanin, 0.0001f)); + float Eumelanin = Melanin * (1 - InRedness); + float Pheomelanin = Melanin * InRedness; + + float3 DyeAbsorption = hair_color_to_absorption(math::saturate(InDyeColor)); + float3 Absorption = Eumelanin * float3(0.506f, 0.841f, 1.653f) + Pheomelanin * float3(0.343f, 0.733f, 1.924f); + + return hair_absorption_to_color(Absorption + DyeAbsorption); +} + +export float3 local_object_bounds_min() +[[ + anno::description("Local Object Bounds Min"), + anno::noinline() +]] +{ + return float3(0.0); +} + +export float3 local_object_bounds_max() +[[ + anno::description("Local Object Bounds Max"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float3 object_bounds() +[[ + anno::description("Object Bounds"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float object_radius() +[[ + anno::description("Object Radius"), + anno::noinline() +]] +{ + return 100.0f; +} + +export float3 object_world_position(uniform bool up_z = true) +[[ + anno::description("Object World Position"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)*state::meters_per_scene_unit()*100.0; +} + +export float3 object_orientation() +[[ + anno::description("Object Orientation"), + anno::noinline() +]] +{ + return float3(0); +} + +export float rcp(float x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float2 rcp(float2 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float3 rcp(float3 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float4 rcp(float4 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export int BitFieldExtractI32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractI32 int"), + anno::noinline() +]] +{ + Size &= 3; + Offset &= 3; + + if (Size == 0) + return 0; + else if (Offset + Size < 32) + return (Data << (32 - Size - Offset)) >> (32 - Size); + else + return Data >> Offset; +} + +export int BitFieldExtractI32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractI32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(int(Data), int(Size), int(Offset)); +} + +export int BitFieldExtractU32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractU32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export int BitFieldExtractU32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractU32 int"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export float3 EyeAdaptationInverseLookup(float3 LightValue, float Alpha) +[[ + anno::description("EyeAdaptationInverseLookup"), + anno::noinline() +]] +{ + float Adaptation = 1.0f; + + // When Alpha=0.0, we want to multiply by 1.0. when Alpha = 1.0, we want to multiply by 1/Adaptation. + // So the lerped value is: + // LerpLogScale = Lerp(log(1),log(1/Adaptaiton),T) + // Which is simplified as: + // LerpLogScale = Lerp(0,-log(Adaptation),T) + // LerpLogScale = -T * logAdaptation; + + float LerpLogScale = -Alpha * math::log(Adaptation); + float Scale = math::exp(LerpLogScale); + return LightValue * Scale; +} diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl new file mode 100644 index 0000000000000000000000000000000000000000..9aad34bcd7bd5f29f99549120f776102febec45d --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/Num608bbc47c6ff5a0001d607d8.mdl @@ -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 Num608bbc47c6ff5a0001d607d8( + uniform texture_2d Normal_Tex = texture_2d("../textures/normal_1.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_1.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_1.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_1.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_1.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_1.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); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/OmniUe4Base.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/OmniUe4Base.mdl new file mode 100644 index 0000000000000000000000000000000000000000..a441fbaf28040302c7aaabfbcf14b24a85bdf643 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/OmniUe4Base.mdl @@ -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 + ) +); diff --git a/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/OmniUe4Function.mdl b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/OmniUe4Function.mdl new file mode 100644 index 0000000000000000000000000000000000000000..f0801afff6f0870ea2574c9e9b6e2043e79e9a79 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/organize_colorful_cups/SubUSDs/materials/OmniUe4Function.mdl @@ -0,0 +1,1413 @@ +/*************************************************************************************************** + * 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.1 - using absolute import paths when importing standard modules + +mdl 1.6; + +import ::df::*; +import ::state::*; +import ::math::*; +import ::tex::*; +import ::anno::*; + + +export float3 convert_to_left_hand(float3 vec3, uniform bool up_z = true, uniform bool is_position = true) +[[ + anno::description("convert from RH to LH"), + anno::noinline() +]] +{ + float4x4 ZupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4x4 YupConversion = float4x4( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + float4 vec4 = float4(vec3.x, vec3.y, vec3.z, is_position ? 1.0f : 0.0f); + + vec4 = vec4 * (up_z ? ZupConversion : YupConversion); + + return float3(vec4.x, vec4.y, vec4.z); +} + +export float3 transform_vector_from_tangent_to_world(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from tangent space to world space"), + anno::noinline() +]] +{ + /* flip_tangent_v */ + return convert_to_left_hand( + tangent_u * vector.x - tangent_v * vector.y + state::normal() * vector.z, + up_z, false); +} + +export float3 transform_vector_from_world_to_tangent(float3 vector, + uniform bool up_z = true, + float3 tangent_u = state::texture_tangent_u(0), + float3 tangent_v = state::texture_tangent_v(0)) +[[ + anno::description("Transform vector from world space to tangent space"), + anno::noinline() +]] +{ + float3 vecRH = convert_to_left_hand(vector, up_z, false); + /* flip_tangent_v */ + return vecRH.x * float3(tangent_u.x, -tangent_v.x, state::normal().x) + + vecRH.y * float3(tangent_u.y, -tangent_v.y, state::normal().y) + + vecRH.z * float3(tangent_u.z, -tangent_v.z, state::normal().z); +} + +export float4 unpack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Unpack a normal stored in a normal map"), + anno::noinline() +]] +{ + float2 normal_xy = float2(texture_sample.x, texture_sample.y); + + normal_xy = normal_xy * float2(2.0,2.0) - float2(1.0,1.0); + float normal_z = math::sqrt( math::saturate( 1.0 - math::dot( normal_xy, normal_xy ) ) ); + return float4( normal_xy.x, normal_xy.y, normal_z, 1.0 ); +} + +// for get color value from normal. +export float4 pack_normal_map( + float4 texture_sample = float4(0.0, 0.0, 1.0, 1.0) + ) +[[ + anno::description("Pack to color from a normal") +]] +{ + float2 return_xy = float2(texture_sample.x, texture_sample.y); + + return_xy = (return_xy + float2(1.0,1.0)) / float2(2.0,2.0); + + return float4( return_xy.x, return_xy.y, 0.0, 1.0 ); +} + +export float4 greyscale_texture_lookup( + float4 texture_sample = float4(0.0, 0.0, 0.0, 1.0) + ) +[[ + anno::description("Sampling a greyscale texture"), + anno::noinline() +]] +{ + return float4(texture_sample.x, texture_sample.x, texture_sample.x, texture_sample.x); +} + +export float3 pixel_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Pixel normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 vertex_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Vertex normal in world space"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); +} + +export float3 landscape_normal_world_space(uniform bool up_z = true) +[[ + anno::description("Landscape normal in world space") +]] +{ + float3 normalFromNormalmap = math::floor((::vertex_normal_world_space(up_z) * 0.5 + 0.5) * 255.0) / 255.0 * 2.0 - 1.0; + + float2 normalXY = float2(normalFromNormalmap.x, normalFromNormalmap.y); + return float3(normalXY.x, normalXY.y, math::sqrt(math::saturate(1.0 - math::dot(normalXY, normalXY)))); +} + +// Different implementation specific between mdl and hlsl for smoothstep +export float smoothstep(float a, float b, float l) +{ + if (a < b) + { + return math::smoothstep(a, b, l); + } + else if (a > b) + { + return 1.0 - math::smoothstep(b, a, l); + } + else + { + return l <= a ? 0.0 : 1.0; + } +} + +export float2 smoothstep(float2 a, float2 b, float2 l) +{ + return float2(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y)); +} + +export float3 smoothstep(float3 a, float3 b, float3 l) +{ + return float3(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z)); +} + +export float4 smoothstep(float4 a, float4 b, float4 l) +{ + return float4(smoothstep(a.x, b.x, l.x), smoothstep(a.y, b.y, l.y), smoothstep(a.z, b.z, l.z), smoothstep(a.w, b.w, l.w)); +} + +export float2 smoothstep(float2 a, float2 b, float l) +{ + return float2(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l)); +} + +export float3 smoothstep(float3 a, float3 b, float l) +{ + return float3(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l)); +} + +export float4 smoothstep(float4 a, float4 b, float l) +{ + return float4(smoothstep(a.x, b.x, l), smoothstep(a.y, b.y, l), smoothstep(a.z, b.z, l), smoothstep(a.w, b.w, l)); +} + +export float2 smoothstep(float a, float b, float2 l) +{ + return float2(smoothstep(a, b, l.x), smoothstep(a, b, l.y)); +} + +export float3 smoothstep(float a, float b, float3 l) +{ + return float3(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z)); +} + +export float4 smoothstep(float a, float b, float4 l) +{ + return float4(smoothstep(a, b, l.x), smoothstep(a, b, l.y), smoothstep(a, b, l.z), smoothstep(a, b, l.w)); +} + +//------------------ Random from UE4 ----------------------- +float length2(float3 v) +{ + return math::dot(v, v); +} + +float3 GetPerlinNoiseGradientTextureAt(uniform texture_2d PerlinNoiseGradientTexture, float3 v) +{ + const float2 ZShear = float2(17.0f, 89.0f); + + float2 OffsetA = v.z * ZShear; + float2 TexA = (float2(v.x, v.y) + OffsetA + 0.5f) / 128.0f; + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA.x,1.0-TexA.y),tex::wrap_repeat,tex::wrap_repeat); + return float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z) * 2.0 - 1.0; +} + +float3 SkewSimplex(float3 In) +{ + return In + math::dot(In, float3(1.0 / 3.0f) ); +} +float3 UnSkewSimplex(float3 In) +{ + return In - math::dot(In, float3(1.0 / 6.0f) ); +} + +// 3D random number generator inspired by PCGs (permuted congruential generator) +// Using a **simple** Feistel cipher in place of the usual xor shift permutation step +// @param v = 3D integer coordinate +// @return three elements w/ 16 random bits each (0-0xffff). +// ~8 ALU operations for result.x (7 mad, 1 >>) +// ~10 ALU operations for result.xy (8 mad, 2 >>) +// ~12 ALU operations for result.xyz (9 mad, 3 >>) + +//TODO: uint3 +int3 Rand3DPCG16(int3 p) +{ + // taking a signed int then reinterpreting as unsigned gives good behavior for negatives + //TODO: uint3 + int3 v = int3(p); + + // Linear congruential step. These LCG constants are from Numerical Recipies + // For additional #'s, PCG would do multiple LCG steps and scramble each on output + // So v here is the RNG state + v = v * 1664525 + 1013904223; + + // PCG uses xorshift for the final shuffle, but it is expensive (and cheap + // versions of xorshift have visible artifacts). Instead, use simple MAD Feistel steps + // + // Feistel ciphers divide the state into separate parts (usually by bits) + // then apply a series of permutation steps one part at a time. The permutations + // use a reversible operation (usually ^) to part being updated with the result of + // a permutation function on the other parts and the key. + // + // In this case, I'm using v.x, v.y and v.z as the parts, using + instead of ^ for + // the combination function, and just multiplying the other two parts (no key) for + // the permutation function. + // + // That gives a simple mad per round. + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + v.x += v.y*v.z; + v.y += v.z*v.x; + v.z += v.x*v.y; + + // only top 16 bits are well shuffled + return v >> 16; +} + +// Wraps noise for tiling texture creation +// @param v = unwrapped texture parameter +// @param bTiling = true to tile, false to not tile +// @param RepeatSize = number of units before repeating +// @return either original or wrapped coord +float3 NoiseTileWrap(float3 v, bool bTiling, float RepeatSize) +{ + return bTiling ? (math::frac(v / RepeatSize) * RepeatSize) : v; +} + +// Evaluate polynomial to get smooth transitions for Perlin noise +// only needed by Perlin functions in this file +// scalar(per component): 2 add, 5 mul +float4 PerlinRamp(float4 t) +{ + return t * t * t * (t * (t * 6 - 15) + 10); +} + +// Blum-Blum-Shub-inspired pseudo random number generator +// http://www.umbc.edu/~olano/papers/mNoise.pdf +// real BBS uses ((s*s) mod M) with bignums and M as the product of two huge Blum primes +// instead, we use a single prime M just small enough not to overflow +// note that the above paper used 61, which fits in a half, but is unusably bad +// @param Integer valued floating point seed +// @return random number in range [0,1) +// ~8 ALU operations (5 *, 3 frac) +float RandBBSfloat(float seed) +{ + float BBS_PRIME24 = 4093.0; + float s = math::frac(seed / BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + s = math::frac(s * s * BBS_PRIME24); + return s; +} + +// Modified noise gradient term +// @param seed - random seed for integer lattice position +// @param offset - [-1,1] offset of evaluation point from lattice point +// @return gradient direction (xyz) and contribution (w) from this lattice point +float4 MGradient(int seed, float3 offset) +{ + //TODO uint + int rand = Rand3DPCG16(int3(seed,0,0)).x; + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1.0 / 0x4000, 1.0 / 0x2000, 1.0 / 0x1000); + float3 direction = float3(int3(rand, rand, rand) & MGradientMask) * MGradientScale - 1; + return float4(direction.x, direction.y, direction.z, math::dot(direction, offset)); +} + +// compute Perlin and related noise corner seed values +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = true to return seed values for a repeating noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @param seed000-seed111 = hash function seeds for the eight corners +// @return fractional part of v +struct SeedValue +{ + float3 fv = float3(0); + float seed000 = 0; + float seed001 = 0; + float seed010 = 0; + float seed011 = 0; + float seed100 = 0; + float seed101 = 0; + float seed110 = 0; + float seed111 = 0; +}; + +SeedValue NoiseSeeds(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds; + seeds.fv = math::frac(v); + float3 iv = math::floor(v); + + const float3 primes = float3(19, 47, 101); + + if (bTiling) + { // can't algebraically combine with primes + seeds.seed000 = math::dot(primes, NoiseTileWrap(iv, true, RepeatSize)); + seeds.seed100 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 0), true, RepeatSize)); + seeds.seed010 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 0), true, RepeatSize)); + seeds.seed110 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 0), true, RepeatSize)); + seeds.seed001 = math::dot(primes, NoiseTileWrap(iv + float3(0, 0, 1), true, RepeatSize)); + seeds.seed101 = math::dot(primes, NoiseTileWrap(iv + float3(1, 0, 1), true, RepeatSize)); + seeds.seed011 = math::dot(primes, NoiseTileWrap(iv + float3(0, 1, 1), true, RepeatSize)); + seeds.seed111 = math::dot(primes, NoiseTileWrap(iv + float3(1, 1, 1), true, RepeatSize)); + } + else + { // get to combine offsets with multiplication by primes in this case + seeds.seed000 = math::dot(iv, primes); + seeds.seed100 = seeds.seed000 + primes.x; + seeds.seed010 = seeds.seed000 + primes.y; + seeds.seed110 = seeds.seed100 + primes.y; + seeds.seed001 = seeds.seed000 + primes.z; + seeds.seed101 = seeds.seed100 + primes.z; + seeds.seed011 = seeds.seed010 + primes.z; + seeds.seed111 = seeds.seed110 + primes.z; + } + + return seeds; +} + +struct SimplexWeights +{ + float4 Result = float4(0); + float3 PosA = float3(0); + float3 PosB = float3(0); + float3 PosC = float3(0); + float3 PosD = float3(0); +}; + +// Computed weights and sample positions for simplex interpolation +// @return float4(a,b,c, d) Barycentric coordinate defined as Filtered = Tex(PosA) * a + Tex(PosB) * b + Tex(PosC) * c + Tex(PosD) * d +SimplexWeights ComputeSimplexWeights3D(float3 OrthogonalPos) +{ + SimplexWeights weights; + float3 OrthogonalPosFloor = math::floor(OrthogonalPos); + + weights.PosA = OrthogonalPosFloor; + weights.PosB = weights.PosA + float3(1, 1, 1); + + OrthogonalPos -= OrthogonalPosFloor; + + float Largest = math::max(OrthogonalPos.x, math::max(OrthogonalPos.y, OrthogonalPos.z)); + float Smallest = math::min(OrthogonalPos.x, math::min(OrthogonalPos.y, OrthogonalPos.z)); + + weights.PosC = weights.PosA + float3(Largest == OrthogonalPos.x, Largest == OrthogonalPos.y, Largest == OrthogonalPos.z); + weights.PosD = weights.PosA + float3(Smallest != OrthogonalPos.x, Smallest != OrthogonalPos.y, Smallest != OrthogonalPos.z); + + float RG = OrthogonalPos.x - OrthogonalPos.y; + float RB = OrthogonalPos.x - OrthogonalPos.z; + float GB = OrthogonalPos.y - OrthogonalPos.z; + + weights.Result.z = + math::min(math::max(0, RG), math::max(0, RB)) // X + + math::min(math::max(0, -RG), math::max(0, GB)) // Y + + math::min(math::max(0, -RB), math::max(0, -GB)); // Z + + weights.Result.w = + math::min(math::max(0, -RG), math::max(0, -RB)) // X + + math::min(math::max(0, RG), math::max(0, -GB)) // Y + + math::min(math::max(0, RB), math::max(0, GB)); // Z + + weights.Result.y = Smallest; + weights.Result.x = 1.0f - weights.Result.y - weights.Result.z - weights.Result.w; + + return weights; +} + +// filtered 3D gradient simple noise (few texture lookups, high quality) +// @param v >0 +// @return random number in the range -1 .. 1 +float SimplexNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 EvalPos) +{ + float3 OrthogonalPos = SkewSimplex(EvalPos); + + SimplexWeights Weights = ComputeSimplexWeights3D(OrthogonalPos); + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 32 bit) + float3 A = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosA); + float3 B = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosB); + float3 C = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosC); + float3 D = GetPerlinNoiseGradientTextureAt(PerlinNoiseGradientTexture, Weights.PosD); + + Weights.PosA = UnSkewSimplex(Weights.PosA); + Weights.PosB = UnSkewSimplex(Weights.PosB); + Weights.PosC = UnSkewSimplex(Weights.PosC); + Weights.PosD = UnSkewSimplex(Weights.PosD); + + float DistanceWeight; + + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosA)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float a = math::dot(A, EvalPos - Weights.PosA) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosB)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float b = math::dot(B, EvalPos - Weights.PosB) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosC)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float c = math::dot(C, EvalPos - Weights.PosC) * DistanceWeight; + DistanceWeight = math::saturate(0.6f - length2(EvalPos - Weights.PosD)); DistanceWeight *= DistanceWeight; DistanceWeight *= DistanceWeight; + float d = math::dot(D, EvalPos - Weights.PosD) * DistanceWeight; + + return 32 * (a + b + c + d); +} + +// filtered 3D noise, can be optimized +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_TEX(uniform texture_2d PerlinNoiseGradientTexture, float3 v, bool bTiling, float RepeatSize) +{ + bTiling = true; + float3 fv = math::frac(v); + float3 iv0 = NoiseTileWrap(math::floor(v), bTiling, RepeatSize); + float3 iv1 = NoiseTileWrap(iv0 + 1, bTiling, RepeatSize); + + const int2 ZShear = int2(17, 89); + + float2 OffsetA = iv0.z * ZShear; + float2 OffsetB = OffsetA + ZShear; // non-tiling, use relative offset + if (bTiling) // tiling, have to compute from wrapped coordinates + { + OffsetB = iv1.z * ZShear; + } + + // Texture size scale factor + float ts = 1 / 128.0f; + + // texture coordinates for iv0.xy, as offset for both z slices + float2 TexA0 = (float2(iv0.x, iv0.y) + OffsetA + 0.5f) * ts; + float2 TexB0 = (float2(iv0.x, iv0.y) + OffsetB + 0.5f) * ts; + + // texture coordinates for iv1.xy, as offset for both z slices + float2 TexA1 = TexA0 + ts; // for non-tiling, can compute relative to existing coordinates + float2 TexB1 = TexB0 + ts; + if (bTiling) // for tiling, need to compute from wrapped coordinates + { + TexA1 = (float2(iv1.x, iv1.y) + OffsetA + 0.5f) * ts; + TexB1 = (float2(iv1.x, iv1.y) + OffsetB + 0.5f) * ts; + } + + + // can be optimized to 1 or 2 texture lookups (4 or 8 channel encoded in 8, 16 or 32 bit) + float4 PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + float3 PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 A = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 B = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA0.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 C = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexA1.x,1.0-TexA1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 D = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 E = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB0.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 F = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB0.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 G = PerlinNoiseColor * 2 - 1; + PerlinNoise = tex::lookup_float4(PerlinNoiseGradientTexture,float2(TexB1.x,1.0-TexB1.y),tex::wrap_repeat,tex::wrap_repeat); + PerlinNoiseColor = float3(PerlinNoise.x, PerlinNoise.y, PerlinNoise.z); + float3 H = PerlinNoiseColor * 2 - 1; + + float a = math::dot(A, fv - float3(0, 0, 0)); + float b = math::dot(B, fv - float3(1, 0, 0)); + float c = math::dot(C, fv - float3(0, 1, 0)); + float d = math::dot(D, fv - float3(1, 1, 0)); + float e = math::dot(E, fv - float3(0, 0, 1)); + float f = math::dot(F, fv - float3(1, 0, 1)); + float g = math::dot(G, fv - float3(0, 1, 1)); + float h = math::dot(H, fv - float3(1, 1, 1)); + + float4 Weights = PerlinRamp(math::frac(float4(fv.x, fv.y, fv.z, 0))); + + float i = math::lerp(math::lerp(a, b, Weights.x), math::lerp(c, d, Weights.x), Weights.y); + float j = math::lerp(math::lerp(e, f, Weights.x), math::lerp(g, h, Weights.x), Weights.y); + + return math::lerp(i, j, Weights.z); +} + +// @return random number in the range -1 .. 1 +// scalar: 6 frac, 31 mul/mad, 15 add, +float FastGradientPerlinNoise3D_TEX(uniform texture_3d PerlinNoise3DTexture, float3 xyz) +{ + // needs to be the same value when creating the PerlinNoise3D texture + float Extent = 16; + + // last texel replicated and needed for filtering + // scalar: 3 frac, 6 mul + xyz = math::frac(xyz / (Extent - 1)) * (Extent - 1); + + // scalar: 3 frac + float3 uvw = math::frac(xyz); + // = floor(xyz); + // scalar: 3 add + float3 p0 = xyz - uvw; +// float3 f = math::pow(uvw, 2) * 3.0f - math::pow(uvw, 3) * 2.0f; // original perlin hermite (ok when used without bump mapping) + // scalar: 2*3 add 5*3 mul + float4 pr = PerlinRamp(float4(uvw.x, uvw.y, uvw.z, 0)); + float3 f = float3(pr.x, pr.y, pr.z); // new, better with continues second derivative for bump mapping + // scalar: 3 add + float3 p = p0 + f; + // scalar: 3 mad + // TODO: need reverse??? + float4 NoiseSample = tex::lookup_float4(PerlinNoise3DTexture, p / Extent + 0.5f / Extent); // +0.5f to get rid of bilinear offset + + // reconstruct from 8bit (using mad with 2 constants and dot4 was same instruction count) + // scalar: 4 mad, 3 mul, 3 add + float3 n = float3(NoiseSample.x, NoiseSample.y, NoiseSample.z) * 255.0f / 127.0f - 1.0f; + float d = NoiseSample.w * 255.f - 127; + return math::dot(xyz, n) - d; +} + +// Perlin-style "Modified Noise" +// http://www.umbc.edu/~olano/papers/index.html#mNoise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float GradientNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = MGradient(int(seeds.seed000), seeds.fv - float3(0, 0, 0)).w; + float rand100 = MGradient(int(seeds.seed100), seeds.fv - float3(1, 0, 0)).w; + float rand010 = MGradient(int(seeds.seed010), seeds.fv - float3(0, 1, 0)).w; + float rand110 = MGradient(int(seeds.seed110), seeds.fv - float3(1, 1, 0)).w; + float rand001 = MGradient(int(seeds.seed001), seeds.fv - float3(0, 0, 1)).w; + float rand101 = MGradient(int(seeds.seed101), seeds.fv - float3(1, 0, 1)).w; + float rand011 = MGradient(int(seeds.seed011), seeds.fv - float3(0, 1, 1)).w; + float rand111 = MGradient(int(seeds.seed111), seeds.fv - float3(1, 1, 1)).w; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D value noise - used to be incorrectly called Perlin noise +// @param v = 3D noise argument, use float3(x,y,0) for 2D or float3(x,0,0) for 1D +// @param bTiling = repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension +// @return random number in the range -1 .. 1 +float ValueNoise3D_ALU(float3 v, bool bTiling, float RepeatSize) +{ + SeedValue seeds = NoiseSeeds(v, bTiling, RepeatSize); + + float rand000 = RandBBSfloat(seeds.seed000) * 2 - 1; + float rand100 = RandBBSfloat(seeds.seed100) * 2 - 1; + float rand010 = RandBBSfloat(seeds.seed010) * 2 - 1; + float rand110 = RandBBSfloat(seeds.seed110) * 2 - 1; + float rand001 = RandBBSfloat(seeds.seed001) * 2 - 1; + float rand101 = RandBBSfloat(seeds.seed101) * 2 - 1; + float rand011 = RandBBSfloat(seeds.seed011) * 2 - 1; + float rand111 = RandBBSfloat(seeds.seed111) * 2 - 1; + + float4 Weights = PerlinRamp(float4(seeds.fv.x, seeds.fv.y, seeds.fv.z, 0)); + + float i = math::lerp(math::lerp(rand000, rand100, Weights.x), math::lerp(rand010, rand110, Weights.x), Weights.y); + float j = math::lerp(math::lerp(rand001, rand101, Weights.x), math::lerp(rand011, rand111, Weights.x), Weights.y); + return math::lerp(i, j, Weights.z); +} + +// 3D jitter offset within a voronoi noise cell +// @param pos - integer lattice corner +// @return random offsets vector +float3 VoronoiCornerSample(float3 pos, int Quality) +{ + // random values in [-0.5, 0.5] + float3 noise = float3(Rand3DPCG16(int3(pos))) / 0xffff - 0.5; + + // quality level 1 or 2: searches a 2x2x2 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 2x2x2 search + if (Quality <= 2) + { + return math::normalize(noise) * 0.2588; + } + + // quality level 3: searches a 3x3x3 neighborhood with points distributed on a sphere + // scale factor to guarantee jittered points will be found within a 3x3x3 search + if (Quality == 3) + { + return math::normalize(noise) * 0.3090; + } + + // quality level 4: jitter to anywhere in the cell, needs 4x4x4 search + return noise; +} + +// compare previous best with a new candidate +// not producing point locations makes it easier for compiler to eliminate calculations when they're not needed +// @param minval = location and distance of best candidate seed point before the new one +// @param candidate = candidate seed point +// @param offset = 3D offset to new candidate seed point +// @param bDistanceOnly = if true, only set maxval.w with distance, otherwise maxval.w is distance and maxval.xyz is position +// @return position (if bDistanceOnly is false) and distance to closest seed point so far +float4 VoronoiCompare(float4 minval, float3 candidate, float3 offset, bool bDistanceOnly) +{ + if (bDistanceOnly) + { + return float4(0, 0, 0, math::min(minval.w, math::dot(offset, offset))); + } + else + { + float newdist = math::dot(offset, offset); + return newdist > minval.w ? minval : float4(candidate.x, candidate.y, candidate.z, newdist); + } +} + +// 220 instruction Worley noise +float4 VoronoiNoise3D_ALU(float3 v, int Quality, bool bTiling, float RepeatSize, bool bDistanceOnly) +{ + float3 fv = math::frac(v), fv2 = math::frac(v + 0.5); + float3 iv = math::floor(v), iv2 = math::floor(v + 0.5); + + // with initial minimum distance = infinity (or at least bigger than 4), first min is optimized away + float4 mindist = float4(0,0,0,100); + float3 p, offset; + + // quality level 3: do a 3x3x3 search + if (Quality == 3) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 1; ++offset_x) + { + for (offset_y = -1; offset_y <= 1; ++offset_y) + { + for (offset_z = -1; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + + // everybody else searches a base 2x2x2 neighborhood + else + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = 0; offset_x <= 1; ++offset_x) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // quality level 2, do extra set of points, offset by half a cell + if (Quality == 2) + { + // 467 is just an offset to a different area in the random number field to avoid similar neighbor artifacts + p = offset + VoronoiCornerSample(NoiseTileWrap(iv2 + offset, bTiling, RepeatSize) + 467, Quality); + mindist = VoronoiCompare(mindist, iv2 + p, fv2 - p, bDistanceOnly); + } + } + } + } + } + + // quality level 4: add extra sets of four cells in each direction + if (Quality >= 4) + { + int offset_x; + int offset_y; + int offset_z; + for (offset_x = -1; offset_x <= 2; offset_x += 3) + { + for (offset_y = 0; offset_y <= 1; ++offset_y) + { + for (offset_z = 0; offset_z <= 1; ++offset_z) + { + offset = float3(offset_x, offset_y, offset_z); + // along x axis + p = offset + VoronoiCornerSample(NoiseTileWrap(iv + offset, bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along y axis + p = float3(offset.y, offset.z, offset.x) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.y, offset.z, offset.x), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + + // along z axis + p = float3(offset.z, offset.x, offset.y) + VoronoiCornerSample(NoiseTileWrap(iv + float3(offset.z, offset.x, offset.y), bTiling, RepeatSize), Quality); + mindist = VoronoiCompare(mindist, iv + p, fv - p, bDistanceOnly); + } + } + } + } + + // transform squared distance to real distance + return float4(mindist.x, mindist.y, mindist.z, math::sqrt(mindist.w)); +} + +// Coordinates for corners of a Simplex tetrahedron +// Based on McEwan et al., Efficient computation of noise in GLSL, JGT 2011 +// @param v = 3D noise argument +// @return 4 corner locations +float4x3 SimplexCorners(float3 v) +{ + // find base corner by skewing to tetrahedral space and back + float3 tet = math::floor(v + v.x/3 + v.y/3 + v.z/3); + float3 base = tet - tet.x/6 - tet.y/6 - tet.z/6; + float3 f = v - base; + + // Find offsets to other corners (McEwan did this in tetrahedral space, + // but since skew is along x=y=z axis, this works in Euclidean space too.) + float3 g = math::step(float3(f.y,f.z,f.x), float3(f.x,f.y,f.z)), h = 1 - float3(g.z, g.x, g.y); + float3 a1 = math::min(g, h) - 1.0 / 6.0, a2 = math::max(g, h) - 1.0 / 3.0; + + // four corners + return float4x3(base, base + a1, base + a2, base + 0.5); +} + +// Improved smoothing function for simplex noise +// @param f = fractional distance to four tetrahedral corners +// @return weight for each corner +float4 SimplexSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + return (1 * scale + s*(-3 * scale + s*(3 * scale - s*scale))); +} + +// Derivative of simplex noise smoothing function +// @param f = fractional distanc eto four tetrahedral corners +// @return derivative of smoothing function for each corner by x, y and z +float3x4 SimplexDSmooth(float4x3 f) +{ + const float scale = 1024. / 375.; // scale factor to make noise -1..1 + float4 d = float4(math::dot(f[0], f[0]), math::dot(f[1], f[1]), math::dot(f[2], f[2]), math::dot(f[3], f[3])); + float4 s = math::saturate(2 * d); + s = -12 * scale + s*(24 * scale - s * 12 * scale); + + return float3x4( + s * float4(f[0][0], f[1][0], f[2][0], f[3][0]), + s * float4(f[0][1], f[1][1], f[2][1], f[3][1]), + s * float4(f[0][2], f[1][2], f[2][2], f[3][2])); +} + +// Simplex noise and its Jacobian derivative +// @param v = 3D noise argument +// @param bTiling = whether to repeat noise pattern +// @param RepeatSize = integer units before tiling in each dimension, must be a multiple of 3 +// @return float3x3 Jacobian in J[*].xyz, vector noise in J[*].w +// J[0].w, J[1].w, J[2].w is a Perlin-style simplex noise with vector output, e.g. (Nx, Ny, Nz) +// J[i].x is X derivative of the i'th component of the noise so J[2].x is dNz/dx +// You can use this to compute the noise, gradient, curl, or divergence: +// float3x4 J = JacobianSimplex_ALU(...); +// float3 VNoise = float3(J[0].w, J[1].w, J[2].w); // 3D noise +// float3 Grad = J[0].xyz; // gradient of J[0].w +// float3 Curl = float3(J[1][2]-J[2][1], J[2][0]-J[0][2], J[0][1]-J[1][2]); +// float Div = J[0][0]+J[1][1]+J[2][2]; +// All of these are confirmed to compile out all unneeded terms. +// So Grad of X doesn't compute Y or Z components, and VNoise doesn't do any of the derivative computation. +float3x4 JacobianSimplex_ALU(float3 v, bool bTiling, float RepeatSize) +{ + int3 MGradientMask = int3(0x8000, 0x4000, 0x2000); + float3 MGradientScale = float3(1. / 0x4000, 1. / 0x2000, 1. / 0x1000); + + // corners of tetrahedron + float4x3 T = SimplexCorners(v); + // TODO: uint3 + int3 rand = int3(0); + float4x3 gvec0 = float4x3(1.0); + float4x3 gvec1 = float4x3(1.0); + float4x3 gvec2 = float4x3(1.0); + float4x3 fv = float4x3(1.0); + float3x4 grad = float3x4(1.0); + + // processing of tetrahedral vertices, unrolled + // to compute gradient at each corner + fv[0] = v - T[0]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[0] + 0.5, bTiling, RepeatSize)))); + gvec0[0] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[0] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[0] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][0] = math::dot(gvec0[0], fv[0]); + grad[1][0] = math::dot(gvec1[0], fv[0]); + grad[2][0] = math::dot(gvec2[0], fv[0]); + + fv[1] = v - T[1]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[1] + 0.5, bTiling, RepeatSize)))); + gvec0[1] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec1[1] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][1] = math::dot(gvec0[1], fv[1]); + grad[1][1] = math::dot(gvec1[1], fv[1]); + grad[2][1] = math::dot(gvec2[1], fv[1]); + + fv[2] = v - T[2]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[2] + 0.5, bTiling, RepeatSize)))); + gvec0[2] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[2] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[2] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][2] = math::dot(gvec0[2], fv[2]); + grad[1][2] = math::dot(gvec1[2], fv[2]); + grad[2][2] = math::dot(gvec2[2], fv[2]); + + fv[3] = v - T[3]; + rand = Rand3DPCG16(int3(math::floor(NoiseTileWrap(6 * T[3] + 0.5, bTiling, RepeatSize)))); + gvec0[3] = float3(int3(rand.x,rand.x,rand.x) & MGradientMask) * MGradientScale - 1; + gvec1[3] = float3(int3(rand.y,rand.y,rand.y) & MGradientMask) * MGradientScale - 1; + gvec2[3] = float3(int3(rand.z,rand.z,rand.z) & MGradientMask) * MGradientScale - 1; + grad[0][3] = math::dot(gvec0[3], fv[3]); + grad[1][3] = math::dot(gvec1[3], fv[3]); + grad[2][3] = math::dot(gvec2[3], fv[3]); + + // blend gradients + float4 sv = SimplexSmooth(fv); + float3x4 ds = SimplexDSmooth(fv); + + float3x4 jacobian = float3x4(1.0); + float3 vec0 = gvec0*sv + grad[0]*ds; // NOTE: mdl is column major, convert from UE4 (row major) + jacobian[0] = float4(vec0.x, vec0.y, vec0.z, math::dot(sv, grad[0])); + float3 vec1 = gvec1*sv + grad[1]*ds; + jacobian[1] = float4(vec1.x, vec1.y, vec1.z, math::dot(sv, grad[1])); + float3 vec2 = gvec2*sv + grad[2]*ds; + jacobian[2] = float4(vec2.x, vec2.y, vec2.z, math::dot(sv, grad[2])); + + return jacobian; +} + +// While RepeatSize is a float here, the expectation is that it would be largely integer values coming in from the UI. The downstream logic assumes +// floats for all called functions (NoiseTileWrap) and this prevents any float-to-int conversion errors from automatic type conversion. +float Noise3D_Multiplexer(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, int Function, float3 Position, int Quality, bool bTiling, float RepeatSize) +{ + // verified, HLSL compiled out the switch if Function is a constant + switch(Function) + { + case 0: + return SimplexNoise3D_TEX(PerlinNoiseGradientTexture, Position); + case 1: + return GradientNoise3D_TEX(PerlinNoiseGradientTexture, Position, bTiling, RepeatSize); + case 2: + return FastGradientPerlinNoise3D_TEX(PerlinNoise3DTexture, Position); + case 3: + return GradientNoise3D_ALU(Position, bTiling, RepeatSize); + case 4: + return ValueNoise3D_ALU(Position, bTiling, RepeatSize); + case 5: + return VoronoiNoise3D_ALU(Position, Quality, bTiling, RepeatSize, true).w * 2.0 - 1.0; + } + return 0; +} +//---------------------------------------------------------- + +export float noise(uniform texture_2d PerlinNoiseGradientTexture, uniform texture_3d PerlinNoise3DTexture, float3 Position, float Scale, float Quality, float Function, float Turbulence, float Levels, float OutputMin, float OutputMax, float LevelScale, float FilterWidth, float Tiling, float RepeatSize) +[[ + anno::description("Noise"), + anno::noinline() +]] +{ + Position *= Scale; + FilterWidth *= Scale; + + float Out = 0.0f; + float OutScale = 1.0f; + float InvLevelScale = 1.0f / LevelScale; + + int iFunction(Function); + int iQuality(Quality); + int iLevels(Levels); + bool bTurbulence(Turbulence); + bool bTiling(Tiling); + + for(int i = 0; i < iLevels; ++i) + { + // fade out noise level that are too high frequent (not done through dynamic branching as it usually requires gradient instructions) + OutScale *= math::saturate(1.0 - FilterWidth); + + if(bTurbulence) + { + Out += math::abs(Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize)) * OutScale; + } + else + { + Out += Noise3D_Multiplexer(PerlinNoiseGradientTexture, PerlinNoise3DTexture, iFunction, Position, iQuality, bTiling, RepeatSize) * OutScale; + } + + Position *= LevelScale; + RepeatSize *= LevelScale; + OutScale *= InvLevelScale; + FilterWidth *= LevelScale; + } + + if(!bTurbulence) + { + // bring -1..1 to 0..1 range + Out = Out * 0.5f + 0.5f; + } + + // Out is in 0..1 range + return math::lerp(OutputMin, OutputMax, Out); +} + +// Material node for noise functions returning a vector value +// @param LevelScale usually 2 but higher values allow efficient use of few levels +// @return in user defined range (OutputMin..OutputMax) +export float4 vector4_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise"), + anno::noinline() +]] +{ + float4 result = float4(0,0,0,1); + float3 ret = float3(0); + int iQuality = int(Quality); + int iFunction = int(Function); + bool bTiling = Tiling > 0.0; + + float3x4 Jacobian = JacobianSimplex_ALU(Position, bTiling, TileSize); // compiled out if not used + + // verified, HLSL compiled out the switch if Function is a constant + switch (iFunction) + { + case 0: // Cellnoise + ret = float3(Rand3DPCG16(int3(math::floor(NoiseTileWrap(Position, bTiling, TileSize))))) / 0xffff; + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 1: // Color noise + ret = float3(Jacobian[0].w, Jacobian[1].w, Jacobian[2].w); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 2: // Gradient + result = Jacobian[0]; + break; + case 3: // Curl + ret = float3(Jacobian[2][1] - Jacobian[1][2], Jacobian[0][2] - Jacobian[2][0], Jacobian[1][0] - Jacobian[0][1]); + result = float4(ret.x, ret.y, ret.z, 1); + break; + case 4: // Voronoi + result = VoronoiNoise3D_ALU(Position, iQuality, bTiling, TileSize, false); + break; + } + return result; +} + +export float3 vector3_noise(float3 Position, float Quality, float Function, float Tiling, float TileSize) +[[ + anno::description("Vector Noise float3 version"), + anno::noinline() +]] +{ + float4 noise = vector4_noise(Position, Quality, Function, Tiling, TileSize); + return float3(noise.x, noise.y, noise.z); +} + + +// workaround for ue4 fresnel (without supporting for camera vector) : replacing it with 0.0, means facing to the view +export float fresnel(float exponent [[anno::unused()]], float base_reflect_fraction [[anno::unused()]], float3 normal [[anno::unused()]]) +[[ + anno::description("Fresnel"), + anno::noinline() +]] +{ + return 0.0; +} + +export float fresnel_function(float3 normal_vector [[anno::unused()]], float3 camera_vector [[anno::unused()]], + bool invert_fresnel [[anno::unused()]], float power [[anno::unused()]], + bool use_cheap_contrast [[anno::unused()]], float cheap_contrast_dark [[anno::unused()]], float cheap_contrast_bright [[anno::unused()]], + bool clamp_fresnel_dot_product [[anno::unused()]]) +[[ + anno::description("Fresnel Function"), + anno::noinline() +]] +{ + return 0.0; +} + +export float3 camera_vector(uniform bool up_z = true) +[[ + anno::description("Camera Vector"), + anno::noinline() +]] +{ + // assume camera postion is 0,0,0 + return math::normalize(float3(0) - convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)); +} + +export float pixel_depth() +[[ + anno::description("Pixel Depth"), + anno::noinline() +]] +{ + return 256.0f; +} + +export float scene_depth() +[[ + anno::description("Scene Depth") +]] +{ + return 65500.0f; +} + +export float3 scene_color() +[[ + anno::description("Scene Color") +]] +{ + return float3(1.0f); +} + +export float4 vertex_color() +[[ + anno::description("Vertex Color"), + anno::noinline() +]] +{ + return float4(1.0f); +} + +export float4 vertex_color_from_coordinate(int VertexColorCoordinateIndex) +[[ + anno::description("Vertex Color for float2 PrimVar"), + anno::noinline() +]] +{ + // Kit only supports 4 uv sets, 2 uvs are available to vertex color. if vertex color index is invalid, output the constant WHITE color intead + return (VertexColorCoordinateIndex > 2) ? float4(1.0f) : float4(state::texture_coordinate(VertexColorCoordinateIndex).x, state::texture_coordinate(VertexColorCoordinateIndex).y, state::texture_coordinate(VertexColorCoordinateIndex+1).x, state::texture_coordinate(VertexColorCoordinateIndex+1).y); +} + +export float3 camera_position() +[[ + anno::description("Camera Position"), + anno::noinline() +]] +{ + return float3(1000.0f, 0, 0); +} + +export float3 rotate_about_axis(float4 NormalizedRotationAxisAndAngle, float3 PositionOnAxis, float3 Position) +[[ + anno::description("Rotates Position about the given axis by the given angle") +]] +{ + // Project Position onto the rotation axis and find the closest point on the axis to Position + float3 NormalizedRotationAxis = float3(NormalizedRotationAxisAndAngle.x,NormalizedRotationAxisAndAngle.y,NormalizedRotationAxisAndAngle.z); + float3 ClosestPointOnAxis = PositionOnAxis + NormalizedRotationAxis * math::dot(NormalizedRotationAxis, Position - PositionOnAxis); + // Construct orthogonal axes in the plane of the rotation + float3 UAxis = Position - ClosestPointOnAxis; + float3 VAxis = math::cross(NormalizedRotationAxis, UAxis); + float[2] SinCosAngle = math::sincos(NormalizedRotationAxisAndAngle.w); + // Rotate using the orthogonal axes + float3 R = UAxis * SinCosAngle[1] + VAxis * SinCosAngle[0]; + // Reconstruct the rotated world space position + float3 RotatedPosition = ClosestPointOnAxis + R; + // Convert from position to a position offset + return RotatedPosition - Position; +} + +export float2 rotate_scale_offset_texcoords(float2 InTexCoords, float4 InRotationScale, float2 InOffset) +[[ + anno::description("Returns a float2 texture coordinate after 2x2 transform and offset applied") +]] +{ + return float2(math::dot(InTexCoords, float2(InRotationScale.x, InRotationScale.y)), math::dot(InTexCoords, float2(InRotationScale.z, InRotationScale.w))) + InOffset; +} + +export float3 reflection_custom_world_normal(float3 WorldNormal, bool bNormalizeInputNormal, uniform bool up_z = true) +[[ + anno::description("Reflection vector about the specified world space normal") +]] +{ + if (bNormalizeInputNormal) + { + WorldNormal = math::normalize(WorldNormal); + } + + return -camera_vector(up_z) + WorldNormal * math::dot(WorldNormal, camera_vector(up_z)) * 2.0; +} + +export float3 reflection_vector(uniform bool up_z = true) +[[ + anno::description("Reflection Vector"), + anno::noinline() +]] +{ + float3 normal = convert_to_left_hand(state::transform_normal(state::coordinate_internal,state::coordinate_world,state::normal()), up_z, false); + return reflection_custom_world_normal(normal, false, up_z); +} + +export float dither_temporalAA(float AlphaThreshold = 0.5f, float Random = 1.0f [[anno::unused()]]) +[[ + anno::description("Dither TemporalAA"), + anno::noinline() +]] +{ + return AlphaThreshold; +} + +export float3 black_body( float Temp ) +[[ + anno::description("Black Body"), + anno::noinline() +]] +{ + float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp ); + float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp ); + + float x = 3*u / ( 2*u - 8*v + 4 ); + float y = 2*v / ( 2*u - 8*v + 4 ); + float z = 1 - x - y; + + float Y = 1; + float X = Y/y * x; + float Z = Y/y * z; + + float3x3 XYZtoRGB = float3x3( + float3(3.2404542, -1.5371385, -0.4985314), + float3(-0.9692660, 1.8760108, 0.0415560), + float3(0.0556434, -0.2040259, 1.0572252) + ); + + return XYZtoRGB * float3( X, Y, Z ) * math::pow( 0.0004 * Temp, 4 ); +} + +export float per_instance_random(uniform texture_2d PerlinNoiseGradientTexture, int NumberInstances) +[[ + anno::description("Per Instance Random"), + anno::noinline() +]] +{ + float weight = state::object_id() / float(NumberInstances); + return NumberInstances == 0 ? 0.0 : tex::lookup_float4(PerlinNoiseGradientTexture, float2(weight, 1.0 - weight), tex::wrap_repeat, tex::wrap_repeat).x; +} + +//------------------ Hair from UE4 ----------------------- +float3 hair_absorption_to_color(float3 A) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::exp(-math::sqrt(A) * D); +} + +float3 hair_color_to_absorption(float3 C) +{ + const float B = 0.3f; + float b2 = B * B; + float b3 = B * b2; + float b4 = b2 * b2; + float b5 = B * b4; + float D = (5.969f - 0.215f * B + 2.532f * b2 - 10.73f * b3 + 5.574f * b4 + 0.245f * b5); + return math::pow(math::log(C) / D, 2.0f); +} + +export float3 get_hair_color_from_melanin(float InMelanin, float InRedness, float3 InDyeColor) +[[ + anno::description("Hair Color") +]] +{ + InMelanin = math::saturate(InMelanin); + InRedness = math::saturate(InRedness); + float Melanin = -math::log(math::max(1 - InMelanin, 0.0001f)); + float Eumelanin = Melanin * (1 - InRedness); + float Pheomelanin = Melanin * InRedness; + + float3 DyeAbsorption = hair_color_to_absorption(math::saturate(InDyeColor)); + float3 Absorption = Eumelanin * float3(0.506f, 0.841f, 1.653f) + Pheomelanin * float3(0.343f, 0.733f, 1.924f); + + return hair_absorption_to_color(Absorption + DyeAbsorption); +} + +export float3 local_object_bounds_min() +[[ + anno::description("Local Object Bounds Min"), + anno::noinline() +]] +{ + return float3(0.0); +} + +export float3 local_object_bounds_max() +[[ + anno::description("Local Object Bounds Max"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float3 object_bounds() +[[ + anno::description("Object Bounds"), + anno::noinline() +]] +{ + return float3(100.0); +} + +export float object_radius() +[[ + anno::description("Object Radius"), + anno::noinline() +]] +{ + return 100.0f; +} + +export float3 object_world_position(uniform bool up_z = true) +[[ + anno::description("Object World Position"), + anno::noinline() +]] +{ + return convert_to_left_hand(state::transform_point(state::coordinate_internal,state::coordinate_world,state::position()), up_z)*state::meters_per_scene_unit()*100.0; +} + +export float3 object_orientation() +[[ + anno::description("Object Orientation"), + anno::noinline() +]] +{ + return float3(0); +} + +export float rcp(float x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float2 rcp(float2 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float3 rcp(float3 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export float4 rcp(float4 x) +[[ + anno::description("hlsl rcp"), + anno::noinline() +]] +{ + return 1.0f / x; +} + +export int BitFieldExtractI32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractI32 int"), + anno::noinline() +]] +{ + Size &= 3; + Offset &= 3; + + if (Size == 0) + return 0; + else if (Offset + Size < 32) + return (Data << (32 - Size - Offset)) >> (32 - Size); + else + return Data >> Offset; +} + +export int BitFieldExtractI32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractI32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(int(Data), int(Size), int(Offset)); +} + +export int BitFieldExtractU32(float Data, float Size, float Offset) +[[ + anno::description("BitFieldExtractU32 float"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export int BitFieldExtractU32(int Data, int Size, int Offset) +[[ + anno::description("BitFieldExtractU32 int"), + anno::noinline() +]] +{ + return BitFieldExtractI32(Data, Size, Offset); +} + +export float3 EyeAdaptationInverseLookup(float3 LightValue, float Alpha) +[[ + anno::description("EyeAdaptationInverseLookup"), + anno::noinline() +]] +{ + float Adaptation = 1.0f; + + // When Alpha=0.0, we want to multiply by 1.0. when Alpha = 1.0, we want to multiply by 1/Adaptation. + // So the lerped value is: + // LerpLogScale = Lerp(log(1),log(1/Adaptaiton),T) + // Which is simplified as: + // LerpLogScale = Lerp(0,-log(Adaptation),T) + // LerpLogScale = -T * logAdaptation; + + float LerpLogScale = -Alpha * math::log(Adaptation); + float Scale = math::exp(LerpLogScale); + return LightValue * Scale; +} diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/000/scene.usd b/validation/IROS_C_V3_Aloha_unseen/sort_waste/000/scene.usd new file mode 100644 index 0000000000000000000000000000000000000000..175d5f228aea59517d649424c7436c138e6d1676 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/000/scene.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aea908279c523115220722b4359186e37d186d40e53cd2e18155a24d622f278a +size 70194535 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture0.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture0.png new file mode 100644 index 0000000000000000000000000000000000000000..2755b4a38dbcbc426963af6dcda4bffafeeb5ac8 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f945afaff3871bcbc9ecb43d334a4a2d055c5e669ed2fc03009822b0fdf7e00f +size 145560 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture1.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture1.png new file mode 100644 index 0000000000000000000000000000000000000000..b9cf5ca997b798ebaeb4530867db2e140baa8981 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1db792f60eef26174ee00959e5dc639323fe8fc2193c1c4f85430d6745a76374 +size 812140 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture2.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture2.png new file mode 100644 index 0000000000000000000000000000000000000000..47427fe4d8f6076fb73eaa21a03a053b2c9204ff --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85170cdd1be5823135a83ff2f92d7dc9decf0a751a966e4a1a11bba91455c2a1 +size 935052 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture3.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture3.png new file mode 100644 index 0000000000000000000000000000000000000000..47427fe4d8f6076fb73eaa21a03a053b2c9204ff --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85170cdd1be5823135a83ff2f92d7dc9decf0a751a966e4a1a11bba91455c2a1 +size 935052 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/30f8ba058e1f4e288f5a2ddcba924c3f_texture0.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/30f8ba058e1f4e288f5a2ddcba924c3f_texture0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a0b0c59debf118bdaa545c610f68b6da8c2d8195 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/30f8ba058e1f4e288f5a2ddcba924c3f_texture0.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e134b635a4b82d3a7dd818d828f70990b3cb04f027fbf0a492d4047667168394 +size 102352 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60090c4ad849e10001fbaec3_color.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60090c4ad849e10001fbaec3_color.png new file mode 100644 index 0000000000000000000000000000000000000000..65147eef38b3af6acfbda8b2c7b0de5ecf552a0a --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60090c4ad849e10001fbaec3_color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6dd97c312b05f01d65684cf54ebbd551d9e413b40b60fd53286be193054eae30 +size 174840 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60090c4ad849e10001fbaec3_metallic.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60090c4ad849e10001fbaec3_metallic.png new file mode 100644 index 0000000000000000000000000000000000000000..e3d6bcf6556ed6e3669acc04d94bc3db04cfc9f1 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60090c4ad849e10001fbaec3_metallic.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1266e382e1edbd54779292e4a5d3971ae3b8ec2ecd1d23eac6d60531bb43e3e3 +size 40129 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60f102a500e3a30001d518c5_color.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60f102a500e3a30001d518c5_color.png new file mode 100644 index 0000000000000000000000000000000000000000..6edbeab0718bcac7de00c005f420cd3153a45ec9 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/60f102a500e3a30001d518c5_color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b465976310907cb5db7e44ad537a7d45e7c013453e0efac4b771df58427ab7ee +size 1186804 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_BaseColor.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_BaseColor.png new file mode 100644 index 0000000000000000000000000000000000000000..704bac1b84ff247711dbe6a240d27806a9f1254d --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_BaseColor.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67f233b98739d718596aa128517cce62a7feef61ed7d932a330b8be758ca1fe9 +size 220896 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_Metallic-DefaultMaterial_Roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_Metallic-DefaultMaterial_Roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..64ac61471aa45cf045f4a377ef923e92aa3faeeb --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_Metallic-DefaultMaterial_Roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6fd2be8cc5a8e6d11e1d14f3dddafb4bffaca2f213b233e059f6c3003f76a49d +size 495720 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_Normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_Normal.png new file mode 100644 index 0000000000000000000000000000000000000000..32421df5be3a5653ef4694a46f11a5b0a7da393e --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/DefaultMaterial_Normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86c4bcb8a1d4d0d0ceefc82fe6fa87b338c05f11dad044c7254a1c69b8081bed +size 1009657 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..87b59392959485d5f33b198a1ae5f42c61fff7f1 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f25320a4514ba1fb5b10448c99621a1d4761a003558dc1e74b065ae1b720a5e5 +size 2249920 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_metallic-texture_roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_metallic-texture_roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..1ad5f2a87d1de92d0be5b5edb98ade82ac5969e6 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_metallic-texture_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b07f3c987237a5386ad6b67b0b4cd14d6b89a0fdf25bee13e970f7e9176eda96 +size 2151048 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..9ad29445ee306188bf983a2bfb87355f16ac8acf --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base0_texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2014911e4ffa130e00edb188968cd0ab65dd8f10564d81d85d6811b5b2415db +size 2890272 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..cb8dfbec64717b86632d8c2ab03cf9dfacc589e7 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99b3a6ba05a9273172f513a66cf97cc0aab1f14a502594fe0fd15441ae1c5f27 +size 2783637 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_metallic-texture_roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_metallic-texture_roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..f5e19d1fcf5fbc66b085d1a5258c403b08f66ede --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_metallic-texture_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41e52c27407f0c02452e6765090b3fcd2aaffc80883f0f616e0e3dd41322ea23 +size 2049982 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..8c35d9e467e61f9c98231b948405efd7f7b2def5 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base1_texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dac049009854ba7d7cb48895a399e927721cc72b35378668e1e6131b9921e9ed +size 3533461 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..616965d312173445687c799b6cac6e565f87bb3f --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:628ad35b0028dd0e6aee636618439b927f7fcec8f103c165b056bd355faa4fa9 +size 2540471 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_metallic-texture_roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_metallic-texture_roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..0bcb26a597fba6252fc4cbd11283338f94f8c322 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_metallic-texture_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce91ec0545496035830e9f6045e17f25b9a2c5fa78f952fe176583380025eb27 +size 2128296 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..d863900a479875150d05f254671142627812f811 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base2_texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5350edb34d505bee38e9e49d33b8cfc99eb1f0b7aa7ad124ed8a5e07ca03ba22 +size 3274710 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..249cd6a01a569754216977a62fd947700ce4e0d6 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e252bc3ad87d026dabe3529af058617db787499d191c106014a7e71aa6bcdaa8 +size 2532978 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_metallic-texture_roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_metallic-texture_roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..5f935d90b7c1c5788c0d677af311cd91c4c51cfa --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_metallic-texture_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f842775248d34b0d698733db9b3c7a9c186fc4fac80fedef813d1495225bb67 +size 2191547 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..a52311f8e8f0d34c76ba6a5b57884564df42064b --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base3_texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a55b435ebcbeabc1f98dcdc42270c13f5efae244cbe54bdd069e41742c7897de +size 3111382 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..18dfa96d2399364027b8ed5de021f71c6a8a6e58 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea974bd664d36dd008fb2b89834b5615da3f5dab6c34a2472124b843c49b2b17 +size 2142095 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_metallic-texture_roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_metallic-texture_roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..1381f784ab28bc1125b8ac7de1fd5e33e8ebf2ef --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_metallic-texture_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e40036f7e6cb0358bd41dc24a6e49f477add2bcebfcc4fc09fc2d38cf090953 +size 1830869 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..df0d9a6e27e4063b58c2a273ae7e811ff557db51 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/base5_texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6563df5ca5bfc29fd84b92e476a891d8263e930f5b1ac29c15b5cdc61cff2f08 +size 2472250 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/black.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/black.png new file mode 100644 index 0000000000000000000000000000000000000000..fe25e679621fef83e0b6e7a2a37e761c0f1fb016 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/black.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1737b9d208dc78e4638c6c2e98a46f222c5aa8bbe3dfa7812b869c0351c9d509 +size 197 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/black_1.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/black_1.png new file mode 100644 index 0000000000000000000000000000000000000000..fe25e679621fef83e0b6e7a2a37e761c0f1fb016 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/black_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1737b9d208dc78e4638c6c2e98a46f222c5aa8bbe3dfa7812b869c0351c9d509 +size 197 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/brown_photostudio_02_4k.exr b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/brown_photostudio_02_4k.exr new file mode 100644 index 0000000000000000000000000000000000000000..f2712e277f960d20e233e19cb675a2902691b4d1 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/brown_photostudio_02_4k.exr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:580a912e23d2298f59e983496fd9b4a4646a0659877e0f0391fcddb8813f2034 +size 20159867 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture0.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2e54e60fd1f3d40617ecd2993d8ff636cba393c8 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture0.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b919a9d36e49e487a25af9ce4a5a84425f75254a8bd7d8f38ba31f1afebd621 +size 20492 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture1.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..12ceee756eb7dbc371142e001ec807f16dc5f7ba --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture1.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa3fc713eb27c9c5a3c964ba452e0033243f4144ec4ebd178e9d9190c17aa7d5 +size 127912 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture10.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture10.png new file mode 100644 index 0000000000000000000000000000000000000000..fe181fd2ccd61e02f1527b1590154f56fdd6a072 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture10.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d23fddd696b11e05fccf4fb3c97073c7e1d6c14c3b02e16009a00b323187229 +size 36596 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture11.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture11.png new file mode 100644 index 0000000000000000000000000000000000000000..fe181fd2ccd61e02f1527b1590154f56fdd6a072 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture11.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d23fddd696b11e05fccf4fb3c97073c7e1d6c14c3b02e16009a00b323187229 +size 36596 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture12.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture12.jpg new file mode 100644 index 0000000000000000000000000000000000000000..792a84159805e5c8e27661667fb56c28d7d93652 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture12.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d43f39f0f571160657a3ea65cb2ecb303a344669508eb5e27614f7f3a43d9ec +size 17016 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture13.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture13.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2209f3c643a7bef9f8219e8d3d21f664c9bbe2bc --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture13.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c776f28c01b3d992bc842a1a2f9bf2bb0455b594d0f30aba350d2e3bad9a553a +size 106104 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture14.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture14.png new file mode 100644 index 0000000000000000000000000000000000000000..fa119096cb9e8ac99bdd5c0561dbda5dc8e4886a --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture14.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:347d2c6c91d2c723ac29093f6ba5fa805e839fff78a2bec5ffd7610710c8a68e +size 224 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture15.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture15.jpg new file mode 100644 index 0000000000000000000000000000000000000000..792a84159805e5c8e27661667fb56c28d7d93652 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture15.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d43f39f0f571160657a3ea65cb2ecb303a344669508eb5e27614f7f3a43d9ec +size 17016 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture16.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture16.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6d4588122046ad1d0a8707530bb532d54ee4247c --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture16.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7bc3dcfc49e43533fd6d6ec0caccbfe968e285b6e9d3a5460bf7501e5b967e92 +size 101212 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture17.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture17.png new file mode 100644 index 0000000000000000000000000000000000000000..aa02e37ba163a78099d77a81c9335efe7a272d5a --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture17.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82b00d520640e7cda624d2520817e2922398fef289f7fd252edb4a171712ceb7 +size 20800 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture18.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture18.png new file mode 100644 index 0000000000000000000000000000000000000000..aa02e37ba163a78099d77a81c9335efe7a272d5a --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture18.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82b00d520640e7cda624d2520817e2922398fef289f7fd252edb4a171712ceb7 +size 20800 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture2.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture2.png new file mode 100644 index 0000000000000000000000000000000000000000..4ff547d02d35279e7d146c0040fb61fa7e7a2d4a --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd6090d874ea1db20984e1329dd47e4955ceddc4414468204cd3f4f8fe6495e2 +size 442316 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture3.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5f2269d0f0752b4562b4131bcc02a5dfeecad698 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture3.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb314da7a47d0b14a4d66cbb7cec5294ba9f3533fd34b3bb98cee76ed8ad7800 +size 54376 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture4.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..694d1536ea8ab64292fc4965b42929785259062c --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture4.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e890be549ed585cfe0aef74543260d5f1bbca74d8426cbb78044673af94a63fc +size 19244 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture5.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture5.png new file mode 100644 index 0000000000000000000000000000000000000000..4ec3620fdd12f42b698f184454063d2c27a03cc3 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0b89697adc2640e90101110bc4c2c9b707518a0b7f3d5152ddc1fa2d4cc4cb4 +size 257516 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture6.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture6.jpg new file mode 100644 index 0000000000000000000000000000000000000000..134e9647e0b7c6c45b5c8718da635d40f08f3551 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture6.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d80d582835e0ea15e2c261ff924fee2940823407756ac606f2f640c1e11ec925 +size 46464 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture7.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture7.png new file mode 100644 index 0000000000000000000000000000000000000000..6a108c94262b97b873b7d6df4fffae2bdb2ee658 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture7.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63b67f90b8ea395f4d60b3190d1b454cd49d422122f967760f1713b827711839 +size 55892 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture8.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture8.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5c4c9955e847e0ed6b3d01cb593f2e3077a0faf3 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture8.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93d13b4c5e5a9180b807be0f5e5eec6d1fa0b36a1ab61bb71cc4172b2606a3f7 +size 37752 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture9.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture9.jpg new file mode 100644 index 0000000000000000000000000000000000000000..602020369a37fe2c42ff864f95158a1460a0a4f0 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture9.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d10eee448c5727ea55562da1268cca99ff1cbabc5b5113038708917f2d801e0c +size 116632 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellColor.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellColor.jpg new file mode 100644 index 0000000000000000000000000000000000000000..62e013280b214ad426d75214764f7349c0a9ef36 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellColor.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38643d6fd71344b64234b22c71df665e5d80daab90e87641d3999adaa40b24b5 +size 191258 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellDiffuse.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellDiffuse.jpg new file mode 100644 index 0000000000000000000000000000000000000000..947263cf7ec37c2424c32c3482ac15ccada36a29 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellDiffuse.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07b19c28f2e9f6b8aa509c608cda9705c2dbb0b2a13b3c7c3d817e89c666651a +size 32750 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellSpecular.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellSpecular.jpg new file mode 100644 index 0000000000000000000000000000000000000000..16f5dcebc24dc1043dd2bfb64fdccaa8949b69dc --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_DuracellSpecular.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:576b7733526d8f8d5335b2468f66551a9abde8b781bfcf1b1b2b737c6748cd37 +size 39579 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_EnergizerColor.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_EnergizerColor.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e50cc6efe708f9f6cfa06c33db207197c62f41fe --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_EnergizerColor.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5cf320e15d334697420089d8987994bf8b952c31b9259b5ca28d7488f73b8187 +size 226252 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_EnergizerSpecular.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_EnergizerSpecular.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a207f3d5e6722d1cd23b627f3d5b0863f5fa37aa --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_EnergizerSpecular.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de0191818e9f2d17b574f19f86f689d0d6374fae28244258a700470027bc9270 +size 70739 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_PanasonicColor.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_PanasonicColor.jpg new file mode 100644 index 0000000000000000000000000000000000000000..271cda0cb7c7cc74c0f5573d8ae5cdca8bb32d0e --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_PanasonicColor.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdefd78d07dc4605e374810157128b22412307a21b12040b0b62bfb761342b53 +size 139514 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_PanasonicDiffuse.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_PanasonicDiffuse.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1117fb84b33cdd878fa831849afadf4d59bfbf88 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/flipped_PanasonicDiffuse.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f8945a1c201b36541267ff3bff2708f00a961c5debcd4521bb1a6bbd95145bf +size 105195 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/normal.png new file mode 100644 index 0000000000000000000000000000000000000000..bcd2cbe633402945b9863951d24f055ae6be3bfd --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffa19106ab1ef542307afa48e779c169d23d534bb0acd7c99d986889a19f002c +size 196 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/normal_1.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/normal_1.png new file mode 100644 index 0000000000000000000000000000000000000000..bcd2cbe633402945b9863951d24f055ae6be3bfd --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/normal_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffa19106ab1ef542307afa48e779c169d23d534bb0acd7c99d986889a19f002c +size 196 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/white.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/white.png new file mode 100644 index 0000000000000000000000000000000000000000..8e7c9ddfd5b159635f2775c4487099834432f834 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/white.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3953e0be8bde97630eb7e1ee94a34f08cc408895ddd1244a29958ef5da3ea40 +size 195 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/white_1.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/white_1.png new file mode 100644 index 0000000000000000000000000000000000000000..8e7c9ddfd5b159635f2775c4487099834432f834 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/SubUSDs/textures/white_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3953e0be8bde97630eb7e1ee94a34f08cc408895ddd1244a29958ef5da3ea40 +size 195 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/meta_info.pkl b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/meta_info.pkl new file mode 100644 index 0000000000000000000000000000000000000000..19c52bc7f49fcee634213ac4df7dbad317451c31 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/004/meta_info.pkl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67928b495542f7f5b668cadaf0f54187a961d06b3ec2c9fda0d4fc49cc4370ed +size 9125 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture1.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture1.png new file mode 100644 index 0000000000000000000000000000000000000000..b9cf5ca997b798ebaeb4530867db2e140baa8981 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1db792f60eef26174ee00959e5dc639323fe8fc2193c1c4f85430d6745a76374 +size 812140 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/60090c4ad849e10001fbaec3_color.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/60090c4ad849e10001fbaec3_color.png new file mode 100644 index 0000000000000000000000000000000000000000..65147eef38b3af6acfbda8b2c7b0de5ecf552a0a --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/60090c4ad849e10001fbaec3_color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6dd97c312b05f01d65684cf54ebbd551d9e413b40b60fd53286be193054eae30 +size 174840 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/60f102a500e3a30001d518c5_color.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/60f102a500e3a30001d518c5_color.png new file mode 100644 index 0000000000000000000000000000000000000000..6edbeab0718bcac7de00c005f420cd3153a45ec9 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/60f102a500e3a30001d518c5_color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b465976310907cb5db7e44ad537a7d45e7c013453e0efac4b771df58427ab7ee +size 1186804 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base1_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base1_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..cb8dfbec64717b86632d8c2ab03cf9dfacc589e7 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base1_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99b3a6ba05a9273172f513a66cf97cc0aab1f14a502594fe0fd15441ae1c5f27 +size 2783637 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..249cd6a01a569754216977a62fd947700ce4e0d6 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e252bc3ad87d026dabe3529af058617db787499d191c106014a7e71aa6bcdaa8 +size 2532978 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_metallic-texture_roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_metallic-texture_roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..5f935d90b7c1c5788c0d677af311cd91c4c51cfa --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_metallic-texture_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f842775248d34b0d698733db9b3c7a9c186fc4fac80fedef813d1495225bb67 +size 2191547 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..a52311f8e8f0d34c76ba6a5b57884564df42064b --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/base3_texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a55b435ebcbeabc1f98dcdc42270c13f5efae244cbe54bdd069e41742c7897de +size 3111382 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/brown_photostudio_02_4k.exr b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/brown_photostudio_02_4k.exr new file mode 100644 index 0000000000000000000000000000000000000000..f2712e277f960d20e233e19cb675a2902691b4d1 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/brown_photostudio_02_4k.exr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:580a912e23d2298f59e983496fd9b4a4646a0659877e0f0391fcddb8813f2034 +size 20159867 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture1.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..12ceee756eb7dbc371142e001ec807f16dc5f7ba --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture1.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa3fc713eb27c9c5a3c964ba452e0033243f4144ec4ebd178e9d9190c17aa7d5 +size 127912 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/scene.usd b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/scene.usd new file mode 100644 index 0000000000000000000000000000000000000000..f849f48636ca39ea409520a3baa8b4e9a4ad10b7 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/005/scene.usd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8220943049a3ee4bbde141741f8de95fd0b95bf3f496d5e5c0028a7178d43eb2 +size 70032449 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture0.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture0.png new file mode 100644 index 0000000000000000000000000000000000000000..2755b4a38dbcbc426963af6dcda4bffafeeb5ac8 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f945afaff3871bcbc9ecb43d334a4a2d055c5e669ed2fc03009822b0fdf7e00f +size 145560 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture3.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture3.png new file mode 100644 index 0000000000000000000000000000000000000000..47427fe4d8f6076fb73eaa21a03a053b2c9204ff --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/2b70993763034bef8587d3730c7ca8ff_texture3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85170cdd1be5823135a83ff2f92d7dc9decf0a751a966e4a1a11bba91455c2a1 +size 935052 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/60090c4ad849e10001fbaec3_metallic.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/60090c4ad849e10001fbaec3_metallic.png new file mode 100644 index 0000000000000000000000000000000000000000..e3d6bcf6556ed6e3669acc04d94bc3db04cfc9f1 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/60090c4ad849e10001fbaec3_metallic.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1266e382e1edbd54779292e4a5d3971ae3b8ec2ecd1d23eac6d60531bb43e3e3 +size 40129 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/DefaultMaterial_Metallic-DefaultMaterial_Roughness.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/DefaultMaterial_Metallic-DefaultMaterial_Roughness.png new file mode 100644 index 0000000000000000000000000000000000000000..64ac61471aa45cf045f4a377ef923e92aa3faeeb --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/DefaultMaterial_Metallic-DefaultMaterial_Roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6fd2be8cc5a8e6d11e1d14f3dddafb4bffaca2f213b233e059f6c3003f76a49d +size 495720 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/base2_texture_diffuse.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/base2_texture_diffuse.png new file mode 100644 index 0000000000000000000000000000000000000000..616965d312173445687c799b6cac6e565f87bb3f --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/base2_texture_diffuse.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:628ad35b0028dd0e6aee636618439b927f7fcec8f103c165b056bd355faa4fa9 +size 2540471 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/base5_texture_normal.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/base5_texture_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..df0d9a6e27e4063b58c2a273ae7e811ff557db51 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/base5_texture_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6563df5ca5bfc29fd84b92e476a891d8263e930f5b1ac29c15b5cdc61cff2f08 +size 2472250 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/black.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/black.png new file mode 100644 index 0000000000000000000000000000000000000000..fe25e679621fef83e0b6e7a2a37e761c0f1fb016 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/black.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1737b9d208dc78e4638c6c2e98a46f222c5aa8bbe3dfa7812b869c0351c9d509 +size 197 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture10.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture10.png new file mode 100644 index 0000000000000000000000000000000000000000..fe181fd2ccd61e02f1527b1590154f56fdd6a072 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture10.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d23fddd696b11e05fccf4fb3c97073c7e1d6c14c3b02e16009a00b323187229 +size 36596 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture16.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture16.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6d4588122046ad1d0a8707530bb532d54ee4247c --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture16.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7bc3dcfc49e43533fd6d6ec0caccbfe968e285b6e9d3a5460bf7501e5b967e92 +size 101212 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture3.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5f2269d0f0752b4562b4131bcc02a5dfeecad698 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture3.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb314da7a47d0b14a4d66cbb7cec5294ba9f3533fd34b3bb98cee76ed8ad7800 +size 54376 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture4.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..694d1536ea8ab64292fc4965b42929785259062c --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture4.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e890be549ed585cfe0aef74543260d5f1bbca74d8426cbb78044673af94a63fc +size 19244 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture5.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture5.png new file mode 100644 index 0000000000000000000000000000000000000000..4ec3620fdd12f42b698f184454063d2c27a03cc3 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/cf2af4b2b8c6420da69ba8d8f73744bc_texture5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0b89697adc2640e90101110bc4c2c9b707518a0b7f3d5152ddc1fa2d4cc4cb4 +size 257516 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/flipped_DuracellColor.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/flipped_DuracellColor.jpg new file mode 100644 index 0000000000000000000000000000000000000000..62e013280b214ad426d75214764f7349c0a9ef36 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/flipped_DuracellColor.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38643d6fd71344b64234b22c71df665e5d80daab90e87641d3999adaa40b24b5 +size 191258 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/flipped_PanasonicDiffuse.jpg b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/flipped_PanasonicDiffuse.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1117fb84b33cdd878fa831849afadf4d59bfbf88 --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/flipped_PanasonicDiffuse.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f8945a1c201b36541267ff3bff2708f00a961c5debcd4521bb1a6bbd95145bf +size 105195 diff --git a/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/normal_1.png b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/normal_1.png new file mode 100644 index 0000000000000000000000000000000000000000..bcd2cbe633402945b9863951d24f055ae6be3bfd --- /dev/null +++ b/validation/IROS_C_V3_Aloha_unseen/sort_waste/SubUSDs/textures/normal_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffa19106ab1ef542307afa48e779c169d23d534bb0acd7c99d986889a19f002c +size 196