Community
Arnold General Rendering Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't convert Renderman's Voronoi cell noise into the one for Arnold Maya in C++

5 REPLIES 5
Reply
Message 1 of 6
sone0206YA3T6
496 Views, 5 Replies

Can't convert Renderman's Voronoi cell noise into the one for Arnold Maya in C++

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.

2374-resultcellnoise.png

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);
}
Tags (2)
Labels (2)
5 REPLIES 5
Message 2 of 6
zenop
in reply to: sone0206YA3T6

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

Message 3 of 6
timh5D75Z
in reply to: sone0206YA3T6

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.

Message 4 of 6
sone0206YA3T6
in reply to: timh5D75Z

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.

Message 5 of 6
sone0206YA3T6
in reply to: timh5D75Z

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++.

Message 6 of 6
sone0206YA3T6
in reply to: zenop

Thank you very much for your advice!!

The link is really great for my study!! I will read it this weekend:)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report