This is my first post here, so welcome to everyone.
I have a scene with a sphere and some cubes between the sphere and camera. All cubes have primary visibility turned off and double sided turned on. Now, I want my shader to count intersections between shaded point P and camera.
I came up with something like this:
shader_evaluate { AtPoint pw = sg->P; AtVector av = -sg->Rd; AtVector an = sg->N; AtPoint pnt = sg->P; int hitnum = 0; AtShaderGlobals* hitpoint = AiShaderGlobals(); AtRay ar; double maxLength = 1000; AiMakeRay(&ar, AI_RAY_ALL, &pnt, &av, maxLength, sg); bool hit = AiTraceProbe(&ar, hitpoint); AtColor ac = AiColor(pw.x, pw.y, pw.z); while (hit) { hitnum++; pnt = hitpoint->P; av = hitpoint->Rd; AiMakeRay(&ar, AI_RAY_ALL, &pnt, &av, maxLength, hitpoint); hit = AiTraceProbe(&ar, hitpoint); } float res = hitnum; ac = AiColor(res, res, res); sg->out.RGB = ac; }
Unfortunately, I get only 2 intersections in rendered image, even when there are two or more cubes between observer and shaded sphere. Question is, what's wrong with my shader?
Version: MtoA 1.4.2.1
Solved! Go to Solution.
Solved by maxtarpini. Go to Solution.
Just an hint. Are you color picking the color managed result to check your hits ? Because then it's correct.. those are the resulting intersections.. in gamma space however. In facts if you were expecting 6 intersections .. 6^(1/2.2) ~= 2
I'm afraid it's not it. Please, have a look at the rendered image. I divided it by 2, to better see the result. As you can see, I get two values - 1.0 and 2.0, arranged in a strange way. I have no idea, why it renders like that. I must have done something wrong, but I can't figure out what 🙂
Try changing the ray type.. from AI_RAY_ALL to anything like AI_RAY_ALL_DIFFUSE .. it's working here .. the former type probably gets some internal massage. Side view it's just to see the setup, cubes are in front of the camera in the persp view. You see RGBA returns correctly 6, while gamma'ed value is around 2 as pointed above.