Removed RenderArea and added terrain rasterization to canvas

This commit is contained in:
Michaël Lemaire 2014-06-18 22:10:46 +02:00
parent f94d93ae60
commit bc34a2b823
24 changed files with 142 additions and 1235 deletions

View file

@ -5,16 +5,17 @@
#include "CameraDefinition.h"
#include "AtmosphereDefinition.h"
#include "SoftwareRenderer.h"
#include "SoftwareCanvasRenderer.h"
#include "Scenery.h"
#include "RenderConfig.h"
void startRender(SoftwareRenderer* renderer, char* outputpath, RenderArea::RenderParams params)
void startRender(SoftwareRenderer *renderer, char *outputpath, const RenderConfig &params)
{
printf("\rRendering %s ... \n", outputpath);
/*printf("\rRendering %s ... \n", outputpath);
renderer->start(params);
printf("\rSaving %s ... \n", outputpath);
remove(outputpath);
renderer->render_area->saveToFile(outputpath);
renderer->render_area->saveToFile(outputpath);*/
}
void displayHelp()
@ -43,9 +44,9 @@ void _previewUpdate(double progress)
int main(int argc, char** argv)
{
SoftwareRenderer* renderer;
SoftwareCanvasRenderer* renderer;
char* conf_file_path = NULL;
RenderArea::RenderParams conf_render_params = {800, 600, 1, 5};
RenderConfig conf_render_params(800, 600, 1, 5);
int conf_first_picture = 0;
int conf_nb_pictures = 1;
double conf_daytime_start = 0.4;
@ -177,8 +178,8 @@ int main(int argc, char** argv)
Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z};
camera->setLocation(camera->getLocation().add(step));
renderer = new SoftwareRenderer(scenery);
renderer->setPreviewCallbacks(NULL, NULL, _previewUpdate);
renderer = new SoftwareCanvasRenderer();
renderer->setScenery(scenery);
if (outputcount >= conf_first_picture)
{

View file

@ -12,6 +12,7 @@
#include "mainwindow.h"
#include "dialogrender.h"
#include "dialogexplorer.h"
#include "RenderConfig.h"
#include "DesktopScenery.h"
#include "BasePreview.h"
#include "SoftwareCanvasRenderer.h"
@ -252,7 +253,7 @@ void FreeFormHelper::processRenderClicked()
emit needAlterRenderer(&renderer);
DialogRender* dialog = new DialogRender(_form_widget, &renderer);
RenderArea::RenderParams params = {400, 300, 1, 3};
RenderConfig params(400, 300, 1, 3);
dialog->startRender(params);
delete dialog;

View file

@ -18,7 +18,7 @@
#include <QComboBox>
#include "tools.h"
#include "SoftwareRenderer.h"
#include "RenderConfig.h"
#include "Scenery.h"
#include "ColorProfile.h"
#include "SoftwareCanvasRenderer.h"
@ -51,7 +51,7 @@ static void _renderUpdate(double progress)
class RenderThread:public QThread
{
public:
RenderThread(DialogRender* dialog, SoftwareCanvasRenderer* renderer, RenderArea::RenderParams params):QThread()
RenderThread(DialogRender* dialog, SoftwareCanvasRenderer* renderer, const RenderConfig &params):QThread()
{
_dialog = dialog;
_renderer = renderer;
@ -59,14 +59,14 @@ public:
}
void run()
{
// FIXME Pass config to render
_renderer->render();
_renderer->start(_params);
_dialog->tellRenderEnded();
}
private:
DialogRender* _dialog;
SoftwareCanvasRenderer* _renderer;
RenderArea::RenderParams _params;
RenderConfig _params;
};
class _RenderArea:public QWidget
@ -183,14 +183,13 @@ void DialogRender::tellRenderEnded()
emit renderEnded();
}
void DialogRender::startRender(RenderArea::RenderParams params)
void DialogRender::startRender(const RenderConfig &params)
{
_started = time(NULL);
canvas_renderer->setSize(params.width, params.height, params.antialias);
applyRenderSize(params.width, params.height);
canvas_renderer->setPreviewCallbacks(_renderStart, _renderDraw, _renderUpdate);
_render_thread = new RenderThread(this, canvas_renderer, params);
_render_thread->start();
@ -218,11 +217,11 @@ void DialogRender::saveRender()
filepath = filepath.append(".png");
}
std::string filepathstr = filepath.toStdString();
if (canvas_renderer->render_area->saveToFile((char*)filepathstr.c_str()))
/*if (canvas_renderer->render_area->saveToFile((char*)filepathstr.c_str()))
{
QMessageBox::information(this, "Message", QString(tr("The picture %1 has been saved.")).arg(filepath));
}
else
else*/
{
QMessageBox::critical(this, "Message", QString(tr("Can't write to file : %1")).arg(filepath));
}
@ -232,13 +231,12 @@ void DialogRender::saveRender()
void DialogRender::toneMappingChanged()
{
ColorProfile profile((ColorProfile::ToneMappingOperator)_tonemapping_control->currentIndex(), ((double)_exposure_control->value()) * 0.01);
canvas_renderer->render_area->setToneMapping(profile);
//canvas_renderer->render_area->setToneMapping(profile);
}
void DialogRender::loadLastRender()
{
applyRenderSize(canvas_renderer->render_width, canvas_renderer->render_height);
canvas_renderer->setPreviewCallbacks(_renderStart, _renderDraw, _renderUpdate);
renderEnded();
toneMappingChanged();

View file

@ -5,7 +5,6 @@
#include <ctime>
#include <QDialog>
#include "RenderArea.h"
class QThread;
class QProgressBar;
@ -25,7 +24,7 @@ public:
void tellRenderSize(int width, int height);
void tellProgressChange(double value);
void tellRenderEnded();
void startRender(RenderArea::RenderParams params);
void startRender(const RenderConfig &params);
void loadLastRender();
QImage* pixbuf;

View file

@ -108,7 +108,7 @@ void FormRender::startQuickRender()
_renderer_inited = true;
DialogRender* dialog = new DialogRender(this, _renderer);
RenderArea::RenderParams params = {400, 300, 1, 3};
RenderConfig params(400, 300, 1, 3);
dialog->startRender(params);
delete dialog;

View file

@ -5,7 +5,7 @@
#include "baseform.h"
#include "RenderArea.h"
#include "RenderConfig.h"
class FormRender : public BaseForm
{
@ -29,7 +29,7 @@ protected slots:
virtual void configChangeEvent();
private:
RenderArea::RenderParams _params;
RenderConfig _params;
CameraDefinition* _camera;
SoftwareCanvasRenderer* _renderer;
bool _renderer_inited;

View file

@ -20,7 +20,6 @@ public:
inline SoftwareRenderer *getRenderer() const {return renderer;}
virtual void rasterize() = 0;
virtual void rasterizeToCanvas(CanvasPortion* canvas);
protected:

View file

@ -1,792 +0,0 @@
#include "RenderArea.h"
#include "Vector3.h"
#include "ColorProfile.h"
#include "Mutex.h"
#include "CameraDefinition.h"
#include "SoftwareRenderer.h"
#include "Thread.h"
#include "PictureWriter.h"
struct RenderFragment
{
struct
{
unsigned char dirty : 1;
unsigned char edge : 1;
unsigned char callback : 6;
} flags;
union
{
struct {
double x;
double y;
double z;
} location;
struct {
double r;
double g;
double b;
} color;
} data;
double z;
};
typedef struct
{
int x;
int y;
struct {
double x;
double y;
double z;
} pixel;
struct {
double x;
double y;
double z;
} location;
int callback;
} ScanPoint;
struct FragmentCallback
{
RenderArea::f_RenderFragmentCallback function;
void* data;
};
typedef struct
{
ScanPoint* up;
ScanPoint* down;
int left;
int right;
} RenderScanlines;
typedef struct
{
int startx;
int endx;
int starty;
int endy;
int finished;
int interrupt;
int pixel_done;
Thread* thread;
RenderArea* area;
} RenderChunk;
static void _callbackStart(int, int, const Color&) {}
static void _callbackDraw(int, int, const Color&) {}
static void _callbackUpdate(double) {}
RenderArea::RenderArea(SoftwareRenderer* renderer)
{
this->renderer = renderer;
this->hdr_mapping = new ColorProfile;
this->params.width = 1;
this->params.height = 1;
this->params.antialias = 1;
this->params.quality = 5;
this->pixel_count = 1;
this->pixels = new RenderFragment[1];
this->fragment_callbacks_count = 0;
this->fragment_callbacks = new FragmentCallback[64];
this->background_color = COLOR_TRANSPARENT;
this->dirty_left = 1;
this->dirty_right = -1;
this->dirty_down = 1;
this->dirty_up = -1;
this->dirty_count = 0;
this->lock = new Mutex();
this->callback_start = _callbackStart;
this->callback_draw = _callbackDraw;
this->callback_update = _callbackUpdate;
}
RenderArea::~RenderArea()
{
delete hdr_mapping;
delete lock;
delete[] fragment_callbacks;
delete[] pixels;
}
void RenderArea::setAllDirty()
{
dirty_left = 0;
dirty_right = params.width * params.antialias - 1;
dirty_down = 0;
dirty_up = params.height * params.antialias - 1;
}
void RenderArea::setParams(RenderParams params)
{
int width, height;
width = params.width * params.antialias;
height = params.height * params.antialias;
this->params = params;
delete[] pixels;
pixels = new RenderFragment[width * height];
pixel_count = width * height;
dirty_left = width;
dirty_right = -1;
dirty_down = height;
dirty_up = -1;
dirty_count = 0;
clear();
}
void RenderArea::setToneMapping(const ColorProfile &profile)
{
profile.copy(hdr_mapping);
setAllDirty();
update();
}
void RenderArea::setBackgroundColor(const Color &col)
{
background_color = col;
}
void RenderArea::clear()
{
RenderFragment* pixel;
int x;
int y;
fragment_callbacks_count = 1;
fragment_callbacks[0].function = NULL;
fragment_callbacks[0].data = NULL;
for (x = 0; x < params.width * params.antialias; x++)
{
for (y = 0; y < params.height * params.antialias; y++)
{
pixel = pixels + (y * params.width * params.antialias + x);
pixel->z = -100000000.0;
pixel->flags.dirty = 0;
pixel->flags.callback = 0;
pixel->data.color.r = background_color.r;
pixel->data.color.g = background_color.g;
pixel->data.color.b = background_color.b;
}
}
callback_start(params.width, params.height, background_color);
dirty_left = params.width * params.antialias;
dirty_right = -1;
dirty_down = params.height * params.antialias;
dirty_up = -1;
dirty_count = 0;
}
static inline void _setDirtyPixel(RenderArea* area, int x, int y)
{
if (x < area->dirty_left)
{
area->dirty_left = x;
}
if (x > area->dirty_right)
{
area->dirty_right = x;
}
if (y < area->dirty_down)
{
area->dirty_down = y;
}
if (y > area->dirty_up)
{
area->dirty_up = y;
}
area->dirty_count++;
}
static inline Color _getFinalPixel(RenderArea* area, int x, int y)
{
Color result, col;
int sx, sy;
double factor = 1.0 / (double)(area->params.antialias * area->params.antialias);
RenderFragment* pixel_data;
result.r = result.g = result.b = 0.0;
result.a = 1.0;
for (sx = 0; sx < area->params.antialias; sx++)
{
for (sy = 0; sy < area->params.antialias; sy++)
{
pixel_data = area->pixels + (y * area->params.antialias + sy) * area->params.width * area->params.antialias + (x * area->params.antialias + sx);
if (pixel_data->flags.dirty)
{
if (pixel_data->flags.edge)
{
col = COLOR_GREY;
}
else
{
col = COLOR_WHITE;
}
}
else
{
col.r = pixel_data->data.color.r;
col.g = pixel_data->data.color.g;
col.b = pixel_data->data.color.b;
}
result.r += col.r * factor;
result.g += col.g * factor;
result.b += col.b * factor;
}
}
return area->hdr_mapping->apply(result);
}
void RenderArea::processDirtyPixels()
{
int x, y;
int down, up, left, right;
down = dirty_down / params.antialias;
up = dirty_up / params.antialias;
left = dirty_left / params.antialias;
right = dirty_right / params.antialias;
for (y = down; y <= up; y++)
{
for (x = left; x <= right; x++)
{
callback_draw(x, y, _getFinalPixel(this, x, y));
}
}
callback_update(renderer->render_progress);
dirty_left = params.width * params.antialias;
dirty_right = -1;
dirty_down = params.height * params.antialias;
dirty_up = -1;
dirty_count = 0;
}
void RenderArea::update()
{
lock->acquire();
processDirtyPixels();
lock->release();
}
static inline unsigned int _pushCallback(RenderArea* area, FragmentCallback callback)
{
int i;
for (i = 0; i < area->fragment_callbacks_count; i++)
{
if (area->fragment_callbacks[i].function == callback.function && area->fragment_callbacks[i].data == callback.data)
{
return i;
}
}
if (area->fragment_callbacks_count >= 64)
{
return 0;
}
else
{
area->fragment_callbacks[area->fragment_callbacks_count].function = callback.function;
area->fragment_callbacks[area->fragment_callbacks_count].data = callback.data;
return area->fragment_callbacks_count++;
}
}
void RenderArea::pushFragment(int x, int y, double z, int edge, const Vector3 &location, int callback)
{
RenderFragment* pixel_data;
if (x >= 0 && x < params.width * params.antialias && y >= 0 && y < params.height * params.antialias && z > 1.0)
{
pixel_data = pixels + (y * params.width * params.antialias + x);
if (z > pixel_data->z)
{
pixel_data->flags.dirty = (unsigned char)1;
pixel_data->flags.edge = (unsigned char)edge;
pixel_data->flags.callback = (unsigned char)callback;
pixel_data->data.location.x = location.x;
pixel_data->data.location.y = location.y;
pixel_data->data.location.z = location.z;
pixel_data->z = z;
_setDirtyPixel(this, x, y);
}
}
}
static void _scanGetDiff(ScanPoint* v1, ScanPoint* v2, ScanPoint* result)
{
result->pixel.x = v2->pixel.x - v1->pixel.x;
result->pixel.y = v2->pixel.y - v1->pixel.y;
result->pixel.z = v2->pixel.z - v1->pixel.z;
result->location.x = v2->location.x - v1->location.x;
result->location.y = v2->location.y - v1->location.y;
result->location.z = v2->location.z - v1->location.z;
result->callback = v1->callback;
}
static void _scanInterpolate(CameraDefinition* camera, ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
{
Vector3 vec1(v1->pixel.x, v1->pixel.y, v1->pixel.z);
Vector3 vecdiff(diff->pixel.x, diff->pixel.y, diff->pixel.z);
double v1depth = camera->getRealDepth(vec1);
double v2depth = camera->getRealDepth(vec1.add(vecdiff));
double factor = ((1.0 - value) / v1depth + value / v2depth);
result->pixel.x = v1->pixel.x + diff->pixel.x * value;
result->pixel.y = v1->pixel.y + diff->pixel.y * value;
result->pixel.z = v1->pixel.z + diff->pixel.z * value;
result->location.x = ((1.0 - value) * (v1->location.x / v1depth) + value * (v1->location.x + diff->location.x) / v2depth) / factor;
result->location.y = ((1.0 - value) * (v1->location.y / v1depth) + value * (v1->location.y + diff->location.y) / v2depth) / factor;
result->location.z = ((1.0 - value) * (v1->location.z / v1depth) + value * (v1->location.z + diff->location.z) / v2depth) / factor;
result->callback = v1->callback;
}
static void _pushScanPoint(RenderArea* area, RenderScanlines* scanlines, ScanPoint* point)
{
point->x = (int)floor(point->pixel.x);
point->y = (int)floor(point->pixel.y);
if (point->x < 0 || point->x >= area->params.width * area->params.antialias)
{
// Point outside scanline range
return;
}
else if (scanlines->right < 0)
{
// First point pushed
scanlines->left = point->x;
scanlines->right = point->x;
scanlines->up[point->x] = *point;
scanlines->down[point->x] = *point;
}
else if (point->x > scanlines->right)
{
// Grow scanlines to right
for (int x = scanlines->right + 1; x < point->x; x++)
{
scanlines->up[x].y = -1;
scanlines->down[x].y = area->params.height * area->params.antialias;
}
scanlines->right = point->x;
scanlines->up[point->x] = *point;
scanlines->down[point->x] = *point;
}
else if (point->x < scanlines->left)
{
// Grow scanlines to left
for (int x = point->x + 1; x < scanlines->left; x++)
{
scanlines->up[x].y = -1;
scanlines->down[x].y = area->params.height * area->params.antialias;
}
scanlines->left = point->x;
scanlines->up[point->x] = *point;
scanlines->down[point->x] = *point;
}
else
{
// Expand existing scanline
if (point->y > scanlines->up[point->x].y)
{
scanlines->up[point->x] = *point;
}
if (point->y < scanlines->down[point->x].y)
{
scanlines->down[point->x] = *point;
}
}
}
static void _pushScanLineEdge(RenderArea* area, RenderScanlines* scanlines, ScanPoint* point1, ScanPoint* point2)
{
double dx, fx;
ScanPoint diff, point;
int startx = lround(point1->pixel.x);
int endx = lround(point2->pixel.x);
int curx;
if (endx < startx)
{
_pushScanLineEdge(area, scanlines, point2, point1);
}
else if (endx < 0 || startx >= area->params.width * area->params.antialias)
{
return;
}
else if (startx == endx)
{
_pushScanPoint(area, scanlines, point1);
_pushScanPoint(area, scanlines, point2);
}
else
{
if (startx < 0)
{
startx = 0;
}
if (endx >= area->params.width * area->params.antialias)
{
endx = area->params.width * area->params.antialias - 1;
}
dx = point2->pixel.x - point1->pixel.x;
_scanGetDiff(point1, point2, &diff);
for (curx = startx; curx <= endx; curx++)
{
fx = (double)curx + 0.5;
if (fx < point1->pixel.x)
{
fx = point1->pixel.x;
}
else if (fx > point2->pixel.x)
{
fx = point2->pixel.x;
}
fx = fx - point1->pixel.x;
_scanInterpolate(area->renderer->render_camera, point1, &diff, fx / dx, &point);
/*point.pixel.x = (double)curx;*/
_pushScanPoint(area, scanlines, &point);
}
}
}
static void _renderScanLines(RenderArea* area, RenderScanlines* scanlines)
{
int x, starty, endy, cury;
ScanPoint diff;
double dy, fy;
ScanPoint up, down, current;
if (scanlines->right > 0)
{
for (x = scanlines->left; x <= scanlines->right; x++)
{
up = scanlines->up[x];
down = scanlines->down[x];
starty = down.y;
endy = up.y;
if (endy < 0 || starty >= area->params.height * area->params.antialias)
{
continue;
}
if (starty < 0)
{
starty = 0;
}
if (endy >= area->params.height * area->params.antialias)
{
endy = area->params.height * area->params.antialias - 1;
}
dy = up.pixel.y - down.pixel.y;
_scanGetDiff(&down, &up, &diff);
current.x = x;
for (cury = starty; cury <= endy; cury++)
{
fy = (double)cury + 0.5;
if (fy < down.pixel.y)
{
fy = down.pixel.y;
}
else if (fy > up.pixel.y)
{
fy = up.pixel.y;
}
fy = fy - down.pixel.y;
current.y = cury;
_scanInterpolate(area->renderer->render_camera, &down, &diff, fy / dy, &current);
Vector3 veclocation = Vector3(current.location.x, current.location.y, current.location.z);
area->pushFragment(current.x, current.y, current.pixel.z, (cury == starty || cury == endy), veclocation, current.callback);
}
}
}
}
void RenderArea::pushTriangle(const Vector3 &pixel1, const Vector3 &pixel2, const Vector3 &pixel3, const Vector3 &location1, const Vector3 &location2, const Vector3 &location3, f_RenderFragmentCallback callback, void* callback_data)
{
FragmentCallback fragment_callback = {callback, callback_data};
ScanPoint point1, point2, point3;
double limit_width = (double)(params.width * params.antialias - 1);
double limit_height = (double)(params.height * params.antialias - 1);
/* Filter if outside screen */
if (pixel1.z < 1.0 || pixel2.z < 1.0 || pixel3.z < 1.0 || (pixel1.x < 0.0 && pixel2.x < 0.0 && pixel3.x < 0.0) || (pixel1.y < 0.0 && pixel2.y < 0.0 && pixel3.y < 0.0) || (pixel1.x > limit_width && pixel2.x > limit_width && pixel3.x > limit_width) || (pixel1.y > limit_height && pixel2.y > limit_height && pixel3.y > limit_height))
{
return;
}
/* Prepare fragment callback */
lock->acquire();
point1.callback = _pushCallback(this, fragment_callback);
lock->release();
/* Prepare vertices */
point1.pixel.x = pixel1.x;
point1.pixel.y = pixel1.y;
point1.pixel.z = pixel1.z;
point1.location.x = location1.x;
point1.location.y = location1.y;
point1.location.z = location1.z;
point2.pixel.x = pixel2.x;
point2.pixel.y = pixel2.y;
point2.pixel.z = pixel2.z;
point2.location.x = location2.x;
point2.location.y = location2.y;
point2.location.z = location2.z;
point2.callback = point1.callback;
point3.pixel.x = pixel3.x;
point3.pixel.y = pixel3.y;
point3.pixel.z = pixel3.z;
point3.location.x = location3.x;
point3.location.y = location3.y;
point3.location.z = location3.z;
point3.callback = point1.callback;
/* Prepare scanlines */
// TODO Don't create scanlines for each triangles (one by thread is more appropriate)
RenderScanlines scanlines;
int width = params.width * params.antialias;
scanlines.left = width;
scanlines.right = -1;
scanlines.up = new ScanPoint[width];
scanlines.down = new ScanPoint[width];
/* Render edges in scanlines */
_pushScanLineEdge(this, &scanlines, &point1, &point2);
_pushScanLineEdge(this, &scanlines, &point2, &point3);
_pushScanLineEdge(this, &scanlines, &point3, &point1);
/* Commit scanlines to area */
lock->acquire();
_renderScanLines(this, &scanlines);
lock->release();
/* Free scalines */
delete[] scanlines.up;
delete[] scanlines.down;
}
Color RenderArea::getPixel(int x, int y)
{
Color result;
lock->acquire();
result = _getFinalPixel(this, x, y);
lock->release();
return result;
}
void* _renderPostProcessChunk(void* data)
{
int x, y;
RenderFragment* fragment;
RenderChunk* chunk = (RenderChunk*)data;
for (x = chunk->startx; x <= chunk->endx; x++)
{
for (y = chunk->starty; y <= chunk->endy; y++)
{
fragment = chunk->area->pixels + (y * chunk->area->params.width * chunk->area->params.antialias + x);
if (fragment->flags.dirty)
{
FragmentCallback callback;
Color col;
callback = chunk->area->fragment_callbacks[fragment->flags.callback];
if (callback.function)
{
Vector3 location(fragment->data.location.x, fragment->data.location.y, fragment->data.location.z);
col = callback.function(chunk->area->renderer, location, callback.data);
/*colorNormalize(&col);*/
}
else
{
col = COLOR_BLACK;
}
fragment->data.color.r = col.r;
fragment->data.color.g = col.g;
fragment->data.color.b = col.b;
chunk->area->lock->acquire();
fragment->flags.dirty = 0;
_setDirtyPixel(chunk->area, x, y);
chunk->area->lock->release();
}
chunk->area->pixel_done++;
}
if (chunk->interrupt)
{
break;
}
}
chunk->finished = 1;
return NULL;
}
#define MAX_CHUNKS 8
void RenderArea::postProcess(int nbchunks)
{
volatile RenderChunk chunks[MAX_CHUNKS];
int i;
int x, y, dx, dy, nx, ny;
int loops, running;
if (nbchunks > MAX_CHUNKS)
{
nbchunks = MAX_CHUNKS;
}
if (nbchunks < 1)
{
nbchunks = 1;
}
nx = 10;
ny = 10;
dx = params.width * params.antialias / nx;
dy = params.height * params.antialias / ny;
x = 0;
y = 0;
pixel_done = 0;
for (i = 0; i < nbchunks; i++)
{
chunks[i].thread = NULL;
chunks[i].area = this;
}
running = 0;
loops = 0;
while ((x < nx && !renderer->render_interrupt) || running > 0)
{
Thread::timeSleepMs(50);
for (i = 0; i < nbchunks; i++)
{
if (chunks[i].thread)
{
if (chunks[i].finished)
{
chunks[i].thread->join();
delete chunks[i].thread;
chunks[i].thread = NULL;
running--;
}
else if (renderer->render_interrupt)
{
chunks[i].interrupt = 1;
}
}
renderer->render_progress = 0.1 + ((double)pixel_done / (double)pixel_count) * 0.9;
if (x < nx && !chunks[i].thread && !renderer->render_interrupt)
{
chunks[i].finished = 0;
chunks[i].interrupt = 0;
chunks[i].startx = x * dx;
if (x == nx - 1)
{
chunks[i].endx = params.width * params.antialias - 1;
}
else
{
chunks[i].endx = (x + 1) * dx - 1;
}
chunks[i].starty = y * dy;
if (y == ny - 1)
{
chunks[i].endy = params.height * params.antialias - 1;
}
else
{
chunks[i].endy = (y + 1) * dy - 1;
}
chunks[i].thread = new Thread(_renderPostProcessChunk);
chunks[i].thread->start((void*)(chunks + i));
running++;
if (++y >= ny)
{
x++;
y = 0;
}
}
}
if (++loops >= 10)
{
lock->acquire();
processDirtyPixels();
lock->release();
loops = 0;
}
}
processDirtyPixels();
callback_update(1.0);
}
class RenderWriter:public PictureWriter
{
public:
RenderWriter(RenderArea *area): area(area) {}
virtual unsigned int getPixel(int x, int y) override
{
Color result = _getFinalPixel(area, x, y);
result.normalize();
return result.to32BitBGRA();
}
private:
RenderArea *area;
};
int RenderArea::saveToFile(const std::string &path)
{
RenderWriter writer(this);
return writer.save(path, params.width, params.height);
}
void RenderArea::setPreviewCallbacks(RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
{
callback_start = start ? start : _callbackStart;
callback_draw = draw ? draw : _callbackDraw;
callback_update = update ? update : _callbackUpdate;
callback_start(params.width, params.height, background_color);
setAllDirty();
processDirtyPixels();
callback_update(0.0);
}

View file

@ -1,76 +0,0 @@
#ifndef RENDERAREA_H
#define RENDERAREA_H
#include "software_global.h"
#include "Color.h"
typedef struct RenderFragment RenderFragment;
typedef struct FragmentCallback FragmentCallback;
namespace paysages {
namespace software {
class SOFTWARESHARED_EXPORT RenderArea
{
public:
typedef struct
{
int width;
int height;
int antialias;
int quality;
} RenderParams;
typedef Color (*f_RenderFragmentCallback)(SoftwareRenderer* renderer, const Vector3 &location, void* data);
typedef void (*RenderCallbackStart)(int width, int height, const Color &background);
typedef void (*RenderCallbackDraw)(int x, int y, const Color &col);
typedef void (*RenderCallbackUpdate)(double progress);
public:
RenderArea(SoftwareRenderer* parent);
~RenderArea();
void setParams(RenderParams params);
void setToneMapping(const ColorProfile &profile);
void setBackgroundColor(const Color& col);
void clear();
void update();
void pushTriangle(const Vector3 &pixel1, const Vector3 &pixel2, const Vector3 &pixel3, const Vector3 &location1, const Vector3 &location2, const Vector3 &location3, f_RenderFragmentCallback callback, void* callback_data);
Color getPixel(int x, int y);
void postProcess(int nbchunks);
int saveToFile(const std::string &path);
void setPreviewCallbacks(RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update);
void setAllDirty();
void processDirtyPixels();
void pushFragment(int x, int y, double z, int edge, const Vector3 &location, int callback);
public:
ColorProfile* hdr_mapping;
SoftwareRenderer* renderer;
RenderParams params;
int pixel_count;
int pixel_done;
RenderFragment* pixels;
int fragment_callbacks_count;
FragmentCallback* fragment_callbacks;
Color background_color;
volatile int dirty_left;
volatile int dirty_right;
volatile int dirty_up;
volatile int dirty_down;
volatile int dirty_count;
Mutex* lock;
RenderCallbackStart callback_start;
RenderCallbackDraw callback_draw;
RenderCallbackUpdate callback_update;
};
}
}
#endif // RENDERAREA_H

View file

@ -0,0 +1,30 @@
#include "RenderConfig.h"
RenderConfig::RenderConfig(int width, int height, int antialias, int quality):
width(width), height(height), antialias(antialias), quality(quality)
{
if (this->width <= 0)
{
this->width = 400;
}
if (this->height <= 0)
{
this->height = this->width * 4 / 3;
}
if (this->antialias < 1)
{
this->antialias = 1;
}
if (this->antialias > 4)
{
this->antialias = 4;
}
if (this->quality < 1)
{
this->quality = 1;
}
if (this->quality > 10)
{
this->quality = 10;
}
}

View file

@ -0,0 +1,23 @@
#ifndef RENDERCONFIG_H
#define RENDERCONFIG_H
#include "software_global.h"
namespace paysages {
namespace software {
class SOFTWARESHARED_EXPORT RenderConfig
{
public:
RenderConfig(int width=0, int height=0, int antialias=1, int quality=5);
int width;
int height;
int antialias;
int quality;
};
}
}
#endif // RENDERCONFIG_H

View file

@ -30,61 +30,6 @@ static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &loc
return result;
}
void SkyRasterizer::rasterize()
{
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 */
renderer->pushQuad(vertex1, vertex4, vertex3, vertex2, _postProcessFragment, NULL);
}
}
}
void SkyRasterizer::rasterizeToCanvas(CanvasPortion* canvas)
{
int res_i, res_j;

View file

@ -13,7 +13,6 @@ class SOFTWARESHARED_EXPORT SkyRasterizer: public Rasterizer
public:
SkyRasterizer(SoftwareRenderer* renderer, int client_id);
virtual void rasterize();
virtual void rasterizeToCanvas(CanvasPortion* canvas);
};

View file

@ -13,9 +13,9 @@ SoftwareCanvasRenderer::SoftwareCanvasRenderer()
started = false;
canvas = new Canvas();
rasterizers.push_back(new TerrainRasterizer(this, 0));
rasterizers.push_back(new SkyRasterizer(this, 0));
rasterizers.push_back(new WaterRasterizer(this, 1));
rasterizers.push_back(new SkyRasterizer(this, 2));
rasterizers.push_back(new TerrainRasterizer(this, 2));
}
SoftwareCanvasRenderer::~SoftwareCanvasRenderer()
@ -41,6 +41,9 @@ void SoftwareCanvasRenderer::render()
// TEMP
started = true;
CanvasPortion *portion = canvas->at(0, 0);
render_width = canvas->getWidth();
render_height = canvas->getHeight();
render_quality = 3;
render_camera->setRenderSize(canvas->getWidth(), canvas->getHeight());

