2013-12-08 17:05:18 +00:00
|
|
|
#include "WaterRasterizer.h"
|
2013-02-27 16:38:27 +00:00
|
|
|
|
2013-12-08 17:05:18 +00:00
|
|
|
#include "SoftwareRenderer.h"
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "WaterRenderer.h"
|
2013-12-09 10:59:57 +00:00
|
|
|
#include "ParallelQueue.h"
|
2013-12-08 17:05:18 +00:00
|
|
|
|
2014-06-12 15:45:59 +00:00
|
|
|
WaterRasterizer::WaterRasterizer(SoftwareRenderer* renderer, int client_id):
|
2014-08-16 11:34:55 +00:00
|
|
|
Rasterizer(renderer, client_id, Color(0.1, 0.3, 0.6))
|
2013-12-08 17:05:18 +00:00
|
|
|
{
|
|
|
|
}
|
2013-02-27 16:38:27 +00:00
|
|
|
|
2013-12-11 11:46:39 +00:00
|
|
|
static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &location, void*)
|
2013-02-27 16:38:27 +00:00
|
|
|
{
|
2013-12-08 19:54:34 +00:00
|
|
|
return renderer->getWaterRenderer()->getResult(location.x, location.z).final;
|
2013-02-27 16:38:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 18:10:05 +00:00
|
|
|
static inline Vector3 _getFirstPassVertex(SoftwareRenderer* renderer, double x, double z)
|
2013-02-27 16:38:27 +00:00
|
|
|
{
|
|
|
|
Vector3 result;
|
|
|
|
|
|
|
|
result.x = x;
|
2013-12-08 19:54:34 +00:00
|
|
|
result.y = renderer->getWaterRenderer()->getHeight(x, z);
|
2013-02-27 16:38:27 +00:00
|
|
|
result.z = z;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-06-18 18:10:05 +00:00
|
|
|
void WaterRasterizer::rasterizeQuad(CanvasPortion* canvas, double x, double z, double size)
|
|
|
|
{
|
|
|
|
Vector3 v1, v2, v3, v4;
|
|
|
|
|
|
|
|
v1 = _getFirstPassVertex(renderer, x, z);
|
|
|
|
v2 = _getFirstPassVertex(renderer, x, z + size);
|
|
|
|
v3 = _getFirstPassVertex(renderer, x + size, z + size);
|
|
|
|
v4 = _getFirstPassVertex(renderer, x + size, z);
|
|
|
|
|
|
|
|
pushQuad(canvas, v1, v2, v3, v4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaterRasterizer::rasterizeToCanvas(CanvasPortion *canvas)
|
|
|
|
{
|
|
|
|
int chunk_factor, chunk_count, i;
|
|
|
|
Vector3 cam = renderer->getCameraLocation(VECTOR_ZERO);
|
|
|
|
double radius_int, radius_ext, base_chunk_size, chunk_size;
|
|
|
|
|
|
|
|
base_chunk_size = 2.0 / (double)renderer->render_quality;
|
|
|
|
if (renderer->render_quality > 7)
|
|
|
|
{
|
|
|
|
base_chunk_size *= 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk_factor = 1;
|
|
|
|
chunk_count = 2;
|
|
|
|
radius_int = 0.0;
|
|
|
|
radius_ext = base_chunk_size;
|
|
|
|
chunk_size = base_chunk_size;
|
|
|
|
|
|
|
|
double cx = cam.x - fmod(cam.x, base_chunk_size);
|
|
|
|
double cz = cam.z - fmod(cam.x, base_chunk_size);
|
|
|
|
|
|
|
|
while (radius_int < 20000.0)
|
|
|
|
{
|
|
|
|
if (!renderer->addRenderProgress(0.0))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < chunk_count - 1; i++)
|
|
|
|
{
|
|
|
|
rasterizeQuad(canvas, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size);
|
|
|
|
rasterizeQuad(canvas, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size);
|
|
|
|
rasterizeQuad(canvas, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size);
|
|
|
|
rasterizeQuad(canvas, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radius_int > 20.0 && chunk_count % 64 == 0 && (double)chunk_factor < radius_int / 20.0)
|
|
|
|
{
|
|
|
|
chunk_count /= 2;
|
|
|
|
chunk_factor *= 2;
|
|
|
|
}
|
|
|
|
chunk_count += 2;
|
|
|
|
chunk_size = base_chunk_size * chunk_factor;
|
|
|
|
radius_int = radius_ext;
|
|
|
|
radius_ext += chunk_size;
|
|
|
|
}
|
|
|
|
}
|