diff options
-rw-r--r-- | dimension/common.terminals | 2 | ||||
-rw-r--r-- | dimension/grammar.declarations | 2 | ||||
-rw-r--r-- | dimension/grammar.rules | 5 | ||||
-rw-r--r-- | dimension/lexer.l | 1 | ||||
-rw-r--r-- | dimension/realize.c | 7 | ||||
-rw-r--r-- | libdimension/dimension/scene.h | 1 | ||||
-rw-r--r-- | libdimension/raytrace.c | 4 | ||||
-rw-r--r-- | libdimension/scene.c | 2 |
8 files changed, 20 insertions, 4 deletions
diff --git a/dimension/common.terminals b/dimension/common.terminals index 079aede..5a0d778 100644 --- a/dimension/common.terminals +++ b/dimension/common.terminals @@ -80,7 +80,7 @@ %token DMNSN_T_ALTITUDE %token DMNSN_T_ALWAYS_SAMPLE %token DMNSN_T_AMBIENT "ambient" -%token DMNSN_T_AMBIENT_LIGHT +%token DMNSN_T_AMBIENT_LIGHT "ambient_light" %token DMNSN_T_ANGLE "angle" %token DMNSN_T_APERTURE %token DMNSN_T_APPEND diff --git a/dimension/grammar.declarations b/dimension/grammar.declarations index 58b995f..ef3f7a2 100644 --- a/dimension/grammar.declarations +++ b/dimension/grammar.declarations @@ -23,7 +23,7 @@ %name-prefix "dmnsn_yy" -%expect 12 +%expect 13 %parse-param {const char *filename} %parse-param {void *yyscanner} diff --git a/dimension/grammar.rules b/dimension/grammar.rules index 1ce3e1f..0e9d6f1 100644 --- a/dimension/grammar.rules +++ b/dimension/grammar.rules @@ -55,7 +55,10 @@ GLOBAL_SETTINGS_ITEMS: /* empty */ { } ; -GLOBAL_SETTINGS_ITEM: "assumed_gamma" FLOAT { +GLOBAL_SETTINGS_ITEM: "ambient_light" COLOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_AMBIENT, @$, $2); + } + | "assumed_gamma" FLOAT { dmnsn_diagnostic(@1, "WARNING: assumed_gamma not supported"); $$ = dmnsn_new_astnode1(DMNSN_AST_ASSUMED_GAMMA, @$, $2); diff --git a/dimension/lexer.l b/dimension/lexer.l index 8216091..5e1afa2 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -169,6 +169,7 @@ unsigned long wchar; "acos" RETURN_TOKEN(DMNSN_T_ACOS); "acosh" RETURN_TOKEN(DMNSN_T_ACOSH); "ambient" RETURN_TOKEN(DMNSN_T_AMBIENT); +"ambient_light" RETURN_TOKEN(DMNSN_T_AMBIENT_LIGHT); "angle" RETURN_TOKEN(DMNSN_T_ANGLE); "asc" RETURN_TOKEN(DMNSN_T_ASC); "ascii" RETURN_TOKEN(DMNSN_T_ASCII); diff --git a/dimension/realize.c b/dimension/realize.c index 15d4104..d4b45cb 100644 --- a/dimension/realize.c +++ b/dimension/realize.c @@ -239,6 +239,13 @@ dmnsn_realize_global_settings(dmnsn_astnode astnode, dmnsn_scene *scene) dmnsn_astnode child; switch (item->type) { + case DMNSN_AST_AMBIENT: + dmnsn_array_get(item->children, 0, &child); + scene->ambient = dmnsn_realize_color(child); + scene->ambient.filter = 0.0; + scene->ambient.trans = 0.0; + break; + case DMNSN_AST_MAX_TRACE_LEVEL: dmnsn_array_get(item->children, 0, &child); scene->reclimit = dmnsn_realize_integer(child); diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h index 57ef32b..489e4e5 100644 --- a/libdimension/dimension/scene.h +++ b/libdimension/dimension/scene.h @@ -44,6 +44,7 @@ typedef unsigned int dmnsn_quality; typedef struct dmnsn_scene { /* World attributes */ dmnsn_color background; /**< Background color. */ + dmnsn_color ambient; /**< Global ambient color. */ dmnsn_texture *default_texture; /**< Default object texture. */ /** Camera. */ diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 74f4557..e6596e4 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -337,9 +337,11 @@ dmnsn_raytrace_light_ray(const dmnsn_raytrace_state *state, static void dmnsn_raytrace_lighting(dmnsn_raytrace_state *state) { - /* The illuminated color */ + /* The ambient color */ state->diffuse = TEXTURE_CALLBACK(state, finish, ambient_fn, dmnsn_black, state->pigment); + state->diffuse = dmnsn_color_illuminate(state->scene->ambient, + state->diffuse); if (!TEXTURE_HAS_CALLBACK(state, finish, diffuse_fn) && !TEXTURE_HAS_CALLBACK(state, finish, specular_fn)) diff --git a/libdimension/scene.c b/libdimension/scene.c index fc5bb92..9eca7b7 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -32,6 +32,8 @@ dmnsn_new_scene() { dmnsn_scene *scene = dmnsn_malloc(sizeof(dmnsn_scene)); + scene->background = dmnsn_black; + scene->ambient = dmnsn_white; scene->default_texture = dmnsn_new_texture(); scene->camera = NULL; scene->canvas = NULL; |