View file

@ -22,8 +22,6 @@
SoftwareRenderer::SoftwareRenderer(Scenery* scenery)
{
RenderArea::RenderParams params = {1, 1, 1, 5};
render_quality = 5;
render_width = 1;
render_height = 1;
@ -31,8 +29,6 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery)
render_progress = 0.0;
is_rendering = 0;
render_camera = new CameraDefinition;
render_area = new RenderArea(this);
render_area->setParams(params);
atmosphere_renderer = new BaseAtmosphereRenderer(this);
clouds_renderer = new CloudsRenderer(this);
@ -59,7 +55,6 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery)
SoftwareRenderer::~SoftwareRenderer()
{
delete render_camera;
delete render_area;
delete fluid_medium;
delete lighting;
@ -108,18 +103,6 @@ void SoftwareRenderer::prepare()
//fluid_medium->registerMedium(water_renderer);
}
void SoftwareRenderer::rasterize()
{
TerrainRasterizer terrain(this, 0);
terrain.rasterize();
WaterRasterizer water(this, 1);
water.rasterize();
SkyRasterizer sky(this, 2);
sky.rasterize();
}
void SoftwareRenderer::disableClouds()
{
scenery->getClouds()->clear();
@ -164,63 +147,6 @@ void SoftwareRenderer::disableAtmosphere(const std::vector<LightComponent> &ligh
atmosphere_renderer->setStaticLights(lights);
}
void SoftwareRenderer::setPreviewCallbacks(RenderArea::RenderCallbackStart start, RenderArea::RenderCallbackDraw draw, RenderArea::RenderCallbackUpdate update)
{
render_area->setPreviewCallbacks(start, draw, update);
}
static void* _renderFirstPass(void* data)
{
SoftwareRenderer* renderer = (SoftwareRenderer*)data;
renderer->rasterize();
renderer->is_rendering = 0;
return NULL;
}
void SoftwareRenderer::start(RenderArea::RenderParams params)
{
Thread thread(_renderFirstPass);
int loops;
int core_count = System::getCoreCount();
params.antialias = (params.antialias < 1) ? 1 : params.antialias;
params.antialias = (params.antialias > 4) ? 4 : params.antialias;
render_quality = params.quality;
render_width = params.width * params.antialias;
render_height = params.height * params.antialias;
render_interrupt = 0;
render_progress = 0.0;
prepare();
render_camera->setRenderSize(render_width, render_height);
render_area->setBackgroundColor(COLOR_BLACK);
render_area->setParams(params);
render_area->clear();
is_rendering = 1;
thread.start(this);
loops = 0;
while (is_rendering)
{
Thread::timeSleepMs(100);
if (++loops >= 10)
{
render_area->update();
loops = 0;
}
}
thread.join();
is_rendering = 1;
render_area->postProcess(core_count);
is_rendering = 0;
}
void SoftwareRenderer::interrupt()
{
render_interrupt = 1;
@ -296,37 +222,3 @@ Vector3 SoftwareRenderer::unprojectPoint(const Vector3 &point)
{
return render_camera->unproject(point);
}
void SoftwareRenderer::pushTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
Vector3 p1, p2, p3;
p1 = projectPoint(v1);
p2 = projectPoint(v2);
p3 = projectPoint(v3);
render_area->pushTriangle(p1, p2, p3, v1, v2, v3, callback, callback_data);
}
void SoftwareRenderer::pushQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
pushTriangle(v2, v3, v1, callback, callback_data);
pushTriangle(v4, v1, v3, callback, callback_data);
}
void SoftwareRenderer::pushDisplacedTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
Vector3 p1, p2, p3;
p1 = projectPoint(v1);
p2 = projectPoint(v2);
p3 = projectPoint(v3);
render_area->pushTriangle(p1, p2, p3, ov1, ov2, ov3, callback, callback_data);
}
void SoftwareRenderer::pushDisplacedQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, const Vector3 &ov4, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
pushDisplacedTriangle(v2, v3, v1, ov2, ov3, ov1, callback, callback_data);
pushDisplacedTriangle(v4, v1, v3, ov4, ov1, ov3, callback, callback_data);
}

