plug-ins: Remove GimpRGB from Lighting Effects plug-in

This commit is contained in:
Alx Sa 2024-09-11 03:05:27 +00:00
parent b8712b27de
commit 0d6754efd7
9 changed files with 353 additions and 285 deletions

View file

@ -24,7 +24,7 @@ void
compute_image (void) compute_image (void)
{ {
gint xcount, ycount; gint xcount, ycount;
GimpRGB color; gdouble color[4];
glong progress_counter = 0; glong progress_counter = 0;
GimpVector3 p; GimpVector3 p;
GimpImage *new_image = NULL; GimpImage *new_image = NULL;
@ -114,14 +114,14 @@ compute_image (void)
for (xcount = 0; xcount < width; xcount++) for (xcount = 0; xcount < width; xcount++)
{ {
p = int_to_pos (xcount, ycount); p = int_to_pos (xcount, ycount);
color = (* ray_func) (&p); (* ray_func) (&p, color);
row[index++] = (guchar) (color.r * 255.0); row[index++] = (guchar) (color[0] * 255.0);
row[index++] = (guchar) (color.g * 255.0); row[index++] = (guchar) (color[1] * 255.0);
row[index++] = (guchar) (color.b * 255.0); row[index++] = (guchar) (color[2] * 255.0);
if (has_alpha) if (has_alpha)
row[index++] = (guchar) (color.a * 255.0); row[index++] = (guchar) (color[3] * 255.0);
progress_counter++; progress_counter++;
} }
@ -236,37 +236,37 @@ copy_from_config (GimpProcedureConfig *config)
if (color_1) if (color_1)
{ {
gegl_color_get_pixel (color_1, babl_format ("R'G'B'A double"), gegl_color_get_pixel (color_1, babl_format ("R'G'B'A double"),
&mapvals.lightsource[0].color); mapvals.lightsource[0].color);
g_object_unref (color_1); g_object_unref (color_1);
} }
if (color_2) if (color_2)
{ {
gegl_color_get_pixel (color_2, babl_format ("R'G'B'A double"), gegl_color_get_pixel (color_2, babl_format ("R'G'B'A double"),
&mapvals.lightsource[1].color); mapvals.lightsource[1].color);
g_object_unref (color_2); g_object_unref (color_2);
} }
if (color_3) if (color_3)
{ {
gegl_color_get_pixel (color_3, babl_format ("R'G'B'A double"), gegl_color_get_pixel (color_3, babl_format ("R'G'B'A double"),
&mapvals.lightsource[2].color); mapvals.lightsource[2].color);
g_object_unref (color_3); g_object_unref (color_3);
} }
if (color_4) if (color_4)
{ {
gegl_color_get_pixel (color_4, babl_format ("R'G'B'A double"), gegl_color_get_pixel (color_4, babl_format ("R'G'B'A double"),
&mapvals.lightsource[3].color); mapvals.lightsource[3].color);
g_object_unref (color_4); g_object_unref (color_4);
} }
if (color_5) if (color_5)
{ {
gegl_color_get_pixel (color_5, babl_format ("R'G'B'A double"), gegl_color_get_pixel (color_5, babl_format ("R'G'B'A double"),
&mapvals.lightsource[4].color); mapvals.lightsource[4].color);
g_object_unref (color_5); g_object_unref (color_5);
} }
if (color_6) if (color_6)
{ {
gegl_color_get_pixel (color_6, babl_format ("R'G'B'A double"), gegl_color_get_pixel (color_6, babl_format ("R'G'B'A double"),
&mapvals.lightsource[5].color); mapvals.lightsource[5].color);
g_object_unref (color_6); g_object_unref (color_6);
} }

View file

@ -33,7 +33,7 @@ cairo_surface_t *preview_surface = NULL;
glong maxcounter; glong maxcounter;
gint width, height; gint width, height;
gint env_width, env_height; gint env_width, env_height;
GimpRGB background; gdouble background[4];
gint border_x1, border_y1, border_x2, border_y2; gint border_x1, border_y1, border_x2, border_y2;
@ -67,28 +67,24 @@ peek_map (GeglBuffer *buffer,
return ret_val; return ret_val;
} }
GimpRGB void
peek (gint x, peek (gint x,
gint y) gint y,
gdouble *color)
{ {
GimpRGB color;
gegl_buffer_sample (source_buffer, x, y, NULL, gegl_buffer_sample (source_buffer, x, y, NULL,
&color, babl_format ("R'G'B'A double"), color, babl_format ("R'G'B'A double"),
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE); GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if (! babl_format_has_alpha (gegl_buffer_get_format (source_buffer))) if (! babl_format_has_alpha (gegl_buffer_get_format (source_buffer)))
color.a = 1.0; color[3] = 1.0;
return color;
} }
GimpRGB void
peek_env_map (gint x, peek_env_map (gint x,
gint y) gint y,
gdouble *color)
{ {
GimpRGB color;
if (x < 0) if (x < 0)
x = 0; x = 0;
else if (x >= env_width) else if (x >= env_width)
@ -99,18 +95,16 @@ peek_env_map (gint x,
y = env_height - 1; y = env_height - 1;
gegl_buffer_sample (env_buffer, x, y, NULL, gegl_buffer_sample (env_buffer, x, y, NULL,
&color, babl_format ("R'G'B'A double"), color, babl_format ("R'G'B'A double"),
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE); GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
color.a = 1.0; color[3] = 1.0;
return color;
} }
void void
poke (gint x, poke (gint x,
gint y, gint y,
GimpRGB *color) gdouble *color)
{ {
if (x < 0) if (x < 0)
x = 0; x = 0;
@ -237,18 +231,17 @@ pos_to_float (gdouble x,
/* Quartics bilinear interpolation stuff. */ /* Quartics bilinear interpolation stuff. */
/**********************************************/ /**********************************************/
GimpRGB void
get_image_color (gdouble u, get_image_color (gdouble u,
gdouble v, gdouble v,
gint *inside) gint *inside,
gdouble *color)
{ {
gint x1; gint x1;
gint y1; gint y1;
gint x2; gint x2;
gint y2; gint y2;
GimpRGB p[4]; gdouble p[4];
GimpRGB p_rgba;
gdouble pixel[4];
gdouble pixels[16]; gdouble pixels[16];
x1 = RINT (u); x1 = RINT (u);
@ -257,7 +250,10 @@ get_image_color (gdouble u,
if (check_bounds (x1, y1) == FALSE) if (check_bounds (x1, y1) == FALSE)
{ {
*inside = FALSE; *inside = FALSE;
return background; for (gint i = 0; i < 4; i++)
color[i] = background[i];
return;
} }
x2 = (x1 + 1); x2 = (x1 + 1);
@ -266,28 +262,26 @@ get_image_color (gdouble u,
if (check_bounds (x2, y2) == FALSE) if (check_bounds (x2, y2) == FALSE)
{ {
*inside = TRUE; *inside = TRUE;
return peek (x1, y1); peek (x1, y1, color);
return;
} }
*inside = TRUE; *inside = TRUE;
p[0] = peek (x1, y1); peek (x1, y1, p);
p[1] = peek (x2, y1);
p[2] = peek (x1, y2);
p[3] = peek (x2, y2);
for (gint i = 0; i < 4; i++) for (gint i = 0; i < 4; i++)
{ pixels[i] = p[i];
pixels[(i * 4)] = p[i].r; peek (x2, y1, p);
pixels[(i * 4) + 1] = p[i].g; for (gint i = 0; i < 4; i++)
pixels[(i * 4) + 2] = p[i].b; pixels[i + 4] = p[i];
pixels[(i * 4) + 3] = p[i].a; peek (x1, y2, p);
} for (gint i = 0; i < 4; i++)
pixels[i + 8] = p[i];
peek (x2, y2, p);
for (gint i = 0; i < 4; i++)
pixels[i + 12] = p[i];
gimp_bilinear_rgb (u, v, pixels, TRUE, pixel); gimp_bilinear_rgb (u, v, pixels, TRUE, color);
gimp_rgba_set (&p_rgba, pixel[0], pixel[1], pixel[2], pixel[3]);
return p_rgba;
} }
gdouble gdouble

View file

@ -23,7 +23,7 @@ extern cairo_surface_t *preview_surface;
extern glong maxcounter; extern glong maxcounter;
extern gint width,height,env_width,env_height; extern gint width,height,env_width,env_height;
extern GimpRGB background; extern gdouble background[4];
extern gint border_x1, border_y1, border_x2, border_y2; extern gint border_x1, border_y1, border_x2, border_y2;
@ -34,13 +34,15 @@ guchar peek_map (GeglBuffer *buffer,
const Babl *format, const Babl *format,
gint x, gint x,
gint y); gint y);
GimpRGB peek (gint x, void peek (gint x,
gint y); gint y,
GimpRGB peek_env_map (gint x, gdouble *color);
gint y); void peek_env_map (gint x,
gint y,
gdouble *color);
void poke (gint x, void poke (gint x,
gint y, gint y,
GimpRGB *color); gdouble *color);
gint check_bounds (gint x, gint check_bounds (gint x,
gint y); gint y);
GimpVector3 int_to_pos (gint x, GimpVector3 int_to_pos (gint x,
@ -55,9 +57,10 @@ void pos_to_float (gdouble x,
gdouble y, gdouble y,
gdouble *xf, gdouble *xf,
gdouble *yf); gdouble *yf);
GimpRGB get_image_color (gdouble u, void get_image_color (gdouble u,
gdouble v, gdouble v,
gint *inside); gint *inside,
gdouble *color);
gdouble get_map_value (GeglBuffer *buffer, gdouble get_map_value (GeglBuffer *buffer,
const Babl *format, const Babl *format,
gdouble u, gdouble u,

View file

@ -652,7 +652,8 @@ set_default_settings (void)
gimp_vector3_set (&mapvals.lightsource[0].position, -1.0, -1.0, 1.0); gimp_vector3_set (&mapvals.lightsource[0].position, -1.0, -1.0, 1.0);
gimp_vector3_set (&mapvals.lightsource[0].direction, -1.0, -1.0, 1.0); gimp_vector3_set (&mapvals.lightsource[0].direction, -1.0, -1.0, 1.0);
gimp_rgba_set (&mapvals.lightsource[0].color, 1.0, 1.0, 1.0, 1.0); for (gint i = 0; i < 4; i++)
mapvals.lightsource[0].color[i] = 1.0;
mapvals.lightsource[0].intensity = 1.0; mapvals.lightsource[0].intensity = 1.0;
mapvals.lightsource[0].type = POINT_LIGHT; mapvals.lightsource[0].type = POINT_LIGHT;
mapvals.lightsource[0].active = TRUE; mapvals.lightsource[0].active = TRUE;
@ -673,7 +674,8 @@ set_default_settings (void)
for (k = 1; k < NUM_LIGHTS; k++) for (k = 1; k < NUM_LIGHTS; k++)
{ {
gimp_rgba_set (&mapvals.lightsource[k].color, 1.0, 1.0, 1.0, 1.0); for (gint i = 0; i < 4; i++)
mapvals.lightsource[k].color[i] = 1.0;
mapvals.lightsource[k].intensity = 1.0; mapvals.lightsource[k].intensity = 1.0;
mapvals.lightsource[k].type = NO_LIGHT; mapvals.lightsource[k].type = NO_LIGHT;
mapvals.lightsource[k].active = TRUE; mapvals.lightsource[k].active = TRUE;

View file

@ -44,7 +44,6 @@ typedef struct
gdouble specular_ref; gdouble specular_ref;
gdouble highlight; gdouble highlight;
gboolean metallic; gboolean metallic;
GimpRGB color;
} MaterialSettings; } MaterialSettings;
typedef struct typedef struct
@ -52,7 +51,7 @@ typedef struct
LightType type; LightType type;
GimpVector3 position; GimpVector3 position;
GimpVector3 direction; GimpVector3 direction;
GimpRGB color; gdouble color[4];
gdouble intensity; gdouble intensity;
gboolean active; gboolean active;
} LightSettings; } LightSettings;
@ -72,7 +71,6 @@ typedef struct
GimpVector3 planenormal; GimpVector3 planenormal;
LightSettings lightsource[NUM_LIGHTS]; LightSettings lightsource[NUM_LIGHTS];
MaterialSettings material; MaterialSettings material;
MaterialSettings ref_material;
gdouble pixel_threshold; gdouble pixel_threshold;
gdouble bumpmax,bumpmin; gdouble bumpmax,bumpmin;

View file

@ -36,18 +36,24 @@ static guint preview_update_timer = 0;
/* Protos */ /* Protos */
/* ====== */ /* ====== */
static gboolean static gboolean interactive_preview_timer_callback (gpointer data);
interactive_preview_timer_callback ( gpointer data );
void composite_behind (gdouble *color1,
gdouble *color2);
static void static void
compute_preview (gint startx, gint starty, gint w, gint h) compute_preview (gint startx,
gint starty,
gint w,
gint h)
{ {
gint xcnt, ycnt, f1, f2; gint xcnt, ycnt, f1, f2;
guchar r, g, b; guchar r, g, b;
gdouble imagex, imagey; gdouble imagex, imagey;
gint32 index = 0; gint32 index = 0;
GimpRGB color; gdouble color[4];
GimpRGB lightcheck, darkcheck; gdouble lightcheck[4] = { GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, 1.0 };
gdouble darkcheck[4] = { GIMP_CHECK_DARK, GIMP_CHECK_DARK, GIMP_CHECK_DARK, 1.0 };
GimpVector3 pos; GimpVector3 pos;
get_ray_func ray_func; get_ray_func ray_func;
@ -88,12 +94,6 @@ compute_preview (gint startx, gint starty, gint w, gint h)
precompute_init (width, height); precompute_init (width, height);
gimp_rgba_set (&lightcheck,
GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT,
1.0);
gimp_rgba_set (&darkcheck, GIMP_CHECK_DARK, GIMP_CHECK_DARK,
GIMP_CHECK_DARK, 1.0);
if (mapvals.bump_mapped == TRUE && mapvals.bumpmap_id != -1) if (mapvals.bump_mapped == TRUE && mapvals.bumpmap_id != -1)
{ {
bumpmap_setup (gimp_drawable_get_by_id (mapvals.bumpmap_id)); bumpmap_setup (gimp_drawable_get_by_id (mapvals.bumpmap_id));
@ -138,9 +138,9 @@ compute_preview (gint startx, gint starty, gint w, gint h)
precompute_normals (0, width, RINT (imagey)); precompute_normals (0, width, RINT (imagey));
} }
color = (*ray_func) (&pos); (*ray_func) (&pos, color);
if (color.a < 1.0) if (color[3] < 1.0)
{ {
f1 = ((xcnt % 32) < 16); f1 = ((xcnt % 32) < 16);
f2 = ((ycnt % 32) < 16); f2 = ((ycnt % 32) < 16);
@ -148,25 +148,33 @@ compute_preview (gint startx, gint starty, gint w, gint h)
if (f1) if (f1)
{ {
if (color.a == 0.0) if (color[3] == 0.0)
color = lightcheck; {
else for (gint i = 0; i < 4; i++)
gimp_rgb_composite (&color, color[i] = lightcheck[i];
&lightcheck,
GIMP_RGB_COMPOSITE_BEHIND);
} }
else else
{ {
if (color.a == 0.0) composite_behind (color, lightcheck);
color = darkcheck; }
}
else else
gimp_rgb_composite (&color, {
&darkcheck, if (color[3] == 0.0)
GIMP_RGB_COMPOSITE_BEHIND); {
for (gint i = 0; i < 4; i++)
color[i] = darkcheck[i];
}
else
{
composite_behind (color, darkcheck);
}
} }
} }
gimp_rgb_get_uchar (&color, &r, &g, &b); r = (guchar) (color[0] * 255);
g = (guchar) (color[1] * 255);
b = (guchar) (color[2] * 255);
GIMP_CAIRO_RGB24_SET_PIXEL((preview_rgb_data + index), r, g, b); GIMP_CAIRO_RGB24_SET_PIXEL((preview_rgb_data + index), r, g, b);
index += 4; index += 4;
imagex++; imagex++;
@ -497,3 +505,21 @@ interactive_preview_timer_callback (gpointer data)
return FALSE; return FALSE;
} }
void
composite_behind (gdouble *color1,
gdouble *color2)
{
g_return_if_fail (color1 != NULL);
g_return_if_fail (color2 != NULL);
if (color1[3] < 1.0)
{
gdouble factor = color2[3] * (1.0 - color1[3]);
color1[0] = color2[0] * factor + color1[0] * color1[3];
color1[1] = color2[1] * factor + color1[1] * color1[3];
color1[2] = color2[2] * factor + color1[2] * color1[3];
color1[3] = factor + color1[3];
}
}

View file

@ -24,16 +24,17 @@ static gint pre_h = -1;
/* Phong shading */ /* Phong shading */
/*****************/ /*****************/
static GimpRGB static void
phong_shade (GimpVector3 *position, phong_shade (GimpVector3 *position,
GimpVector3 *viewpoint, GimpVector3 *viewpoint,
GimpVector3 *normal, GimpVector3 *normal,
GimpVector3 *lightposition, GimpVector3 *lightposition,
GimpRGB *diff_col, gdouble *diff_col,
GimpRGB *light_col, gdouble *light_col,
LightType light_type) LightType light_type,
gdouble *diffuse_color)
{ {
GimpRGB diffuse_color, specular_color; gdouble specular_color[4];
gdouble nl, rv, dist; gdouble nl, rv, dist;
GimpVector3 l, v, n, lnormal, h; GimpVector3 l, v, n, lnormal, h;
@ -81,30 +82,41 @@ phong_shade (GimpVector3 *position,
/* Compute diffuse and specular intensity contribution */ /* Compute diffuse and specular intensity contribution */
/* =================================================== */ /* =================================================== */
diffuse_color = *light_col; for (gint i = 0; i < 4; i++)
gimp_rgb_multiply (&diffuse_color, mapvals.material.diffuse_int); diffuse_color[i] = light_col[i];
diffuse_color.r *= diff_col->r; for (gint i = 0; i < 3; i++)
diffuse_color.g *= diff_col->g; diffuse_color[i] *= mapvals.material.diffuse_int;
diffuse_color.b *= diff_col->b;
gimp_rgb_multiply (&diffuse_color, nl); diffuse_color[0] *= diff_col[0];
diffuse_color[1] *= diff_col[1];
diffuse_color[2] *= diff_col[2];
for (gint i = 0; i < 3; i++)
diffuse_color[i] *= nl;
for (gint i = 0; i < 4; i++)
specular_color[i] = light_col[i];
specular_color = *light_col;
if (mapvals.material.metallic) /* for metals, specular color = diffuse color */ if (mapvals.material.metallic) /* for metals, specular color = diffuse color */
{ {
specular_color.r *= diff_col->r; specular_color[0] *= diff_col[0];
specular_color.g *= diff_col->g; specular_color[1] *= diff_col[1];
specular_color.b *= diff_col->b; specular_color[2] *= diff_col[2];
}
gimp_rgb_multiply (&specular_color, mapvals.material.specular_ref);
gimp_rgb_multiply (&specular_color, rv);
gimp_rgb_add (&diffuse_color, &specular_color);
gimp_rgb_clamp (&diffuse_color);
} }
gimp_rgb_clamp (&diffuse_color); for (gint i = 0; i < 3; i++)
{
specular_color[i] *= mapvals.material.specular_ref;
specular_color[i] *= rv;
}
return diffuse_color; for (gint i = 0; i < 3; i++)
diffuse_color[i] += specular_color[i];
for (gint i = 0; i < 4; i++)
diffuse_color[i] = CLAMP (diffuse_color[i], 0.0, 1.0);
}
for (gint i = 0; i < 4; i++)
diffuse_color[i] = CLAMP (diffuse_color[i], 0.0, 1.0);
} }
void void
@ -521,13 +533,13 @@ sphere_to_image (GimpVector3 *normal,
/* These routines computes the color of the surface at a given point */ /* These routines computes the color of the surface at a given point */
/*********************************************************************/ /*********************************************************************/
GimpRGB void
get_ray_color (GimpVector3 *position) get_ray_color (GimpVector3 *position,
gdouble *color_sum)
{ {
GimpRGB color; gdouble color[4];
GimpRGB color_int; gdouble color_int[4];
GimpRGB color_sum; gdouble light_color[4];
GimpRGB light_color;
gint x, f; gint x, f;
gdouble xf, yf; gdouble xf, yf;
GimpVector3 normal, *p; GimpVector3 normal, *p;
@ -539,14 +551,16 @@ get_ray_color (GimpVector3 *position)
if (mapvals.transparent_background && heights[1][x] == 0) if (mapvals.transparent_background && heights[1][x] == 0)
{ {
gimp_rgb_set_alpha (&color_sum, 0.0); color_sum[3] = 0.0;
} }
else else
{ {
color = get_image_color (xf, yf, &f); get_image_color (xf, yf, &f, color);
color_sum = color; for (gint i = 0; i < 4; i++)
gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); color_sum[i] = color[i];
for (gint i = 0; i < 3; i++)
color_sum[i] *= mapvals.material.ambient_int;
for (k = 0; k < NUM_LIGHTS; k++) for (k = 0; k < NUM_LIGHTS; k++)
{ {
@ -558,49 +572,53 @@ get_ray_color (GimpVector3 *position)
else else
p = &mapvals.lightsource[k].direction; p = &mapvals.lightsource[k].direction;
color_int = mapvals.lightsource[k].color; for (gint i = 0; i < 4; i++)
gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); color_int[i] = mapvals.lightsource[k].color[i];
for (gint i = 0; i < 3; i++)
color_int[i] *= mapvals.lightsource[k].intensity;
if (mapvals.bump_mapped == FALSE || if (mapvals.bump_mapped == FALSE ||
mapvals.bumpmap_id == -1) mapvals.bumpmap_id == -1)
{ {
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&mapvals.planenormal, &mapvals.planenormal,
p, p,
&color, color,
&color_int, color_int,
mapvals.lightsource[k].type); mapvals.lightsource[k].type,
light_color);
} }
else else
{ {
normal = vertex_normals[1][(gint) RINT (xf)]; normal = vertex_normals[1][(gint) RINT (xf)];
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&normal, &normal,
p, p,
&color, color,
&color_int, color_int,
mapvals.lightsource[k].type); mapvals.lightsource[k].type,
light_color);
} }
gimp_rgb_add (&color_sum, &light_color); for (gint i = 0; i < 3; i++)
color_sum[i] += light_color[i];
} }
} }
gimp_rgb_clamp (&color_sum); for (gint i = 0; i < 4; i++)
color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0);
return color_sum;
} }
GimpRGB void
get_ray_color_ref (GimpVector3 *position) get_ray_color_ref (GimpVector3 *position,
gdouble *color_sum)
{ {
GimpRGB color_sum; gdouble color_int[4];
GimpRGB color_int; gdouble light_color[4];
GimpRGB light_color; gdouble color[4], env_color[4];
GimpRGB color, env_color;
gint x, f; gint x, f;
gdouble xf, yf; gdouble xf, yf;
GimpVector3 normal, *p, v, r; GimpVector3 normal, *p, v, r;
@ -625,13 +643,16 @@ get_ray_color_ref (GimpVector3 *position)
if (mapvals.transparent_background && heights[1][x] == 0) if (mapvals.transparent_background && heights[1][x] == 0)
{ {
gimp_rgb_set_alpha (&color_sum, 0.0); color_sum[3] = 0.0;
} }
else else
{ {
color = get_image_color (xf, yf, &f); get_image_color (xf, yf, &f, color);
color_sum = color;
gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); for (gint i = 0; i < 4; i++)
color_sum[i] = color[i];
for (gint i = 0; i < 3; i++)
color_sum[i] *= mapvals.material.ambient_int;
for (k = 0; k < NUM_LIGHTS; k++) for (k = 0; k < NUM_LIGHTS; k++)
{ {
@ -643,16 +664,19 @@ get_ray_color_ref (GimpVector3 *position)
else if (mapvals.lightsource[k].type == POINT_LIGHT) else if (mapvals.lightsource[k].type == POINT_LIGHT)
p = &mapvals.lightsource[k].position; p = &mapvals.lightsource[k].position;
color_int = mapvals.lightsource[k].color; for (gint i = 0; i < 4; i++)
gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); color_int[i] = mapvals.lightsource[k].color[i];
for (gint i = 0; i < 3; i++)
color_int[i] *= mapvals.lightsource[k].intensity;
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&normal, &normal,
p, p,
&color, color,
&color_int, color_int,
mapvals.lightsource[0].type); mapvals.lightsource[0].type,
light_color);
} }
gimp_vector3_sub (&v, &mapvals.viewpoint, position); gimp_vector3_sub (&v, &mapvals.viewpoint, position);
@ -664,37 +688,39 @@ get_ray_color_ref (GimpVector3 *position)
/* =============================== */ /* =============================== */
sphere_to_image (&r, &xf, &yf); sphere_to_image (&r, &xf, &yf);
env_color = peek_env_map (RINT (env_width * xf), peek_env_map (RINT (env_width * xf),
RINT (env_height * yf)); RINT (env_height * yf),
env_color);
tmpval = mapvals.material.diffuse_int; tmpval = mapvals.material.diffuse_int;
mapvals.material.diffuse_int = 0.; mapvals.material.diffuse_int = 0.;
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&normal, &normal,
&r, &r,
&color, color,
&env_color, env_color,
DIRECTIONAL_LIGHT); DIRECTIONAL_LIGHT,
light_color);
mapvals.material.diffuse_int = tmpval; mapvals.material.diffuse_int = tmpval;
gimp_rgb_add (&color_sum, &light_color); for (gint i = 0; i < 3; i++)
color_sum[i] += light_color[i];
} }
gimp_rgb_clamp (&color_sum); for (gint i = 0; i < 4; i++)
color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0);
return color_sum;
} }
GimpRGB void
get_ray_color_no_bilinear (GimpVector3 *position) get_ray_color_no_bilinear (GimpVector3 *position,
gdouble *color_sum)
{ {
GimpRGB color; gdouble color[4];
GimpRGB color_int; gdouble color_int[4];
GimpRGB color_sum; gdouble light_color[4];
GimpRGB light_color;
gint x; gint x;
gdouble xf, yf; gdouble xf, yf;
GimpVector3 normal, *p; GimpVector3 normal, *p;
@ -706,14 +732,16 @@ get_ray_color_no_bilinear (GimpVector3 *position)
if (mapvals.transparent_background && heights[1][x] == 0) if (mapvals.transparent_background && heights[1][x] == 0)
{ {
gimp_rgb_set_alpha (&color_sum, 0.0); color_sum[3] = 0.0;
} }
else else
{ {
color = peek (x, RINT (yf)); peek (x, RINT (yf), color);
color_sum = color; for (gint i = 0; i < 4; i++)
gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); color_sum[i] = color[i];
for (gint i = 0; i < 3; i++)
color_sum[i] *= mapvals.material.ambient_int;
for (k = 0; k < NUM_LIGHTS; k++) for (k = 0; k < NUM_LIGHTS; k++)
{ {
@ -725,49 +753,53 @@ get_ray_color_no_bilinear (GimpVector3 *position)
else if (mapvals.lightsource[k].type == POINT_LIGHT) else if (mapvals.lightsource[k].type == POINT_LIGHT)
p = &mapvals.lightsource[k].position; p = &mapvals.lightsource[k].position;
color_int = mapvals.lightsource[k].color; for (gint i = 0; i < 4; i++)
gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); color_int[i] = mapvals.lightsource[k].color[i];
for (gint i = 0; i < 3; i++)
color_int[i] *= mapvals.lightsource[k].intensity;
if (mapvals.bump_mapped == FALSE || if (mapvals.bump_mapped == FALSE ||
mapvals.bumpmap_id == -1) mapvals.bumpmap_id == -1)
{ {
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&mapvals.planenormal, &mapvals.planenormal,
p, p,
&color, color,
&color_int, color_int,
mapvals.lightsource[k].type); mapvals.lightsource[k].type,
light_color);
} }
else else
{ {
normal = vertex_normals[1][x]; normal = vertex_normals[1][x];
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&normal, &normal,
p, p,
&color, color,
&color_int, color_int,
mapvals.lightsource[k].type); mapvals.lightsource[k].type,
light_color);
} }
gimp_rgb_add (&color_sum, &light_color); for (gint i = 0; i < 3; i++)
color_sum[i] += light_color[i];
} }
} }
gimp_rgb_clamp (&color_sum); for (gint i = 0; i < 4; i++)
color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0);
return color_sum;
} }
GimpRGB void
get_ray_color_no_bilinear_ref (GimpVector3 *position) get_ray_color_no_bilinear_ref (GimpVector3 *position,
gdouble *color_sum)
{ {
GimpRGB color_sum; gdouble color_int[4];
GimpRGB color_int; gdouble light_color[4];
GimpRGB light_color; gdouble color[4], env_color[4];
GimpRGB color, env_color;
gint x; gint x;
gdouble xf, yf; gdouble xf, yf;
GimpVector3 normal, *p, v, r; GimpVector3 normal, *p, v, r;
@ -792,13 +824,16 @@ get_ray_color_no_bilinear_ref (GimpVector3 *position)
if (mapvals.transparent_background && heights[1][x] == 0) if (mapvals.transparent_background && heights[1][x] == 0)
{ {
gimp_rgb_set_alpha (&color_sum, 0.0); color_sum[3] = 0.0;
} }
else else
{ {
color = peek (RINT (xf), RINT (yf)); peek (RINT (xf), RINT (yf), color);
color_sum = color;
gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); for (gint i = 0; i < 4; i++)
color_sum[i] = color[i];
for (gint i = 0; i < 3; i++)
color_sum[i] *= mapvals.material.ambient_int;
for (k = 0; k < NUM_LIGHTS; k++) for (k = 0; k < NUM_LIGHTS; k++)
{ {
@ -810,16 +845,19 @@ get_ray_color_no_bilinear_ref (GimpVector3 *position)
else if (mapvals.lightsource[k].type == POINT_LIGHT) else if (mapvals.lightsource[k].type == POINT_LIGHT)
p = &mapvals.lightsource[k].position; p = &mapvals.lightsource[k].position;
color_int = mapvals.lightsource[k].color; for (gint i = 0; i < 4; i++)
gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); color_int[i] = mapvals.lightsource[k].color[i];
for (gint i = 0; i < 3; i++)
color_int[i] *= mapvals.lightsource[k].intensity;
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&normal, &normal,
p, p,
&color, color,
&color_int, color_int,
mapvals.lightsource[0].type); mapvals.lightsource[0].type,
light_color);
} }
gimp_vector3_sub (&v, &mapvals.viewpoint, position); gimp_vector3_sub (&v, &mapvals.viewpoint, position);
@ -831,26 +869,28 @@ get_ray_color_no_bilinear_ref (GimpVector3 *position)
/* =============================== */ /* =============================== */
sphere_to_image (&r, &xf, &yf); sphere_to_image (&r, &xf, &yf);
env_color = peek_env_map (RINT (env_width * xf), peek_env_map (RINT (env_width * xf),
RINT (env_height * yf)); RINT (env_height * yf),
env_color);
tmpval = mapvals.material.diffuse_int; tmpval = mapvals.material.diffuse_int;
mapvals.material.diffuse_int = 0.; mapvals.material.diffuse_int = 0.0;
light_color = phong_shade (position, phong_shade (position,
&mapvals.viewpoint, &mapvals.viewpoint,
&normal, &normal,
&r, &r,
&color, color,
&env_color, env_color,
DIRECTIONAL_LIGHT); DIRECTIONAL_LIGHT,
light_color);
mapvals.material.diffuse_int = tmpval; mapvals.material.diffuse_int = tmpval;
gimp_rgb_add (&color_sum, &light_color); for (gint i = 0; i < 3; i++)
color_sum[i] += light_color[i];
} }
gimp_rgb_clamp (&color_sum); for (gint i = 0; i < 4; i++)
color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0);
return color_sum;
} }

