Skip to content

Commit 91ac6a5

Browse files
committed
Planar projection :
- orithonornal_basis - project_to_plane - planar_projection
1 parent 07de3ef commit 91ac6a5

4 files changed

Lines changed: 191 additions & 0 deletions

File tree

libraries/stdlib/stdlib_defs.mtlx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,40 @@
14231423
<output name="out" type="vector3" doc="Offset surface normal; connect this to a shader's 'normal' input." />
14241424
</nodedef>
14251425

1426+
<!--
1427+
Node: <orthonormal_basis>
1428+
Compute orthonormal basis
1429+
-->
1430+
<nodedef name="ND_orthonormal_basis_1_0_vector3_vector3" node="orthonormal_basis" version="1.0" isdefaultversion="true" nodegroup="geometric" uiname="Orthonormal Basis" doc="Compute perpendicular basis vectors from a primary direction and normal">
1431+
<input name="primary_dir" type="vector3" value="1,0,0" uiname="Primary Direction" doc="Primary direction. Maps to U axis output" />
1432+
<input name="normal_dir" type="vector3" value="0,0,1" uiname="Normal Direction" doc="Normal direction." />
1433+
<output name="out_u_axis" type="vector3" uiname="U Axis"/>
1434+
<output name="out_v_axis" type="vector3" uiname="V Axis"/>
1435+
</nodedef>
1436+
1437+
<!--
1438+
Node: <project_to_plane>
1439+
Projection point to to infinite plane
1440+
-->
1441+
<nodedef name="ND_project_to_plane_1_0_vector3" node="project_to_plane" version="1.0" isdefaultversion="true" nodegroup="geometric" uiname="Project to Plane" doc="Project 3D point onto an infinite 3D plane">
1442+
<input name="point" type="vector3" value="0,0,0" uiname="Input Position" doc="Point to project" />
1443+
<input name="plane_origin" type="vector3" value="0,0,0" uiname="Plane Origin" doc="Position of the origin of the plane" />
1444+
<input name="plane_normal" type="vector3" value="0,0,1" uiname="Plane Normal" doc="Normal of the plane" />
1445+
<output name="out" type="vector3" uiname="Projected Position"/>
1446+
</nodedef>
1447+
1448+
<!--
1449+
Node: <planar_projection>
1450+
Planar projection of a 3d point to a plane to produce texture coordinates
1451+
-->
1452+
<nodedef name="ND_planar_projection_1_0_vector2" node="planar_projection" version="1.0" isdefaultversion="true" nodegroup="geometric" uiname="Planar UV Projection" doc="Compute texture coordinates of a projection of a 3d point to a plane">
1453+
<input name="point" type="vector3" value="0,0,0" uiname="Input Position" doc="Input position" />
1454+
<input name="plane_origin" type="vector3" value="0,0,0" uiname="Plane Origin" doc="Position of origin of the plane" />
1455+
<input name="plane_normal" type="vector3" value="0,0,1" uiname="Plane Normal" doc="Normal of the plane" />
1456+
<input name="u_vector" type="vector3" value="1,0,0" uiname="U Direction" doc="Specify the direction of U" />
1457+
<output name="out" type="vector2" uiname="UV Coordinates" />
1458+
</nodedef>
1459+
14261460
<!-- ======================================================================== -->
14271461
<!-- Application nodes -->
14281462
<!-- ======================================================================== -->

libraries/stdlib/stdlib_ng.mtlx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,95 @@
29042904
<output name="out" type="vector3" nodename="N_normalmap" />
29052905
</nodegraph>
29062906

