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); }
You can replace:
dist = offset.offset;
by:
dist = AiV3Dot(offset, offset);
There's loads of implementations of this specific noise pattern online for you to look at, e.g: https://github.com/sambler/osl-shaders/blob/master/lib/noises_osl.h#L190
You can also use the AiCellular function in the procedural texturing API to do this more easily. And if you're just looking for voronoi cells, I believe that's what the flakes shader uses under the hood. Just turn the density up.
Thank you very much for your advice!!
AiCellular function looks extremely useful, but since I am such a beginner in writing shaders and don't know much about C++, I've just got stuck on how to use AiCellular function.. I googled about void function, but I haven't figured out how I can implement AiCellular function into the code...
Please help me if you already have used the function before.
When it comes to the flakes shader, I tried and found this is what I was looking for!! I will definitely use in the near future, but for now I would like to write the shader one in order to get used to coding shaders in C++.
Thank you very much for your advice!!
The link is really great for my study!! I will read it this weekend:)