2013-12-01 18:24:53 +00:00
|
|
|
#include "SkyRasterizer.h"
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
#include "Vector3.h"
|
|
|
|
#include "Color.h"
|
|
|
|
#include "SoftwareRenderer.h"
|
|
|
|
#include "AtmosphereRenderer.h"
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "AtmosphereResult.h"
|
2013-12-01 18:24:53 +00:00
|
|
|
#include "CloudsRenderer.h"
|
2014-06-12 15:45:59 +00:00
|
|
|
#include "Rasterizer.h"
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
#define SPHERE_SIZE 20000.0
|
|
|
|
|
2014-06-12 15:45:59 +00:00
|
|
|
SkyRasterizer::SkyRasterizer(SoftwareRenderer* renderer, int client_id):
|
|
|
|
Rasterizer(renderer, client_id)
|
2013-12-01 18:24:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-11 11:46:39 +00:00
|
|
|
static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &location, void*)
|
2012-12-09 17:49:28 +00:00
|
|
|
{
|
2013-01-31 15:10:11 +00:00
|
|
|
Vector3 camera_location, direction;
|
2012-12-09 17:49:28 +00:00
|
|
|
Color result;
|
|
|
|
|
2013-12-09 10:59:57 +00:00
|
|
|
camera_location = renderer->getCameraLocation(location);
|
2013-12-11 10:32:10 +00:00
|
|
|
direction = location.sub(camera_location);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
/* TODO Don't compute result->color if it's fully covered by clouds */
|
2013-12-11 10:32:10 +00:00
|
|
|
result = renderer->getAtmosphereRenderer()->getSkyColor(direction.normalize()).final;
|
|
|
|
result = renderer->getCloudsRenderer()->getColor(camera_location, camera_location.add(direction.scale(10.0)), result);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-06-12 15:45:59 +00:00
|
|
|
void SkyRasterizer::rasterizeToCanvas(CanvasPortion* canvas)
|
|
|
|
{
|
|
|
|
int res_i, res_j;
|
|
|
|
int i, j;
|
|
|
|
double step_i, step_j;
|
|
|
|
double current_i, current_j;
|
|
|
|
Vector3 vertex1, vertex2, vertex3, vertex4;
|
|
|
|
Vector3 camera_location, direction;
|
|
|
|
|
|
|
|
res_i = renderer->render_quality * 40;
|
|
|
|
res_j = renderer->render_quality * 20;
|
|
|
|
step_i = M_PI * 2.0 / (double)res_i;
|
|
|
|
step_j = M_PI / (double)res_j;
|
|
|
|
|
|
|
|
camera_location = renderer->getCameraLocation(VECTOR_ZERO);
|
|
|
|
|
|
|
|
for (j = 0; j < res_j; j++)
|
|
|
|
{
|
|
|
|
if (!renderer->addRenderProgress(0.0))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_j = (double)(j - res_j / 2) * step_j;
|
|
|
|
|
|
|
|
for (i = 0; i < res_i; i++)
|
|
|
|
{
|
|
|
|
current_i = (double)i * step_i;
|
|
|
|
|
|
|
|
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j);
|
|
|
|
direction.y = SPHERE_SIZE * sin(current_j);
|
|
|
|
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j);
|
|
|
|
vertex1 = camera_location.add(direction);
|
|
|
|
|
|
|
|
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j);
|
|
|
|
direction.y = SPHERE_SIZE * sin(current_j);
|
|
|
|
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j);
|
|
|
|
vertex2 = camera_location.add(direction);
|
|
|
|
|
|
|
|
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j);
|
|
|
|
direction.y = SPHERE_SIZE * sin(current_j + step_j);
|
|
|
|
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j + step_j);
|
|
|
|
vertex3 = camera_location.add(direction);
|
|
|
|
|
|
|
|
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j);
|
|
|
|
direction.y = SPHERE_SIZE * sin(current_j + step_j);
|
|
|
|
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j + step_j);
|
|
|
|
vertex4 = camera_location.add(direction);
|
|
|
|
|
|
|
|
/* TODO Triangles at poles */
|
|
|
|
pushQuad(canvas, vertex1, vertex4, vertex3, vertex2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|