1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
|
/*******************************************************************************
* normal.cpp
*
* This module implements solid texturing functions that perturb the surface
* normal to create a bumpy effect.
*
* ---------------------------------------------------------------------------
* Persistence of Vision Ray Tracer ('POV-Ray') version 3.7.
* Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd.
*
* POV-Ray is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* POV-Ray is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------------
* POV-Ray is based on the popular DKB raytracer version 2.12.
* DKBTrace was originally written by David K. Buck.
* DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
* ---------------------------------------------------------------------------
* $File: //depot/public/povray/3.x/source/backend/texture/normal.cpp $
* $Revision: #1 $
* $Change: 6069 $
* $DateTime: 2013/11/06 11:59:40 $
* $Author: chrisc $
*******************************************************************************/
/*
* Some texture ideas garnered from SIGGRAPH '85 Volume 19 Number 3,
* "An Image Synthesizer" By Ken Perlin.
*
* Further Ideas Garnered from "The RenderMan Companion" (Addison Wesley)
*/
// frame.h must always be the first POV file included (pulls in platform config)
#include "backend/frame.h"
#include "backend/texture/normal.h"
#include "backend/texture/texture.h"
#include "backend/texture/pigment.h"
#include "backend/support/imageutil.h"
#include "backend/scene/objects.h"
#include "backend/scene/threaddata.h"
#include "backend/math/vector.h"
#include "base/pov_err.h"
// this must be the last file included
#include "base/povdebug.h"
namespace pov
{
/*****************************************************************************
* Local preprocessor defines
******************************************************************************/
/*****************************************************************************
* Local typedefs
******************************************************************************/
/*****************************************************************************
* Local constants
******************************************************************************/
static const VECTOR Pyramid_Vect [4]= {{ 0.942809041,-0.333333333, 0.0},
{-0.471404521,-0.333333333, 0.816496581},
{-0.471404521,-0.333333333,-0.816496581},
{ 0.0 , 1.0 , 0.0}};
/*****************************************************************************
* Static functions
******************************************************************************/
static void ripples (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR Vector, const TraceThreadData *Thread);
static void waves (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR Vector, const TraceThreadData *Thread);
static void bumps (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal);
static void dents (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, const TraceThreadData *Thread);
static void wrinkles (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal);
static void quilted (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal);
static DBL Hermite_Cubic (DBL T1, const UV_VECT UV1, const UV_VECT UV2);
static DBL Do_Slope_Map (DBL value, const BLEND_MAP *Blend_Map);
static void Do_Average_Normals (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, Intersection *Inter, const Ray *ray, TraceThreadData *Thread);
static void facets (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, TraceThreadData *Thread);
/*****************************************************************************
*
* FUNCTION
*
* ripples
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
static void ripples (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, const TraceThreadData *Thread)
{
unsigned int i;
DBL length, scalar, index;
VECTOR point;
for (i = 0 ; i < Thread->numberOfWaves ; i++)
{
VSub (point, EPoint, *Thread->waveSources[i]);
VLength (length, point);
if (length == 0.0)
length = 1.0;
index = length * Tnormal->Frequency + Tnormal->Phase;
scalar = cycloidal(index) * Tnormal ->Amount;
VAddScaledEq(normal, scalar / (length * (DBL)Thread->numberOfWaves), point);
}
}
/*****************************************************************************
*
* FUNCTION
*
* waves
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
static void waves (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, const TraceThreadData *Thread)
{
unsigned int i;
DBL length, scalar, index, sinValue ;
VECTOR point;
for (i = 0 ; i < Thread->numberOfWaves ; i++)
{
VSub (point, EPoint, *Thread->waveSources[i]);
VLength (length, point);
if (length == 0.0)
{
length = 1.0;
}
index = length * Tnormal->Frequency * Thread->waveFrequencies[i] + Tnormal->Phase;
sinValue = cycloidal(index);
scalar = sinValue * Tnormal->Amount / Thread->waveFrequencies[i];
VAddScaledEq(normal, scalar / (length * (DBL)Thread->numberOfWaves), point);
}
}
/*****************************************************************************
*
* FUNCTION
*
* bumps
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
static void bumps (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal)
{
VECTOR bump_turb;
/* Get normal displacement value. */
DNoise (bump_turb, EPoint);
/* Displace "normal". */
VAddScaledEq(normal, Tnormal->Amount, bump_turb);
}
/*****************************************************************************
*
* FUNCTION
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
* Dents is similar to bumps, but uses noise() to control the amount of
* dnoise() perturbation of the object normal...
*
* CHANGES
*
******************************************************************************/
static void dents (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, const TraceThreadData *Thread)
{
DBL noise;
VECTOR stucco_turb;
noise = Noise (EPoint, GetNoiseGen(reinterpret_cast<const TPATTERN *>(Tnormal), Thread));
noise = noise * noise * noise * Tnormal->Amount;
/* Get normal displacement value. */
DNoise(stucco_turb, EPoint);
/* Displace "normal". */
VAddScaledEq(normal, noise, stucco_turb);
}
/*****************************************************************************
*
* FUNCTION
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* Wrinkles - This is my implementation of the dented() routine, using
* a surface iterative fractal derived from DTurbulence.
*
* This is a 3-D version (thanks to DNoise()...) of the usual version
* using the singular Noise()...
*
* Seems to look a lot like wrinkles, however... (hmmm)
*
* Idea garnered from the April 89 Byte Graphics Supplement on RenderMan,
* refined from "The RenderMan Companion, by Steve Upstill of Pixar,
* (C) 1990 Addison-Wesley.
*
* CHANGES
*
******************************************************************************/
static void wrinkles (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal)
{
int i;
DBL scale = 1.0;
VECTOR result, value, value2;
Make_Vector(result, 0.0, 0.0, 0.0);
for (i = 0; i < 10; scale *= 2.0, i++)
{
VScale(value2,EPoint,scale);
DNoise(value, value2);
result[X] += fabs(value[X] / scale);
result[Y] += fabs(value[Y] / scale);
result[Z] += fabs(value[Z] / scale);
}
/* Displace "normal". */
VAddScaledEq(normal, Tnormal->Amount, result);
}
/*****************************************************************************
*
* FUNCTION
*
* quilted
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* Dan Farmer '94
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
static void quilted (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal)
{
VECTOR value;
DBL t;
value[X] = EPoint[X]-FLOOR(EPoint[X])-0.5;
value[Y] = EPoint[Y]-FLOOR(EPoint[Y])-0.5;
value[Z] = EPoint[Z]-FLOOR(EPoint[Z])-0.5;
t = sqrt(value[X]*value[X]+value[Y]*value[Y]+value[Z]*value[Z]);
t = quilt_cubic(t, Tnormal->Vals.Quilted.Control0, Tnormal->Vals.Quilted.Control1);
value[X] *= t;
value[Y] *= t;
value[Z] *= t;
VAddScaledEq (normal, Tnormal->Amount,value);
}
/*****************************************************************************
*
* FUNCTION
*
* facets
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* Ronald Parker '98
*
* DESCRIPTION
*
* This pattern is based on the "Crackle" pattern and creates a faceted
* look on a curved surface.
*
* CHANGES
*
******************************************************************************/
static void facets (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, TraceThreadData *Thread)
{
int i;
int thisseed;
DBL sum, minsum;
VECTOR sv, tv, dv, t1, add, newnormal, pert;
DBL scale;
int UseSquare;
int UseUnity;
DBL Metric;
VECTOR *cv = Thread->Facets_Cube;
Metric = Tnormal->Vals.Facets.Metric;
UseSquare = (Metric == 2 );
UseUnity = (Metric == 1 );
VNormalize( normal, normal );
if ( Tnormal->Vals.Facets.UseCoords )
{
Assign_Vector(tv,EPoint);
}
else
{
Assign_Vector(tv,normal);
}
if ( Tnormal->Vals.Facets.Size < 1e-6 )
{
scale = 1e6;
}
else
{
scale = 1. / Tnormal->Vals.Facets.Size;
}
VScaleEq( tv, scale );
/*
* Check to see if the input point is in the same unit cube as the last
* call to this function, to use cache of cubelets for speed.
*/
thisseed = PickInCube(tv, t1);
if (thisseed != Thread->Facets_Last_Seed)
{
/*
* No, not same unit cube. Calculate the random points for this new
* cube and its 80 neighbours which differ in any axis by 1 or 2.
* Why distance of 2? If there is 1 point in each cube, located
* randomly, it is possible for the closest random point to be in the
* cube 2 over, or the one two over and one up. It is NOT possible
* for it to be two over and two up. Picture a 3x3x3 cube with 9 more
* cubes glued onto each face.
*/
/* Now store a points for this cube and each of the 80 neighbour cubes. */
int cvc = 0;
for (add[X] = -2.0; add[X] < 2.5; add[X] +=1.0)
{
for (add[Y] = -2.0; add[Y] < 2.5; add[Y] += 1.0)
{
for (add[Z] = -2.0; add[Z] < 2.5; add[Z] += 1.0)
{
/* For each cubelet in a 5x5 cube. */
if ((fabs(add[X])>1.5)+(fabs(add[Y])>1.5)+(fabs(add[Z])>1.5) <= 1.0)
{
/* Yes, it's within a 3d knight move away. */
VAdd(sv, tv, add);
PickInCube(sv, t1);
cv[cvc][X] = t1[X];
cv[cvc][Y] = t1[Y];
cv[cvc][Z] = t1[Z];
cvc++;
}
}
}
}
Thread->Facets_Last_Seed = thisseed;
Thread->Facets_CVC = cvc;
}
/*
* Find the point with the shortest distance from the input point.
*/
VSub(dv, cv[0], tv);
if ( UseSquare )
{
minsum = VSumSqr(dv);
}
else if ( UseUnity )
{
minsum = dv[X]+dv[Y]+dv[Z];
}
else
{
minsum = pow(fabs(dv[X]), Metric)+
pow(fabs(dv[Y]), Metric)+
pow(fabs(dv[Z]), Metric);
}
Assign_Vector( newnormal, cv[0] );
/* Loop for the 81 cubelets to find closest. */
for (i = 1; i < Thread->Facets_CVC; i++)
{
VSub(dv, cv[i], tv);
if ( UseSquare )
{
sum = VSumSqr(dv);
}
else
{
if ( UseUnity )
{
sum = dv[X]+dv[Y]+dv[Z];
}
else
{
sum = pow(fabs(dv[X]), Metric)+
pow(fabs(dv[Y]), Metric)+
pow(fabs(dv[Z]), Metric);
}
}
if (sum < minsum)
{
minsum = sum;
Assign_Vector( newnormal, cv[i] );
}
}
if ( Tnormal->Vals.Facets.UseCoords )
{
DNoise( pert, newnormal );
VDot( sum, pert, normal );
VScale( newnormal, normal, sum );
VSubEq( pert, newnormal );
VAddScaledEq( normal, Tnormal->Vals.Facets.UseCoords, pert );
}
else
{
Assign_Vector( normal, newnormal );
}
}
/*****************************************************************************
*
* FUNCTION
*
* Create_Tnormal
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* pointer to the created Tnormal
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION : Allocate memory for new Tnormal and initialize it to
* system default values.
*
* CHANGES
*
******************************************************************************/
TNORMAL *Create_Tnormal ()
{
TNORMAL *New;
New = reinterpret_cast<TNORMAL *>(POV_MALLOC(sizeof(TNORMAL), "normal"));
Init_TPat_Fields(reinterpret_cast<TPATTERN *>(New));
New->Amount = 0.5;
/* NK delta */
New->Delta = (float)0.02; /* this is a good starting point for delta */
return (New);
}
/*****************************************************************************
*
* FUNCTION
*
* Copy_Tnormal
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
TNORMAL *Copy_Tnormal (const TNORMAL *Old)
{
TNORMAL *New;
if (Old != NULL)
{
New = Create_Tnormal();
Copy_TPat_Fields (reinterpret_cast<TPATTERN *>(New), reinterpret_cast<const TPATTERN *>(Old));
New->Amount = Old->Amount;
New->Delta = Old->Delta;
}
else
{
New = NULL;
}
return (New);
}
/*****************************************************************************
*
* FUNCTION
*
* Destroy_Tnormal
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
void Destroy_Tnormal(TNORMAL *Tnormal)
{
if (Tnormal != NULL)
{
Destroy_TPat_Fields (reinterpret_cast<TPATTERN *>(Tnormal));
POV_FREE(Tnormal);
}
}
/*****************************************************************************
*
* FUNCTION
*
* Post_Tnormal
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
void Post_Tnormal (TNORMAL *Tnormal)
{
int i;
BLEND_MAP *Map;
if (Tnormal != NULL)
{
if (Tnormal->Flags & POST_DONE)
{
return;
}
if (Tnormal->Type == NO_PATTERN)
{
throw POV_EXCEPTION_STRING("No normal type given.");
}
Tnormal->Flags |= POST_DONE;
if ((Map = Tnormal->Blend_Map) != NULL)
{
for (i = 0; i < Map->Number_Of_Entries; i++)
{
switch (Map->Type)
{
case PIGMENT_TYPE:
Post_Pigment(Map->Blend_Map_Entries[i].Vals.Pigment);
break;
case NORMAL_TYPE:
Map->Blend_Map_Entries[i].Vals.Tnormal->Flags |=
(Tnormal->Flags & DONT_SCALE_BUMPS_FLAG);
Post_Tnormal(Map->Blend_Map_Entries[i].Vals.Tnormal);
break;
case TEXTURE_TYPE:
Post_Textures(Map->Blend_Map_Entries[i].Vals.Texture);
break;
case SLOPE_TYPE:
case COLOUR_TYPE:
case PATTERN_TYPE:
break;
default:
throw POV_EXCEPTION_STRING("Unknown pattern type in Post_Tnormal.");
}
}
}
}
}
/*****************************************************************************
*
* FUNCTION
*
* Perturb_Normal
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* POV-Ray Team
*
* DESCRIPTION
*
* CHANGES
* Added intersectin parameter for UV mapping - NK 1998
*
******************************************************************************/
void Perturb_Normal(VECTOR Layer_Normal, const TNORMAL *Tnormal, const VECTOR EPoint, Intersection *Intersection, const Ray *ray, TraceThreadData *Thread)
{
VECTOR TPoint,P1;
DBL value1,value2,Amount;
int i;
const BLEND_MAP *Blend_Map;
const BLEND_MAP_ENTRY *Prev, *Cur;
if (Tnormal==NULL)
{
return;
}
/* If normal_map present, use it and return */
if ((Blend_Map=Tnormal->Blend_Map) != NULL)
{
if ((Blend_Map->Type == NORMAL_TYPE) && (Tnormal->Type == UV_MAP_PATTERN))
{
UV_VECT UV_Coords;
Cur = &(Tnormal->Blend_Map->Blend_Map_Entries[0]);
/* Don't bother warping, simply get the UV vect of the intersection */
Intersection->Object->UVCoord(UV_Coords, Intersection, Thread);
TPoint[X] = UV_Coords[U];
TPoint[Y] = UV_Coords[V];
TPoint[Z] = 0;
Perturb_Normal(Layer_Normal,Cur->Vals.Tnormal,TPoint,Intersection,ray,Thread);
VNormalizeEq(Layer_Normal);
Assign_Vector(Intersection->PNormal, Layer_Normal); /* -hdf- June 98 */
return;
}
else if ((Blend_Map->Type == NORMAL_TYPE) && (Tnormal->Type != AVERAGE_PATTERN))
{
/* NK 19 Nov 1999 added Warp_EPoint */
Warp_EPoint (TPoint, EPoint, reinterpret_cast<const TPATTERN *>(Tnormal));
value1 = Evaluate_TPat(reinterpret_cast<const TPATTERN *>(Tnormal),TPoint,Intersection,ray,Thread);
Search_Blend_Map (value1,Blend_Map,&Prev,&Cur);
Warp_Normal(Layer_Normal,Layer_Normal, reinterpret_cast<const TPATTERN *>(Tnormal), Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
Assign_Vector(P1,Layer_Normal);
Warp_EPoint (TPoint, EPoint, reinterpret_cast<const TPATTERN *>(Tnormal));
Perturb_Normal(Layer_Normal,Cur->Vals.Tnormal,TPoint,Intersection,ray,Thread);
if (Prev != Cur)
{
Perturb_Normal(P1,Prev->Vals.Tnormal,TPoint,Intersection,ray,Thread);
value2 = (value1-Prev->value)/(Cur->value-Prev->value);
value1 = 1.0-value2;
VLinComb2(Layer_Normal,value1,P1,value2,Layer_Normal);
}
UnWarp_Normal(Layer_Normal,Layer_Normal, reinterpret_cast<const TPATTERN *>(Tnormal), Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
VNormalizeEq(Layer_Normal);
Assign_Vector(Intersection->PNormal, Layer_Normal); /* -hdf- June 98 */
return;
}
}
/* No normal_map. */
if (Tnormal->Type <= LAST_NORM_ONLY_PATTERN)
{
Warp_Normal(Layer_Normal,Layer_Normal, reinterpret_cast<const TPATTERN *>(Tnormal),
Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
Warp_EPoint (TPoint, EPoint, reinterpret_cast<const TPATTERN *>(Tnormal));
switch (Tnormal->Type)
{
case BITMAP_PATTERN: bump_map (TPoint, Tnormal, Layer_Normal); break;
case BUMPS_PATTERN: bumps (TPoint, Tnormal, Layer_Normal); break;
case DENTS_PATTERN: dents (TPoint, Tnormal, Layer_Normal, Thread); break;
case RIPPLES_PATTERN: ripples (TPoint, Tnormal, Layer_Normal, Thread); break;
case WAVES_PATTERN: waves (TPoint, Tnormal, Layer_Normal, Thread); break;
case WRINKLES_PATTERN: wrinkles (TPoint, Tnormal, Layer_Normal); break;
case QUILTED_PATTERN: quilted (TPoint, Tnormal, Layer_Normal); break;
case FACETS_PATTERN: facets (TPoint, Tnormal, Layer_Normal, Thread); break;
case AVERAGE_PATTERN: Do_Average_Normals (TPoint, Tnormal, Layer_Normal, Intersection, ray, Thread); break;
default:
throw POV_EXCEPTION_STRING("Normal pattern not yet implemented.");
}
UnWarp_Normal(Layer_Normal,Layer_Normal, reinterpret_cast<const TPATTERN *>(Tnormal),
Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
}
else
{
Warp_Normal(Layer_Normal,Layer_Normal, reinterpret_cast<const TPATTERN *>(Tnormal),
Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
Amount=Tnormal->Amount * -5.0; /*fudge factor*/
Amount*=0.02/Tnormal->Delta; /* NK delta */
/* warp the center point first - this is the last warp */
Warp_EPoint(TPoint,EPoint,reinterpret_cast<const TPATTERN *>(Tnormal));
for(i=0; i<=3; i++)
{
VAddScaled(P1,TPoint,Tnormal->Delta,Pyramid_Vect[i]); /* NK delta */
value1 = Do_Slope_Map(Evaluate_TPat(reinterpret_cast<const TPATTERN *>(Tnormal),P1,Intersection,ray,Thread),Blend_Map);
VAddScaledEq(Layer_Normal,value1*Amount,Pyramid_Vect[i]);
}
UnWarp_Normal(Layer_Normal,Layer_Normal,reinterpret_cast<const TPATTERN *>(Tnormal),
Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
}
if ( Intersection )
Assign_Vector(Intersection->PNormal, Layer_Normal); /* -hdf- June 98 */
}
/*****************************************************************************
*
* FUNCTION
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
static DBL Do_Slope_Map (DBL value, const BLEND_MAP *Blend_Map)
{
DBL Result;
const BLEND_MAP_ENTRY *Prev, *Cur;
if (Blend_Map == NULL)
{
return(value);
}
Search_Blend_Map (value,Blend_Map,&Prev,&Cur);
if (Prev == Cur)
{
return(Cur->Vals.Point_Slope[0]);
}
Result = (value-Prev->value)/(Cur->value-Prev->value);
return(Hermite_Cubic(Result, Prev->Vals.Point_Slope, Cur->Vals.Point_Slope));
}
/*****************************************************************************
*
* FUNCTION
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* DESCRIPTION
*
* CHANGES
*
******************************************************************************/
static DBL Hermite_Cubic(DBL T1, const UV_VECT UV1, const UV_VECT UV2)
{
DBL TT=T1*T1;
DBL TTT=TT*T1;
DBL rv; /* simplified equation for poor Symantec */
rv = TTT*(UV1[1]+UV2[1]+2.0*(UV1[0]-UV2[0]));
rv += -TT*(2.0*UV1[1]+UV2[1]+3.0*(UV1[0]-UV2[0]));
rv += T1*UV1[1] +UV1[0];
return (rv);
}
/*****************************************************************************
*
* FUNCTION
*
* INPUT
*
* OUTPUT
*
* RETURNS
*
* AUTHOR
*
* DESCRIPTION
*
* CHANGES
* Added intersectin parameter for UV mapping - NK 1998
*
******************************************************************************/
static void Do_Average_Normals (const VECTOR EPoint, const TNORMAL *Tnormal, VECTOR normal, Intersection *Inter, const Ray *ray, TraceThreadData *Thread)
{
int i;
BLEND_MAP *Map = Tnormal->Blend_Map;
SNGL Value;
SNGL Total = 0.0;
VECTOR V1,V2;
Make_Vector (V1, 0.0, 0.0, 0.0);
for (i = 0; i < Map->Number_Of_Entries; i++)
{
Value = Map->Blend_Map_Entries[i].value;
Assign_Vector(V2,normal);
Perturb_Normal(V2,Map->Blend_Map_Entries[i].Vals.Tnormal,EPoint,Inter,ray,Thread);
VAddScaledEq(V1,Value,V2);
Total += Value;
}
VInverseScale(normal,V1,Total);
}
}
|