paysages: Big big refactoring for scenery and renderer (WIP - Clouds still broken).
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@233 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
48ea553f49
commit
4e70d8ca8c
33 changed files with 571 additions and 340 deletions
12
cli/main.c
12
cli/main.c
|
@ -3,11 +3,14 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
#include "../lib_paysages/auto.h"
|
||||
#include "../lib_paysages/render.h"
|
||||
#include "../lib_paysages/scenery.h"
|
||||
|
||||
void startRender(char* outputpath)
|
||||
void startRender(Renderer* renderer, char* outputpath)
|
||||
{
|
||||
printf("\rRendering %s ... \n", outputpath);
|
||||
autoRenderSceneTwoPass(0);
|
||||
autoRenderSceneTwoPass(renderer, 0);
|
||||
printf("\rSaving %s ... \n", outputpath);
|
||||
remove(outputpath);
|
||||
renderSaveToFile(outputpath);
|
||||
|
@ -26,6 +29,7 @@ void _previewUpdate(double progress)
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Renderer renderer;
|
||||
int conf_render_width = 800;
|
||||
int conf_render_height = 600;
|
||||
int conf_render_quality = 5;
|
||||
|
@ -94,8 +98,8 @@ int main(int argc, char** argv)
|
|||
printf("Initializing ...\n");
|
||||
paysagesInit();
|
||||
|
||||
renderer = sceneryGetStandardRenderer(conf_render_quality);
|
||||
renderSetSize(conf_render_width, conf_render_height);
|
||||
renderSetQuality(conf_render_quality);
|
||||
renderSetPreviewCallbacks(NULL, NULL, NULL, _previewUpdate);
|
||||
|
||||
for (outputcount = 0; outputcount < conf_nb_pictures; outputcount++)
|
||||
|
@ -103,7 +107,7 @@ int main(int argc, char** argv)
|
|||
autoSetDaytimeFraction(conf_daytime_start);
|
||||
|
||||
sprintf(outputpath, "output/pic%05d.png", outputcount);
|
||||
startRender(outputpath);
|
||||
startRender(&renderer, outputpath);
|
||||
|
||||
conf_daytime_start += conf_daytime_step;
|
||||
}
|
||||
|
|
|
@ -5,15 +5,25 @@
|
|||
#include <QColor>
|
||||
#include <QPainter>
|
||||
|
||||
#include "../lib_paysages/render.h"
|
||||
#include "../lib_paysages/renderer.h"
|
||||
#include "../lib_paysages/scenery.h"
|
||||
#include "../lib_paysages/auto.h"
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
|
||||
class RenderThread:public QThread
|
||||
{
|
||||
public:
|
||||
RenderThread(Renderer* renderer):QThread()
|
||||
{
|
||||
_renderer = renderer;
|
||||
}
|
||||
void run()
|
||||
{
|
||||
autoRenderSceneTwoPass(0);
|
||||
autoRenderSceneTwoPass(_renderer, 0);
|
||||
}
|
||||
private:
|
||||
Renderer* _renderer;
|
||||
};
|
||||
|
||||
static DialogRender* _current_dialog;
|
||||
|
@ -89,12 +99,13 @@ DialogRender::DialogRender(QWidget *parent):
|
|||
|
||||
void DialogRender::startRender(int quality, int width, int height)
|
||||
{
|
||||
renderSetSize(width, height);
|
||||
autoSetRenderQuality(quality);
|
||||
Renderer renderer;
|
||||
|
||||
renderer = sceneryGetStandardRenderer(quality);
|
||||
renderSetSize(width, height);
|
||||
renderSetPreviewCallbacks(_renderResize, _renderClear, _renderDraw, _renderUpdate);
|
||||
|
||||
render_thread = new RenderThread();
|
||||
render_thread = new RenderThread(&renderer);
|
||||
render_thread->start();
|
||||
|
||||
exec();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QMessageBox>
|
||||
|
||||
#include "dialogrender.h"
|
||||
#include "../lib_paysages/render.h"
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
|
||||
/**************** Form ****************/
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "../lib_paysages/sky.h"
|
||||
#include "../lib_paysages/scenery.h"
|
||||
#include "../lib_paysages/renderer.h"
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
#include "../lib_paysages/shared/constants.h"
|
||||
|
||||
|
@ -19,6 +21,7 @@ public:
|
|||
PreviewEast(QWidget* parent):
|
||||
Preview(parent)
|
||||
{
|
||||
_renderer = rendererGetFake();
|
||||
}
|
||||
protected:
|
||||
QColor getColor(double x, double y)
|
||||
|
@ -30,8 +33,10 @@ protected:
|
|||
look.y = -y;
|
||||
look.z = x;
|
||||
|
||||
return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL));
|
||||
return colorToQColor(skyGetColor(&_definition, &_renderer, eye, look));
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
};
|
||||
|
||||
class PreviewWest:public Preview
|
||||
|
@ -40,6 +45,7 @@ public:
|
|||
PreviewWest(QWidget* parent):
|
||||
Preview(parent)
|
||||
{
|
||||
_renderer = rendererGetFake();
|
||||
}
|
||||
protected:
|
||||
QColor getColor(double x, double y)
|
||||
|
@ -51,8 +57,10 @@ protected:
|
|||
look.y = -y;
|
||||
look.z = -x;
|
||||
|
||||
return colorToQColor(skyGetColorCustom(eye, look, &_definition, NULL, NULL));
|
||||
return colorToQColor(skyGetColor(&_definition, &_renderer, eye, look));
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
};
|
||||
|
||||
/**************** Form ****************/
|
||||
|
@ -79,13 +87,13 @@ FormSky::FormSky(QWidget *parent):
|
|||
|
||||
void FormSky::revertConfig()
|
||||
{
|
||||
skyCopyDefinition(skyGetDefinition(), &_definition);
|
||||
sceneryGetSky(&_definition);
|
||||
BaseForm::revertConfig();
|
||||
}
|
||||
|
||||
void FormSky::applyConfig()
|
||||
{
|
||||
skySetDefinition(_definition);
|
||||
scenerySetSky(&_definition);
|
||||
BaseForm::applyConfig();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "../lib_paysages/terrain.h"
|
||||
#include "../lib_paysages/scenery.h"
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
#include "../lib_paysages/shared/constants.h"
|
||||
|
||||
|
@ -15,8 +16,7 @@ static TerrainDefinition _definition;
|
|||
class PreviewTerrainHeight:public Preview
|
||||
{
|
||||
public:
|
||||
PreviewTerrainHeight(QWidget* parent):
|
||||
Preview(parent)
|
||||
PreviewTerrainHeight(QWidget* parent):Preview(parent)
|
||||
{
|
||||
}
|
||||
protected:
|
||||
|
@ -24,7 +24,7 @@ protected:
|
|||
{
|
||||
double height;
|
||||
|
||||
height = terrainGetHeightNormalizedCustom(x, y, &_definition);
|
||||
height = terrainGetHeightNormalized(&_definition, x, y);
|
||||
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
|
||||
}
|
||||
};
|
||||
|
@ -32,23 +32,18 @@ protected:
|
|||
class PreviewTerrainColor:public Preview
|
||||
{
|
||||
public:
|
||||
PreviewTerrainColor(QWidget* parent):
|
||||
Preview(parent)
|
||||
PreviewTerrainColor(QWidget* parent):Preview(parent)
|
||||
{
|
||||
_lighting_environment.filter = NULL;
|
||||
|
||||
_environment.toggle_fog = 0;
|
||||
_environment.lighting_definition = NULL;
|
||||
_environment.lighting_environment = &_lighting_environment;
|
||||
// TODO Use custom renderer
|
||||
_renderer = sceneryGetStandardRenderer(3);
|
||||
}
|
||||
protected:
|
||||
QColor getColor(double x, double y)
|
||||
{
|
||||
return colorToQColor(terrainGetColorCustom(x, y, scaling, &_definition, NULL, &_environment));
|
||||
return colorToQColor(terrainGetColor(&_definition, &_renderer, x, y, scaling));
|
||||
}
|
||||
private:
|
||||
LightingEnvironment _lighting_environment;
|
||||
TerrainEnvironment _environment;
|
||||
Renderer _renderer;
|
||||
};
|
||||
|
||||
/**************** Form ****************/
|
||||
|
@ -71,13 +66,13 @@ FormTerrain::FormTerrain(QWidget *parent):
|
|||
|
||||
void FormTerrain::revertConfig()
|
||||
{
|
||||
terrainCopyDefinition(terrainGetDefinition(), &_definition);
|
||||
sceneryGetTerrain(&_definition);
|
||||
BaseForm::revertConfig();
|
||||
}
|
||||
|
||||
void FormTerrain::applyConfig()
|
||||
{
|
||||
terrainSetDefinition(_definition);
|
||||
scenerySetTerrain(&_definition);
|
||||
BaseForm::applyConfig();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "../lib_paysages/terrain.h"
|
||||
#include "../lib_paysages/water.h"
|
||||
#include "../lib_paysages/scenery.h"
|
||||
#include "../lib_paysages/renderer.h"
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
#include "../lib_paysages/shared/constants.h"
|
||||
|
||||
|
@ -16,19 +18,20 @@ static WaterDefinition _definition;
|
|||
class PreviewWaterCoverage:public Preview
|
||||
{
|
||||
public:
|
||||
PreviewWaterCoverage(QWidget* parent):
|
||||
Preview(parent)
|
||||
PreviewWaterCoverage(QWidget* parent):Preview(parent)
|
||||
{
|
||||
_terrain = terrainCreateDefinition();
|
||||
sceneryGetTerrain(&_terrain);
|
||||
}
|
||||
protected:
|
||||
QColor getColor(double x, double y)
|
||||
{
|
||||
double height;
|
||||
|
||||
height = terrainGetHeight(x, y);
|
||||
height = terrainGetHeight(&_terrain, x, y);
|
||||
if (height > _definition.height)
|
||||
{
|
||||
height = terrainGetHeightNormalized(x, y);
|
||||
height = terrainGetHeightNormalized(&_terrain, x, y);
|
||||
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
|
||||
}
|
||||
else
|
||||
|
@ -36,24 +39,24 @@ protected:
|
|||
return colorToQColor(_definition.main_color);
|
||||
}
|
||||
}
|
||||
private:
|
||||
TerrainDefinition _terrain;
|
||||
};
|
||||
|
||||
class PreviewWaterColor:public Preview
|
||||
{
|
||||
public:
|
||||
PreviewWaterColor(QWidget* parent):
|
||||
Preview(parent)
|
||||
PreviewWaterColor(QWidget* parent):Preview(parent)
|
||||
{
|
||||
_water = waterCreateDefinition();
|
||||
_renderer = rendererGetFake();
|
||||
_renderer.rayWalking = _rayWalking;
|
||||
// TODO Lighting
|
||||
}
|
||||
protected:
|
||||
QColor getColor(double x, double y)
|
||||
{
|
||||
Vector3 eye, look, location;
|
||||
WaterDefinition definition;
|
||||
WaterEnvironment environment;
|
||||
LightingEnvironment lighting_environment;
|
||||
WaterQuality quality;
|
||||
Color result;
|
||||
|
||||
eye.x = 0.0;
|
||||
eye.y = scaling;
|
||||
|
@ -65,8 +68,7 @@ protected:
|
|||
|
||||
if (look.y > -0.0001)
|
||||
{
|
||||
result = this->rayCastFromWater(eye, look).hit_color;
|
||||
return colorToQColor(result);
|
||||
return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color);
|
||||
}
|
||||
|
||||
location.x = eye.x - look.x * eye.y / look.y;
|
||||
|
@ -75,27 +77,17 @@ protected:
|
|||
|
||||
if (location.z > 0.0)
|
||||
{
|
||||
result = this->rayCastFromWater(eye, look).hit_color;
|
||||
return colorToQColor(result);
|
||||
return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color);
|
||||
}
|
||||
|
||||
definition = _definition;
|
||||
definition.height = 0.0;
|
||||
lighting_environment.filter = NULL;
|
||||
environment.reflection_function = (RayCastingFunction)(&this->rayCastFromWater);
|
||||
environment.refraction_function = (RayCastingFunction)(&this->rayCastFromWater);
|
||||
environment.toggle_fog = 0;
|
||||
environment.lighting_definition = NULL;
|
||||
environment.lighting_environment = &lighting_environment;
|
||||
quality.force_detail = 0.0001;
|
||||
quality.detail_boost = 1.0;
|
||||
|
||||
result = waterGetColorCustom(location, look, &definition, &quality, &environment).final;
|
||||
return colorToQColor(result);
|
||||
_water.height = 0.0;
|
||||
return colorToQColor(waterGetColor(&_definition, &_renderer, location, look));
|
||||
}
|
||||
|
||||
private:
|
||||
static RayCastingResult rayCastFromWater(Vector3 start, Vector3 direction)
|
||||
Renderer _renderer;
|
||||
WaterDefinition _water;
|
||||
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
||||
{
|
||||
RayCastingResult result;
|
||||
double x, y;
|
||||
|
@ -104,12 +96,12 @@ private:
|
|||
if (direction.z < 0.0001)
|
||||
{
|
||||
result.hit_color = COLOR_WHITE;
|
||||
result.hit_location = start;
|
||||
result.hit_location = location;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = start.x + direction.x * (0.0 - start.z) / direction.z;
|
||||
y = start.y + direction.y * (0.0 - start.z) / direction.z;
|
||||
x = location.x + direction.x * (0.0 - location.z) / direction.z;
|
||||
y = location.y + direction.y * (0.0 - location.z) / direction.z;
|
||||
|
||||
if (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0))
|
||||
{
|
||||
|
@ -154,12 +146,12 @@ FormWater::FormWater(QWidget *parent):
|
|||
|
||||
void FormWater::revertConfig()
|
||||
{
|
||||
waterCopyDefinition(waterGetDefinition(), &_definition);
|
||||
sceneryGetWater(&_definition);
|
||||
BaseForm::revertConfig();
|
||||
}
|
||||
|
||||
void FormWater::applyConfig()
|
||||
{
|
||||
waterSetDefinition(_definition);
|
||||
scenerySetWater(&_definition);
|
||||
BaseForm::applyConfig();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "formrender.h"
|
||||
#include "dialogrender.h"
|
||||
|
||||
#include "../lib_paysages/auto.h"
|
||||
#include "../lib_paysages/shared/functions.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
|
@ -12,4 +12,4 @@ static inline QColor colorToQColor(Color color)
|
|||
return QColor(color.r * 255.0, color.g * 255.0, color.b * 255.0, color.a * 255.0);
|
||||
}
|
||||
|
||||
#endif // _PAYSAGES_QT_TOOLS_H_
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <unistd.h>
|
||||
#include "auto.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
@ -7,8 +8,8 @@
|
|||
#include "shared/functions.h"
|
||||
#include "shared/constants.h"
|
||||
#include "shared/globals.h"
|
||||
#include "shared/system.h"
|
||||
|
||||
#include "system.h"
|
||||
#include "water.h"
|
||||
#include "clouds.h"
|
||||
#include "sky.h"
|
||||
|
@ -17,40 +18,10 @@
|
|||
#include "textures.h"
|
||||
#include "lighting.h"
|
||||
#include "scenery.h"
|
||||
#include "render.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static int _cpu_count = 1;
|
||||
static int _is_rendering = 0;
|
||||
|
||||
void autoInit()
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD processAffinityMask;
|
||||
DWORD systemAffinityMask;
|
||||
|
||||
if (GetProcessAffinityMask( GetCurrentProcess(),
|
||||
&processAffinityMask,
|
||||
&systemAffinityMask)){
|
||||
processAffinityMask = (processAffinityMask & 0x55555555)
|
||||
+ (processAffinityMask >> 1 & 0x55555555);
|
||||
processAffinityMask = (processAffinityMask & 0x33333333)
|
||||
+ (processAffinityMask >> 2 & 0x33333333);
|
||||
processAffinityMask = (processAffinityMask & 0x0f0f0f0f)
|
||||
+ (processAffinityMask >> 4 & 0x0f0f0f0f);
|
||||
processAffinityMask = (processAffinityMask & 0x00ff00ff)
|
||||
+ (processAffinityMask >> 8 & 0x00ff00ff);
|
||||
_cpu_count = (processAffinityMask & 0x0000ffff)
|
||||
+ (processAffinityMask >>16 & 0x0000ffff);
|
||||
}
|
||||
#endif
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
_cpu_count = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
#endif
|
||||
}
|
||||
|
||||
void autoSetDaytime(int hour, int minute)
|
||||
{
|
||||
autoSetDaytimeFraction((double)hour / 24.0 + (double)minute / 1440.0);
|
||||
|
@ -252,29 +223,12 @@ void autoGenRealisticLandscape(int seed)
|
|||
|
||||
void* _renderFirstPass(void* data)
|
||||
{
|
||||
if (!renderSetNextProgressStep(0.0, 0.01))
|
||||
{
|
||||
_is_rendering = 0;
|
||||
return NULL;
|
||||
}
|
||||
skyRender(renderTellProgress);
|
||||
if (!renderSetNextProgressStep(0.01, 0.085))
|
||||
{
|
||||
_is_rendering = 0;
|
||||
return NULL;
|
||||
}
|
||||
terrainRender(renderTellProgress);
|
||||
if (!renderSetNextProgressStep(0.085, 0.1))
|
||||
{
|
||||
_is_rendering = 0;
|
||||
return NULL;
|
||||
}
|
||||
waterRender(renderTellProgress);
|
||||
sceneryRenderFirstPass((Renderer*)data);
|
||||
_is_rendering = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void autoRenderSceneTwoPass(int postonly)
|
||||
void autoRenderSceneTwoPass(Renderer* renderer, int postonly)
|
||||
{
|
||||
Thread* thread;
|
||||
int loops;
|
||||
|
@ -284,7 +238,7 @@ void autoRenderSceneTwoPass(int postonly)
|
|||
renderClear();
|
||||
|
||||
_is_rendering = 1;
|
||||
thread = threadCreate(_renderFirstPass, NULL);
|
||||
thread = threadCreate(_renderFirstPass, renderer);
|
||||
loops = 0;
|
||||
|
||||
while (_is_rendering)
|
||||
|
@ -300,10 +254,7 @@ void autoRenderSceneTwoPass(int postonly)
|
|||
|
||||
threadJoin(thread);
|
||||
}
|
||||
if (renderSetNextProgressStep(0.1, 1.0))
|
||||
{
|
||||
renderPostProcess(_cpu_count);
|
||||
}
|
||||
sceneryRenderSecondPass(renderer);
|
||||
}
|
||||
|
||||
static int _postProcessRayTracingOverlay(RenderFragment* fragment)
|
||||
|
|
20
lib_paysages/auto.h
Normal file
20
lib_paysages/auto.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef _PAYSAGES_AUTO_H_
|
||||
#define _PAYSAGES_AUTO_H_
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void autoSetDaytime(int hour, int minute);
|
||||
void autoSetDaytimeFraction(double daytime);
|
||||
void autoGenRealisticLandscape(int seed);
|
||||
void autoRenderSceneTwoPass(Renderer* renderer, int postonly);
|
||||
void autoRenderSceneRayTracing();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "render.h"
|
||||
#include "shared/types.h"
|
||||
#include "shared/globals.h"
|
||||
#include "shared/constants.h"
|
||||
|
@ -118,7 +119,7 @@ void cameraProjectToFragment(CameraDefinition* camera, double x, double y, doubl
|
|||
*/
|
||||
void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback)
|
||||
{
|
||||
Vertex v1, v2, v3, v4;
|
||||
/*Vertex v1, v2, v3, v4;
|
||||
Vector3 v;
|
||||
|
||||
v.x = 0.0;
|
||||
|
@ -149,5 +150,5 @@ void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCall
|
|||
v4.color = col;
|
||||
v4.callback = callback;
|
||||
|
||||
renderPushQuad(&v1, &v2, &v3, &v4);
|
||||
renderPushQuad(&v1, &v2, &v3, &v4);*/
|
||||
}
|
||||
|
|
|
@ -480,8 +480,7 @@ Color cloudsGetLayerColor(CloudsLayerDefinition* definition, Renderer* renderer,
|
|||
direction = v3Normalize(direction);
|
||||
result = COLOR_TRANSPARENT;
|
||||
|
||||
/* TODO Flexible precision */
|
||||
detail = renderGetPrecision(start) / definition->scaling;
|
||||
detail = renderer->getPrecision(renderer, start) / definition->scaling;
|
||||
|
||||
segment_count = _findSegments(definition, renderer, start, direction, detail, 20, 60.0, max_length, &inside_length, &total_length, segments);
|
||||
for (i = 0; i < segment_count; i++)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "shared/types.h"
|
||||
#include "shared/constants.h"
|
||||
|
@ -72,6 +73,11 @@ double colorNormalize(Color* col)
|
|||
{
|
||||
double max = colorGetValue(col);
|
||||
|
||||
assert(col->r >= 0.0);
|
||||
assert(col->g >= 0.0);
|
||||
assert(col->b >= 0.0);
|
||||
assert(col->a >= 0.0);
|
||||
|
||||
if (max > 1.0)
|
||||
{
|
||||
col->r /= max;
|
||||
|
|
|
@ -27,6 +27,7 @@ void fogSetDistance(double near, double far)
|
|||
|
||||
Color fogApplyToLocation(Vector3 location, Color base)
|
||||
{
|
||||
return base;
|
||||
// TODO Don't use camera_location
|
||||
/*Color mask = _col;
|
||||
double distance = v3Norm(v3Sub(camera_location, location));
|
||||
|
|
|
@ -25,14 +25,34 @@ void lightingInit()
|
|||
_LIGHT_NULL.direction.z = 0.0;
|
||||
}
|
||||
|
||||
void lightingSave(FILE* f)
|
||||
void lightingSave(FILE* f, LightingDefinition* definition)
|
||||
{
|
||||
// TODO
|
||||
int i;
|
||||
|
||||
toolsSaveInt(f, definition->autosetfromsky);
|
||||
toolsSaveInt(f, definition->nblights);
|
||||
for (i = 0; i < definition->nblights; i++)
|
||||
{
|
||||
colorSave(definition->lights[i].color, f);
|
||||
v3Save(definition->lights[i].direction, f);
|
||||
toolsSaveDouble(f, definition->lights[i].maxshadow);
|
||||
}
|
||||
}
|
||||
|
||||
void lightingLoad(FILE* f)
|
||||
void lightingLoad(FILE* f, LightingDefinition* definition)
|
||||
{
|
||||
// TODO
|
||||
int i;
|
||||
|
||||
definition->autosetfromsky = toolsLoadInt(f);
|
||||
definition->nblights = toolsLoadInt(f);
|
||||
for (i = 0; i < definition->nblights; i++)
|
||||
{
|
||||
definition->lights[i].color = colorLoad(f);
|
||||
definition->lights[i].direction = v3Load(f);
|
||||
definition->lights[i].maxshadow = toolsLoadDouble(f);
|
||||
}
|
||||
|
||||
lightingValidateDefinition(definition);
|
||||
}
|
||||
|
||||
LightingDefinition lightingCreateDefinition()
|
||||
|
|
|
@ -27,16 +27,9 @@ typedef struct
|
|||
LightDefinition _autolights[LIGHTING_MAX_LIGHTS];
|
||||
} LightingDefinition;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Color base;
|
||||
double reflection;
|
||||
double shininess;
|
||||
} SurfaceMaterial;
|
||||
|
||||
void lightingInit();
|
||||
void lightingSave(FILE* f);
|
||||
void lightingLoad(FILE* f);
|
||||
void lightingSave(FILE* f, LightingDefinition* definition);
|
||||
void lightingLoad(FILE* f, LightingDefinition* definition);
|
||||
|
||||
LightingDefinition lightingCreateDefinition();
|
||||
void lightingDeleteDefinition(LightingDefinition* definition);
|
||||
|
|
|
@ -8,28 +8,30 @@
|
|||
#include "shared/constants.h"
|
||||
#include "shared/functions.h"
|
||||
#include "shared/globals.h"
|
||||
#include "shared/system.h"
|
||||
|
||||
#include "terrain.h"
|
||||
#include "water.h"
|
||||
#include "lighting.h"
|
||||
#include "textures.h"
|
||||
#include "sky.h"
|
||||
#include "clouds.h"
|
||||
#include "auto.h"
|
||||
#include "system.h"
|
||||
#include "camera.h"
|
||||
#include "scenery.h"
|
||||
#include "render.h"
|
||||
|
||||
void paysagesInit()
|
||||
{
|
||||
CameraDefinition camera;
|
||||
|
||||
systemInit();
|
||||
ilInit();
|
||||
iluInit();
|
||||
|
||||
autoInit();
|
||||
sceneryInit();
|
||||
renderInit();
|
||||
|
||||
cameraSetLocation(-12.0, 5.0, 2.0);
|
||||
cameraSetTarget(0.0, 5.0, 0.0);
|
||||
camera = cameraCreateDefinition();
|
||||
cameraSetLocation(&camera, -12.0, 5.0, 2.0);
|
||||
cameraSetTarget(&camera, 0.0, 5.0, 0.0);
|
||||
scenerySetCamera(&camera);
|
||||
cameraDeleteDefinition(&camera);
|
||||
|
||||
autoSetRenderQuality(5);
|
||||
autoGenRealisticLandscape(0);
|
||||
autoSetDaytime(8, 30);
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
#include "shared/types.h"
|
||||
#include "shared/constants.h"
|
||||
#include "shared/functions.h"
|
||||
#include "shared/system.h"
|
||||
#include "render.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
@ -9,6 +6,11 @@
|
|||
#include "IL/il.h"
|
||||
#include "IL/ilu.h"
|
||||
|
||||
#include "shared/types.h"
|
||||
#include "shared/constants.h"
|
||||
#include "shared/functions.h"
|
||||
#include "system.h"
|
||||
|
||||
int render_width;
|
||||
int render_height;
|
||||
int render_quality;
|
||||
|
@ -166,17 +168,6 @@ void renderSetBackgroundColor(Color* col)
|
|||
background_color = *col;
|
||||
}
|
||||
|
||||
double renderGetPrecision(Vector3 location)
|
||||
{
|
||||
Vector3 projected;
|
||||
|
||||
projected = cameraProject(location);
|
||||
projected.x += 1.0;
|
||||
//projected.y += 1.0;
|
||||
|
||||
return v3Norm(v3Sub(cameraUnproject(projected), location)); // / (double)render_quality;
|
||||
}
|
||||
|
||||
int _sortRenderFragment(void const* a, void const* b)
|
||||
{
|
||||
double za, zb;
|
||||
|
@ -375,6 +366,7 @@ static void __vertexGetDiff(Vertex* v1, Vertex* v2, Vertex* result)
|
|||
result->color.b = v2->color.b - v1->color.b;
|
||||
result->color.a = v2->color.a - v1->color.a;
|
||||
result->callback = v1->callback;
|
||||
result->callback_data = v1->callback_data;
|
||||
}
|
||||
|
||||
static void __vertexInterpolate(Vertex* v1, Vertex* diff, double value, Vertex* result)
|
||||
|
@ -390,6 +382,7 @@ static void __vertexInterpolate(Vertex* v1, Vertex* diff, double value, Vertex*
|
|||
result->color.b = v1->color.b + diff->color.b * value;
|
||||
result->color.a = v1->color.a + diff->color.a * value;
|
||||
result->callback = v1->callback;
|
||||
result->callback_data = v1->callback_data;
|
||||
}
|
||||
|
||||
static void __pushScanLinePoint(RenderFragment point)
|
||||
|
@ -567,15 +560,15 @@ static void __renderScanLines()
|
|||
}
|
||||
}
|
||||
|
||||
void renderPushTriangle(Vertex* v1, Vertex* v2, Vertex* v3)
|
||||
void renderPushTriangle(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3)
|
||||
{
|
||||
Vector3 p1, p2, p3;
|
||||
double limit_width = (double)(render_width - 1);
|
||||
double limit_height = (double)(render_height - 1);
|
||||
|
||||
p1 = cameraProject(v1->location);
|
||||
p2 = cameraProject(v2->location);
|
||||
p3 = cameraProject(v3->location);
|
||||
p1 = renderer->projectPoint(renderer, v1->location);
|
||||
p2 = renderer->projectPoint(renderer, v2->location);
|
||||
p3 = renderer->projectPoint(renderer, v3->location);
|
||||
|
||||
/* Filter if outside screen */
|
||||
if (p1.z < 1.0 || p2.z < 1.0 || p3.z < 1.0 || (p1.x < 0.0 && p2.x < 0.0 && p3.x < 0.0) || (p1.y < 0.0 && p2.y < 0.0 && p3.y < 0.0) || (p1.x > limit_width && p2.x > limit_width && p3.x > limit_width) || (p1.y > limit_height && p2.y > limit_height && p3.y > limit_height))
|
||||
|
@ -592,10 +585,10 @@ void renderPushTriangle(Vertex* v1, Vertex* v2, Vertex* v3)
|
|||
mutexRelease(_lock);
|
||||
}
|
||||
|
||||
void renderPushQuad(Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4)
|
||||
void renderPushQuad(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4)
|
||||
{
|
||||
renderPushTriangle(v2, v3, v1);
|
||||
renderPushTriangle(v4, v1, v3);
|
||||
renderPushTriangle(renderer, v2, v3, v1);
|
||||
renderPushTriangle(renderer, v4, v1, v3);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -606,6 +599,7 @@ typedef struct {
|
|||
int finished;
|
||||
int interrupt;
|
||||
Thread* thread;
|
||||
Renderer* renderer;
|
||||
} RenderChunk;
|
||||
|
||||
void* _renderPostProcessChunk(void* data)
|
||||
|
@ -631,7 +625,7 @@ void* _renderPostProcessChunk(void* data)
|
|||
{
|
||||
if (fragments[i].vertex.callback)
|
||||
{
|
||||
if (fragments[i].vertex.callback(fragments + i))
|
||||
if (fragments[i].vertex.callback(fragments + i, chunk->renderer, fragments[i].vertex.callback_data))
|
||||
{
|
||||
/* TODO Store over-exposure */
|
||||
colorNormalize(&fragments[i].vertex.color);
|
||||
|
@ -658,7 +652,7 @@ void* _renderPostProcessChunk(void* data)
|
|||
}
|
||||
|
||||
#define MAX_CHUNKS 8
|
||||
void renderPostProcess(int nbchunks)
|
||||
void renderPostProcess(Renderer* renderer, int nbchunks)
|
||||
{
|
||||
volatile RenderChunk chunks[MAX_CHUNKS];
|
||||
int i;
|
||||
|
@ -685,6 +679,7 @@ void renderPostProcess(int nbchunks)
|
|||
for (i = 0; i < nbchunks; i++)
|
||||
{
|
||||
chunks[i].thread = NULL;
|
||||
chunks[i].renderer = renderer;
|
||||
}
|
||||
|
||||
running = 0;
|
||||
|
|
36
lib_paysages/render.h
Normal file
36
lib_paysages/render.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef _PAYSAGES_RENDER_H_
|
||||
#define _PAYSAGES_RENDER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "shared/types.h"
|
||||
#include "renderer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void renderInit();
|
||||
void renderSave(FILE* f);
|
||||
void renderLoad(FILE* f);
|
||||
void renderSetSize(int width, int height);
|
||||
int renderSetQuality(int quality);
|
||||
void renderClear();
|
||||
void renderUpdate();
|
||||
void renderInterrupt();
|
||||
void renderSetBackgroundColor(Color* col);
|
||||
void renderAddFragment(RenderFragment* fragment);
|
||||
void renderPushFragment(int x, int y, double z, Vertex* vertex);
|
||||
void renderPushTriangle(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3);
|
||||
void renderPushQuad(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4);
|
||||
void renderPostProcess(Renderer* renderer, int nbchunks);
|
||||
void renderSaveToFile(const char* path);
|
||||
void renderSetPreviewCallbacks(PreviewCallbackResize resize, PreviewCallbackClear clear, PreviewCallbackDraw draw, PreviewCallbackUpdate update);
|
||||
int renderSetNextProgressStep(double start, double end);
|
||||
int renderTellProgress(double progress);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,11 +1,59 @@
|
|||
#include "renderer.h"
|
||||
#include "shared/constants.h"
|
||||
#include "lighting.h"
|
||||
|
||||
static Color _fakeFilterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light)
|
||||
RayCastingResult _RAYCASTING_NULL = {0};
|
||||
|
||||
static Color _filterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light)
|
||||
{
|
||||
return light_color;
|
||||
}
|
||||
|
||||
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
|
||||
{
|
||||
return material.base;
|
||||
}
|
||||
|
||||
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
||||
{
|
||||
return _RAYCASTING_NULL;
|
||||
}
|
||||
|
||||
static double _getTerrainHeight(Renderer* renderer, double x, double z)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
|
||||
{
|
||||
return COLOR_TRANSPARENT;
|
||||
}
|
||||
|
||||
static Color _applyAtmosphere(Renderer* renderer, Vector3 location, Color base)
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3 end)
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
||||
{
|
||||
return point;
|
||||
}
|
||||
|
||||
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
||||
{
|
||||
return point;
|
||||
}
|
||||
|
||||
static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||
{
|
||||
return 0.001;
|
||||
}
|
||||
|
||||
Renderer rendererGetFake()
|
||||
{
|
||||
Renderer result;
|
||||
|
@ -13,7 +61,16 @@ Renderer rendererGetFake()
|
|||
result.render_quality = 5;
|
||||
result.camera_location = VECTOR_ZERO;
|
||||
|
||||
result.filterLight = _fakeFilterLight;
|
||||
result.filterLight = _filterLight;
|
||||
result.applyLightingToSurface = _applyLightingToSurface;
|
||||
result.rayWalking = _rayWalking;
|
||||
result.getTerrainHeight = _getTerrainHeight;
|
||||
result.applyTextures = _applyTextures;
|
||||
result.applyAtmosphere = _applyAtmosphere;
|
||||
result.applyClouds = _applyClouds;
|
||||
result.projectPoint = _projectPoint;
|
||||
result.unprojectPoint = _unprojectPoint;
|
||||
result.getPrecision = _getPrecision;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,21 @@ struct Renderer
|
|||
int render_quality;
|
||||
Vector3 camera_location;
|
||||
|
||||
/* Render related */
|
||||
double (*getPrecision)(Renderer* renderer, Vector3 location);
|
||||
Vector3 (*projectPoint)(Renderer* renderer, Vector3 point);
|
||||
Vector3 (*unprojectPoint)(Renderer* renderer, Vector3 point);
|
||||
|
||||
/* Scenery related */
|
||||
RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds);
|
||||
double (*getTerrainHeight)(Renderer* renderer, double x, double z);
|
||||
Color (*applyTextures)(Renderer* renderer, Vector3 location, double precision);
|
||||
Color (*applyAtmosphere)(Renderer* renderer, Vector3 location, Color base);
|
||||
Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end);
|
||||
|
||||
/* Lighting related */
|
||||
Color (*filterLight)(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light);
|
||||
Color (*applyLightingToSurface)(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material);
|
||||
|
||||
/* Custom data */
|
||||
void* customData[10];
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "scenery.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "shared/functions.h"
|
||||
#include "system.h"
|
||||
#include "render.h"
|
||||
|
||||
CameraDefinition _camera;
|
||||
CloudsDefinition _clouds;
|
||||
|
@ -10,41 +13,6 @@ TerrainDefinition _terrain;
|
|||
TexturesDefinition _textures;
|
||||
WaterDefinition _water;
|
||||
|
||||
static Color _filterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light)
|
||||
{
|
||||
Color result;
|
||||
|
||||
result = waterLightFilter(&_water, renderer, light_color, at_location, light_location, direction_to_light);
|
||||
result = terrainLightFilter(&_terrain, renderer, result, at_location, light_location, direction_to_light);
|
||||
// TODO atmosphere filter
|
||||
// TODO clouds filter
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static RayCastingResult _reflectionFunction(Vector3 start, Vector3 direction)
|
||||
{
|
||||
RayCastingResult result;
|
||||
|
||||
if (!terrainProjectRay(start, direction, &result.hit_location, &result.hit_color))
|
||||
{
|
||||
result.hit_color = skyProjectRay(start, direction);
|
||||
/* TODO hit_location */
|
||||
}
|
||||
|
||||
result.hit = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
static RayCastingResult _refractionFunction(Vector3 start, Vector3 direction)
|
||||
{
|
||||
RayCastingResult result;
|
||||
|
||||
result.hit = terrainProjectRay(start, direction, &result.hit_location, &result.hit_color);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void sceneryInit()
|
||||
{
|
||||
cameraInit();
|
||||
|
@ -128,7 +96,7 @@ void scenerySetClouds(CloudsDefinition* clouds)
|
|||
|
||||
void sceneryGetClouds(CloudsDefinition* clouds)
|
||||
{
|
||||
cloudsCopyDefinition(_clouds, clouds);
|
||||
cloudsCopyDefinition(&_clouds, clouds);
|
||||
}
|
||||
|
||||
void scenerySetLighting(LightingDefinition* lighting)
|
||||
|
@ -188,10 +156,134 @@ void sceneryGetWater(WaterDefinition* water)
|
|||
waterCopyDefinition(&_water, water);
|
||||
}
|
||||
|
||||
Renderer sceneryGetStandardRenderer()
|
||||
void sceneryRenderFirstPass(Renderer* renderer)
|
||||
{
|
||||
if (!renderSetNextProgressStep(0.0, 0.01))
|
||||
{
|
||||
return;
|
||||
}
|
||||
skyRender(&_sky, renderer, renderTellProgress);
|
||||
if (!renderSetNextProgressStep(0.01, 0.085))
|
||||
{
|
||||
return;
|
||||
}
|
||||
terrainRender(&_terrain, renderer, renderTellProgress);
|
||||
if (!renderSetNextProgressStep(0.085, 0.1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
waterRender(&_water, renderer, renderTellProgress);
|
||||
}
|
||||
|
||||
void sceneryRender()
|
||||
void sceneryRenderSecondPass(Renderer* renderer)
|
||||
{
|
||||
if (renderSetNextProgressStep(0.1, 1.0))
|
||||
{
|
||||
renderPostProcess(renderer, systemGetCoreCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******* Standard renderer *********/
|
||||
static Color _filterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light)
|
||||
{
|
||||
Color result;
|
||||
|
||||
result = waterLightFilter(&_water, renderer, light_color, at_location, light_location, direction_to_light);
|
||||
result = terrainLightFilter(&_terrain, renderer, result, at_location, light_location, direction_to_light);
|
||||
// TODO atmosphere filter
|
||||
// TODO clouds filter
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
|
||||
{
|
||||
return lightingApplyToSurface(&_lighting, renderer, location, normal, material);
|
||||
}
|
||||
|
||||
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
||||
{
|
||||
RayCastingResult result;
|
||||
|
||||
if (!terrainProjectRay(&_terrain, renderer, location, direction, &result.hit_location, &result.hit_color))
|
||||
{
|
||||
result.hit_color = skyGetColor(&_sky, renderer, location, direction);
|
||||
/* TODO hit_location */
|
||||
}
|
||||
|
||||
result.hit = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
static double _getTerrainHeight(Renderer* renderer, double x, double z)
|
||||
{
|
||||
return terrainGetHeight(&_terrain, x, z);
|
||||
}
|
||||
|
||||
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
|
||||
{
|
||||
return texturesGetColor(&_textures, renderer, location, precision);
|
||||
}
|
||||
|
||||
static Color _applyAtmosphere(Renderer* renderer, Vector3 location, Color base)
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3 end)
|
||||
{
|
||||
Color clouds;
|
||||
|
||||
clouds = cloudsGetColor(&_clouds, renderer, start, end);
|
||||
colorMask(&base, &clouds);
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
||||
{
|
||||
return cameraProject(&_camera, point);
|
||||
}
|
||||
|
||||
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
||||
{
|
||||
return cameraUnproject(&_camera, point);
|
||||
}
|
||||
|
||||
static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||
{
|
||||
Vector3 projected;
|
||||
|
||||
projected = cameraProject(&_camera, location);
|
||||
projected.x += 1.0;
|
||||
//projected.y += 1.0;
|
||||
|
||||
return v3Norm(v3Sub(cameraUnproject(&_camera, projected), location)); // / (double)render_quality;
|
||||
}
|
||||
|
||||
Renderer sceneryGetStandardRenderer(int quality)
|
||||
{
|
||||
Renderer result;
|
||||
|
||||
result.camera_location = _camera.location;
|
||||
result.render_quality = quality;
|
||||
|
||||
result.filterLight = _filterLight;
|
||||
result.applyLightingToSurface = _applyLightingToSurface;
|
||||
result.rayWalking = _rayWalking;
|
||||
result.getTerrainHeight = _getTerrainHeight;
|
||||
result.applyTextures = _applyTextures;
|
||||
result.applyAtmosphere = _applyAtmosphere;
|
||||
result.applyClouds = _applyClouds;
|
||||
result.projectPoint = _projectPoint;
|
||||
result.unprojectPoint = _unprojectPoint;
|
||||
result.getPrecision = _getPrecision;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,9 @@ void sceneryGetTextures(TexturesDefinition* textures);
|
|||
void scenerySetWater(WaterDefinition* water);
|
||||
void sceneryGetWater(WaterDefinition* water);
|
||||
|
||||
Renderer sceneryGetStandardRenderer();
|
||||
void sceneryRender();
|
||||
Renderer sceneryGetStandardRenderer(int quality);
|
||||
void sceneryRenderFirstPass(Renderer* renderer);
|
||||
void sceneryRenderSecondPass(Renderer* renderer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,14 +21,6 @@ void arrayReplace(Array* array, void* item, int position);
|
|||
void arrayLStrip(Array* array, int count);
|
||||
void arrayClear(Array* array);
|
||||
|
||||
/* auto.c */
|
||||
void autoInit();
|
||||
void autoSetDaytime(int hour, int minute);
|
||||
void autoSetDaytimeFraction(double daytime);
|
||||
void autoGenRealisticLandscape(int seed);
|
||||
void autoRenderSceneTwoPass(int postonly);
|
||||
void autoRenderSceneRayTracing();
|
||||
|
||||
/* color.c */
|
||||
void colorSave(Color col, FILE* f);
|
||||
Color colorLoad(FILE* f);
|
||||
|
@ -85,27 +77,6 @@ void fogSetColor(Color col);
|
|||
void fogSetDistance(double near, double far);
|
||||
Color fogApplyToLocation(Vector3 location, Color base);
|
||||
|
||||
/* render.c */
|
||||
void renderInit();
|
||||
void renderSave(FILE* f);
|
||||
void renderLoad(FILE* f);
|
||||
void renderSetSize(int width, int height);
|
||||
int renderSetQuality(int quality);
|
||||
void renderClear();
|
||||
void renderUpdate();
|
||||
void renderInterrupt();
|
||||
void renderSetBackgroundColor(Color* col);
|
||||
double renderGetPrecision(Vector3 location);
|
||||
void renderAddFragment(RenderFragment* fragment);
|
||||
void renderPushFragment(int x, int y, double z, Vertex* vertex);
|
||||
void renderPushTriangle(Vertex* v1, Vertex* v2, Vertex* v3);
|
||||
void renderPushQuad(Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4);
|
||||
void renderPostProcess(int nbchunks);
|
||||
void renderSaveToFile(const char* path);
|
||||
void renderSetPreviewCallbacks(PreviewCallbackResize resize, PreviewCallbackClear clear, PreviewCallbackDraw draw, PreviewCallbackUpdate update);
|
||||
int renderSetNextProgressStep(double start, double end);
|
||||
int renderTellProgress(double progress);
|
||||
|
||||
/* tools.c */
|
||||
double toolsRandom();
|
||||
double toolsBicubicInterpolate(double stencil[16], double x, double y);
|
||||
|
|
|
@ -53,8 +53,9 @@ typedef struct
|
|||
} ColorGradation;
|
||||
|
||||
struct RenderFragment;
|
||||
struct Renderer;
|
||||
|
||||
typedef int(*f_RenderFragmentCallback)(struct RenderFragment*);
|
||||
typedef int(*f_RenderFragmentCallback)(struct RenderFragment*, struct Renderer* renderer, void* data);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -62,6 +63,7 @@ typedef struct
|
|||
Vector3 normal;
|
||||
Color color;
|
||||
f_RenderFragmentCallback callback;
|
||||
void* callback_data;
|
||||
} Vertex;
|
||||
|
||||
typedef struct RenderFragment
|
||||
|
@ -87,6 +89,13 @@ typedef struct
|
|||
void* data;
|
||||
} Array;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Color base;
|
||||
double reflection;
|
||||
double shininess;
|
||||
} SurfaceMaterial;
|
||||
|
||||
typedef struct Zone Zone;
|
||||
|
||||
typedef void (*PreviewCallbackResize)(int width, int height);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "shared/functions.h"
|
||||
#include "shared/globals.h"
|
||||
#include "shared/constants.h"
|
||||
#include "render.h"
|
||||
#include "clouds.h"
|
||||
#include "sky.h"
|
||||
#include "lighting.h"
|
||||
|
@ -92,7 +93,7 @@ int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)
|
|||
|
||||
if (max_lights > 0)
|
||||
{
|
||||
lights[0].color = colorGradationGet(sky->sun_color, sky->daytime);
|
||||
lights[0].color = colorGradationGet(&sky->sun_color, sky->daytime);
|
||||
lights[0].direction = v3Scale(sun_direction, -1.0);
|
||||
lights[0].maxshadow = 1.0;
|
||||
nblights = 1;
|
||||
|
@ -137,20 +138,21 @@ Color skyGetColor(SkyDefinition* definition, Renderer* renderer, Vector3 eye, Ve
|
|||
}
|
||||
}
|
||||
|
||||
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer)
|
||||
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data)
|
||||
{
|
||||
// TODO
|
||||
/*Vector3 location, direction;
|
||||
Color color_sky, color_clouds;
|
||||
Vector3 location, direction;
|
||||
Color result;
|
||||
SkyDefinition* definition;
|
||||
|
||||
definition = (SkyDefinition*)data;
|
||||
|
||||
location = fragment->vertex.location;
|
||||
direction = v3Sub(location, camera_location);
|
||||
direction = v3Sub(location, renderer->camera_location);
|
||||
|
||||
color_sky = skyGetColor(camera_location, v3Normalize(direction));
|
||||
color_clouds = cloudsGetColor(camera_location, v3Add(camera_location, v3Scale(direction, 10.0)));
|
||||
result = skyGetColor(definition, renderer, renderer->camera_location, v3Normalize(direction));
|
||||
result = renderer->applyClouds(renderer, result, renderer->camera_location, v3Add(renderer->camera_location, v3Scale(direction, 10.0)));
|
||||
|
||||
colorMask(&color_sky, &color_clouds);
|
||||
fragment->vertex.color = color_sky;*/
|
||||
fragment->vertex.color = result;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -194,6 +196,7 @@ void skyRender(SkyDefinition* definition, Renderer* renderer, RenderProgressCall
|
|||
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
|
||||
vertex1.color = col;
|
||||
vertex1.callback = _postProcessFragment;
|
||||
vertex1.callback_data = definition;
|
||||
|
||||
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j);
|
||||
direction.y = SPHERE_SIZE * sin(current_j);
|
||||
|
@ -202,6 +205,7 @@ void skyRender(SkyDefinition* definition, Renderer* renderer, RenderProgressCall
|
|||
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
|
||||
vertex2.color = col;
|
||||
vertex2.callback = _postProcessFragment;
|
||||
vertex2.callback_data = definition;
|
||||
|
||||
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j);
|
||||
direction.y = SPHERE_SIZE * sin(current_j + step_j);
|
||||
|
@ -210,6 +214,7 @@ void skyRender(SkyDefinition* definition, Renderer* renderer, RenderProgressCall
|
|||
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
|
||||
vertex3.color = col;
|
||||
vertex3.callback = _postProcessFragment;
|
||||
vertex3.callback_data = definition;
|
||||
|
||||
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j);
|
||||
direction.y = SPHERE_SIZE * sin(current_j + step_j);
|
||||
|
@ -218,9 +223,10 @@ void skyRender(SkyDefinition* definition, Renderer* renderer, RenderProgressCall
|
|||
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
|
||||
vertex4.color = col;
|
||||
vertex4.callback = _postProcessFragment;
|
||||
vertex4.callback_data = definition;
|
||||
|
||||
/* TODO Triangles at poles */
|
||||
renderPushQuad(&vertex1, &vertex4, &vertex3, &vertex2);
|
||||
renderPushQuad(renderer, &vertex1, &vertex4, &vertex3, &vertex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,10 +31,7 @@ void skyCopyDefinition(SkyDefinition* source, SkyDefinition* destination);
|
|||
void skyValidateDefinition(SkyDefinition* definition);
|
||||
|
||||
int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights);
|
||||
|
||||
Color skyGetColor(SkyDefinition* definition, Renderer* renderer, Vector3 eye, Vector3 look);
|
||||
Color skyProjectRay(SkyDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction);
|
||||
|
||||
void skyRender(SkyDefinition* definition, Renderer* renderer, RenderProgressCallback callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
47
lib_paysages/system.c
Normal file
47
lib_paysages/system.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "system.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static int _core_count = 1;
|
||||
|
||||
static int _getCoreCount()
|
||||
{
|
||||
int core_count = 1;
|
||||
#ifdef WIN32
|
||||
DWORD processAffinityMask;
|
||||
DWORD systemAffinityMask;
|
||||
|
||||
if (GetProcessAffinityMask( GetCurrentProcess(),
|
||||
&processAffinityMask,
|
||||
&systemAffinityMask)){
|
||||
processAffinityMask = (processAffinityMask & 0x55555555)
|
||||
+ (processAffinityMask >> 1 & 0x55555555);
|
||||
processAffinityMask = (processAffinityMask & 0x33333333)
|
||||
+ (processAffinityMask >> 2 & 0x33333333);
|
||||
processAffinityMask = (processAffinityMask & 0x0f0f0f0f)
|
||||
+ (processAffinityMask >> 4 & 0x0f0f0f0f);
|
||||
processAffinityMask = (processAffinityMask & 0x00ff00ff)
|
||||
+ (processAffinityMask >> 8 & 0x00ff00ff);
|
||||
core_count = (processAffinityMask & 0x0000ffff)
|
||||
+ (processAffinityMask >>16 & 0x0000ffff);
|
||||
}
|
||||
#endif
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
core_count = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
#endif
|
||||
return core_count;
|
||||
}
|
||||
|
||||
void systemInit()
|
||||
{
|
||||
g_thread_init(NULL);
|
||||
_core_count = _getCoreCount();
|
||||
}
|
||||
|
||||
int systemGetCoreCount()
|
||||
{
|
||||
return _core_count;
|
||||
}
|
|
@ -10,10 +10,8 @@ extern "C" {
|
|||
typedef GThread Thread;
|
||||
typedef void*(*ThreadFunction)(void* data);
|
||||
|
||||
static inline void systemInit()
|
||||
{
|
||||
g_thread_init(NULL);
|
||||
}
|
||||
void systemInit();
|
||||
int systemGetCoreCount();
|
||||
|
||||
static inline Thread* threadCreate(ThreadFunction function, void* data)
|
||||
{
|
|
@ -10,6 +10,7 @@
|
|||
#include "shared/globals.h"
|
||||
#include "shared/constants.h"
|
||||
|
||||
#include "render.h"
|
||||
#include "textures.h"
|
||||
#include "water.h"
|
||||
|
||||
|
@ -50,7 +51,7 @@ void terrainLoad(FILE* f, TerrainDefinition* definition)
|
|||
{
|
||||
modifier = modifierCreate();
|
||||
modifierLoad(modifier, f);
|
||||
terrainAddModifier(&definition, modifier);
|
||||
terrainAddModifier(definition, modifier);
|
||||
modifierDelete(modifier);
|
||||
}
|
||||
|
||||
|
@ -86,7 +87,7 @@ void terrainCopyDefinition(TerrainDefinition* source, TerrainDefinition* destina
|
|||
{
|
||||
int i;
|
||||
|
||||
noiseCopy(source.height_noise, destination->height_noise);
|
||||
noiseCopy(source->height_noise, destination->height_noise);
|
||||
destination->height_factor = source->height_factor;
|
||||
destination->scaling = source->scaling;
|
||||
|
||||
|
@ -201,7 +202,7 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo
|
|||
{
|
||||
inc_value = diff;
|
||||
}
|
||||
} while (light_factor > 0.0 && length < 50.0 && location.y <= definition._max_height);
|
||||
} while (light_factor > 0.0 && length < 50.0 && location.y <= definition->_max_height);
|
||||
|
||||
if (light_factor <= 0.0)
|
||||
{
|
||||
|
@ -220,15 +221,9 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo
|
|||
static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector3 point, double precision)
|
||||
{
|
||||
Color color;
|
||||
TextureEnvironment texenv;
|
||||
|
||||
color = COLOR_RED;
|
||||
//color = texturesGetColorCustom(point, precision, NULL, &texenv);
|
||||
/*if (environment->toggle_fog)
|
||||
{
|
||||
color = fogApplyToLocation(point, color);
|
||||
}*/
|
||||
//color = cloudsApplySegmentResult(color, camera_location, point);
|
||||
color = renderer->applyTextures(renderer, point, precision);
|
||||
color = renderer->applyAtmosphere(renderer, point, color);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
@ -271,22 +266,25 @@ int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3
|
|||
{
|
||||
inc_value = diff;
|
||||
}
|
||||
} while (length < 50.0 && start.y <= definition._max_height);
|
||||
} while (length < 50.0 && start.y <= definition->_max_height);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _postProcessFragment(RenderFragment* fragment)
|
||||
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data)
|
||||
{
|
||||
/*Vector3 point;
|
||||
Vector3 point;
|
||||
double precision;
|
||||
TerrainDefinition* definition;
|
||||
|
||||
definition = (TerrainDefinition*)data;
|
||||
|
||||
point = fragment->vertex.location;
|
||||
precision = renderGetPrecision(point);
|
||||
precision = renderer->getPrecision(renderer, point);
|
||||
|
||||
point = _getPoint(&_definition, point.x, point.z, precision);
|
||||
point = _getPoint(definition, point.x, point.z, precision);
|
||||
|
||||
fragment->vertex.color = _getColor(&_definition, &_environment, point, precision);*/
|
||||
fragment->vertex.color = _getColor(definition, renderer, point, precision);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -304,11 +302,12 @@ static Vertex _getFirstPassVertex(TerrainDefinition* definition, double x, doubl
|
|||
result.color.a = 1.0;
|
||||
result.normal.x = result.normal.y = result.normal.z = 0.0;
|
||||
result.callback = _postProcessFragment;
|
||||
result.callback_data = definition;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void _renderQuad(TerrainDefinition* definition, double x, double z, double size)
|
||||
static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, double x, double z, double size)
|
||||
{
|
||||
Vertex v1, v2, v3, v4;
|
||||
|
||||
|
@ -316,7 +315,7 @@ static void _renderQuad(TerrainDefinition* definition, double x, double z, doubl
|
|||
v2 = _getFirstPassVertex(definition, x, z + size, size);
|
||||
v3 = _getFirstPassVertex(definition, x + size, z + size, size);
|
||||
v4 = _getFirstPassVertex(definition, x + size, z, size);
|
||||
renderPushQuad(&v1, &v2, &v3, &v4);
|
||||
renderPushQuad(renderer, &v1, &v2, &v3, &v4);
|
||||
}
|
||||
|
||||
double terrainGetHeight(TerrainDefinition* definition, double x, double z)
|
||||
|
@ -326,7 +325,14 @@ double terrainGetHeight(TerrainDefinition* definition, double x, double z)
|
|||
|
||||
double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z)
|
||||
{
|
||||
if (definition->_max_height == 0.0)
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.5 + _getHeight(definition, x, z, 0.0) / (definition->_max_height * 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double x, double z, double detail)
|
||||
|
@ -362,10 +368,10 @@ void terrainRender(TerrainDefinition* definition, Renderer* renderer, RenderProg
|
|||
|
||||
for (i = 0; i < chunk_count - 1; i++)
|
||||
{
|
||||
_renderQuad(definition, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size);
|
||||
_renderQuad(definition, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size);
|
||||
_renderQuad(definition, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size);
|
||||
_renderQuad(definition, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size);
|
||||
_renderQuad(definition, renderer, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size);
|
||||
_renderQuad(definition, renderer, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size);
|
||||
_renderQuad(definition, renderer, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size);
|
||||
_renderQuad(definition, renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size);
|
||||
}
|
||||
|
||||
if (chunk_count % 64 == 0 && chunk_size / radius_int < visible_chunk_size)
|
||||
|
|
|
@ -45,7 +45,7 @@ void texturesLoad(FILE* f, TexturesDefinition* definition)
|
|||
n = toolsLoadInt(f);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
layer = definition->nbtextures + texturesAddLayer(definition);
|
||||
layer = definition->textures + texturesAddLayer(definition);
|
||||
|
||||
zoneLoad(layer->zone, f);
|
||||
noiseLoad(layer->bump_noise, f);
|
||||
|
@ -110,15 +110,15 @@ TextureLayerDefinition texturesLayerCreateDefinition()
|
|||
|
||||
void texturesLayerDeleteDefinition(TextureLayerDefinition* definition)
|
||||
{
|
||||
zoneDelete(definition.zone);
|
||||
noiseDeleteGenerator(definition.bump_noise);
|
||||
zoneDelete(definition->zone);
|
||||
noiseDeleteGenerator(definition->bump_noise);
|
||||
}
|
||||
|
||||
void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination)
|
||||
{
|
||||
destination->color = source.color;
|
||||
noiseCopy(source.bump_noise, destination->bump_noise);
|
||||
zoneCopy(source.zone, destination->zone);
|
||||
destination->color = source->color;
|
||||
noiseCopy(source->bump_noise, destination->bump_noise);
|
||||
zoneCopy(source->zone, destination->zone);
|
||||
}
|
||||
|
||||
void texturesLayerValidateDefinition(TextureLayerDefinition* definition)
|
||||
|
@ -146,7 +146,7 @@ int texturesAddLayer(TexturesDefinition* definition)
|
|||
{
|
||||
if (definition->nbtextures < TEXTURES_MAX_LAYERS)
|
||||
{
|
||||
_textures[definition->nbtextures] = texturesCreateDefinition();
|
||||
definition->textures[definition->nbtextures] = texturesLayerCreateDefinition();
|
||||
|
||||
return definition->nbtextures++;
|
||||
}
|
||||
|
@ -169,23 +169,23 @@ void texturesDeleteLayer(TexturesDefinition* definition, int layer)
|
|||
}
|
||||
}
|
||||
|
||||
static inline Vector3 _getNormal(TextureLayerDefinition* definition, Vector3 point, double scale)
|
||||
static inline Vector3 _getNormal(TextureLayerDefinition* definition, Renderer* renderer, Vector3 point, double scale)
|
||||
{
|
||||
Vector3 dpoint, ref, normal;
|
||||
|
||||
ref.x = 0.0;
|
||||
ref.y = 0.0;
|
||||
point.y = terrainGetHeight(point.x, point.z) + noiseGet2DTotal(definition->bump_noise, point.x, point.z);
|
||||
point.y = renderer->getTerrainHeight(renderer, point.x, point.z) + noiseGet2DTotal(definition->bump_noise, point.x, point.z);
|
||||
|
||||
dpoint.x = point.x - scale;
|
||||
dpoint.z = point.z;
|
||||
dpoint.y = terrainGetHeight(dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
dpoint.y = renderer->getTerrainHeight(renderer, dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
ref.z = -1.0;
|
||||
normal = v3Normalize(v3Cross(ref, v3Sub(dpoint, point)));
|
||||
|
||||
dpoint.x = point.x + scale;
|
||||
dpoint.z = point.z;
|
||||
dpoint.y = terrainGetHeight(dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
dpoint.y = renderer->getTerrainHeight(renderer, dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
ref.z = 1.0;
|
||||
normal = v3Add(normal, v3Normalize(v3Cross(ref, v3Sub(dpoint, point))));
|
||||
|
||||
|
@ -193,13 +193,13 @@ static inline Vector3 _getNormal(TextureLayerDefinition* definition, Vector3 poi
|
|||
|
||||
dpoint.x = point.x;
|
||||
dpoint.z = point.z - scale;
|
||||
dpoint.y = terrainGetHeight(dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
dpoint.y = renderer->getTerrainHeight(renderer, dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
ref.x = 1.0;
|
||||
normal = v3Add(normal, v3Normalize(v3Cross(ref, v3Sub(dpoint, point))));
|
||||
|
||||
dpoint.x = point.x;
|
||||
dpoint.z = point.z + scale;
|
||||
dpoint.y = terrainGetHeight(dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
dpoint.y = renderer->getTerrainHeight(renderer, dpoint.x, dpoint.z) + noiseGet2DTotal(definition->bump_noise, dpoint.x, dpoint.z);
|
||||
ref.x = -1.0;
|
||||
normal = v3Add(normal, v3Normalize(v3Cross(ref, v3Sub(dpoint, point))));
|
||||
|
||||
|
@ -214,7 +214,7 @@ Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* render
|
|||
SurfaceMaterial material;
|
||||
|
||||
result = COLOR_TRANSPARENT;
|
||||
normal = _getNormal(definition, location, detail * 0.3);
|
||||
normal = _getNormal(definition, renderer, location, detail * 0.3);
|
||||
|
||||
coverage = zoneGetValue(definition->zone, location, normal);
|
||||
if (coverage > 0.0)
|
||||
|
@ -229,7 +229,7 @@ Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* render
|
|||
return result;
|
||||
}
|
||||
|
||||
Color texturesGetColorCustom(TexturesDefinition* definition, Renderer* renderer, Vector3 location, double detail)
|
||||
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, Vector3 location, double detail)
|
||||
{
|
||||
Color result, tex_color;
|
||||
int i;
|
||||
|
@ -238,7 +238,7 @@ Color texturesGetColorCustom(TexturesDefinition* definition, Renderer* renderer,
|
|||
for (i = 0; i < definition->nbtextures; i++)
|
||||
{
|
||||
/* TODO Do not compute layers fully covered */
|
||||
tex_color = texturesGetLayerColor(_textures + i, renderer, location, detail);
|
||||
tex_color = texturesGetLayerColor(definition->textures + i, renderer, location, detail);
|
||||
if (tex_color.a > 0.0001)
|
||||
{
|
||||
colorMask(&result, &tex_color);
|
||||
|
|
|
@ -45,7 +45,7 @@ int texturesAddLayer(TexturesDefinition* definition);
|
|||
void texturesDeleteLayer(TexturesDefinition* definition, int layer);
|
||||
|
||||
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
|
||||
Color texturesGetColorCustom(TexturesDefinition* definition, Renderer* renderer, Vector3 location, double detail);
|
||||
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, Vector3 location, double detail);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "shared/functions.h"
|
||||
#include "shared/constants.h"
|
||||
#include "shared/globals.h"
|
||||
|
||||
#include "render.h"
|
||||
#include "terrain.h"
|
||||
#include "lighting.h"
|
||||
|
||||
|
@ -16,7 +16,7 @@ void waterInit()
|
|||
|
||||
void waterSave(FILE* f, WaterDefinition* definition)
|
||||
{
|
||||
toolsSaveDouble(f, definition.height);
|
||||
toolsSaveDouble(f, definition->height);
|
||||
colorSave(definition->main_color, f);
|
||||
colorSave(definition->depth_color, f);
|
||||
toolsSaveDouble(f, definition->transparency_depth);
|
||||
|
@ -69,7 +69,7 @@ void waterCopyDefinition(WaterDefinition* source, WaterDefinition* destination)
|
|||
NoiseGenerator* noise;
|
||||
|
||||
noise = destination->waves_noise;
|
||||
*destination = source;
|
||||
*destination = *source;
|
||||
destination->waves_noise = noise;
|
||||
noiseCopy(source->waves_noise, destination->waves_noise);
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
|
|||
|
||||
normal = _getNormal(definition, location, detail);
|
||||
look = v3Normalize(look);
|
||||
result.reflected = renderer->rayWalking(renderer, location, _reflectRay(look, normal), 0).hit_color;
|
||||
refracted = renderer->rayWalking(renderer, location, _refractRay(look, normal), 0);
|
||||
result.reflected = renderer->rayWalking(renderer, location, _reflectRay(look, normal), 1, 0, 1, 1).hit_color;
|
||||
refracted = renderer->rayWalking(renderer, location, _refractRay(look, normal), 1, 0, 1, 1);
|
||||
depth = v3Norm(v3Sub(location, refracted.hit_location));
|
||||
if (depth > definition->transparency_depth)
|
||||
{
|
||||
|
@ -202,10 +202,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
|
|||
material.reflection = 0.8;
|
||||
material.shininess = 0.6;
|
||||
color = renderer->applyLightingToSurface(renderer, location, normal, material);
|
||||
/*if (environment->toggle_fog)
|
||||
{
|
||||
color = fogApplyToLocation(location, color);
|
||||
}*/
|
||||
color = renderer->applyAtmosphere(renderer, location, color);
|
||||
|
||||
result.base = definition->main_color;
|
||||
result.final = color;
|
||||
|
@ -218,19 +215,19 @@ Color waterGetColor(WaterDefinition* definition, Renderer* renderer, Vector3 loc
|
|||
return waterGetColorDetail(definition, renderer, location, look).final;
|
||||
}
|
||||
|
||||
static int _postProcessFragment(RenderFragment* fragment)
|
||||
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data)
|
||||
{
|
||||
/* fragment->vertex.color = waterGetColor(fragment->vertex.location, v3Sub(fragment->vertex.location, camera_location)); */
|
||||
fragment->vertex.color = waterGetColor((WaterDefinition*)data, renderer, fragment->vertex.location, v3Sub(fragment->vertex.location, renderer->camera_location));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Vertex _getFirstPassVertex(double x, double z, double precision)
|
||||
static Vertex _getFirstPassVertex(WaterDefinition* definition, double x, double z, double precision)
|
||||
{
|
||||
Vertex result;
|
||||
double value;
|
||||
|
||||
result.location.x = x;
|
||||
result.location.y = _getHeight(&_definition, x, z, 0.0);
|
||||
result.location.y = _getHeight(definition, x, z, 0.0);
|
||||
result.location.z = z;
|
||||
value = sin(x) * sin(x) * cos(z) * cos(z);
|
||||
result.color.r = 0.0;
|
||||
|
@ -239,19 +236,20 @@ static Vertex _getFirstPassVertex(double x, double z, double precision)
|
|||
result.color.a = 1.0;
|
||||
result.normal.x = result.normal.y = result.normal.z = 0.0;
|
||||
result.callback = _postProcessFragment;
|
||||
result.callback_data = definition;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void _renderQuad(double x, double z, double size)
|
||||
static void _renderQuad(WaterDefinition* definition, Renderer* renderer, double x, double z, double size)
|
||||
{
|
||||
Vertex v1, v2, v3, v4;
|
||||
|
||||
v1 = _getFirstPassVertex(x, z, size);
|
||||
v2 = _getFirstPassVertex(x, z + size, size);
|
||||
v3 = _getFirstPassVertex(x + size, z + size, size);
|
||||
v4 = _getFirstPassVertex(x + size, z, size);
|
||||
renderPushQuad(&v1, &v2, &v3, &v4);
|
||||
v1 = _getFirstPassVertex(definition, x, z, size);
|
||||
v2 = _getFirstPassVertex(definition, x, z + size, size);
|
||||
v3 = _getFirstPassVertex(definition, x + size, z + size, size);
|
||||
v4 = _getFirstPassVertex(definition, x + size, z, size);
|
||||
renderPushQuad(renderer, &v1, &v2, &v3, &v4);
|
||||
}
|
||||
|
||||
void waterRender(WaterDefinition* definition, Renderer* renderer, RenderProgressCallback callback)
|
||||
|
@ -278,10 +276,10 @@ void waterRender(WaterDefinition* definition, Renderer* renderer, RenderProgress
|
|||
|
||||
for (i = 0; i < chunk_count - 1; i++)
|
||||
{
|
||||
_renderQuad(cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size);
|
||||
_renderQuad(cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size);
|
||||
_renderQuad(cx + radius_int - chunk_size * i, cz + radius_int, chunk_size);
|
||||
_renderQuad(cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size);
|
||||
_renderQuad(definition, renderer, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size);
|
||||
_renderQuad(definition, renderer, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size);
|
||||
_renderQuad(definition, renderer, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size);
|
||||
_renderQuad(definition, renderer, 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)
|
||||
|
|
Loading…
Reference in a new issue