summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-08-21 13:24:13 -0600
committerTavian Barnes <tavianator@gmail.com>2011-08-21 13:24:13 -0600
commit942fd9ff8e267b361de580a95fa247e486120891 (patch)
tree683835731d05db901d98d10ba0023bb1ef3fb285
parent6b1fcde7af64ca81079dffe1d62096228693b5d6 (diff)
downloaddimension-942fd9ff8e267b361de580a95fa247e486120891.tar.xz
Replace sky_spheres with a single background pigment.
-rw-r--r--dimension/dimension.in3
-rw-r--r--dimension/tests/demo.dmnsn19
-rw-r--r--libdimension-python/dimension.pxd14
-rw-r--r--libdimension-python/dimension.pyx53
-rwxr-xr-xlibdimension-python/tests/demo.py3
-rw-r--r--libdimension/Makefile.am2
-rw-r--r--libdimension/dimension.h1
-rw-r--r--libdimension/dimension/scene.h3
-rw-r--r--libdimension/dimension/sky_sphere.h61
-rw-r--r--libdimension/raytrace.c16
-rw-r--r--libdimension/scene.c11
-rw-r--r--libdimension/sky_sphere.c70
-rw-r--r--libdimension/tests/render.c11
13 files changed, 32 insertions, 235 deletions
diff --git a/dimension/dimension.in b/dimension/dimension.in
index cfebe78..c637d26 100644
--- a/dimension/dimension.in
+++ b/dimension/dimension.in
@@ -151,7 +151,6 @@ camera = PerspectiveCamera()
default_texture = Texture(finish = Ambient(0.1) + Diffuse(0.7))
default_interior = Interior()
background = Black
-sky_sphere = None
recursion_limit = None
# Execute the input script
@@ -178,8 +177,6 @@ scene.outer_width = _args.width
scene.outer_height = _args.height
scene.default_texture = default_texture
scene.background = background
-if sky_sphere is not None:
- scene.sky_sphere = sky_sphere
if recursion_limit is not None:
scene.recursion_limit = recursion_limit
if _args.threads is not None:
diff --git a/dimension/tests/demo.dmnsn b/dimension/tests/demo.dmnsn
index 04783a0..fbf51da 100644
--- a/dimension/tests/demo.dmnsn
+++ b/dimension/tests/demo.dmnsn
@@ -23,19 +23,12 @@ camera = PerspectiveCamera(location = (0, 0.25, -4),
camera.transform(rotate(53*Y))
# Background
-background = Clear
-
-# Sky sphere
-sky_sphere = SkySphere(
- [
- PigmentMap(
- pattern = Gradient(Y),
- map = {
- 0: Orange,
- 0.35: Color(0, 0.1, 0.2, trans = 0.1, filter = 0.0),
- },
- ),
- ]
+background = PigmentMap(
+ pattern = Gradient(Y),
+ map = {
+ 0: Orange,
+ 0.35: Color(0, 0.1, 0.2, trans = 0.1, filter = 0.0),
+ },
)
# Lights
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd
index 7b3ba6e..4590e89 100644
--- a/libdimension-python/dimension.pxd
+++ b/libdimension-python/dimension.pxd
@@ -346,17 +346,6 @@ cdef extern from "../libdimension/dimension.h":
dmnsn_camera *dmnsn_new_perspective_camera()
- ###############
- # Sky Spheres #
- ###############
-
- ctypedef struct dmnsn_sky_sphere:
- dmnsn_array *pigments
- dmnsn_matrix trans
-
- dmnsn_sky_sphere *dmnsn_new_sky_sphere()
- void dmnsn_delete_sky_sphere(dmnsn_sky_sphere *sky_sphere)
-
##########
# Scenes #
##########
@@ -371,8 +360,7 @@ cdef extern from "../libdimension/dimension.h":
DMNSN_RENDER_FULL
ctypedef struct dmnsn_scene:
- dmnsn_color background
- dmnsn_sky_sphere *sky_sphere
+ dmnsn_pigment *background
dmnsn_texture *default_texture
dmnsn_interior *default_interior
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index d0bd4e7..a9ca3ac 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -1283,38 +1283,6 @@ cdef class PerspectiveCamera(Camera):
# Move the camera into position
self.transform(translate(Vector(location)))
-###############
-# Sky Spheres #
-###############
-
-cdef class SkySphere:
- """A scene background."""
- cdef dmnsn_sky_sphere *_sky_sphere
-
- def __init__(self, pigments):
- """
- Create a SkySphere.
-
- Keyword arguments:
- pigments -- the list of pigments that make up the background, in back-to-
- front order
- """
- self._sky_sphere = dmnsn_new_sky_sphere()
-
- cdef Pigment real_pigment
- for pigment in pigments:
- real_pigment = Pigment(pigment)
- DMNSN_INCREF(real_pigment._pigment)
- dmnsn_array_push(self._sky_sphere.pigments, &real_pigment._pigment)
-
- def __dealloc__(self):
- dmnsn_delete_sky_sphere(self._sky_sphere)
-
- def transform(self, Matrix trans not None):
- """Transform a sky sphere."""
- self._sky_sphere.trans = dmnsn_matrix_mul(trans._m, self._sky_sphere.trans)
- return self
-
##########
# Scenes #
##########
@@ -1400,18 +1368,17 @@ cdef class Scene:
DMNSN_INCREF(self._scene.default_interior)
property background:
- """The solid background color of the scene (default: Black)."""
+ """The background pigment of the scene (default: Black)."""
def __get__(self):
- return _Color(self._scene.background)
- def __set__(self, color):
- self._scene.background = Color(color)._c
-
- property sky_sphere:
- """The background sky pattern of the scene."""
- def __set__(self, SkySphere sky_sphere not None):
- dmnsn_delete_sky_sphere(self._scene.sky_sphere)
- self._scene.sky_sphere = sky_sphere._sky_sphere
- DMNSN_INCREF(self._scene.sky_sphere)
+ if self._scene.background == NULL:
+ return None
+ else:
+ return _Pigment(self._scene.background)
+ def __set__(self, pigment):
+ dmnsn_delete_pigment(self._scene.background)
+ cdef Pigment real_pigment = Pigment(pigment)
+ self._scene.background = real_pigment._pigment
+ DMNSN_INCREF(self._scene.background)
property adc_bailout:
"""The adaptive depth control bailout (default: 1/255)."""
diff --git a/libdimension-python/tests/demo.py b/libdimension-python/tests/demo.py
index 307aafc..fe3518c 100755
--- a/libdimension-python/tests/demo.py
+++ b/libdimension-python/tests/demo.py
@@ -49,8 +49,7 @@ scene = Scene(canvas = canvas,
lights = lights,
camera = camera)
scene.default_texture = Texture(finish = Ambient(0.1) + Diffuse(0.7))
-scene.background = Clear
-scene.sky_sphere = sky_sphere
+scene.background = background
scene.adc_bailout = 1/255
scene.recursion_limit = 5
scene.raytrace()
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 <dimension/lights.h>
#include <dimension/camera.h>
#include <dimension/cameras.h>
-#include <dimension/sky_sphere.h>
#include <dimension/scene.h>
#include <dimension/raytrace.h>
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 <tavianator@tavianator.com> *
- * *
- * 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 *
- * <http://www.gnu.org/licenses/>. *
- *************************************************************************/
-
-/**
- * @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 <tavianator@tavianator.com> *
- * *
- * 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 *
- * <http://www.gnu.org/licenses/>. *
- *************************************************************************/
-
-/**
- * @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;