WIP on fluid medium traversal

This commit is contained in:
Michaël Lemaire 2013-11-10 17:04:38 +01:00
parent 0edd90c477
commit 4a39eda2dc
12 changed files with 140 additions and 62 deletions

View file

@ -161,6 +161,12 @@ else:unix: LIBS += -L$$OUT_PWD/../definition/ -lpaysages_definition
INCLUDEPATH += $$PWD/../definition
DEPENDPATH += $$PWD/../definition
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../render/software/release/ -lpaysages_render_software
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../render/software/debug/ -lpaysages_render_software
else:unix: LIBS += -L$$OUT_PWD/../render/software/ -lpaysages_render_software
INCLUDEPATH += $$PWD/../render/software
DEPENDPATH += $$PWD/../render/software
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../render/opengl/release/ -lpaysages_render_opengl
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../render/opengl/debug/ -lpaysages_render_opengl
else:unix: LIBS += -L$$OUT_PWD/../render/opengl/ -lpaysages_render_opengl

View file

@ -6,11 +6,13 @@ namespace paysages
namespace system {}
namespace basics {}
namespace definition {}
namespace software {}
namespace opengl {}
}
using namespace paysages::system;
using namespace paysages::basics;
using namespace paysages::definition;
using namespace paysages::software;
using namespace paysages::opengl;
#endif // EDITING_GLOBAL_H

View file

@ -12,6 +12,7 @@
#include "rendering/water/public.h"
#include "Scenery.h"
#include "PackStream.h"
#include "SoftwareRenderer.h"
/**************** Previews ****************/
class PreviewRenderLandscape : public BasePreview
@ -182,7 +183,7 @@ void FormRender::startQuickRender()
{
rendererDelete(_renderer);
}
_renderer = sceneryCreateStandardRenderer();
_renderer = new SoftwareRenderer();
_renderer_inited = true;
DialogRender* dialog = new DialogRender(this, _renderer);
@ -198,7 +199,7 @@ void FormRender::startRender()
{
rendererDelete(_renderer);
}
_renderer = sceneryCreateStandardRenderer();
_renderer = new SoftwareRenderer();
_renderer_inited = true;
DialogRender* dialog = new DialogRender(this, _renderer);

View file

@ -4,3 +4,23 @@ FluidMediumTraversal::FluidMediumTraversal(SoftwareRenderer* renderer):
renderer(renderer)
{
}
FluidMediumTraversal::~FluidMediumTraversal()
{
}
void FluidMediumTraversal::setCollector(FluidMediumCollector *collector)
{
}
void FluidMediumTraversal::getTraversedMedia(std::vector<FluidMediumInterface> &media, const SpaceCoordinates &start, const SpaceCoordinates &end)
{
}
void FluidMediumTraversal::collectHalfLine(const SpaceCoordinates &start, const Vector3 &direction)
{
}
void FluidMediumTraversal::collectSegment(const SpaceCoordinates &start, const SpaceCoordinates &end)
{
}

View file

@ -1,14 +1,30 @@
#include "SoftwareRenderer.h"
#include "Scenery.h"
#include "FluidMediumTraversal.h"
SoftwareRenderer::SoftwareRenderer(Scenery* scenery):
scenery(scenery)
SoftwareRenderer::SoftwareRenderer(Scenery* scenery)
{
fluid_medium = new FluidMediumTraversal(this);
if (scenery)
{
this->scenery = scenery;
}
else
{
this->scenery = Scenery::getCurrent();
}
this->scenery->bindToRenderer(this);
}
SoftwareRenderer::~SoftwareRenderer()
{
delete fluid_medium;
}
Color SoftwareRenderer::applyMediumTraversal(Vector3 location, Color color)
{
// TODO
return color;
}

View file

