[WIP] Removed old atmosphere renderer
This commit is contained in:
parent
fca6f4c96e
commit
b0d9ead01d
18 changed files with 108 additions and 208 deletions
|
@ -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;
|
27
src/render/software/AtmosphereModelBruneton.h
Normal file
27
src/render/software/AtmosphereModelBruneton.h
Normal file
|
@ -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
|
|
@ -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;
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
#include "software_global.h"
|
||||
|
||||
// TEMP
|
||||
#include "atmosphere/public.h"
|
||||
|
||||
namespace paysages {
|
||||
namespace software {
|
||||
|
||||
|
|
21
src/render/software/AtmosphereResult.cpp
Normal file
21
src/render/software/AtmosphereResult.cpp
Normal file
|
@ -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);
|
||||
}
|
28
src/render/software/AtmosphereResult.h
Normal file
28
src/render/software/AtmosphereResult.h
Normal file
|
@ -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
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
#include "private.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#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
|
||||
};
|
|
@ -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
|
|
@ -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
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue