2012-12-09 17:49:28 +00:00
|
|
|
#include "public.h"
|
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "../renderer.h"
|
2013-11-12 20:34:35 +00:00
|
|
|
#include "clouds/public.h"
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-11-17 22:02:36 +00:00
|
|
|
static Color _postProcessFragment(Renderer* renderer, 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-01-31 15:10:11 +00:00
|
|
|
camera_location = renderer->getCameraLocation(renderer, location);
|
|
|
|
direction = v3Sub(location, camera_location);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
/* TODO Don't compute result->color if it's fully covered by clouds */
|
2013-03-14 17:29:12 +00:00
|
|
|
result = renderer->atmosphere->getSkyColor(renderer, v3Normalize(direction)).final;
|
2013-01-31 15:10:11 +00:00
|
|
|
result = renderer->clouds->getColor(renderer, result, camera_location, v3Add(camera_location, v3Scale(direction, 10.0)));
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void atmosphereRenderSkydome(Renderer* renderer)
|
|
|
|
{
|
|
|
|
int res_i, res_j;
|
|
|
|
int i, j;
|
|
|
|
double step_i, step_j;
|
|
|
|
double current_i, current_j;
|
|
|
|
Vector3 vertex1, vertex2, vertex3, vertex4;
|
2013-01-31 15:10:11 +00:00
|
|
|
Vector3 camera_location, direction;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-01-31 15:10:11 +00:00
|
|
|
camera_location = renderer->getCameraLocation(renderer, VECTOR_ZERO);
|
|
|
|
|
2012-12-09 17:49:28 +00:00
|
|
|
for (j = 0; j < res_j; j++)
|
|
|
|
{
|
|
|
|
if (!renderer->addRenderProgress(renderer, 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);
|
2013-01-31 15:10:11 +00:00
|
|
|
vertex1 = v3Add(camera_location, direction);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
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);
|
2013-01-31 15:10:11 +00:00
|
|
|
vertex2 = v3Add(camera_location, direction);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
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);
|
2013-01-31 15:10:11 +00:00
|
|
|
vertex3 = v3Add(camera_location, direction);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
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);
|
2013-01-31 15:10:11 +00:00
|
|
|
vertex4 = v3Add(camera_location, direction);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
/* TODO Triangles at poles */
|
|
|
|
renderer->pushQuad(renderer, vertex1, vertex4, vertex3, vertex2, _postProcessFragment, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|