@ -19,11 +19,13 @@ class SOFTWARESHARED_EXPORT SoftwareRenderer: public Renderer
{
public:
SoftwareRenderer(Scenery* scenery);
SoftwareRenderer(Scenery* scenery=0);
virtual ~SoftwareRenderer();
inline Scenery* getScenery() const {return scenery;}
virtual Color applyMediumTraversal(Vector3 location, Color color);
private:
Scenery* scenery;
FluidMediumTraversal* fluid_medium;

View file

@ -39,6 +39,11 @@ Scenery::~Scenery()
WaterDefinitionClass.destroy(water);
}
Scenery* Scenery::getCurrent()
{
return _main_scenery;
}
void Scenery::save(PackStream* stream)
{
BaseDefinition::save(stream);

View file

@ -30,6 +30,8 @@ public:
Scenery();
virtual ~Scenery();
static Scenery* getCurrent();
virtual void save(PackStream* stream);
virtual void load(PackStream* stream);

View file

@ -117,69 +117,89 @@ static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vecto
return result;
}
static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color color)
Renderer::Renderer()
{
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final;
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
RenderParams params = {1, 1, 1, 5};
render_quality = 5;
render_width = 1;
render_height = 1;
render_interrupt = 0;
render_progress = 0.0;
is_rendering = 0;
render_camera = cameraCreateDefinition();
render_area = renderCreateArea(this);
renderSetParams(render_area, params);
addRenderProgress = _addRenderProgress;
getCameraLocation = _getCameraLocation;
getCameraDirection = _getCameraDirection;
getPrecision = _getPrecision;
projectPoint = _projectPoint;
unprojectPoint = _unprojectPoint;
pushTriangle = _pushTriangle;
pushQuad = _pushQuad;
pushDisplacedTriangle = _pushDisplacedTriangle;
pushDisplacedQuad = _pushDisplacedQuad;
rayWalking = _rayWalking;
applyLightingToSurface = _applyLightingToSurface;
lighting = lightingManagerCreate();
atmosphere = (AtmosphereRenderer*)AtmosphereRendererClass.create();
clouds = (CloudsRenderer*)CloudsRendererClass.create();
terrain = (TerrainRenderer*)TerrainRendererClass.create();
textures = (TexturesRenderer*)TexturesRendererClass.create();
water = (WaterRenderer*)WaterRendererClass.create();
}
Renderer::~Renderer()
{
cameraDeleteDefinition(render_camera);
lightingManagerDelete(lighting);
AtmosphereRendererClass.destroy(atmosphere);
CloudsRendererClass.destroy(clouds);
TerrainRendererClass.destroy(terrain);
TexturesRendererClass.destroy(textures);
WaterRendererClass.destroy(water);
renderDeleteArea(render_area);
}
Color Renderer::applyMediumTraversal(Vector3 location, Color color)
{
color = atmosphere->applyAerialPerspective(this, location, color).final;
color = clouds->getColor(this, color, getCameraLocation(this, location), location);
return color;
}
// Old API compat
Renderer* rendererCreate()
{
Renderer* result = new Renderer;
RenderParams params = {1, 1, 1, 5};
result->render_quality = 5;
result->render_width = 1;
result->render_height = 1;
result->render_interrupt = 0;
result->render_progress = 0.0;
result->is_rendering = 0;
result->render_camera = cameraCreateDefinition();
result->render_area = renderCreateArea(result);
renderSetParams(result->render_area, params);
result->addRenderProgress = _addRenderProgress;
result->getCameraLocation = _getCameraLocation;
result->getCameraDirection = _getCameraDirection;
result->getPrecision = _getPrecision;
result->projectPoint = _projectPoint;
result->unprojectPoint = _unprojectPoint;
result->pushTriangle = _pushTriangle;
result->pushQuad = _pushQuad;
result->pushDisplacedTriangle = _pushDisplacedTriangle;
result->pushDisplacedQuad = _pushDisplacedQuad;
result->rayWalking = _rayWalking;
result->applyLightingToSurface = _applyLightingToSurface;
result->applyMediumTraversal = _applyMediumTraversal;
result->lighting = lightingManagerCreate();
result->atmosphere = (AtmosphereRenderer*)AtmosphereRendererClass.create();
result->clouds = (CloudsRenderer*)CloudsRendererClass.create();
result->terrain = (TerrainRenderer*)TerrainRendererClass.create();
result->textures = (TexturesRenderer*)TexturesRendererClass.create();
result->water = (WaterRenderer*)WaterRendererClass.create();
return result;
return new Renderer();
}
void rendererDelete(Renderer* renderer)
{
cameraDeleteDefinition(renderer->render_camera);
lightingManagerDelete(renderer->lighting);
AtmosphereRendererClass.destroy(renderer->atmosphere);
CloudsRendererClass.destroy(renderer->clouds);
TerrainRendererClass.destroy(renderer->terrain);
TexturesRendererClass.destroy(renderer->textures);
WaterRendererClass.destroy(renderer->water);
renderDeleteArea(renderer->render_area);
delete renderer;
}

View file

@ -14,8 +14,12 @@ class TexturesRenderer;
class CloudsRenderer;
class WaterRenderer;
struct Renderer
class Renderer
{
public:
Renderer();
virtual ~Renderer();
/* Render base configuration */
int render_quality;
int render_width;
@ -40,7 +44,7 @@ struct Renderer
/* Shortcuts */
Color(*applyLightingToSurface)(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material);
Color(*applyMediumTraversal)(Renderer* renderer, Vector3 location, Color color);
virtual Color applyMediumTraversal(Vector3 location, Color color);
/* Scenery related */
RayCastingResult(*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds);

View file

@ -148,7 +148,7 @@ static Color _realGetFinalColor(Renderer* renderer, Vector3 location, double pre
{
/* TODO Restore precision control */
TexturesResult textures = renderer->textures->applyToTerrain(renderer, location.x, location.z);
return renderer->applyMediumTraversal(renderer, textures.final_location, textures.final_color);
return renderer->applyMediumTraversal(textures.final_location, textures.final_color);
}
static RayCastingResult _fakeCastRay(Renderer* renderer, Vector3 start, Vector3 direction)

View file

@ -290,7 +290,7 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z)
colorMask(&color, &foam);
/* Bring color to the camera */
color = renderer->applyMediumTraversal(renderer, location, color);
color = renderer->applyMediumTraversal(location, color);
result.base = definition->material._rgb;
result.final = color;