From 5e4b4e59a91de29b2900d0d319f63f569200c039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sat, 25 May 2013 15:20:11 +0200 Subject: [PATCH] Working on clouds walking --- src/rendering/clouds/clo_lighting.c | 2 ++ src/rendering/clouds/clo_lighting.h | 30 +++++++++++++++++++++++++ src/rendering/clouds/clo_walking.c | 8 +++++-- src/rendering/clouds/clo_walking.h | 34 +++++++++++++++++++++++++---- src/testing/test_clouds.c | 22 +++++++++---------- 5 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 src/rendering/clouds/clo_lighting.c create mode 100644 src/rendering/clouds/clo_lighting.h diff --git a/src/rendering/clouds/clo_lighting.c b/src/rendering/clouds/clo_lighting.c new file mode 100644 index 0000000..3576b55 --- /dev/null +++ b/src/rendering/clouds/clo_lighting.c @@ -0,0 +1,2 @@ +#include "clo_lighting.h" + diff --git a/src/rendering/clouds/clo_lighting.h b/src/rendering/clouds/clo_lighting.h new file mode 100644 index 0000000..6c5cd1c --- /dev/null +++ b/src/rendering/clouds/clo_lighting.h @@ -0,0 +1,30 @@ +#ifndef _PAYSAGES_CLOUDS_LIGHTING_H_ +#define _PAYSAGES_CLOUDS_LIGHTING_H_ + +#include "public.h" +#include "../tools/euclid.h" + +/** + * Cloud lighting helpers. + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* + * Bind fake lighting functions to a renderer. + */ +void cloudsBindFakeLightingToRenderer(CloudsRenderer* renderer); + +/* + * Bind real lighting functions to a renderer. + */ +void cloudsBindRealLightingToRenderer(CloudsRenderer* renderer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/rendering/clouds/clo_walking.c b/src/rendering/clouds/clo_walking.c index 5efb929..e4987ee 100644 --- a/src/rendering/clouds/clo_walking.c +++ b/src/rendering/clouds/clo_walking.c @@ -136,8 +136,8 @@ int cloudsGetLayerPrimarySegments(Renderer* renderer, CloudsLayerDefinition* lay /* exiting the cloud */ segment_length += step_length; - out_segments->enter = segment_start; - out_segments->exit = walker; + out_segments->entry_point = segment_start; + out_segments->exit_point = walker; out_segments->length = segment_length; out_segments++; if (++segment_count >= max_segments) @@ -155,3 +155,7 @@ int cloudsGetLayerPrimarySegments(Renderer* renderer, CloudsLayerDefinition* lay return segment_count; } + +int cloudsGetLayerSecondarySampling(Renderer* renderer, CloudsLayerDefinition* layer, CloudPrimarySegment* segment, int max_control_points, CloudSecondaryControlPoint* out_control_points) +{ +} diff --git a/src/rendering/clouds/clo_walking.h b/src/rendering/clouds/clo_walking.h index 2ad19b3..489be79 100644 --- a/src/rendering/clouds/clo_walking.h +++ b/src/rendering/clouds/clo_walking.h @@ -5,7 +5,7 @@ #include "../tools/euclid.h" /** - * Functions to walk through a cloud layer. + * Functions to walk through a cloud layer (sampling). */ #ifdef __cplusplus @@ -15,11 +15,25 @@ extern "C" typedef struct { - Vector3 enter; - Vector3 exit; + Vector3 entry_point; + Vector3 exit_point; double length; } CloudPrimarySegment; +typedef struct +{ + /** Distance factor of the control point from the segment start */ + double distance; + /** Location of the control point */ + Vector3 location; + /** Global density at the control point (no edge noise applied) */ + double global_density; + /** Particle dentisy at the control point, using edge noise */ + double particle_density; + /** Estimated distance to nearest cloud exit */ + double nearest_exit_distance; +} CloudSecondaryControlPoint; + /** * Optimize the search limits in a layer. * @@ -38,11 +52,23 @@ int cloudsOptimizeWalkingBounds(CloudsLayerDefinition* layer, Vector3* start, Ve * @param start Start position of the lookup * @param end End position of the lookup * @param max_segments Maximum number of segments to collect - * @param out_segments Allocated space to fill found segments + * @param out_segments Allocated space to fill found segments (must be at least 'max_segments' long) * @return Number of segments found */ int cloudsGetLayerPrimarySegments(Renderer* renderer, CloudsLayerDefinition* layer, Vector3 start, Vector3 end, int max_segments, CloudPrimarySegment* out_segments); +/** + * Sample a primary segment with refined details, collecting material interaction. + * + * @param renderer The renderer environment + * @param layer The cloud layer + * @param segment The primary segment to sample + * @param max_control_points Maximum number of control points to sample + * @param out_control_points Allocated space to fill with secondary control points (must be at least 'max_control_points' long) + * @return Number of control points sampled + */ +int cloudsGetLayerSecondarySampling(Renderer* renderer, CloudsLayerDefinition* layer, CloudPrimarySegment* segment, int max_control_points, CloudSecondaryControlPoint* out_control_points); + #ifdef __cplusplus } #endif diff --git a/src/testing/test_clouds.c b/src/testing/test_clouds.c index 7ab715e..8636c7a 100644 --- a/src/testing/test_clouds.c +++ b/src/testing/test_clouds.c @@ -221,18 +221,18 @@ START_TEST(test_clouds_primary_segments) ck_assert_int_eq(segment_count, 2); for (i = 0; i < segment_count; i++) { - ck_assert_double_eq(segments[i].enter.y, 0.0); - ck_assert_double_eq(segments[i].enter.z, 0.0); - ck_assert_double_eq(segments[i].exit.y, 0.0); - ck_assert_double_eq(segments[i].exit.z, 0.0); + ck_assert_double_eq(segments[i].entry_point.y, 0.0); + ck_assert_double_eq(segments[i].entry_point.z, 0.0); + ck_assert_double_eq(segments[i].exit_point.y, 0.0); + ck_assert_double_eq(segments[i].exit_point.z, 0.0); } - ck_assert_double_in_range(segments[0].enter.x, -0.5, 0.0); - ck_assert_double_in_range(segments[0].exit.x, 0.5, 1.0); - ck_assert_double_in_range(segments[0].length, 0.5, 1.5); - ck_assert_double_gte(segments[1].enter.x, segments[0].exit.x); - ck_assert_double_in_range(segments[1].enter.x, 0.5, 1.0); - ck_assert_double_in_range(segments[1].exit.x, 1.5, 2.0); - ck_assert_double_in_range(segments[1].length, 0.5, 1.5); + ck_assert_double_in_range(segments[0].entry_point.x, -0.4, 0.0); + ck_assert_double_in_range(segments[0].exit_point.x, 0.5, 1.0); + ck_assert_double_in_range(segments[0].length, 0.5, 1.3); + ck_assert_double_gte(segments[1].entry_point.x, segments[0].exit_point.x); + ck_assert_double_in_range(segments[1].entry_point.x, 0.5, 1.0); + ck_assert_double_in_range(segments[1].exit_point.x, 1.5, 1.9); + ck_assert_double_in_range(segments[1].length, 0.5, 1.3); cloudsGetLayerType().callback_delete(layer); rendererDelete(renderer);