2013-11-09 17:46:34 +00:00
|
|
|
#include "SoftwareRenderer.h"
|
|
|
|
|
2013-11-14 17:47:03 +00:00
|
|
|
#include "CameraDefinition.h"
|
2013-11-10 16:04:38 +00:00
|
|
|
#include "Scenery.h"
|
2013-11-11 14:42:11 +00:00
|
|
|
#include "FluidMediumManager.h"
|
2013-11-12 20:34:35 +00:00
|
|
|
#include "AtmosphereRenderer.h"
|
2013-11-15 23:27:40 +00:00
|
|
|
#include "AtmosphereDefinition.h"
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "AtmosphereResult.h"
|
2013-12-01 18:24:53 +00:00
|
|
|
#include "CloudsRenderer.h"
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "TerrainRenderer.h"
|
|
|
|
#include "TexturesRenderer.h"
|
|
|
|
#include "WaterRenderer.h"
|
2013-12-01 18:24:53 +00:00
|
|
|
#include "SkyRasterizer.h"
|
2013-12-05 15:44:18 +00:00
|
|
|
#include "TerrainRasterizer.h"
|
2013-12-08 17:05:18 +00:00
|
|
|
#include "WaterRasterizer.h"
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "LightStatus.h"
|
|
|
|
#include "LightingManager.h"
|
2013-11-12 20:34:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Legacy compatibility
|
2013-11-17 21:36:18 +00:00
|
|
|
#include "renderer.h"
|
|
|
|
static double _getPrecision(Renderer* renderer, Vector3 location)
|
|
|
|
{
|
|
|
|
Vector3 projected;
|
|
|
|
|
|
|
|
projected = renderer->render_camera->project(location);
|
|
|
|
projected.x += 1.0;
|
|
|
|
//projected.y += 1.0;
|
|
|
|
|
|
|
|
return v3Norm(v3Sub(renderer->render_camera->unproject(projected), location)); // / (double)render_quality;
|
|
|
|
}
|
2013-11-09 17:46:34 +00:00
|
|
|
|
2013-11-10 16:04:38 +00:00
|
|
|
SoftwareRenderer::SoftwareRenderer(Scenery* scenery)
|
2013-11-09 17:46:34 +00:00
|
|
|
{
|
2013-11-12 20:34:35 +00:00
|
|
|
atmosphere_renderer = new BaseAtmosphereRenderer(this);
|
2013-12-01 18:24:53 +00:00
|
|
|
clouds_renderer = new CloudsRenderer(this);
|
2013-12-08 19:54:34 +00:00
|
|
|
terrain_renderer = new TerrainRenderer(this);
|
|
|
|
textures_renderer = new TexturesRenderer(this);
|
|
|
|
water_renderer = new WaterRenderer(this);
|
2013-11-12 20:34:35 +00:00
|
|
|
|
2013-11-11 14:42:11 +00:00
|
|
|
fluid_medium = new FluidMediumManager(this);
|
2013-11-10 16:04:38 +00:00
|
|
|
|
|
|
|
if (scenery)
|
|
|
|
{
|
|
|
|
this->scenery = scenery;
|
2013-11-13 22:36:52 +00:00
|
|
|
own_scenery = false;
|
2013-11-10 16:04:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-13 22:36:52 +00:00
|
|
|
this->scenery = new Scenery;
|
|
|
|
own_scenery = true;
|
2013-11-10 16:04:38 +00:00
|
|
|
}
|
2013-11-09 17:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SoftwareRenderer::~SoftwareRenderer()
|
|
|
|
{
|
2013-11-12 20:34:35 +00:00
|
|
|
delete atmosphere_renderer;
|
2013-12-01 18:24:53 +00:00
|
|
|
delete clouds_renderer;
|
2013-12-08 19:54:34 +00:00
|
|
|
delete terrain_renderer;
|
|
|
|
delete textures_renderer;
|
|
|
|
delete water_renderer;
|
2013-11-12 20:34:35 +00:00
|
|
|
|
2013-11-09 17:46:34 +00:00
|
|
|
delete fluid_medium;
|
2013-11-13 22:36:52 +00:00
|
|
|
|
|
|
|
if (own_scenery)
|
|
|
|
{
|
|
|
|
delete scenery;
|
|
|
|
}
|
2013-11-09 17:46:34 +00:00
|
|
|
}
|
2013-11-10 16:04:38 +00:00
|
|
|
|
2013-11-17 21:36:18 +00:00
|
|
|
void SoftwareRenderer::setScenery(Scenery* scenery)
|
|
|
|
{
|
|
|
|
if (!own_scenery)
|
|
|
|
{
|
|
|
|
this->scenery = new Scenery;
|
|
|
|
own_scenery = true;
|
|
|
|
}
|
|
|
|
scenery->copy(this->scenery);
|
|
|
|
}
|
|
|
|
|
2013-11-12 20:34:35 +00:00
|
|
|
void SoftwareRenderer::prepare()
|
2013-11-10 16:04:38 +00:00
|
|
|
{
|
2013-11-12 20:34:35 +00:00
|
|
|
// Prepare sub renderers
|
|
|
|
delete atmosphere_renderer;
|
|
|
|
atmosphere_renderer = new SoftwareBrunetonAtmosphereRenderer(this);
|
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
delete clouds_renderer;
|
|
|
|
clouds_renderer = new CloudsRenderer(this);
|
|
|
|
clouds_renderer->update();
|
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
delete terrain_renderer;
|
|
|
|
terrain_renderer = new TerrainRenderer(this);
|
|
|
|
|
|
|
|
delete textures_renderer;
|
|
|
|
textures_renderer = new TexturesRenderer(this);
|
2013-11-17 21:36:18 +00:00
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
delete water_renderer;
|
|
|
|
water_renderer = new WaterRenderer(this);
|
2013-11-12 20:34:35 +00:00
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
// Setup transitional renderers (for C-legacy subsystems)
|
|
|
|
getPrecision = _getPrecision;
|
2013-11-17 21:36:18 +00:00
|
|
|
|
2013-11-12 20:34:35 +00:00
|
|
|
// Prepare global tools
|
|
|
|
fluid_medium->clearMedia();
|
2013-11-11 14:42:11 +00:00
|
|
|
//fluid_medium->registerMedium(water_renderer);
|
2013-11-10 16:04:38 +00:00
|
|
|
}
|
2013-11-11 14:42:11 +00:00
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
void SoftwareRenderer::rasterize()
|
2013-11-11 14:42:11 +00:00
|
|
|
{
|
2013-12-05 15:44:18 +00:00
|
|
|
TerrainRasterizer terrain(this);
|
|
|
|
terrain.renderSurface();
|
|
|
|
|
2013-12-08 17:05:18 +00:00
|
|
|
WaterRasterizer water(this);
|
|
|
|
water.renderSurface();
|
2013-12-01 18:24:53 +00:00
|
|
|
|
|
|
|
SkyRasterizer sky(this);
|
|
|
|
sky.rasterize();
|
|
|
|
}
|
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
Color SoftwareRenderer::applyLightingToSurface(const Vector3 &location, const Vector3 &normal, const SurfaceMaterial &material)
|
|
|
|
{
|
|
|
|
LightStatus status(lighting, location, getCameraLocation(this, location));
|
|
|
|
atmosphere_renderer->getLightingStatus(&status, normal, 0);
|
|
|
|
return status.apply(normal, material);
|
|
|
|
}
|
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
Color SoftwareRenderer::applyMediumTraversal(Vector3 location, Color color)
|
|
|
|
{
|
2013-12-08 19:54:34 +00:00
|
|
|
color = atmosphere_renderer->applyAerialPerspective(location, color).final;
|
2013-12-01 18:24:53 +00:00
|
|
|
color = clouds_renderer->getColor(getCameraLocation(this, location), location, color);
|
|
|
|
return color;
|
|
|
|
|
|
|
|
/*Vector3 eye = cameraGetLocation(scenery->getCamera());
|
|
|
|
return fluid_medium->applyTraversal(eye, location, color);*/
|
|
|
|
}
|
2013-12-08 16:56:59 +00:00
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
RayCastingResult SoftwareRenderer::rayWalking(const Vector3 &location, const Vector3 &direction, int, int, int, int)
|
2013-12-08 16:56:59 +00:00
|
|
|
{
|
2013-12-08 19:54:34 +00:00
|
|
|
RayCastingResult result;
|
|
|
|
Color sky_color;
|
|
|
|
|
|
|
|
result = terrain_renderer->castRay(location, direction);
|
|
|
|
if (!result.hit)
|
|
|
|
{
|
|
|
|
sky_color = atmosphere_renderer->getSkyColor(direction).final;
|
|
|
|
|
|
|
|
result.hit = 1;
|
|
|
|
result.hit_location = v3Add(location, v3Scale(direction, 1000.0));
|
|
|
|
result.hit_color = clouds_renderer->getColor(location, result.hit_location, sky_color);
|
|
|
|
}
|
|
|
|
|
2013-12-08 16:56:59 +00:00
|
|
|
return result;
|
|
|
|
}
|