2907+
<!--
2908+
Node: <orthonormal_basis>
2909+
-->
2910+
<nodegraph name="NG_orthonormal_basis_1_0_vector3_vector3" nodedef="ND_orthonormal_basis_1_0_vector3_vector3" doc="Compute perpendicular basis vectors from a primary direction and normal">
2911+
<normalize name="norm_primary" type="vector3">
2912+
<input name="in" type="vector3" interfacename="primary_dir" />
2913+
</normalize>
2914+
<normalize name="norm_normal" type="vector3">
2915+
<input name="in" type="vector3" interfacename="normal_dir" />
2916+
</normalize>
2917+
<dotproduct name="dot_primary_normal" type="float">
2918+
<input name="in1" type="vector3" nodename="norm_primary" />
2919+
<input name="in2" type="vector3" nodename="norm_normal" />
2920+
</dotproduct>
2921+
<multiply name="parallel_component" type="vector3">
2922+
<input name="in1" type="vector3" nodename="norm_normal" />
2923+
<input name="in2" type="float" nodename="dot_primary_normal" />
2924+
</multiply>
2925+
<subtract name="ortho_u" type="vector3">
2926+
<input name="in1" type="vector3" nodename="norm_primary" />
2927+
<input name="in2" type="vector3" nodename="parallel_component" />
2928+
</subtract>
2929+
<normalize name="final_u" type="vector3">
2930+
<input name="in" type="vector3" nodename="ortho_u" />
2931+
</normalize>
2932+
<crossproduct name="final_v" type="vector3">
2933+
<input name="in1" type="vector3" nodename="norm_normal" />
2934+
<input name="in2" type="vector3" nodename="final_u" />
2935+
</crossproduct>
2936+
<output name="out_u_axis" type="vector3" nodename="final_u" />
2937+
<output name="out_v_axis" type="vector3" nodename="final_v" />
2938+
</nodegraph>
2939+
2940+
<!--
2941+
Node: <project_to_plane>
2942+
-->
2943+
<nodegraph name="NG_project_to_plane_1_0_vector3" nodedef="ND_project_to_plane_1_0_vector3" doc="Project 3D point onto an infinite 3D plane">
2944+
<subtract name="relative_pos" type="vector3">
2945+
<input name="in1" type="vector3" interfacename="point" />
2946+
<input name="in2" type="vector3" interfacename="plane_origin" />
2947+
</subtract>
2948+
<dotproduct name="signed_dist" type="float">
2949+
<input name="in1" type="vector3" nodename="relative_pos" />
2950+
<input name="in2" type="vector3" interfacename="plane_normal" />
2951+
</dotproduct>
2952+
<multiply name="offset_vec" type="vector3">
2953+
<input name="in1" type="vector3" interfacename="plane_normal" />
2954+
<input name="in2" type="float" nodename="signed_dist" />
2955+
</multiply>
2956+
<subtract name="projected_pos" type="vector3">
2957+
<input name="in1" type="vector3" nodename="relative_pos" />
2958+
<input name="in2" type="vector3" nodename="offset_vec" />
2959+
</subtract>
2960+
<output name="out" type="vector3" nodename="projected_pos" />
2961+
</nodegraph>
2962+
2963+
<!--
2964+
Node: <planar_projection>
2965+
-->
2966+
<nodegraph name="NG_planar_projection_1_0_vector2" nodedef="ND_planar_projection_1_0_vector2" doc="Compute texture coordinates of a projection of a 3d point to a plane">
2967+
<!-- Project position to plane -->
2968+
<project_to_plane name="point_proj" type="vector3">
2969+
<input name="point" type="vector3" interfacename="point" />
2970+
<input name="plane_origin" type="vector3" interfacename="plane_origin" />
2971+
<input name="plane_normal" type="vector3" interfacename="plane_normal" />
2972+
</project_to_plane>
2973+
<!-- Generate orthonormal basis -->
2974+
<orthonormal_basis name="basis_gen" type="multioutput">
2975+
<input name="primary_dir" type="vector3" interfacename="u_vector" />
2976+
<input name="normal_dir" type="vector3" interfacename="plane_normal" />
2977+
<output name="out_u_axis" type="vector3" />
2978+
<output name="out_v_axis" type="vector3" />
2979+
</orthonormal_basis>
2980+
<!-- Calculate UV coordinates -->
2981+
<dotproduct name="u_coord" type="float">
2982+
<input name="in1" type="vector3" nodename="point_proj" />
2983+
<input name="in2" type="vector3" nodename="basis_gen" output="out_u_axis" />
2984+
</dotproduct>
2985+
<dotproduct name="v_coord" type="float">
2986+
<input name="in1" type="vector3" nodename="point_proj" />
2987+
<input name="in2" type="vector3" nodename="basis_gen" output="out_v_axis" />
2988+
</dotproduct>
2989+
<combine2 name="combined_uv" type="vector2">
2990+
<input name="in1" type="float" nodename="u_coord" />
2991+
<input name="in2" type="float" nodename="v_coord" />
2992+
</combine2>
2993+
<output name="out" type="vector2" nodename="combined_uv" />
2994+
</nodegraph>
2995+
29072996
<!-- ======================================================================== -->
29082997
<!-- Global nodes -->
29092998
<!-- ======================================================================== -->