View file

@ -3,7 +3,6 @@
#include "software_global.h"
#include "RenderArea.h"
#include "RayCastingManager.h"
namespace paysages {
@ -26,7 +25,6 @@ public:
CameraDefinition* render_camera;
/* Render related */
RenderArea* render_area;
double render_progress;
int render_interrupt;
int is_rendering;
@ -39,10 +37,6 @@ public:
virtual Vector3 projectPoint(const Vector3 &point);
virtual Vector3 unprojectPoint(const Vector3 &point);
virtual int addRenderProgress(double progress);
virtual void pushTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushDisplacedTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushDisplacedQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, const Vector3 &ov4, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
/*!
* \brief Set the scenery to render.
@ -59,11 +53,6 @@ public:
*/
virtual void prepare();
/*!
* \brief Start the rasterization process.
*/
virtual void rasterize();
/*!
* \brief Disable the clouds feature.
*
@ -78,8 +67,6 @@ public:
void disableAtmosphere();
void disableAtmosphere(const std::vector<LightComponent> &lights);
void setPreviewCallbacks(RenderArea::RenderCallbackStart start, RenderArea::RenderCallbackDraw draw, RenderArea::RenderCallbackUpdate update);
void start(RenderArea::RenderParams params);
void interrupt();
inline Scenery* getScenery() const {return scenery;}

View file

@ -8,6 +8,7 @@
#include "TexturesRenderer.h"
#include "Scenery.h"
#include "ParallelQueue.h"
#include "CanvasPortion.h"
TerrainRasterizer::TerrainRasterizer(SoftwareRenderer* renderer, int client_id):
Rasterizer(renderer, client_id)
@ -25,7 +26,30 @@ static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &poi
return renderer->getTerrainRenderer()->getFinalColor(point, precision);
}
static void _renderQuad(SoftwareRenderer* renderer, double x, double z, double size, double water_height)
void TerrainRasterizer::tessellateChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, int detail)
{
if (detail < 1)
{
return;
}
double water_height = renderer->getWaterRenderer()->getHeightInfo().min_height;
double startx = chunk->point_nw.x;
double startz = chunk->point_nw.z;
double size = (chunk->point_ne.x - chunk->point_nw.x) / (double)detail;
int i, j;
for (i = 0; i < detail; i++)
{
for (j = 0; j < detail; j++)
{
renderQuad(canvas, startx + (double)i * size, startz + (double)j * size, size, water_height);
}
}
}
void TerrainRasterizer::renderQuad(CanvasPortion *canvas, double x, double z, double size, double water_height)
{
Vector3 ov1, ov2, ov3, ov4;
Vector3 dv1, dv2, dv3, dv4;
@ -50,30 +74,7 @@ static void _renderQuad(SoftwareRenderer* renderer, double x, double z, double s
if (dv1.y > water_height || dv2.y > water_height || dv3.y > water_height || dv4.y > water_height)
{
renderer->pushDisplacedQuad(dv1, dv2, dv3, dv4, ov1, ov2, ov3, ov4, _postProcessFragment, NULL);
}
}
void TerrainRasterizer::tessellateChunk(TerrainChunkInfo* chunk, int detail)
{
if (detail < 1)
{
return;
}
double water_height = renderer->getWaterRenderer()->getHeightInfo().min_height;
double startx = chunk->point_nw.x;
double startz = chunk->point_nw.z;
double size = (chunk->point_ne.x - chunk->point_nw.x) / (double)detail;
int i, j;
for (i = 0; i < detail; i++)
{
for (j = 0; j < detail; j++)
{
_renderQuad(renderer, startx + (double)i * size, startz + (double)j * size, size, water_height);
}
pushDisplacedQuad(canvas, dv1, dv2, dv3, dv4, ov1, ov2, ov3, ov4);
}
}
@ -130,7 +131,7 @@ static void _getChunk(SoftwareRenderer* renderer, TerrainRasterizer::TerrainChun
}
}
void TerrainRasterizer::getTessellationInfo(int displaced)
void TerrainRasterizer::getTessellationInfo(CanvasPortion* canvas, int displaced)
{
TerrainChunkInfo chunk;
int chunk_factor, chunk_count, i;
@ -157,25 +158,25 @@ void TerrainRasterizer::getTessellationInfo(int displaced)
for (i = 0; i < chunk_count - 1; i++)
{
_getChunk(renderer, &chunk, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size, displaced);
if (!processChunk(&chunk, progress))
if (!processChunk(canvas, &chunk, progress))
{
return;
}
_getChunk(renderer, &chunk, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size, displaced);
if (!processChunk(&chunk, progress))
if (!processChunk(canvas, &chunk, progress))
{
return;
}
_getChunk(renderer, &chunk, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size, displaced);
if (!processChunk(&chunk, progress))
if (!processChunk(canvas, &chunk, progress))
{
return;
}
_getChunk(renderer, &chunk, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size, displaced);
if (!processChunk(&chunk, progress))
if (!processChunk(canvas, &chunk, progress))
{
return;
}
@ -196,6 +197,7 @@ void TerrainRasterizer::getTessellationInfo(int displaced)
typedef struct
{
TerrainRasterizer* rasterizer;
CanvasPortion *canvas;
TerrainRasterizer::TerrainChunkInfo chunk;
} ParallelRasterInfo;
@ -205,18 +207,19 @@ static int _parallelJobCallback(ParallelQueue*, int, void* data, int stopping)
if (!stopping)
{
info->rasterizer->tessellateChunk(&info->chunk, info->chunk.detail_hint);
info->rasterizer->tessellateChunk(info->canvas, &info->chunk, info->chunk.detail_hint);
}
delete info;
return 0;
}
int TerrainRasterizer::processChunk(TerrainChunkInfo* chunk, double progress)
int TerrainRasterizer::processChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, double progress)
{
ParallelRasterInfo* info = new ParallelRasterInfo;
info->rasterizer = this;
info->canvas = canvas;
info->chunk = *chunk;
if (!queue->addJob(_parallelJobCallback, info))
@ -230,16 +233,15 @@ int TerrainRasterizer::processChunk(TerrainChunkInfo* chunk, double progress)
void TerrainRasterizer::rasterize()
{
queue = new ParallelQueue();
renderer->render_progress = 0.0;
getTessellationInfo(0);
renderer->render_progress = 0.05;
queue->wait();
}
void TerrainRasterizer::rasterizeToCanvas(CanvasPortion *canvas)
{
queue = new ParallelQueue();
renderer->render_progress = 0.0;
getTessellationInfo(canvas, 0);
renderer->render_progress = 0.05;
queue->wait();
}

View file

@ -27,19 +27,21 @@ public:
/**
* Method called for each chunk tessellated by getTessellationInfo.
*/
int processChunk(TerrainChunkInfo* chunk, double progress);
int processChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, double progress);
/**
* Tessellate the terrain, calling processChunk for each chunk.
*
* The terrain will be broken in chunks, most detailed near the camera.
*/
void getTessellationInfo(int displaced);
void getTessellationInfo(CanvasPortion* canvas, int displaced);
/**
* Tessellate a terrain chunk, pushing the quads in the render area.
*/
void tessellateChunk(TerrainChunkInfo* chunk, int detail);
void tessellateChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, int detail);
void renderQuad(CanvasPortion* canvas, double x, double z, double size, double water_height);
/**
* Start the final rasterization of terrain.

View file

@ -25,110 +25,6 @@ static inline Vector3 _getFirstPassVertex(SoftwareRenderer* renderer, double x,
return result;
}
static void _renderQuad(SoftwareRenderer* renderer, 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);
renderer->pushQuad(v1, v2, v3, v4, _postProcessFragment, NULL);
}
typedef struct
{
SoftwareRenderer* renderer;
int i;
double cx;
double cz;
double radius_int;
double chunk_size;
double radius_ext;
} ParallelRasterInfo;
static int _parallelJobCallback(ParallelQueue*, int, void* data, int stopping)
{
ParallelRasterInfo* info = (ParallelRasterInfo*)data;
if (!stopping)
{
_renderQuad(info->renderer, info->cx - info->radius_ext + info->chunk_size * info->i, info->cz - info->radius_ext, info->chunk_size);
_renderQuad(info->renderer, info->cx + info->radius_int, info->cz - info->radius_ext + info->chunk_size * info->i, info->chunk_size);
_renderQuad(info->renderer, info->cx + info->radius_int - info->chunk_size * info->i, info->cz + info->radius_int, info->chunk_size);
_renderQuad(info->renderer, info->cx - info->radius_ext, info->cz + info->radius_int - info->chunk_size * info->i, info->chunk_size);
}
delete info;
return 0;
}
void WaterRasterizer::rasterize()
{
ParallelRasterInfo* info;
ParallelQueue* queue;
queue = new ParallelQueue();
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++)
{
info = new ParallelRasterInfo;
info->renderer = renderer;
info->cx = cx;
info->cz = cz;
info->i = i;
info->radius_int = radius_int;
info->radius_ext = radius_ext;
info->chunk_size = chunk_size;
if (!queue->addJob(_parallelJobCallback, info))
{
delete info;
}
}
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;
}
queue->wait();
delete queue;
}
void WaterRasterizer::rasterizeQuad(CanvasPortion* canvas, double x, double z, double size)
{
Vector3 v1, v2, v3, v4;

View file

@ -15,8 +15,6 @@ public:
void rasterizeQuad(CanvasPortion* canvas, double x, double z, double size);
virtual void rasterize();
virtual void rasterizeToCanvas(CanvasPortion* canvas);
};

View file

@ -34,7 +34,6 @@ SOURCES += SoftwareRenderer.cpp \
TerrainRenderer.cpp \
TexturesRenderer.cpp \
WaterRenderer.cpp \
RenderArea.cpp \
RayCastingManager.cpp \
NightSky.cpp \
TerrainRayWalker.cpp \
@ -45,7 +44,8 @@ SOURCES += SoftwareRenderer.cpp \
SoftwareCanvasRenderer.cpp \
Rasterizer.cpp \
CanvasLiveClient.cpp \
CanvasPreview.cpp
CanvasPreview.cpp \
RenderConfig.cpp
HEADERS += SoftwareRenderer.h\
software_global.h \
@ -69,7 +69,6 @@ HEADERS += SoftwareRenderer.h\
TerrainRenderer.h \
TexturesRenderer.h \
WaterRenderer.h \
RenderArea.h \
RayCastingManager.h \
NightSky.h \
TerrainRayWalker.h \
@ -80,7 +79,8 @@ HEADERS += SoftwareRenderer.h\
SoftwareCanvasRenderer.h \
Rasterizer.h \
CanvasLiveClient.h \
CanvasPreview.h
CanvasPreview.h \
RenderConfig.h
unix:!symbian {
maemo5 {

View file

@ -15,7 +15,7 @@ namespace paysages {
namespace software {
class SoftwareRenderer;
class SoftwareCanvasRenderer;
class RenderArea;
class RenderConfig;
class FluidMediumManager;
class FluidMediumInterface;

View file

@ -31,7 +31,7 @@ TEST(Bruneton, AerialPerspective1)
renderer.render_camera->setTarget(VECTOR_EAST);
renderer.render_camera->setRenderSize(renderer.render_width, renderer.render_height);
RenderArea::RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
/*RenderArea::RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
renderer.render_area->setParams(params);
renderer.render_area->setBackgroundColor(COLOR_BLACK);
renderer.render_area->clear();
@ -43,7 +43,7 @@ TEST(Bruneton, AerialPerspective1)
renderer.pushQuad(Vector3(30.0, -10.0, 25.0), Vector3(30.0, -10.0, 30.0), Vector3(30.0, 50.0, 30.0), Vector3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderer.render_area->postProcess(System::getCoreCount());
renderer.render_area->saveToFile("./output/test_bruneton_perspective.png");
renderer.render_area->saveToFile("./output/test_bruneton_perspective.png");*/
}
TEST(Bruneton, AerialPerspective2)
@ -67,7 +67,7 @@ TEST(Bruneton, AerialPerspective2)
renderer.render_camera->setTarget(VECTOR_EAST);
renderer.render_camera->setRenderSize(renderer.render_width, renderer.render_height);
RenderArea::RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
/*RenderArea::RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
renderer.render_area->setParams(params);
renderer.render_area->setBackgroundColor(COLOR_BLACK);
renderer.render_area->clear();
@ -79,5 +79,5 @@ TEST(Bruneton, AerialPerspective2)
renderer.pushQuad(Vector3(30.0, -10.0, 25.0), Vector3(30.0, -10.0, 30.0), Vector3(30.0, 50.0, 30.0), Vector3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderer.render_area->postProcess(System::getCoreCount());
renderer.render_area->saveToFile("./output/test_bruneton_perspective1.png");
renderer.render_area->saveToFile("./output/test_bruneton_perspective1.png");*/
}

