summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-11-09 15:20:58 -0500
committerTavian Barnes <tavianator@gmail.com>2009-11-09 16:07:33 -0500
commit5138e55d3eb41255b1436d40ceba134876c3c5cd (patch)
tree5a3e00248c328b097c4b71e225c597d19a372363
parent319491781c1389d82897075b6d890e74d82a08a9 (diff)
downloaddimension-5138e55d3eb41255b1436d40ceba134876c3c5cd.tar.xz
Add support for finishes (BRDFs).
-rw-r--r--libdimension/Makefile.am2
-rw-r--r--libdimension/dimension/finishes.h31
-rw-r--r--libdimension/dimension/texture.h27
-rw-r--r--libdimension/finishes.c41
-rw-r--r--libdimension/scene.c2
-rw-r--r--libdimension/texture.c29
6 files changed, 129 insertions, 3 deletions
diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am
index 15151d6..fb15f44 100644
--- a/libdimension/Makefile.am
+++ b/libdimension/Makefile.am
@@ -24,6 +24,7 @@ nobase_include_HEADERS = dimension.h \
dimension/canvas.h \
dimension/color.h \
dimension/error.h \
+ dimension/finishes.h \
dimension/geometry.h \
dimension/gl.h \
dimension/light.h \
@@ -46,6 +47,7 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \
color.c \
dimension_impl.h \
error.c \
+ finishes.c \
geometry.c \
gl.c \
inlines.c \
diff --git a/libdimension/dimension/finishes.h b/libdimension/dimension/finishes.h
new file mode 100644
index 0000000..da18a6f
--- /dev/null
+++ b/libdimension/dimension/finishes.h
@@ -0,0 +1,31 @@
+/*************************************************************************
+ * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.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/>. *
+ *************************************************************************/
+
+/*
+ * Custom finishes.
+ */
+
+#ifndef DIMENSION_FINISHES_H
+#define DIMENSION_FINISHES_H
+
+/* A specular finish */
+dmnsn_finish *dmnsn_new_specular_finish();
+
+#endif /* DIMENSION_FINISHES_H */
diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h
index c26e840..4d0e2d7 100644
--- a/libdimension/dimension/texture.h
+++ b/libdimension/dimension/texture.h
@@ -50,11 +50,38 @@ dmnsn_pigment *dmnsn_new_pigment();
void dmnsn_delete_pigment(dmnsn_pigment *pigment);
/*
+ * Finishes
+ */
+
+/* Forward-declare dmnsn_finish */
+typedef struct dmnsn_finish dmnsn_finish;
+
+/* Finish callback */
+typedef dmnsn_color dmnsn_finish_fn(const dmnsn_finish *finish,
+ dmnsn_color color, dmnsn_vector x0,
+ dmnsn_vector normal,
+ dmnsn_vector reflected);
+
+/* dmnsn_finish definition */
+struct dmnsn_finish {
+ /* Callbacks */
+ dmnsn_finish_fn *finish_fn;
+ dmnsn_free_fn *free_fn;
+
+ /* Generic pointer */
+ void *ptr;
+};
+
+dmnsn_finish *dmnsn_new_finish();
+void dmnsn_delete_finish(dmnsn_finish *finish);
+
+/*
* A complete texture
*/
typedef struct {
dmnsn_pigment *pigment;
+ dmnsn_finish *finish;
} dmnsn_texture;
dmnsn_texture *dmnsn_new_texture();
diff --git a/libdimension/finishes.c b/libdimension/finishes.c
new file mode 100644
index 0000000..d78bc96
--- /dev/null
+++ b/libdimension/finishes.c
@@ -0,0 +1,41 @@
+/*************************************************************************
+ * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.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/>. *
+ *************************************************************************/
+
+#include "dimension.h"
+#include <stdlib.h> /* For malloc */
+
+static dmnsn_color
+dmnsn_specular_finish_fn(const dmnsn_finish *finish,
+ dmnsn_color color, dmnsn_vector x0,
+ dmnsn_vector normal, dmnsn_vector reflected)
+{
+ return dmnsn_color_mul(dmnsn_vector_dot(normal, reflected), color);
+}
+
+/* A specular finish */
+dmnsn_finish *
+dmnsn_new_specular_finish()
+{
+ dmnsn_finish *finish = dmnsn_new_finish();
+ if (finish) {
+ finish->finish_fn = &dmnsn_specular_finish_fn;
+ }
+ return finish;
+}
diff --git a/libdimension/scene.c b/libdimension/scene.c
index 65362a5..38b1d19 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -27,7 +27,7 @@ dmnsn_new_scene()
{
dmnsn_scene *scene = malloc(sizeof(dmnsn_scene));
if (scene) {
- scene->default_texture = NULL;
+ scene->default_texture = dmnsn_new_texture();
scene->camera = NULL;
scene->canvas = NULL;
diff --git a/libdimension/texture.c b/libdimension/texture.c
index 3867628..a9d7de1 100644
--- a/libdimension/texture.c
+++ b/libdimension/texture.c
@@ -21,7 +21,7 @@
#include "dimension.h"
#include <stdlib.h> /* For malloc */
-/* Allocate an dummy pigment */
+/* Allocate a dummy pigment */
dmnsn_pigment *
dmnsn_new_pigment()
{
@@ -44,6 +44,29 @@ dmnsn_delete_pigment(dmnsn_pigment *pigment)
}
}
+/* Allocate a dummy finish */
+dmnsn_finish *
+dmnsn_new_finish()
+{
+ dmnsn_finish *finish = malloc(sizeof(dmnsn_finish));
+ if (finish) {
+ finish->free_fn = NULL;
+ }
+ return finish;
+}
+
+/* Free a finish */
+void
+dmnsn_delete_finish(dmnsn_finish *finish)
+{
+ if (finish) {
+ if (finish->free_fn) {
+ (*finish->free_fn)(finish->ptr);
+ }
+ free(finish);
+ }
+}
+
/* Allocate a dummy texture */
dmnsn_texture *
dmnsn_new_texture()
@@ -51,15 +74,17 @@ dmnsn_new_texture()
dmnsn_texture *texture = malloc(sizeof(dmnsn_texture));
if (texture) {
texture->pigment = NULL;
+ texture->finish = NULL;
}
return texture;
}
-/* Free a dummy texture */
+/* Free a texture */
void
dmnsn_delete_texture(dmnsn_texture *texture)
{
if (texture) {
+ dmnsn_delete_finish(texture->finish);
dmnsn_delete_pigment(texture->pigment);
free(texture);
}