resources/Images/alpha_test.png

958 Bytes
Loading
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0"?>
2+
<materialx version="1.39" colorspace="lin_rec709">
3+
<position name="position_object" type="vector3">
4+
<input name="space" type="string" value="object" />
5+
</position>
6+
<position name="position_world" type="vector3">
7+
<input name="space" type="string" value="world" />
8+
</position>
9+
<planar_projection name="planar_projection_world" type="vector2">
10+
<input name="point" type="vector3" nodename="position_world" />
11+
<input name="plane_origin" type="vector3" value="0, 0, 0" />
12+
<input name="plane_normal" type="vector3" value="0, 0, 1" />
13+
<input name="u_vector" type="vector3" value="1, 0, 0" />
14+
</planar_projection>
15+
<surfacematerial name="project_material" type="material">
16+
<input name="surfaceshader" type="surfaceshader" nodename="project_shader" />
17+
</surfacematerial>
18+
<surface_unlit name="project_shader" type="surfaceshader">
19+
<input name="emission" type="float" value="1" />
20+
<input name="emission_color" type="color3" nodename="convert_color4" />
21+
<input name="transmission" type="float" value="0" />
22+
<input name="transmission_color" type="color3" value="1, 1, 1" />
23+
<input name="opacity" type="float" value="1" />
24+
</surface_unlit>
25+
<surfacematerial name="project_blend_material" type="material">
26+
<input name="surfaceshader" type="surfaceshader" nodename="project_shader_blend" />
27+
</surfacematerial>
28+
<surface_unlit name="project_shader_blend" type="surfaceshader">
29+
<input name="emission" type="float" value="1" />
30+
<input name="emission_color" type="color3" nodename="convert_color5" />
31+
<input name="transmission" type="float" value="0" />
32+
<input name="transmission_color" type="color3" value="1, 1, 1" />
33+
<input name="opacity" type="float" value="1" />
34+
</surface_unlit>
35+
<convert name="convert_color5" type="color3">
36+
<input name="in" type="color4" nodename="blend_images" />
37+
</convert>
38+
<image name="image_project_object" type="color4">
39+
<input name="file" type="filename" value="D:\Work\materialx\MaterialXLab\prototyping\image_diff\placeholder.png" colorspace="srgb_texture" fileprefix="" />
40+
<input name="layer" type="string" value="" />
41+
<input name="default" type="color4" value="0, 0, 0, 0" />
42+
<input name="texcoord" type="vector2" nodename="planar_projection_object" />
43+
<input name="uaddressmode" type="string" value="periodic" />
44+
<input name="vaddressmode" type="string" value="periodic" />
45+
</image>
46+
<planar_projection name="planar_projection_object" type="vector2">
47+
<input name="point" type="vector3" nodename="position_object" />
48+
<input name="plane_origin" type="vector3" value="0, 0, 0" />
49+
<input name="plane_normal" type="vector3" value="0, 1, 0" />
50+
<input name="u_vector" type="vector3" value="1, 0, 0" />
51+
</planar_projection>
52+
<image name="image_project_world" type="color4">
53+
<input name="file" type="filename" value="D:\Work\materialx\bernard_MaterialX\resources\Images\alpha_test.png" colorspace="srgb_texture" fileprefix="" />
54+
<input name="layer" type="string" value="" />
55+
<input name="default" type="color4" value="0, 0, 0, 0" />
56+
<input name="texcoord" type="vector2" nodename="planar_projection_world" />
57+
<input name="uaddressmode" type="string" value="periodic" />
58+
<input name="vaddressmode" type="string" value="periodic" />
59+
</image>
60+
<convert name="convert_color4" type="color3">
61+
<input name="in" type="color4" nodename="image_project_world" />
62+
</convert>
63+
<mix name="blend_images" type="color4">
64+
<input name="fg" type="color4" nodename="image_project_world" />
65+
<input name="bg" type="color4" nodename="image_project_object" />
66+
<input name="mix" type="color4" value="0.5, 0.5, 0.5, 0.5" />
67+
</mix>
68+
</materialx>

0 commit comments

Comments
 (0)