From 0d3906a93e9117580a53d45025698e7fee38dd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 22 Jan 2013 13:32:39 +0000 Subject: [PATCH] paysages : Added shortcut in global renderer for surface lighting. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@504 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- lib_paysages/atmosphere/preview.c | 7 +------ lib_paysages/renderer.c | 11 +++++++++++ lib_paysages/renderer.h | 3 +++ lib_paysages/textures.c | 8 +------- lib_paysages/water.c | 7 +------ 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib_paysages/atmosphere/preview.c b/lib_paysages/atmosphere/preview.c index ed79ab1..afb2187 100644 --- a/lib_paysages/atmosphere/preview.c +++ b/lib_paysages/atmosphere/preview.c @@ -129,16 +129,11 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin if (_checkHit(eye, direction, &hit, &normal)) { Color color; - LightStatus* light; normal = m4Transform(rotation, normal); hit = m4Transform(rotation, hit); - light = lightingCreateStatus(renderer->lighting, hit, eye); - renderer->atmosphere->getLightingStatus(renderer, light, normal, 1); - color = lightingApplyStatus(light, normal, &MOUNT_MATERIAL); - lightingDeleteStatus(light); - + color = renderer->applyLightingToSurface(renderer, hit, normal, &MOUNT_MATERIAL); return renderer->atmosphere->applyAerialPerspective(renderer, hit, color); } else diff --git a/lib_paysages/renderer.c b/lib_paysages/renderer.c index 9ef5a58..7bbaee4 100644 --- a/lib_paysages/renderer.c +++ b/lib_paysages/renderer.c @@ -74,6 +74,15 @@ static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3 return base; } +Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material) +{ + LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->camera_location); + renderer->atmosphere->getLightingStatus(renderer, light, normal, 0); + Color result = lightingApplyStatus(light, normal, material); + lightingDeleteStatus(light); + return result; +} + Renderer* rendererCreate() { Renderer* result = malloc(sizeof(Renderer)); @@ -103,6 +112,8 @@ Renderer* rendererCreate() result->applyTextures = _applyTextures; result->applyClouds = _applyClouds; + result->applyLightingToSurface = _applyLightingToSurface; + result->lighting = lightingManagerCreate(); result->atmosphere = AtmosphereRendererClass.create(); diff --git a/lib_paysages/renderer.h b/lib_paysages/renderer.h index f18a186..06d6f8e 100644 --- a/lib_paysages/renderer.h +++ b/lib_paysages/renderer.h @@ -31,6 +31,9 @@ struct Renderer void (*pushTriangle)(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data); void (*pushQuad)(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data); + /* Shortcuts */ + Color (*applyLightingToSurface)(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material); + /* Scenery related */ RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds); HeightInfo (*getWaterHeightInfo)(Renderer* renderer); diff --git a/lib_paysages/textures.c b/lib_paysages/textures.c index 788cebf..ec8c56c 100644 --- a/lib_paysages/textures.c +++ b/lib_paysages/textures.c @@ -268,13 +268,7 @@ double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* re static inline Color _getLayerColor(Renderer* renderer, TextureResult texture) { - LightStatus* light; - Color result; - light = lightingCreateStatus(renderer->lighting, texture.location, renderer->camera_location); - renderer->atmosphere->getLightingStatus(renderer, light, texture.normal, 1); - result = lightingApplyStatus(light, texture.normal, &texture.definition->material); - lightingDeleteStatus(light); - return result; + return renderer->applyLightingToSurface(renderer, texture.location, texture.normal, &texture.definition->material); } Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail) diff --git a/lib_paysages/water.c b/lib_paysages/water.c index 17753f5..9042b6e 100644 --- a/lib_paysages/water.c +++ b/lib_paysages/water.c @@ -310,7 +310,6 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer, RayCastingResult refracted; Vector3 normal; Color color; - LightStatus* light; SurfaceMaterial material; double detail, depth; @@ -351,11 +350,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer, _applyFoam(definition, location, normal, detail, &material); - light = lightingCreateStatus(renderer->lighting, location, renderer->camera_location); - renderer->atmosphere->getLightingStatus(renderer, light, normal, 0); - color = lightingApplyStatus(light, normal, &material); - lightingDeleteStatus(light); - + color = renderer->applyLightingToSurface(renderer, location, normal, &material); color = renderer->atmosphere->applyAerialPerspective(renderer, location, color); color = renderer->applyClouds(renderer, color, renderer->camera_location, location);