From 942fd9ff8e267b361de580a95fa247e486120891 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 21 Aug 2011 13:24:13 -0600 Subject: Replace sky_spheres with a single background pigment. --- libdimension/Makefile.am | 2 -- libdimension/dimension.h | 1 - libdimension/dimension/scene.h | 3 +- libdimension/dimension/sky_sphere.h | 61 -------------------------------- libdimension/raytrace.c | 16 ++++----- libdimension/scene.c | 11 +++--- libdimension/sky_sphere.c | 70 ------------------------------------- libdimension/tests/render.c | 11 ++---- 8 files changed, 14 insertions(+), 161 deletions(-) delete mode 100644 libdimension/dimension/sky_sphere.h delete mode 100644 libdimension/sky_sphere.c (limited to 'libdimension') diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am index a9fe2ea..94b5e98 100644 --- a/libdimension/Makefile.am +++ b/libdimension/Makefile.am @@ -55,7 +55,6 @@ nobase_include_HEADERS = dimension.h \ dimension/raytrace.h \ dimension/refcount.h \ dimension/scene.h \ - dimension/sky_sphere.h \ dimension/texture.h \ dimension/timer.h @@ -104,7 +103,6 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \ raytrace.c \ reflection.c \ scene.c \ - sky_sphere.c \ solid_pigment.c \ sphere.c \ texture.c \ diff --git a/libdimension/dimension.h b/libdimension/dimension.h index 33b8378..309eaa2 100644 --- a/libdimension/dimension.h +++ b/libdimension/dimension.h @@ -104,7 +104,6 @@ typedef void dmnsn_free_fn(void *ptr); #include #include #include -#include #include #include diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h index c35f91f..cbd26ab 100644 --- a/libdimension/dimension/scene.h +++ b/libdimension/dimension/scene.h @@ -40,8 +40,7 @@ typedef unsigned int dmnsn_quality; /** An entire scene. */ typedef struct dmnsn_scene { /* World attributes */ - dmnsn_color background; /**< Background color. */ - dmnsn_sky_sphere *sky_sphere; /**< Sky sphere. */ + dmnsn_pigment *background; /**< Background pigment. */ dmnsn_texture *default_texture; /**< Default object texture. */ dmnsn_interior *default_interior; /**< Default object interior. */ diff --git a/libdimension/dimension/sky_sphere.h b/libdimension/dimension/sky_sphere.h deleted file mode 100644 index 2d2c834..0000000 --- a/libdimension/dimension/sky_sphere.h +++ /dev/null @@ -1,61 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010 Tavian Barnes * - * * - * This file is part of The Dimension Library. * - * * - * The Dimension Library is free software; you can redistribute it and/ * - * or modify it under the terms of the GNU Lesser General Public License * - * as published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Library 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 * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program. If not, see * - * . * - *************************************************************************/ - -/** - * @file - * Sky spheres. - */ - -/** A sky sphere. */ -typedef struct dmnsn_sky_sphere { - /** An array of pigments in inside-to-outside order. */ - dmnsn_array *pigments; - - dmnsn_matrix trans; /**< Transformation matrix. */ - - dmnsn_refcount refcount; /**< @internal Reference count. */ -} dmnsn_sky_sphere; - -/** - * Create a sky sphere. - * @return A new blank sky sphere. - */ -dmnsn_sky_sphere *dmnsn_new_sky_sphere(void); - -/** - * Delete a sky sphere. - * @param[in,out] sky_sphere The sky sphere to delete. - */ -void dmnsn_delete_sky_sphere(dmnsn_sky_sphere *sky_sphere); - -/** - * Initialize a sky sphere. - * @param[in,out] sky_sphere The sky sphere to initialize. - */ -void dmnsn_initialize_sky_sphere(dmnsn_sky_sphere *sky_sphere); - -/** - * Evaluate the color of the sky sphere. - * @param[in] sky_sphere The sky sphere to evaluate. - * @param[in] d The direction to look. - * @return The color of the sky in the direction of \p d. - */ -dmnsn_color dmnsn_sky_sphere_color(const dmnsn_sky_sphere *sky_sphere, - dmnsn_vector d); diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 92947d6..056e7bf 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -205,18 +205,14 @@ dmnsn_raytrace_scene_concurrent(void *ptr, unsigned int thread, /** Calculate the background color. */ static dmnsn_color -dmnsn_raytrace_background(dmnsn_raytrace_state *state, dmnsn_line ray) +dmnsn_raytrace_background(const dmnsn_raytrace_state *state, dmnsn_line ray) { - dmnsn_color color = state->scene->background; - if (state->scene->sky_sphere - && (state->scene->quality & DMNSN_RENDER_PIGMENT)) - { - dmnsn_color sky = dmnsn_sky_sphere_color(state->scene->sky_sphere, - dmnsn_vector_normalized(ray.n)); - color = dmnsn_apply_filter(color, sky); + dmnsn_pigment *background = state->scene->background; + if (state->scene->quality & DMNSN_RENDER_PIGMENT) { + return dmnsn_evaluate_pigment(background, dmnsn_vector_normalized(ray.n)); + } else { + return background->quick_color; } - - return color; } /** Calculate the base pigment at the intersection. */ diff --git a/libdimension/scene.c b/libdimension/scene.c index dc62799..ff2ff62 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -32,8 +32,7 @@ dmnsn_new_scene(void) { dmnsn_scene *scene = dmnsn_malloc(sizeof(dmnsn_scene)); - scene->background = dmnsn_black; - scene->sky_sphere = NULL; + scene->background = NULL; scene->default_texture = dmnsn_new_texture(); scene->default_interior = dmnsn_new_interior(); scene->canvas = NULL; @@ -71,7 +70,7 @@ dmnsn_delete_scene(dmnsn_scene *scene) dmnsn_delete_camera(scene->camera); dmnsn_delete_interior(scene->default_interior); dmnsn_delete_texture(scene->default_texture); - dmnsn_delete_sky_sphere(scene->sky_sphere); + dmnsn_delete_pigment(scene->background); dmnsn_free(scene); } } @@ -89,11 +88,9 @@ dmnsn_initialize_scene(dmnsn_scene *scene) scene->outer_height = scene->canvas->height; } - dmnsn_initialize_texture(scene->default_texture); + dmnsn_initialize_pigment(scene->background); - if (scene->sky_sphere) { - dmnsn_initialize_sky_sphere(scene->sky_sphere); - } + dmnsn_initialize_texture(scene->default_texture); DMNSN_ARRAY_FOREACH (dmnsn_object **, object, scene->objects) { dmnsn_texture_cascade(scene->default_texture, &(*object)->texture); diff --git a/libdimension/sky_sphere.c b/libdimension/sky_sphere.c deleted file mode 100644 index 2279881..0000000 --- a/libdimension/sky_sphere.c +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * This file is part of The Dimension Library. * - * * - * The Dimension Library is free software; you can redistribute it and/ * - * or modify it under the terms of the GNU Lesser General Public License * - * as published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Library 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 * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program. If not, see * - * . * - *************************************************************************/ - -/** - * @file - * Sky spheres. - */ - -#include "dimension.h" - -dmnsn_sky_sphere * -dmnsn_new_sky_sphere(void) -{ - dmnsn_sky_sphere *sky_sphere = dmnsn_malloc(sizeof(dmnsn_sky_sphere)); - sky_sphere->pigments = dmnsn_new_array(sizeof(dmnsn_pigment *)); - sky_sphere->trans = dmnsn_identity_matrix(); - sky_sphere->refcount = 1; - return sky_sphere; -} - -void -dmnsn_delete_sky_sphere(dmnsn_sky_sphere *sky_sphere) -{ - if (DMNSN_DECREF(sky_sphere)) { - DMNSN_ARRAY_FOREACH (dmnsn_pigment **, pigment, sky_sphere->pigments) { - dmnsn_delete_pigment(*pigment); - } - dmnsn_delete_array(sky_sphere->pigments); - dmnsn_free(sky_sphere); - } -} - -void -dmnsn_initialize_sky_sphere(dmnsn_sky_sphere *sky_sphere) -{ - DMNSN_ARRAY_FOREACH (dmnsn_pigment **, pigment, sky_sphere->pigments) { - (*pigment)->trans = dmnsn_matrix_mul(sky_sphere->trans, (*pigment)->trans); - dmnsn_initialize_pigment(*pigment); - } -} - -dmnsn_color -dmnsn_sky_sphere_color(const dmnsn_sky_sphere *sky_sphere, dmnsn_vector d) -{ - dmnsn_color color = dmnsn_clear; - - DMNSN_ARRAY_FOREACH (const dmnsn_pigment **, pigment, sky_sphere->pigments) { - dmnsn_color sky = dmnsn_evaluate_pigment(*pigment, d); - color = dmnsn_apply_filter(color, sky); - } - - return color; -} diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index 577fa6a..ae0301f 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -36,9 +36,6 @@ dmnsn_test_scene_set_defaults(dmnsn_scene *scene) dmnsn_color_from_sRGB(dmnsn_color_mul(0.7, dmnsn_white)) ) ); - - /* Background color */ - scene->background = dmnsn_clear; } static void @@ -75,9 +72,8 @@ dmnsn_test_scene_add_camera(dmnsn_scene *scene) } static void -dmnsn_test_scene_add_sky_sphere(dmnsn_scene *scene) +dmnsn_test_scene_add_background(dmnsn_scene *scene) { - scene->sky_sphere = dmnsn_new_sky_sphere(); dmnsn_pattern *sky_gradient = dmnsn_new_gradient_pattern(dmnsn_y); dmnsn_map *sky_gradient_pigment_map = dmnsn_new_pigment_map(); dmnsn_pigment_map_add_color(sky_gradient_pigment_map, 0.0, dmnsn_orange); @@ -85,10 +81,9 @@ dmnsn_test_scene_add_sky_sphere(dmnsn_scene *scene) dmnsn_new_color5(0.0, 0.1, 0.2, 0.1, 0.0) ); dmnsn_pigment_map_add_color(sky_gradient_pigment_map, 0.35, background); - dmnsn_pigment *sky_pigment = + scene->background = dmnsn_new_pigment_map_pigment(sky_gradient, sky_gradient_pigment_map, DMNSN_PIGMENT_MAP_SRGB); - dmnsn_array_push(scene->sky_sphere->pigments, &sky_pigment); } static void @@ -283,7 +278,7 @@ dmnsn_new_test_scene(void) dmnsn_test_scene_set_defaults(scene); dmnsn_test_scene_add_canvas(scene); dmnsn_test_scene_add_camera(scene); - dmnsn_test_scene_add_sky_sphere(scene); + dmnsn_test_scene_add_background(scene); dmnsn_test_scene_add_lights(scene); dmnsn_test_scene_add_objects(scene); return scene; -- cgit v1.2.3