475
475
get_ray_color_ref (GimpVector3 *position)
477
478
GimpRGB color_int;
478
479
GimpRGB light_color;
479
480
GimpRGB color, env_color;
482
483
GimpVector3 normal, *p, v, r;
485
487
pos_to_float (position->x, position->y, &xf, &yf);
491
if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
492
normal = mapvals.planenormal;
494
normal = vertex_normals[1][(gint) RINT (xf)];
495
gimp_vector3_normalize (&normal);
489
497
if (mapvals.transparent_background && heights[1][x] == 0)
491
gimp_rgb_set_alpha (&light_color, 0.0);
499
gimp_rgb_set_alpha (&color_sum, 0.0);
503
color = get_image_color (xf, yf, &f);
505
gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int);
495
507
for (k = 0; k < NUM_LIGHTS; k++)
509
p = &mapvals.lightsource[k].direction;
497
511
if (!mapvals.lightsource[k].active
498
512
|| mapvals.lightsource[k].type == NO_LIGHT)
500
514
else if (mapvals.lightsource[k].type == POINT_LIGHT)
501
515
p = &mapvals.lightsource[k].position;
503
p = &mapvals.lightsource[k].direction;
505
517
color_int = mapvals.lightsource[k].color;
506
518
gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity);
508
if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
510
light_color = phong_shade (position,
512
&mapvals.planenormal,
516
mapvals.lightsource[0].type);
520
normal = vertex_normals[1][(gint) RINT (xf)];
522
gimp_vector3_sub (&v, &mapvals.viewpoint,position);
523
gimp_vector3_normalize (&v);
525
r = compute_reflected_ray (&normal, &v);
527
/* Get color in the direction of r */
528
/* =============================== */
530
sphere_to_image (&r, &xf, &yf);
531
env_color = peek_env_map (RINT (env_width * xf),
532
RINT (env_height * yf));
534
light_color = phong_shade (position,
540
mapvals.lightsource[0].type);
520
light_color = phong_shade (position,
526
mapvals.lightsource[0].type);
529
gimp_vector3_sub (&v, &mapvals.viewpoint, position);
530
gimp_vector3_normalize (&v);
532
r = compute_reflected_ray (&normal, &v);
534
/* Get color in the direction of r */
535
/* =============================== */
537
sphere_to_image (&r, &xf, &yf);
538
env_color = peek_env_map (RINT (env_width * xf),
539
RINT (env_height * yf));
541
tmpval = mapvals.material.diffuse_int;
542
mapvals.material.diffuse_int = 0.;
544
light_color = phong_shade (position,
552
mapvals.material.diffuse_int = tmpval;
554
gimp_rgb_add (&color_sum, &light_color);
545
gimp_rgb_clamp (&light_color);
557
gimp_rgb_clamp (&color_sum);
629
642
GimpVector3 normal, *p, v, r;
632
646
pos_to_float (position->x, position->y, &xf, &yf);
650
if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
651
normal = mapvals.planenormal;
653
normal = vertex_normals[1][(gint) RINT (xf)];
654
gimp_vector3_normalize (&normal);
636
656
if (mapvals.transparent_background && heights[1][x] == 0)
638
gimp_rgb_set_alpha (&light_color, 0.0);
658
gimp_rgb_set_alpha (&color_sum, 0.0);
662
color = peek (RINT (xf), RINT (yf));
664
gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int);
642
666
for (k = 0; k < NUM_LIGHTS; k++)
668
p = &mapvals.lightsource[k].direction;
644
670
if (!mapvals.lightsource[k].active
645
671
|| mapvals.lightsource[k].type == NO_LIGHT)
647
673
else if (mapvals.lightsource[k].type == POINT_LIGHT)
648
674
p = &mapvals.lightsource[k].position;
650
p = &mapvals.lightsource[k].direction;
652
676
color_int = mapvals.lightsource[k].color;
653
677
gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity);
655
if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1)
657
pos_to_float (position->x, position->y, &xf, &yf);
659
color = peek (RINT (xf), RINT (yf));
661
gimp_vector3_sub (&v, &mapvals.viewpoint, position);
662
gimp_vector3_normalize (&v);
664
r = compute_reflected_ray (&mapvals.planenormal, &v);
666
/* Get color in the direction of r */
667
/* =============================== */
669
sphere_to_image (&r, &xf, &yf);
670
env_color = peek_env_map (RINT (env_width * xf),
671
RINT (env_height * yf));
673
light_color = phong_shade (position,
675
&mapvals.planenormal,
679
mapvals.lightsource[0].type);
683
normal = vertex_normals[1][(gint) RINT (xf)];
685
pos_to_float (position->x, position->y, &xf, &yf);
686
color = peek (RINT (xf), RINT (yf));
688
gimp_vector3_sub (&v, &mapvals.viewpoint, position);
689
gimp_vector3_normalize (&v);
691
r = compute_reflected_ray (&normal, &v);
693
/* Get color in the direction of r */
694
/* =============================== */
696
sphere_to_image (&r, &xf, &yf);
697
env_color = peek_env_map (RINT (env_width * xf),
698
RINT (env_height * yf));
700
679
light_color = phong_shade (position,
701
680
&mapvals.viewpoint,
706
685
mapvals.lightsource[0].type);
688
gimp_vector3_sub (&v, &mapvals.viewpoint, position);
689
gimp_vector3_normalize (&v);
691
r = compute_reflected_ray (&normal, &v);
693
/* Get color in the direction of r */
694
/* =============================== */
696
sphere_to_image (&r, &xf, &yf);
697
env_color = peek_env_map (RINT (env_width * xf),
698
RINT (env_height * yf));
700
tmpval = mapvals.material.diffuse_int;
701
mapvals.material.diffuse_int = 0.;
703
light_color = phong_shade (position,
711
mapvals.material.diffuse_int = tmpval;
713
gimp_rgb_add (&color_sum, &light_color);
711
gimp_rgb_clamp (&light_color);
716
gimp_rgb_clamp (&color_sum);