View file

@ -1,12 +1,17 @@
#ifndef __LIGHTING_SHADE_H__ #ifndef __LIGHTING_SHADE_H__
#define __LIGHTING_SHADE_H__ #define __LIGHTING_SHADE_H__
typedef GimpRGB (* get_ray_func) (GimpVector3 *vector); typedef void (* get_ray_func) (GimpVector3 *vector,
gdouble *color_sum);
GimpRGB get_ray_color (GimpVector3 *position); void get_ray_color (GimpVector3 *position,
GimpRGB get_ray_color_no_bilinear (GimpVector3 *position); gdouble *color_sum);
GimpRGB get_ray_color_ref (GimpVector3 *position); void get_ray_color_no_bilinear (GimpVector3 *position,
GimpRGB get_ray_color_no_bilinear_ref (GimpVector3 *position); gdouble *color_sum);
void get_ray_color_ref (GimpVector3 *position,
gdouble *color_sum);
void get_ray_color_no_bilinear_ref (GimpVector3 *position,
gdouble *color_sum);
void precompute_init (gint w, void precompute_init (gint w,
gint h); gint h);

View file

@ -849,9 +849,9 @@ save_preset_response (GtkFileChooser *chooser,
g_ascii_dtostr (buffer3, blen, source->direction.z)); g_ascii_dtostr (buffer3, blen, source->direction.z));
fprintf (fp, "Color: %s %s %s\n", fprintf (fp, "Color: %s %s %s\n",
g_ascii_dtostr (buffer1, blen, source->color.r), g_ascii_dtostr (buffer1, blen, source->color[0]),
g_ascii_dtostr (buffer2, blen, source->color.g), g_ascii_dtostr (buffer2, blen, source->color[1]),
g_ascii_dtostr (buffer3, blen, source->color.b)); g_ascii_dtostr (buffer3, blen, source->color[2]));
fprintf (fp, "Intensity: %s\n", fprintf (fp, "Intensity: %s\n",
g_ascii_dtostr (buffer1, blen, source->intensity)); g_ascii_dtostr (buffer1, blen, source->intensity));
@ -1005,10 +1005,10 @@ load_preset_response (GtkFileChooser *chooser,
sizeof (buffer2) - 1, sizeof (buffer2) - 1,
sizeof (buffer3) - 1); sizeof (buffer3) - 1);
fscanf (fp, fmt_str, buffer1, buffer2, buffer3); fscanf (fp, fmt_str, buffer1, buffer2, buffer3);
source->color.r = g_ascii_strtod (buffer1, &endptr); source->color[0] = g_ascii_strtod (buffer1, &endptr);
source->color.g = g_ascii_strtod (buffer2, &endptr); source->color[1] = g_ascii_strtod (buffer2, &endptr);
source->color.b = g_ascii_strtod (buffer3, &endptr); source->color[2] = g_ascii_strtod (buffer3, &endptr);
source->color.a = 1.0; source->color[3] = 1.0;
snprintf (fmt_str, sizeof (fmt_str), snprintf (fmt_str, sizeof (fmt_str),
" Intensity: %%%" G_GSIZE_FORMAT "s", " Intensity: %%%" G_GSIZE_FORMAT "s",