Getting the face being rendered

On 01/06/2014 at 15:50, xxxxxxxx wrote:

I'm creating a shader and I need to know what face is being rendered (the index of the face).
I already have the object that is being rendered (the shader works in junction with a tag and it is easy to get the object that is using the tag) and the object must ALWAYS be polygonal.
So, inside my shader I already have the object and I'm sure it is polygonal.
But I want to know how to be able to find what face is being rendered.
I tried using something like this:

def Output(self, sh, cd) :
     if the_tag is not None:
          if op_type != c4d.Opolygon: return c4d.Vector(0) # return black if it isn't a polygonal object

if cd.vd: #if shader is computated in 3d space



if hit is True:
                    print collision.GetIntersection(0)["face_id"]

return c4d.Vector(1.0,0,.5)
          else: #if shader is computated in 2d space
               return c4d.Vector(0.0,1.0,0.0)

But it is not detecting any intersection.
Am I doing it wrong?

On 01/06/2014 at 16:22, xxxxxxxx wrote:

Ok, found it.
Instead of simply using the ray.p value I defined:


And used the start variable in the Intersect instead of ray.p and it worked.
Also, I used GetNearestIntersection instead of GetIntersection.