Message 1 of 6
Can't convert Renderman's Voronoi cell noise into the one for Arnold Maya in C++
Not applicable
09-17-2018
05:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am writing voronoi cell noise for Arnold Maya in C++ for study by reading Advanced Renderman.
Although Writing fbm noise was easily done, I am stuck on creating voronoi cell noise for long time..
I could compile the voronoi cell noise, but it affects nothing in Maya.
The following is the code. I hope someone know what caused the issue.
Also, it would be really awesome if you could give some advice to me since I am still a beginner in C++ and don't know if I could convert all the code from Renderman to Arnold properly.
Thanks,
#include <ai.h>
AI_SHADER_NODE_EXPORT_METHODS(cellNoiseMtd);
enum cellNoiseParams { p_jitter };
node_parameters
{
AiParameterFlt("jitter", 0.5);
}
node_initialize{}
node_update{}
node_finish{}
float voronoi_f1_3d(AtVector PP, float jitter)
{
AtVector thiscell;
AtVector testcell;
AtVector pos;
AtVector offset;
float f1, dist;
AtVector pos1;
thiscell = (floor(PP.x) + 0.5, floor(PP.y) + 0.5, floor(PP.z) + 0.5);
f1 = 1000;
float i, j, k;
for (i = -1; i <= 1; i += 1) {
for (j = -1; j <= 1; j += 1) {
for (k = -1; k <= 1; k += 1) {
testcell = thiscell + (i, j, k);
pos = testcell + jitter * (AiCellNoise3(testcell) - 0.5);
offset = pos - PP;
dist = 0.5; //This line was originally "float dist = offset.offset;" in Advanced Renderman, but I really couldn't find how this can be converted properly for Arnold Maya, so please let me know if someone know the solution.
if (dist < f1) {
f1 = dist; pos1 = pos;
}
}
}
}
f1 = AiSqr(f1);
return f1;
}
shader_evaluate
{
float jitter = AiShaderEvalParamFlt(p_jitter);
AtVector PP;
PP = sg->P;
sg->out.RGB() = voronoi_f1_3d(PP, jitter);
}