~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/Lighting/lighting_shade.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
      gimp_vector3_add (&h, &lnormal, &v);
75
75
      gimp_vector3_normalize (&h);
76
76
 
77
 
      rv = MAX (0., gimp_vector3_inner_product (&n, &h));
 
77
      rv = MAX (0.01, gimp_vector3_inner_product (&n, &h));
78
78
      rv = pow (rv, mapvals.material.highlight);
79
79
      rv *= nl;
80
80
 
474
474
GimpRGB
475
475
get_ray_color_ref (GimpVector3 *position)
476
476
{
 
477
  GimpRGB      color_sum;
477
478
  GimpRGB      color_int;
478
479
  GimpRGB      light_color;
479
480
  GimpRGB      color, env_color;
480
 
  gint         x;
 
481
  gint         x, f;
481
482
  gdouble      xf, yf;
482
483
  GimpVector3  normal, *p, v, r;
483
484
  gint         k;
 
485
  gdouble      tmpval;
484
486
 
485
487
  pos_to_float (position->x, position->y, &xf, &yf);
486
488
 
487
489
  x = RINT (xf);
488
490
 
 
491
  if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
 
492
    normal = mapvals.planenormal;
 
493
  else
 
494
    normal = vertex_normals[1][(gint) RINT (xf)];
 
495
  gimp_vector3_normalize (&normal);
 
496
 
489
497
  if (mapvals.transparent_background && heights[1][x] == 0)
490
498
    {
491
 
      gimp_rgb_set_alpha (&light_color, 0.0);
 
499
      gimp_rgb_set_alpha (&color_sum, 0.0);
492
500
    }
493
501
  else
494
502
    {
 
503
      color = get_image_color (xf, yf, &f);
 
504
      color_sum = color;
 
505
      gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int);
 
506
 
495
507
      for (k = 0; k < NUM_LIGHTS; k++)
496
508
        {
 
509
          p = &mapvals.lightsource[k].direction;
 
510
 
497
511
          if (!mapvals.lightsource[k].active
498
512
              || mapvals.lightsource[k].type == NO_LIGHT)
499
513
            continue;
500
514
          else if (mapvals.lightsource[k].type == POINT_LIGHT)
501
515
            p = &mapvals.lightsource[k].position;
502
 
          else
503
 
            p = &mapvals.lightsource[k].direction;
504
516
 
505
517
          color_int = mapvals.lightsource[k].color;
506
518
          gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity);
507
519
 
508
 
          if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
509
 
            {
510
 
              light_color = phong_shade (position,
511
 
                                         &mapvals.viewpoint,
512
 
                                         &mapvals.planenormal,
513
 
                                         p,
514
 
                                         &color,
515
 
                                         &color_int,
516
 
                                         mapvals.lightsource[0].type);
517
 
            }
518
 
          else
519
 
            {
520
 
              normal = vertex_normals[1][(gint) RINT (xf)];
521
 
 
522
 
              gimp_vector3_sub (&v, &mapvals.viewpoint,position);
523
 
              gimp_vector3_normalize (&v);
524
 
 
525
 
              r = compute_reflected_ray (&normal, &v);
526
 
 
527
 
              /* Get color in the direction of r */
528
 
              /* =============================== */
529
 
 
530
 
              sphere_to_image (&r, &xf, &yf);
531
 
              env_color = peek_env_map (RINT (env_width * xf),
532
 
                                        RINT (env_height * yf));
533
 
 
534
 
              light_color = phong_shade (position,
535
 
                                         &mapvals.viewpoint,
536
 
                                         &normal,
537
 
                                         p,
538
 
                                         &env_color,
539
 
                                         &color_int,
540
 
                                         mapvals.lightsource[0].type);
541
 
            }
 
520
          light_color = phong_shade (position,
 
521
                                     &mapvals.viewpoint,
 
522
                                     &normal,
 
523
                                     p,
 
524
                                     &color,
 
525
                                     &color_int,
 
526
                                     mapvals.lightsource[0].type);
542
527
        }
 
528
 
 
529
      gimp_vector3_sub (&v, &mapvals.viewpoint, position);
 
530
      gimp_vector3_normalize (&v);
 
531
 
 
532
      r = compute_reflected_ray (&normal, &v);
 
533
 
 
534
      /* Get color in the direction of r */
 
535
      /* =============================== */
 
536
 
 
537
      sphere_to_image (&r, &xf, &yf);
 
538
      env_color = peek_env_map (RINT (env_width * xf),
 
539
                                RINT (env_height * yf));
 
540
 
 
541
      tmpval = mapvals.material.diffuse_int;
 
542
      mapvals.material.diffuse_int = 0.;
 
543
 
 
544
      light_color = phong_shade (position,
 
545
                                 &mapvals.viewpoint,
 
546
                                 &normal,
 
547
                                 &r,
 
548
                                 &color,
 
549
                                 &env_color,
 
550
                                 DIRECTIONAL_LIGHT);
 
551
 
 
552
      mapvals.material.diffuse_int = tmpval;
 
553
 
 
554
      gimp_rgb_add (&color_sum, &light_color);
543
555
    }
544
556
 
545
 
  gimp_rgb_clamp (&light_color);
546
 
  return light_color;
 
557
  gimp_rgb_clamp (&color_sum);
 
558
  return color_sum;
547
559
}
548
560
 
549
561
GimpRGB
576
588
 
577
589
      for (k = 0; k < NUM_LIGHTS; k++)
