int Compute_Pigment (COLOUR Colour, PIGMENT *Pigment, VECTOR EPoint, INTERSECTION *Intersect) { int Colour_Found; VECTOR TPoint; DBL value; register DBL fraction; BLEND_MAP_ENTRY *Cur, *Prev; COLOUR Temp_Colour; BLEND_MAP *Blend_Map = Pigment->Blend_Map; UV_VECT UV_Coords; if (Pigment->Type <= LAST_SPECIAL_PATTERN) { Colour_Found = true; switch (Pigment->Type) { case NO_PATTERN: Make_Colour(Colour, 0.0, 0.0, 0.0); break; case PLAIN_PATTERN: Assign_Colour(Colour,Pigment->Colour); break; case AVERAGE_PATTERN: Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment); Do_Average_Pigments(Colour,Pigment,TPoint,Intersect); break; case UV_MAP_PATTERN: if(Intersect == NULL) Error("The 'uv_mapping' pattern cannot be used as part of a pigment function!"); Cur = &(Pigment->Blend_Map->Blend_Map_Entries[0]); if (Blend_Map->Type == COLOUR_TYPE) { Colour_Found = true; Assign_Colour(Colour, Cur->Vals.Colour); } else { /* Don't bother warping, simply get the UV vect of the intersection */ UVCoord(UV_Coords, Intersect->Object, Intersect); TPoint[X] = UV_Coords[U]; TPoint[Y] = UV_Coords[V]; TPoint[Z] = 0; if (Compute_Pigment(Colour, Cur->Vals.Pigment,TPoint,Intersect)) { Colour_Found = true; } } break; case BITMAP_PATTERN: Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment); Make_Colour(Colour, 0.0, 0.0, 0.0); Colour_Found = image_map (TPoint, Pigment, Colour); break; default: Error("Pigment type %d not yet implemented",Pigment->Type); } return(Colour_Found); } Colour_Found = false; /* NK 19 Nov 1999 added Warp_EPoint */ Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment); value = Evaluate_TPat ((TPATTERN *)Pigment,TPoint,Intersect); Search_Blend_Map (value, Blend_Map, &Prev, &Cur); if (Blend_Map->Type == COLOUR_TYPE) { Colour_Found = true; Assign_Colour(Colour, Cur->Vals.Colour); } else { Warp_EPoint (TPoint, EPoint, (TPATTERN *)Pigment); if (Compute_Pigment(Colour, Cur->Vals.Pigment,TPoint,Intersect)) { Colour_Found = true; } } if (Prev != Cur) { if (Blend_Map->Type == COLOUR_TYPE) { Colour_Found = true; Assign_Colour(Temp_Colour, Prev->Vals.Colour); } else { if (Compute_Pigment(Temp_Colour, Prev->Vals.Pigment, TPoint,Intersect)) { Colour_Found = true; } } fraction = (value - Prev->value) / (Cur->value - Prev->value); Colour[pRED] = Temp_Colour[pRED] + fraction * (Colour[pRED] - Temp_Colour[pRED]); Colour[pGREEN] = Temp_Colour[pGREEN] + fraction * (Colour[pGREEN] - Temp_Colour[pGREEN]); Colour[pBLUE] = Temp_Colour[pBLUE] + fraction * (Colour[pBLUE] - Temp_Colour[pBLUE]); Colour[pFILTER] = Temp_Colour[pFILTER] + fraction * (Colour[pFILTER] - Temp_Colour[pFILTER]); Colour[pTRANSM] = Temp_Colour[pTRANSM] + fraction * (Colour[pTRANSM] - Temp_Colour[pTRANSM]); } return(Colour_Found); }
bool Compute_Pigment (Colour& colour, const PIGMENT *Pigment, const VECTOR EPoint, const Intersection *Intersect, const Ray *ray, TraceThreadData *Thread) { int Colour_Found; VECTOR TPoint; DBL value; register DBL fraction; const BLEND_MAP_ENTRY *Cur, *Prev; Colour Temp_Colour; const BLEND_MAP *Blend_Map = Pigment->Blend_Map; UV_VECT UV_Coords; if ((Thread->qualityFlags & Q_QUICKC) != 0 && Pigment->Quick_Colour[pRED] != -1.0 && Pigment->Quick_Colour[pGREEN] != -1.0 && Pigment->Quick_Colour[pBLUE] != -1.0) { colour = Pigment->Quick_Colour; return (true); } if (Pigment->Type <= LAST_SPECIAL_PATTERN) { Colour_Found = true; switch (Pigment->Type) { case NO_PATTERN: colour.clear(); break; case PLAIN_PATTERN: colour = Pigment->colour; break; case AVERAGE_PATTERN: Warp_EPoint (TPoint, EPoint, reinterpret_cast<const TPATTERN *>(Pigment)); Do_Average_Pigments(colour, Pigment, TPoint, Intersect, ray, Thread); break; case UV_MAP_PATTERN: if(Intersect == NULL) throw POV_EXCEPTION_STRING("The 'uv_mapping' pattern cannot be used as part of a pigment function!"); Cur = &(Pigment->Blend_Map->Blend_Map_Entries[0]); if (Blend_Map->Type == COLOUR_TYPE) { Colour_Found = true; Assign_Colour(*colour, Cur->Vals.colour); } else { /* Don't bother warping, simply get the UV vect of the intersection */ Intersect->Object->UVCoord(UV_Coords, Intersect, Thread); TPoint[X] = UV_Coords[U]; TPoint[Y] = UV_Coords[V]; TPoint[Z] = 0; if (Compute_Pigment(colour, Cur->Vals.Pigment,TPoint,Intersect, ray, Thread)) Colour_Found = true; } break; case BITMAP_PATTERN: Warp_EPoint (TPoint, EPoint, reinterpret_cast<const TPATTERN *>(Pigment)); colour.clear(); Colour_Found = image_map (TPoint, Pigment, colour); break; default: throw POV_EXCEPTION_STRING("Pigment type not yet implemented."); } return(Colour_Found); } Colour_Found = false; /* NK 19 Nov 1999 added Warp_EPoint */ Warp_EPoint (TPoint, EPoint, reinterpret_cast<const TPATTERN *>(Pigment)); value = Evaluate_TPat (reinterpret_cast<const TPATTERN *>(Pigment),TPoint,Intersect, ray, Thread); Search_Blend_Map (value, Blend_Map, &Prev, &Cur); if (Blend_Map->Type == COLOUR_TYPE) { Colour_Found = true; Assign_Colour(*colour, Cur->Vals.colour); } else { Warp_EPoint (TPoint, EPoint, reinterpret_cast<const TPATTERN *>(Pigment)); if (Compute_Pigment(colour, Cur->Vals.Pigment,TPoint,Intersect, ray, Thread)) Colour_Found = true; } if (Prev != Cur) { if (Blend_Map->Type == COLOUR_TYPE) { Colour_Found = true; Assign_Colour(*Temp_Colour, Prev->Vals.colour); } else { if (Compute_Pigment(Temp_Colour, Prev->Vals.Pigment, TPoint, Intersect, ray, Thread)) Colour_Found = true; } fraction = (value - Prev->value) / (Cur->value - Prev->value); colour = Temp_Colour + fraction * (colour - Temp_Colour); } return(Colour_Found); }
bool Compute_Pigment (TransColour& colour, const PIGMENT *Pigment, const Vector3d& EPoint, const Intersection *Intersect, const Ray *ray, TraceThreadData *Thread) { bool Colour_Found; Vector3d TPoint; DBL value; if (Thread->qualityFlags.quickColour && Pigment->Quick_Colour.IsValid()) { colour = Pigment->Quick_Colour; return (true); } if (Pigment->Type <= LAST_SPECIAL_PATTERN) { Colour_Found = true; switch (Pigment->Type) { case NO_PATTERN: assert(false); // should have been forced to PLAIN_PATTERN in Post_Pigment colour.Clear(); break; case PLAIN_PATTERN: colour = Pigment->colour; break; case AVERAGE_PATTERN: Warp_EPoint (TPoint, EPoint, Pigment); Do_Average_Pigments(colour, Pigment, TPoint, Intersect, ray, Thread); break; case UV_MAP_PATTERN: if(Intersect == NULL) throw POV_EXCEPTION_STRING("The 'uv_mapping' pattern cannot be used as part of a pigment function!"); Colour_Found = Pigment->Blend_Map->ComputeUVMapped(colour, Intersect, ray, Thread); break; case BITMAP_PATTERN: Warp_EPoint (TPoint, EPoint, Pigment); colour.Clear(); Colour_Found = image_map (TPoint, Pigment, colour); break; default: throw POV_EXCEPTION_STRING("Pigment type not yet implemented."); } return(Colour_Found); } /* NK 19 Nov 1999 added Warp_EPoint */ Warp_EPoint (TPoint, EPoint, Pigment); value = Evaluate_TPat (Pigment, TPoint, Intersect, ray, Thread); return Pigment->Blend_Map->Compute (colour, value, TPoint, Intersect, ray, Thread); }