Vectron Union sample

3D Studio Max Plugin (Export Script Plugins developed by [gk] and KilaD; Integrated Plugin developed by Karba)
Forum rules
Please post only in English in this subforum. For alternate language discussion please go here http://render.otoy.com/forum/viewforum.php?f=18
Post Reply
neonZorglub
OctaneRender Team
Posts: 1005
Joined: Sun Jul 31, 2016 10:08 pm

Here is a small sample to illustrate the use of sdf input parameter in a vectron osl code.
Vectron_001 object is the main object, performing an Union operation of 2 other Vectron objects.
Clicking the buttons 'input1' or 'input2' set 3dsmax in the node Pick mode. You then need to select another Vectron object (Vectron_002, Vectron_003)

union01.png
union_sample.zip
(88.03 KiB) Downloaded 196 times
Note that Bounds.X is set to 0 in the 2 vectron spheres, to avoid being rendered as normal vectron objects

Main vectron osl code:

#include "octane-oslintrin.h"
shader SmoothUnion(
_sdf input1 = _SDFDEF,
_sdf input2 = _SDFDEF,
float Radius = 1,
output _sdf result = _SDFDEF)
{
// pick the SDF parameters using random sampling and prefering the surface
// that is closer
if (hashnoise(P) < (input2.dist - input1.dist)/Radius + 0.5)
{
result = input1;
}
else
{
result = input2;
}

// calculate a new SDF surface from the two input surfaces:

// usually a union is just a minimum operation
result.dist = min(input1.dist, input2.dist);

// but to achieve a smooth transition between two SDFs, we modify the union
// to distort the two surfaces for areas where they have a similar distance,
// i.e. deltaDistances gets small (< r)
float deltaDistances = abs(input1.dist - input2.dist);
float distortion = max(Radius - deltaDistances, 0.0);
result.dist = result.dist - distortion*distortion*0.25/Radius;
}
Post Reply

Return to “Autodesk 3Ds Max”