From b0d9ead01dcc189321818f41b2c72fb2c07ffe3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 8 Dec 2013 18:36:39 +0100 Subject: [PATCH] [WIP] Removed old atmosphere renderer --- .../software/AtmosphereModelBruneton.cpp} | 20 +++- src/render/software/AtmosphereModelBruneton.h | 27 +++++ src/render/software/AtmosphereRenderer.cpp | 3 - src/render/software/AtmosphereRenderer.h | 3 - src/render/software/AtmosphereResult.cpp | 21 ++++ src/render/software/AtmosphereResult.h | 28 +++++ src/render/software/SoftwareRenderer.cpp | 4 +- src/render/software/SoftwareRenderer.h | 2 +- src/render/software/software.pro | 10 +- src/rendering/RenderingScenery.cpp | 1 - src/rendering/atmosphere/atm_render.cpp | 111 ------------------ src/rendering/atmosphere/private.h | 19 --- src/rendering/atmosphere/public.h | 41 ------- src/rendering/renderer.cpp | 11 +- src/rendering/renderer.h | 5 - src/rendering/rendering.pro | 4 - src/rendering/textures/tex_rendering.cpp | 2 +- src/rendering/water/wat_render.cpp | 4 +- 18 files changed, 108 insertions(+), 208 deletions(-) rename src/{rendering/atmosphere/atm_bruneton.cpp => render/software/AtmosphereModelBruneton.cpp} (98%) create mode 100644 src/render/software/AtmosphereModelBruneton.h create mode 100644 src/render/software/AtmosphereResult.cpp create mode 100644 src/render/software/AtmosphereResult.h delete mode 100644 src/rendering/atmosphere/atm_render.cpp delete mode 100644 src/rendering/atmosphere/private.h delete mode 100644 src/rendering/atmosphere/public.h diff --git a/src/rendering/atmosphere/atm_bruneton.cpp b/src/render/software/AtmosphereModelBruneton.cpp similarity index 98% rename from src/rendering/atmosphere/atm_bruneton.cpp rename to src/render/software/AtmosphereModelBruneton.cpp index 45af518..5fef2d8 100644 --- a/src/rendering/atmosphere/atm_bruneton.cpp +++ b/src/render/software/AtmosphereModelBruneton.cpp @@ -1,4 +1,11 @@ -#include "private.h" +#include "AtmosphereModelBruneton.h" + +/* Factor to convert software units to kilometers */ +#define WORLD_SCALING 0.05 +#define SUN_DISTANCE 149597870.0 +#define SUN_DISTANCE_SCALED (SUN_DISTANCE / WORLD_SCALING) +#define SUN_RADIUS 6.955e5 +#define SUN_RADIUS_SCALED (SUN_RADIUS / WORLD_SCALING) /* * Atmospheric scattering, based on E. Bruneton and F.Neyret work. @@ -1150,7 +1157,12 @@ int brunetonInit() static const int _init = brunetonInit(); -AtmosphereResult brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position, Color) +AtmosphereModelBruneton::AtmosphereModelBruneton(AtmosphereRenderer *parent): + parent(parent) +{ +} + +AtmosphereResult getSkyColor(const Vector3 &eye, const Vector3 &direction, const Vector3 &sun_position, const Color &) { double yoffset = GROUND_OFFSET - renderer->water->getHeightInfo(renderer).base_height; eye.y += yoffset; @@ -1184,7 +1196,7 @@ AtmosphereResult brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 di return result; } -AtmosphereResult brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base) +AtmosphereResult applyAerialPerspective(const Vector3 &location, const Color &base) { Vector3 eye = renderer->getCameraLocation(renderer, location); Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), SUN_DISTANCE); @@ -1232,7 +1244,7 @@ AtmosphereResult brunetonApplyAerialPerspective(Renderer* renderer, Vector3 loca return result; } -void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3, int) +void fillLightingStatus(LightStatus *status, const Vector3 &, int) { LightDefinition sun, irradiance; double muS; diff --git a/src/render/software/AtmosphereModelBruneton.h b/src/render/software/AtmosphereModelBruneton.h new file mode 100644 index 0000000..747b195 --- /dev/null +++ b/src/render/software/AtmosphereModelBruneton.h @@ -0,0 +1,27 @@ +#ifndef ATMOSPHEREMODELBRUNETON_H +#define ATMOSPHEREMODELBRUNETON_H + +#include "software_global.h" + +#include "AtmosphereResult.h" + +namespace paysages { +namespace software { + +class SOFTWARESHARED_EXPORT AtmosphereModelBruneton +{ +public: + AtmosphereModelBruneton(AtmosphereRenderer *parent); + + AtmosphereResult getSkyColor(const Vector3 &eye, const Vector3 &direction, const Vector3 &sun_position, const Color &base); + AtmosphereResult applyAerialPerspective(const Vector3 &location, const Color &base); + void fillLightingStatus(LightStatus *status, const Vector3 &normal, int opaque); + +private: + AtmosphereRenderer* parent; +}; + +} +} + +#endif // ATMOSPHEREMODELBRUNETON_H diff --git a/src/render/software/AtmosphereRenderer.cpp b/src/render/software/AtmosphereRenderer.cpp index 0252071..25c62b2 100644 --- a/src/render/software/AtmosphereRenderer.cpp +++ b/src/render/software/AtmosphereRenderer.cpp @@ -5,9 +5,6 @@ #include "AtmosphereDefinition.h" #include "Scenery.h" -// TEMP -#include "atmosphere/private.h" - static inline double _getDayFactor(double daytime) { daytime = 1.0 - fabs(0.5 - daytime) / 0.5; diff --git a/src/render/software/AtmosphereRenderer.h b/src/render/software/AtmosphereRenderer.h index 90353df..ff24ba9 100644 --- a/src/render/software/AtmosphereRenderer.h +++ b/src/render/software/AtmosphereRenderer.h @@ -3,9 +3,6 @@ #include "software_global.h" -// TEMP -#include "atmosphere/public.h" - namespace paysages { namespace software { diff --git a/src/render/software/AtmosphereResult.cpp b/src/render/software/AtmosphereResult.cpp new file mode 100644 index 0000000..a038493 --- /dev/null +++ b/src/render/software/AtmosphereResult.cpp @@ -0,0 +1,21 @@ +#include "AtmosphereResult.h" + +AtmosphereResult::AtmosphereResult() +{ + base = COLOR_BLACK; + inscattering = COLOR_BLACK; + attenuation = COLOR_WHITE; + mask = COLOR_TRANSPARENT; + distance = 0.0; + final = COLOR_BLACK; +} + +void AtmosphereResult::updateFinal() +{ + final.r = base.r * attenuation.r + inscattering.r; + final.g = base.g * attenuation.g + inscattering.g; + final.b = base.b * attenuation.b + inscattering.b; + final.a = 1.0; + + colorMask(&final, &mask); +} diff --git a/src/render/software/AtmosphereResult.h b/src/render/software/AtmosphereResult.h new file mode 100644 index 0000000..c798496 --- /dev/null +++ b/src/render/software/AtmosphereResult.h @@ -0,0 +1,28 @@ +#ifndef ATMOSPHERERESULT_H +#define ATMOSPHERERESULT_H + +#include "software_global.h" + +#include "Color.h" + +namespace paysages { +namespace software { + +class SOFTWARESHARED_EXPORT AtmosphereResult +{ +public: + AtmosphereResult(); + void updateFinal(); + + Color base; + double distance; + Color inscattering; + Color attenuation; + Color mask; + Color final; +}; + +} +} + +#endif // ATMOSPHERERESULT_H diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index c35f4ed..5bf7f2d 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -157,8 +157,8 @@ Color SoftwareRenderer::applyMediumTraversal(Vector3 location, Color color) Color SoftwareRenderer::applyLightingToSurface(const Vector3 &location, const Vector3 &normal, const SurfaceMaterial &material) { - LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location)); - renderer->atmosphere->getLightingStatus(renderer, light, normal, 0); + LightStatus* light = lightingCreateStatus(lighting, location, getCameraLocation(renderer, location)); + atmosphere->getLightingStatus(renderer, light, normal, 0); Color result = lightingApplyStatus(light, normal, material); lightingDeleteStatus(light); return result; diff --git a/src/render/software/SoftwareRenderer.h b/src/render/software/SoftwareRenderer.h index 9089263..7d09a0b 100644 --- a/src/render/software/SoftwareRenderer.h +++ b/src/render/software/SoftwareRenderer.h @@ -46,7 +46,7 @@ public: inline FluidMediumManager* getFluidMediumManager() const {return fluid_medium;} virtual Color applyMediumTraversal(Vector3 location, Color color) override; - virtual Color applyLightingToSurface(const Vector3 &location, const Vector3 &normal, const SurfaceMaterial &material); + virtual Color applyLightingToSurface(const Vector3 &location, const Vector3 &normal, const SurfaceMaterial &material) override; private: Scenery* scenery; diff --git a/src/render/software/software.pro b/src/render/software/software.pro index 36b819b..d423a34 100644 --- a/src/render/software/software.pro +++ b/src/render/software/software.pro @@ -28,7 +28,10 @@ SOURCES += SoftwareRenderer.cpp \ LightingManager.cpp \ LightStatus.cpp \ LightFilter.cpp \ - LightComponent.cpp + LightComponent.cpp \ + WaterRasterizer.cpp \ + AtmosphereResult.cpp \ + AtmosphereModelBruneton.cpp HEADERS += SoftwareRenderer.h\ software_global.h \ @@ -46,7 +49,10 @@ HEADERS += SoftwareRenderer.h\ LightingManager.h \ LightStatus.h \ LightFilter.h \ - LightComponent.h + LightComponent.h \ + WaterRasterizer.h \ + AtmosphereResult.h \ + AtmosphereModelBruneton.h unix:!symbian { maemo5 { diff --git a/src/rendering/RenderingScenery.cpp b/src/rendering/RenderingScenery.cpp index f8ffe07..609bfc3 100644 --- a/src/rendering/RenderingScenery.cpp +++ b/src/rendering/RenderingScenery.cpp @@ -4,7 +4,6 @@ #include "terrain/public.h" #include "textures/public.h" #include "water/public.h" -#include "atmosphere/public.h" #include "CameraDefinition.h" static RenderingScenery _main_scenery; diff --git a/src/rendering/atmosphere/atm_render.cpp b/src/rendering/atmosphere/atm_render.cpp deleted file mode 100644 index 97e9d10..0000000 --- a/src/rendering/atmosphere/atm_render.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "private.h" - -#include -#include -#include -#include "AtmosphereDefinition.h" -#include "../renderer.h" - -/******************** Fake ********************/ -static AtmosphereResult _fakeApplyAerialPerspective(Renderer*, Vector3, Color base) -{ - AtmosphereResult result; - result.base = result.final = base; - result.inscattering = result.attenuation = COLOR_BLACK; - return result; -} - -static AtmosphereResult _fakeGetSkyColor(Renderer*, Vector3) -{ - AtmosphereResult result; - result.base = result.final = COLOR_WHITE; - result.inscattering = result.attenuation = COLOR_BLACK; - return result; -} - -static void _fakeGetLightingStatus(Renderer*, LightStatus* status, Vector3, int) -{ - LightDefinition light; - - light.color.r = 1.0; - light.color.g = 1.0; - light.color.b = 1.0; - light.direction.x = -0.7; - light.direction.y = -0.7; - light.direction.z = 0.7; - light.altered = 0; - light.reflection = 0.0; - lightingPushLight(status, &light); - light.color.r = 0.3; - light.color.g = 0.31; - light.color.b = 0.34; - light.direction.x = 0.7; - light.direction.y = -0.7; - light.direction.z = -0.7; - light.altered = 0; - light.reflection = 0.0; - lightingPushLight(status, &light); -} - -static Vector3 _realGetSunDirection(Renderer* renderer) -{ - Vector3 result; - double sun_angle = (renderer->atmosphere->definition->_daytime + 0.75) * M_PI * 2.0; - result.x = cos(sun_angle); - result.y = sin(sun_angle); - result.z = 0.0; - return result; -} - -void atmosphereInitResult(AtmosphereResult* result) -{ - result->base = COLOR_BLACK; - result->inscattering = COLOR_BLACK; - result->attenuation = COLOR_WHITE; - result->mask = COLOR_TRANSPARENT; - result->distance = 0.0; - result->final = COLOR_BLACK; -} - -void atmosphereUpdateResult(AtmosphereResult* result) -{ - result->final.r = result->base.r * result->attenuation.r + result->inscattering.r; - result->final.g = result->base.g * result->attenuation.g + result->inscattering.g; - result->final.b = result->base.b * result->attenuation.b + result->inscattering.b; - result->final.a = 1.0; - - colorMask(&result->final, &result->mask); -} - -/******************** Renderer ********************/ -static AtmosphereRenderer* _createRenderer() -{ - AtmosphereRenderer* result; - - result = new AtmosphereRenderer; - result->definition = new AtmosphereDefinition(NULL); - - result->getLightingStatus = _fakeGetLightingStatus; - result->getSunDirection = _realGetSunDirection; - result->applyAerialPerspective = _fakeApplyAerialPerspective; - result->getSkyColor = _fakeGetSkyColor; - - return result; -} - -static void _deleteRenderer(AtmosphereRenderer* renderer) -{ - delete renderer->definition; - delete renderer; -} - -static void _bindRenderer(Renderer* renderer, AtmosphereDefinition* definition) -{ - definition->copy(renderer->atmosphere->definition); -} - -StandardRenderer AtmosphereRendererClass = { - (FuncObjectCreate)_createRenderer, - (FuncObjectDelete)_deleteRenderer, - (FuncObjectBind)_bindRenderer -}; diff --git a/src/rendering/atmosphere/private.h b/src/rendering/atmosphere/private.h deleted file mode 100644 index b3b93de..0000000 --- a/src/rendering/atmosphere/private.h +++ /dev/null @@ -1,19 +0,0 @@ -#include "public.h" - -#ifndef _PAYSAGES_ATMOSPHERE_PRIVATE_H_ -#define _PAYSAGES_ATMOSPHERE_PRIVATE_H_ - -#define SPHERE_SIZE 20000.0 - -/* Factor to convert software units to kilometers */ -#define WORLD_SCALING 0.05 -#define SUN_DISTANCE 149597870.0 -#define SUN_DISTANCE_SCALED (SUN_DISTANCE / WORLD_SCALING) -#define SUN_RADIUS 6.955e5 -#define SUN_RADIUS_SCALED (SUN_RADIUS / WORLD_SCALING) - -AtmosphereResult brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position, Color base); -AtmosphereResult brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base); -void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque); - -#endif diff --git a/src/rendering/atmosphere/public.h b/src/rendering/atmosphere/public.h deleted file mode 100644 index 58a9061..0000000 --- a/src/rendering/atmosphere/public.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _PAYSAGES_ATMOSPHERE_PUBLIC_H_ -#define _PAYSAGES_ATMOSPHERE_PUBLIC_H_ - -#include "rendering_global.h" - -#include "../rendering_global.h" -#include "../shared/types.h" -#include "Color.h" - -typedef struct -{ - Color base; - double distance; - Color inscattering; - Color attenuation; - Color mask; - Color final; -} AtmosphereResult; - -typedef AtmosphereResult (*FuncAtmosphereApplyAerialPerspective)(Renderer* renderer, Vector3 location, Color base); -typedef AtmosphereResult (*FuncAtmosphereGetSkyColor)(Renderer* renderer, Vector3 direction); -typedef Vector3 (*FuncAtmosphereGetSunDirection)(Renderer* renderer); - -class AtmosphereRenderer -{ -public: - AtmosphereDefinition* definition; - - FuncAtmosphereApplyAerialPerspective applyAerialPerspective; - FuncAtmosphereGetSkyColor getSkyColor; - FuncAtmosphereGetSunDirection getSunDirection; - - /*void* _internal_data;*/ -}; - -RENDERINGSHARED_EXPORT extern StandardRenderer AtmosphereRendererClass; - -RENDERINGSHARED_EXPORT void atmosphereInitResult(AtmosphereResult* result); -RENDERINGSHARED_EXPORT void atmosphereUpdateResult(AtmosphereResult* result); - -#endif diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index e1d0720..e88b025 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -5,7 +5,6 @@ #include "render.h" #include "RenderingScenery.h" #include "CameraDefinition.h" -#include "atmosphere/public.h" #include "terrain/public.h" #include "textures/public.h" #include "water/public.h" @@ -122,9 +121,6 @@ Renderer::Renderer() rayWalking = _rayWalking; - lighting = lightingManagerCreate(); - - atmosphere = (AtmosphereRenderer*)AtmosphereRendererClass.create(); terrain = (TerrainRenderer*)TerrainRendererClass.create(); textures = (TexturesRenderer*)TexturesRendererClass.create(); water = (WaterRenderer*)WaterRendererClass.create(); @@ -133,9 +129,7 @@ Renderer::Renderer() Renderer::~Renderer() { delete render_camera; - lightingManagerDelete(lighting); - AtmosphereRendererClass.destroy(atmosphere); TerrainRendererClass.destroy(terrain); TexturesRendererClass.destroy(textures); WaterRendererClass.destroy(water); @@ -148,9 +142,9 @@ Color Renderer::applyMediumTraversal(Vector3, Color color) return color; } -Color applyLightingToSurface(const Vector3 &, const Vector3 &, const SurfaceMaterial &material) +Color Renderer::applyLightingToSurface(const Vector3 &, const Vector3 &, const SurfaceMaterial &material) { - return material.base; + return material._rgb; } @@ -161,7 +155,6 @@ Color applyLightingToSurface(const Vector3 &, const Vector3 &, const SurfaceMate - // Old API compat Renderer* rendererCreate() diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h index 60ed86e..a469cec 100644 --- a/src/rendering/renderer.h +++ b/src/rendering/renderer.h @@ -6,7 +6,6 @@ #include "render.h" class LightingManager; -class AtmosphereRenderer; class TerrainRenderer; class TexturesRenderer; class WaterRenderer; @@ -50,11 +49,7 @@ public: /* Scenery related */ RayCastingResult(*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds); - /* Autonomous tools */ - LightingManager* lighting; - /* Autonomous sub-renderers */ - AtmosphereRenderer* atmosphere; TerrainRenderer* terrain; TexturesRenderer* textures; WaterRenderer* water; diff --git a/src/rendering/rendering.pro b/src/rendering/rendering.pro index 28ec3ed..439d71f 100644 --- a/src/rendering/rendering.pro +++ b/src/rendering/rendering.pro @@ -11,8 +11,6 @@ include(../common.pri) SOURCES += main.cpp \ renderer.cpp \ render.cpp \ - atmosphere/atm_render.cpp \ - atmosphere/atm_bruneton.cpp \ terrain/ter_render.cpp \ terrain/ter_painting.cpp \ textures/tex_tools.cpp \ @@ -29,8 +27,6 @@ HEADERS += \ renderer.h \ render.h \ main.h \ - atmosphere/public.h \ - atmosphere/private.h \ shared/types.h \ terrain/public.h \ terrain/private.h \ diff --git a/src/rendering/textures/tex_rendering.cpp b/src/rendering/textures/tex_rendering.cpp index 0abdede..39c3571 100644 --- a/src/rendering/textures/tex_rendering.cpp +++ b/src/rendering/textures/tex_rendering.cpp @@ -132,7 +132,7 @@ static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z if (info->presence > 0.0) { Vector3 normal = _getDetailNormal(renderer, terrain.location, terrain.normal, info->layer); - info->color = renderer->applyLightingToSurface(renderer, terrain.location, normal, info->layer->material); + info->color = renderer->applyLightingToSurface(terrain.location, normal, *info->layer->material); } else { diff --git a/src/rendering/water/wat_render.cpp b/src/rendering/water/wat_render.cpp index abd0152..60ee1da 100644 --- a/src/rendering/water/wat_render.cpp +++ b/src/rendering/water/wat_render.cpp @@ -138,7 +138,7 @@ static inline Color _getFoamMask(Renderer* renderer, WaterDefinition* definition foam_factor = (foam_factor - (1.0 - definition->foam_coverage)) * definition->foam_coverage; /* TODO Re-use base lighting status */ - result = renderer->applyLightingToSurface(renderer, location, normal, definition->foam_material); + result = renderer->applyLightingToSurface(location, normal, *definition->foam_material); result.r *= 2.0; result.g *= 2.0; result.b *= 2.0; @@ -274,7 +274,7 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z) } /* Lighting from environment */ - color = renderer->applyLightingToSurface(renderer, location, normal, definition->material); + color = renderer->applyLightingToSurface(location, normal, *definition->material); color.r += result.reflected.r * definition->reflection + result.refracted.r * definition->transparency; color.g += result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;