View file

@ -34,19 +34,19 @@ static void _render_quad_checker(SoftwareRenderer &renderer)
renderer.render_width = 800;
renderer.render_height = 600;
renderer.render_quality = 1;
renderer.render_area->setToneMapping(ColorProfile(ColorProfile::TONE_MAPPING_CLAMP, 0.0));
//renderer.render_area->setToneMapping(ColorProfile(ColorProfile::TONE_MAPPING_CLAMP, 0.0));
renderer.render_camera->setRenderSize(renderer.render_width, renderer.render_height);
renderer.render_camera->setFov(1.57);
RenderArea::RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
/*RenderConfig params(renderer.render_width, renderer.render_height, 1, 1);
renderer.render_area->setParams(params);
renderer.render_area->setBackgroundColor(COLOR_BLUE);
renderer.render_area->clear();
renderer.pushQuad(Vector3(-1.0, 0.0, 1.0), Vector3(-1.0, 0.0, -1.0), Vector3(1.0, 0.0, -1.0), Vector3(1.0, 0.0, 1.0), _postProcessFragment, NULL);
renderer.render_area->postProcess(System::getCoreCount());
renderer.render_area->postProcess(System::getCoreCount());*/
}
TEST(Render, quad)
@ -61,7 +61,7 @@ TEST(Render, quad)
_render_quad_checker(renderer);
Color col;
/*Color col;
col = renderer.render_area->getPixel(399, 599 - 435);
ASSERT_COLOR_RGBA(col, 1.0, 1.0, 1.0, 1.0);
col = renderer.render_area->getPixel(399, 599 - 436);
@ -71,7 +71,7 @@ TEST(Render, quad)
col = renderer.render_area->getPixel(400, 599 - 436);
ASSERT_COLOR_RGBA(col, 1.0, 1.0, 1.0, 1.0);
renderer.render_area->saveToFile("./output/test_render_quad.png");
renderer.render_area->saveToFile("./output/test_render_quad.png");*/
}
TEST(Render, quad_cut)
@ -86,5 +86,5 @@ TEST(Render, quad_cut)
_render_quad_checker(renderer);
renderer.render_area->saveToFile("./output/test_render_quad_cut.png");
//renderer.render_area->saveToFile("./output/test_render_quad_cut.png");
}