View Full Version : Node material output

02-17-2009, 10:41 AM
Hello everyone,
I've been trying to hunt down some odd behavior in a plugin I'm developing. The plugin has a material output, plus diffuse colour, vector bump and scalar reflection output if the user wishes to use them.
Now, when the plugin evaluates it will calculate colour, for example, when either the material output or diffuse colour output is connected. i.e. it is precisely the same code that is being executed in both these cases.
Without going into too much detail, the plugin I'm writing will call rayCast and fire a ray into the interior of the object only if that ray will hits another surface within a certain range limit will it will perform a rayTrace.

Now, here's the issue that I'm trying to get around or understand (I've attached a diagram to help explain the cause of my problem:
The green ray fired from the spot position in the diagram, the purple reflective surface is then ray traced, which causes another call to my shader's evaluate function.
The grey surface in the diagram should not be hit by the purple ray at all as it is not double sided. This is the case when dealing with the normal node outputs. However, when exactly the same code called by the material node output it seems to reflect off the surface when it should not.
I did a test to see what the highest bounce count was -with the regular node outputs the highest bounce count was 6, but with the material output the count went up to 16 which was then limit for the scene. From a visual inspection it seemed as though reflection had been added reflection values had been added over and over, as though rays were bouncing around inside the object, which shouldn't happen as the purple ray should just pass through the single sided polygon in the diagram.

The only difference in the code path is that the material has some extra code to calculate the reflection ray vector and ray trace in that direction denoted by the red reflected ray from the original spot in the diagram.

So why is it that the evaluation for a material node output is acting this way? (as though it were double sided for reflection rays or something similar) I can find no documentation about the vstack which I'm suspicious about being something to do with this. If vstacking is turned off then the problem goes away, but obviously breaks several key components of the shader. So are there constrains on using ray tracing in material nodes? What's going on here?

02-18-2009, 04:28 AM
Ok, the problem I encountered seemed to be that (perhaps) because of the renderer's vstack. (before I continue it appears that the purple bounce ray was not anything to do with my problem - the problem is simply ray tracing through polygons)
When I fired the ray into an object, it always seemed to hit a front facing polygon - from the diagram in the previous post I thought that the ray should just exit as the surface was not double sided, but it was registering a hit. I usually used a dot product test between the ray and the polygon normal to determine if my shader should shade this surface, but that failed here as it seemed like that internal to the renderer the polygon was double sided. I then switched to using if(na->flags & LWRT_POLYSIDE)...as a replacement for my dot product test. If this is false, then stop shading. All seems to be working well now.

02-18-2009, 03:37 PM
From your explanation I guess that renderer have no idea that your RayTrace() ray is refraction ray.. Don't know that it's flying inside of some material.. Did you try using RayTraceMode() with proper index of refraction to inform renderer that it's inside of material?

02-21-2009, 06:56 AM
Sorry for the delay Sensei.
Yes I did try that and it made no difference. Like I said, the cause was really the evaluation of the surface, regardless of the polyside that was hit.