578
590
        {
 
591
          p = &mapvals.lightsource[k].direction;
 
592
 
579
593
          if (!mapvals.lightsource[k].active
580
594
              || mapvals.lightsource[k].type == NO_LIGHT)
581
595
            continue;
582
596
          else if (mapvals.lightsource[k].type == POINT_LIGHT)
583
597
            p = &mapvals.lightsource[k].position;
584
 
          else
585
 
            p = &mapvals.lightsource[k].direction;
586
598
 
587
599
          color_int = mapvals.lightsource[k].color;
588
600
          gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity);
621
633
GimpRGB
622
634
get_ray_color_no_bilinear_ref (GimpVector3 *position)
623
635
{
 
636
  GimpRGB      color_sum;
624
637
  GimpRGB      color_int;
625
638
  GimpRGB      light_color;
626
639
  GimpRGB      color, env_color;
628
641
  gdouble      xf, yf;
629
642
  GimpVector3  normal, *p, v, r;
630
643
  gint         k;
 
644
  gdouble      tmpval;
631
645
 
632
646
  pos_to_float (position->x, position->y, &xf, &yf);
633
647
 
634
648
  x = RINT (xf);
635
649
 
 
650
  if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
 
651
    normal = mapvals.planenormal;
 
652
  else
 
653
    normal = vertex_normals[1][(gint) RINT (xf)];
 
654
  gimp_vector3_normalize (&normal);
 
655
 
636
656
  if (mapvals.transparent_background && heights[1][x] == 0)
637
657
    {
638
 
      gimp_rgb_set_alpha (&light_color, 0.0);
 
658
      gimp_rgb_set_alpha (&color_sum, 0.0);
639
659
    }
640
660
  else
641
661
    {
 
662
      color = peek (RINT (xf), RINT (yf));
 
663
      color_sum = color;
 
664
      gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int);
 
665
 
642
666
      for (k = 0; k < NUM_LIGHTS; k++)
643
667
        {
 
668
          p = &mapvals.lightsource[k].direction;
 
669
 
644
670
          if (!mapvals.lightsource[k].active
645
671
              || mapvals.lightsource[k].type == NO_LIGHT)
646
672
            continue;
647
673
          else if (mapvals.lightsource[k].type == POINT_LIGHT)
648
674
            p = &mapvals.lightsource[k].position;
649
 
          else
650
 
            p = &mapvals.lightsource[k].direction;
651
675
 
652
676
          color_int = mapvals.lightsource[k].color;
653
677
          gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity);
654
678
 
655
 
          if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
656
 
            {
657
 
              pos_to_float (position->x, position->y, &xf, &yf);
658
 
 
659
 
              color = peek (RINT (xf), RINT (yf));
660
 
 
661
 
              gimp_vector3_sub (&v, &mapvals.viewpoint, position);
662
 
              gimp_vector3_normalize (&v);
663
 
 
664
 
              r = compute_reflected_ray (&mapvals.planenormal, &v);
665
 
 
666
 
              /* Get color in the direction of r */
667
 
              /* =============================== */
668
 
 
669
 
              sphere_to_image (&r, &xf, &yf);
670
 
              env_color = peek_env_map (RINT (env_width * xf),
671
 
                                        RINT (env_height * yf));
672
 
 
673
 
              light_color = phong_shade (position,
674
 
                                         &mapvals.viewpoint,
675
 
                                         &mapvals.planenormal,
676
 
                                         p,
677
 
                                         &env_color,
678
 
                                         &color_int,
679
 
                                         mapvals.lightsource[0].type);
680
 
            }
681
 
          else
682
 
            {
683
 
              normal = vertex_normals[1][(gint) RINT (xf)];
684
 
 
685
 
              pos_to_float (position->x, position->y, &xf, &yf);
686
 
              color = peek (RINT (xf), RINT (yf));
687
 
 
688
 
              gimp_vector3_sub (&v, &mapvals.viewpoint, position);
689
 
              gimp_vector3_normalize (&v);
690
 
 
691
 
              r = compute_reflected_ray (&normal, &v);
692
 
 
693
 
              /* Get color in the direction of r */
694
 
              /* =============================== */
695
 
 
696
 
              sphere_to_image (&r, &xf, &yf);
697
 
              env_color = peek_env_map (RINT (env_width * xf),
698
 
                                        RINT (env_height * yf));
699
 
 
700
679
              light_color = phong_shade (position,
701
680
                                         &mapvals.viewpoint,
702
681
                                         &normal,
703
682
                                         p,
704
 
                                         &env_color,
 
683
                                         &color,
705
684
                                         &color_int,
706
685
                                         mapvals.lightsource[0].type);
707
 
            }
708
686
        }
 
687
 
 
688
      gimp_vector3_sub (&v, &mapvals.viewpoint, position);
 
689
      gimp_vector3_normalize (&v);
 
690
 
 
691
      r = compute_reflected_ray (&normal, &v);
 
692
 
 
693
      /* Get color in the direction of r */
 
694
      /* =============================== */
 
695
 
 
696
      sphere_to_image (&r, &xf, &yf);
 
697
      env_color = peek_env_map (RINT (env_width * xf),
 
698
                                RINT (env_height * yf));
 
699
 
 
700
      tmpval = mapvals.material.diffuse_int;
 
701
      mapvals.material.diffuse_int = 0.;
 
702
 
 
703
      light_color = phong_shade (position,
 
704
                                 &mapvals.viewpoint,
 
705
                                 &normal,
 
706
                                 &r,
 
707
                                 &color,
 
708
                                 &env_color,
 
709
                                 DIRECTIONAL_LIGHT);
 
710
 
 
711
      mapvals.material.diffuse_int = tmpval;
 
712
 
 
713
      gimp_rgb_add (&color_sum, &light_color);
709
714
    }
710
715
 
711
 
 gimp_rgb_clamp (&light_color);
712
 
 return light_color;
 
716
 gimp_rgb_clamp (&color_sum);
 
717
 return color_sum;
713
718
}