paysages : Lighting refactoring (WIP).
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@501 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
b46060f3c4
commit
ae91a39729
33 changed files with 297 additions and 224 deletions
|
@ -39,7 +39,7 @@ void _previewUpdate(double progress)
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Renderer renderer;
|
||||
Renderer* renderer;
|
||||
char* conf_file_path = NULL;
|
||||
RenderParams conf_render_params = {800, 600, 1, 5};
|
||||
int conf_nb_pictures = 1;
|
||||
|
@ -127,20 +127,20 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
renderer = sceneryCreateStandardRenderer();
|
||||
rendererSetPreviewCallbacks(&renderer, NULL, NULL, _previewUpdate);
|
||||
rendererSetPreviewCallbacks(renderer, NULL, NULL, _previewUpdate);
|
||||
|
||||
for (outputcount = 0; outputcount < conf_nb_pictures; outputcount++)
|
||||
{
|
||||
/*autoSetDaytimeFraction(conf_daytime_start);*/ /* TODO */
|
||||
|
||||
sprintf(outputpath, "output/pic%05d.png", outputcount);
|
||||
startRender(&renderer, outputpath, conf_render_params);
|
||||
startRender(renderer, outputpath, conf_render_params);
|
||||
|
||||
conf_daytime_start += conf_daytime_step;
|
||||
}
|
||||
|
||||
printf("Cleaning up ...\n");
|
||||
rendererDelete(&renderer);
|
||||
rendererDelete(renderer);
|
||||
paysagesQuit();
|
||||
|
||||
printf("\rDone. \n");
|
||||
|
|
|
@ -27,14 +27,14 @@ public:
|
|||
protected:
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
return atmosphereGetPreview(&_renderer, x, -y, M_PI_2);
|
||||
return atmosphereGetPreview(_renderer, x, -y, M_PI_2);
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
AtmosphereRendererClass.bind(_renderer.atmosphere, _definition);
|
||||
AtmosphereRendererClass.bind(_renderer, _definition);
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
};
|
||||
|
||||
class PreviewSkyWest:public BasePreview
|
||||
|
@ -51,14 +51,14 @@ public:
|
|||
protected:
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
return atmosphereGetPreview(&_renderer, x, -y, -M_PI_2);
|
||||
return atmosphereGetPreview(_renderer, x, -y, -M_PI_2);
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
AtmosphereRendererClass.bind(_renderer.atmosphere, _definition);
|
||||
AtmosphereRendererClass.bind(_renderer, _definition);
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
};
|
||||
|
||||
/**************** Form ****************/
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
PreviewCloudsCoverage(QWidget* parent, CloudsLayerDefinition* layer):BasePreview(parent)
|
||||
{
|
||||
_renderer = rendererCreate();
|
||||
_renderer.render_quality = 5;
|
||||
_renderer->render_quality = 5;
|
||||
//_renderer.applyLightStatus = _applyLightStatus;
|
||||
|
||||
_original_layer = layer;
|
||||
|
@ -25,6 +25,7 @@ public:
|
|||
~PreviewCloudsCoverage()
|
||||
{
|
||||
cloudsLayerDeleteDefinition(_preview_layer);
|
||||
rendererDelete(_renderer);
|
||||
}
|
||||
protected:
|
||||
Color getColor(double x, double y)
|
||||
|
@ -39,7 +40,7 @@ protected:
|
|||
look.z = 1.0;
|
||||
look = v3Normalize(look);
|
||||
|
||||
return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, eye, v3Add(eye, v3Scale(look, 1000.0)));
|
||||
return cloudsApplyLayer(_preview_layer, COLOR_BLUE, _renderer, eye, v3Add(eye, v3Scale(look, 1000.0)));
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
|
@ -51,7 +52,7 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
CloudsLayerDefinition* _original_layer;
|
||||
CloudsLayerDefinition* _preview_layer;
|
||||
};
|
||||
|
@ -79,10 +80,10 @@ public:
|
|||
lightingValidateDefinition(&_lighting);*/
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer.render_quality = 8;
|
||||
_renderer->render_quality = 8;
|
||||
/*_renderer.alterLight = _alterLight;
|
||||
_renderer.getLightStatus = _getLightStatus;*/
|
||||
_renderer.customData[0] = _preview_layer;
|
||||
_renderer->customData[0] = _preview_layer;
|
||||
//_renderer.customData[1] = &_lighting;
|
||||
|
||||
configScaling(0.5, 2.0, 0.1, 2.0);
|
||||
|
@ -100,7 +101,7 @@ protected:
|
|||
end.y = -y * _preview_layer->thickness * 0.5;
|
||||
end.z = -_preview_layer->thickness * 0.5;
|
||||
|
||||
return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, start, end);
|
||||
return cloudsApplyLayer(_preview_layer, COLOR_BLUE, _renderer, start, end);
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
|
@ -112,7 +113,7 @@ protected:
|
|||
_preview_layer->_custom_coverage = _coverageFunc;
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
CloudsLayerDefinition* _original_layer;
|
||||
CloudsLayerDefinition* _preview_layer;
|
||||
//LightingDefinition _lighting;
|
||||
|
|
|
@ -15,10 +15,10 @@ public:
|
|||
PreviewRenderLandscape(QWidget* parent):BasePreview(parent)
|
||||
{
|
||||
_renderer = rendererCreate();
|
||||
_renderer.applyTextures = _applyTextures;
|
||||
_renderer.camera_location.x = 0.0;
|
||||
_renderer.camera_location.y = 50.0;
|
||||
_renderer.camera_location.z = 0.0;
|
||||
_renderer->applyTextures = _applyTextures;
|
||||
_renderer->camera_location.x = 0.0;
|
||||
_renderer->camera_location.y = 50.0;
|
||||
_renderer->camera_location.z = 0.0;
|
||||
|
||||
_textures = texturesCreateDefinition();
|
||||
_water = waterCreateDefinition();
|
||||
|
@ -26,12 +26,13 @@ public:
|
|||
_atmosphere = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
|
||||
_terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
||||
|
||||
_renderer.customData[0] = &_terrain;
|
||||
_renderer.customData[1] = &_textures;
|
||||
_renderer.customData[3] = &_water;
|
||||
_renderer->customData[0] = &_terrain;
|
||||
_renderer->customData[1] = &_textures;
|
||||
_renderer->customData[3] = &_water;
|
||||
|
||||
addOsd(QString("geolocation"));
|
||||
|
||||
configHdrToneMapping(true);
|
||||
configScaling(0.5, 200.0, 3.0, 50.0);
|
||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||
}
|
||||
|
@ -40,21 +41,21 @@ protected:
|
|||
{
|
||||
Vector3 down = {0.0, -1.0, 0.0};
|
||||
Vector3 location;
|
||||
double height = _renderer.terrain->getHeight(&_renderer, x, y, 1);
|
||||
double height = _renderer->terrain->getHeight(_renderer, x, y, 1);
|
||||
|
||||
if (height < _water.height)
|
||||
{
|
||||
location.x = x;
|
||||
location.y = _water.height;
|
||||
location.z = y;
|
||||
return waterGetColor(&_water, &_renderer, location, down);
|
||||
return waterGetColor(&_water, _renderer, location, down);
|
||||
}
|
||||
else
|
||||
{
|
||||
location.x = x;
|
||||
location.y = height;
|
||||
location.z = y;
|
||||
return _renderer.terrain->getFinalColor(&_renderer, location, scaling);
|
||||
return _renderer->terrain->getFinalColor(_renderer, location, scaling);
|
||||
}
|
||||
}
|
||||
void updateData()
|
||||
|
@ -63,14 +64,14 @@ protected:
|
|||
sceneryGetWater(&_water);
|
||||
|
||||
sceneryGetAtmosphere(_atmosphere);
|
||||
AtmosphereRendererClass.bind(_renderer.atmosphere, _atmosphere);
|
||||
_renderer.atmosphere->applyAerialPerspective = _applyAerialPerspective;
|
||||
AtmosphereRendererClass.bind(_renderer, _atmosphere);
|
||||
_renderer->atmosphere->applyAerialPerspective = _applyAerialPerspective;
|
||||
|
||||
sceneryGetTerrain(_terrain);
|
||||
TerrainRendererClass.bind(_renderer.terrain, _terrain);
|
||||
TerrainRendererClass.bind(_renderer, _terrain);
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
TerrainDefinition* _terrain;
|
||||
WaterDefinition _water;
|
||||
TexturesDefinition _textures;
|
||||
|
@ -126,7 +127,7 @@ FormRender::~FormRender()
|
|||
{
|
||||
if (_renderer_inited)
|
||||
{
|
||||
rendererDelete(&_renderer);
|
||||
rendererDelete(_renderer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,12 +175,12 @@ void FormRender::startQuickRender()
|
|||
{
|
||||
if (_renderer_inited)
|
||||
{
|
||||
rendererDelete(&_renderer);
|
||||
rendererDelete(_renderer);
|
||||
}
|
||||
_renderer = sceneryCreateStandardRenderer();
|
||||
_renderer_inited = true;
|
||||
|
||||
DialogRender* dialog = new DialogRender(this, &_renderer);
|
||||
DialogRender* dialog = new DialogRender(this, _renderer);
|
||||
RenderParams params = {400, 300, 1, 3};
|
||||
dialog->startRender(params);
|
||||
|
||||
|
@ -190,12 +191,12 @@ void FormRender::startRender()
|
|||
{
|
||||
if (_renderer_inited)
|
||||
{
|
||||
rendererDelete(&_renderer);
|
||||
rendererDelete(_renderer);
|
||||
}
|
||||
_renderer = sceneryCreateStandardRenderer();
|
||||
_renderer_inited = true;
|
||||
|
||||
DialogRender* dialog = new DialogRender(this, &_renderer);
|
||||
DialogRender* dialog = new DialogRender(this, _renderer);
|
||||
dialog->startRender(_params);
|
||||
|
||||
delete dialog;
|
||||
|
@ -205,7 +206,7 @@ void FormRender::showRender()
|
|||
{
|
||||
if (_renderer_inited)
|
||||
{
|
||||
DialogRender* dialog = new DialogRender(this, &_renderer);
|
||||
DialogRender* dialog = new DialogRender(this, _renderer);
|
||||
dialog->loadLastRender();
|
||||
|
||||
delete dialog;
|
||||
|
@ -225,7 +226,7 @@ void FormRender::saveRender()
|
|||
{
|
||||
filepath = filepath.append(".png");
|
||||
}
|
||||
if (renderSaveToFile(_renderer.render_area, (char*)filepath.toStdString().c_str()))
|
||||
if (renderSaveToFile(_renderer->render_area, (char*)filepath.toStdString().c_str()))
|
||||
{
|
||||
QMessageBox::information(this, "Message", QString(tr("The picture %1 has been saved.")).arg(filepath));
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ private slots:
|
|||
private:
|
||||
RenderParams _params;
|
||||
CameraDefinition _camera;
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
bool _renderer_inited;
|
||||
BasePreview* _preview_landscape;
|
||||
};
|
||||
|
|
|
@ -24,14 +24,14 @@ public:
|
|||
protected:
|
||||
Color getColor(double x, double y)
|
||||
{
|
||||
return terrainGetPreviewColor(&_renderer, x, -y, scaling);
|
||||
return terrainGetPreviewColor(_renderer, x, -y, scaling);
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
TerrainRendererClass.bind(_renderer.terrain, _definition);
|
||||
TerrainRendererClass.bind(_renderer, _definition);
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
};
|
||||
|
||||
/**************** Form ****************/
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
_terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer.render_quality = 3;
|
||||
_renderer->render_quality = 3;
|
||||
|
||||
_original_layer = layer;
|
||||
_preview_layer = texturesLayerCreateDefinition();
|
||||
|
@ -40,21 +40,21 @@ protected:
|
|||
Vector3 location;
|
||||
Color result;
|
||||
location.x = x;
|
||||
location.y = _renderer.terrain->getHeight(&_renderer, x, y, 1);
|
||||
location.y = _renderer->terrain->getHeight(_renderer, x, y, 1);
|
||||
location.z = y;
|
||||
result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling);
|
||||
result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, _renderer, location, this->scaling);
|
||||
return result;
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
sceneryGetTerrain(_terrain);
|
||||
TerrainRendererClass.bind(_renderer.terrain, _terrain);
|
||||
TerrainRendererClass.bind(_renderer, _terrain);
|
||||
|
||||
texturesLayerCopyDefinition(_original_layer, _preview_layer);
|
||||
}
|
||||
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
TextureLayerDefinition* _original_layer;
|
||||
TextureLayerDefinition* _preview_layer;
|
||||
TerrainDefinition* _terrain;
|
||||
|
@ -82,12 +82,12 @@ public:
|
|||
lightingValidateDefinition(&_lighting);*/
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer.render_quality = 3;
|
||||
/*_renderer.getLightStatus = _getLightStatus;
|
||||
_renderer.customData[0] = &_lighting;*/
|
||||
_renderer.camera_location.x = 0.0;
|
||||
_renderer.camera_location.y = 20.0;
|
||||
_renderer.camera_location.z = 0.0;
|
||||
_renderer->render_quality = 3;
|
||||
/*_renderer->getLightStatus = _getLightStatus;
|
||||
_renderer->customData[0] = &_lighting;*/
|
||||
_renderer->camera_location.x = 0.0;
|
||||
_renderer->camera_location.y = 20.0;
|
||||
_renderer->camera_location.z = 0.0;
|
||||
|
||||
_zone = zoneCreate();
|
||||
|
||||
|
@ -105,7 +105,7 @@ protected:
|
|||
location.x = x;
|
||||
location.y = 0.0;
|
||||
location.z = y;
|
||||
return texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling);
|
||||
return texturesGetLayerColor(_preview_layer, _renderer, location, this->scaling);
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ protected:
|
|||
}
|
||||
private:
|
||||
Zone* _zone;
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
TextureLayerDefinition* _original_layer;
|
||||
TextureLayerDefinition* _preview_layer;
|
||||
//LightingDefinition _lighting;
|
||||
|
|
|
@ -35,10 +35,10 @@ protected:
|
|||
{
|
||||
double height;
|
||||
|
||||
height = _renderer.terrain->getHeight(&_renderer, x, -y, 1);
|
||||
height = _renderer->terrain->getHeight(_renderer, x, -y, 1);
|
||||
if (height > _definition.height)
|
||||
{
|
||||
return terrainGetPreviewColor(&_renderer, x, -y, scaling);
|
||||
return terrainGetPreviewColor(_renderer, x, -y, scaling);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ protected:
|
|||
look.y = -1.0;
|
||||
look.z = 0.0;
|
||||
|
||||
base = waterGetColor(&_water, &_renderer, location, look);
|
||||
base = waterGetColor(&_water, _renderer, location, look);
|
||||
|
||||
if (_highlight_enabled)
|
||||
{
|
||||
|
@ -71,7 +71,7 @@ protected:
|
|||
// TODO Do this only on full refresh
|
||||
TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
||||
sceneryGetTerrain(terrain);
|
||||
TerrainRendererClass.bind(_renderer.terrain, terrain);
|
||||
TerrainRendererClass.bind(_renderer, terrain);
|
||||
TerrainDefinitionClass.destroy(terrain);
|
||||
}
|
||||
void toggleChangeEvent(QString key, bool value)
|
||||
|
@ -83,7 +83,7 @@ protected:
|
|||
}
|
||||
}
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
WaterDefinition _water;
|
||||
bool _highlight_enabled;
|
||||
};
|
||||
|
@ -112,12 +112,12 @@ public:
|
|||
lightingValidateDefinition(&_lighting);*/
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer.rayWalking = _rayWalking;
|
||||
/*_renderer.getLightStatus = _getLightStatus;
|
||||
_renderer.applyLightStatus = _applyLightStatus;*/
|
||||
_renderer.customData[0] = &_water;
|
||||
//_renderer.customData[1] = &_lighting;
|
||||
_renderer.customData[2] = this;
|
||||
_renderer->rayWalking = _rayWalking;
|
||||
/*_renderer->getLightStatus = _getLightStatus;
|
||||
_renderer->applyLightStatus = _applyLightStatus;*/
|
||||
_renderer->customData[0] = &_water;
|
||||
//_renderer->customData[1] = &_lighting;
|
||||
_renderer->customData[2] = this;
|
||||
|
||||
configScaling(10.0, 1000.0, 10.0, 250.0);
|
||||
//configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0);
|
||||
|
@ -141,7 +141,7 @@ protected:
|
|||
|
||||
if (look.y > -0.0001)
|
||||
{
|
||||
return _rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color;
|
||||
return _rayWalking(_renderer, eye, look, 0, 0, 0, 0).hit_color;
|
||||
}
|
||||
|
||||
location.x = eye.x - look.x * eye.y / look.y;
|
||||
|
@ -150,10 +150,10 @@ protected:
|
|||
|
||||
if (location.z > 0.0)
|
||||
{
|
||||
return _rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color;
|
||||
return _rayWalking(_renderer, eye, look, 0, 0, 0, 0).hit_color;
|
||||
}
|
||||
|
||||
return waterGetColor(&_water, &_renderer, location, look);
|
||||
return waterGetColor(&_water, _renderer, location, look);
|
||||
}
|
||||
void updateData()
|
||||
{
|
||||
|
@ -178,7 +178,7 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
WaterDefinition _water;
|
||||
//LightingDefinition _lighting;
|
||||
bool _lighting_enabled;
|
||||
|
|
|
@ -28,14 +28,14 @@ SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* mat
|
|||
_material = material;
|
||||
|
||||
_renderer = rendererCreate();
|
||||
_renderer.camera_location.x = 0.0;
|
||||
_renderer.camera_location.x = 0.0;
|
||||
_renderer.camera_location.z = 10.0;
|
||||
_renderer->camera_location.x = 0.0;
|
||||
_renderer->camera_location.x = 0.0;
|
||||
_renderer->camera_location.z = 10.0;
|
||||
}
|
||||
|
||||
SmallMaterialPreview::~SmallMaterialPreview()
|
||||
{
|
||||
rendererDelete(&_renderer);
|
||||
rendererDelete(_renderer);
|
||||
}
|
||||
|
||||
Color SmallMaterialPreview::getColor(double x, double y)
|
||||
|
|
|
@ -20,7 +20,7 @@ protected:
|
|||
private:
|
||||
SurfaceMaterial* _material;
|
||||
LightStatus* _light;
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
};
|
||||
|
||||
class PreviewMaterial:public BasePreview
|
||||
|
|
|
@ -68,10 +68,10 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
|
|||
sceneryGetTextures(&_textures);
|
||||
|
||||
_renderer = sceneryCreateStandardRenderer();
|
||||
_renderer.render_quality = 3;
|
||||
_renderer.customData[1] = &_textures;
|
||||
_renderer.customData[3] = &_water;
|
||||
_renderer.applyTextures = _applyTextures;
|
||||
_renderer->render_quality = 3;
|
||||
_renderer->customData[1] = &_textures;
|
||||
_renderer->customData[3] = &_water;
|
||||
_renderer->applyTextures = _applyTextures;
|
||||
|
||||
_updated = false;
|
||||
|
||||
|
@ -84,7 +84,7 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
|
|||
{
|
||||
for (int j = 0; j < chunks; j++)
|
||||
{
|
||||
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(&_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize, chunks);
|
||||
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize, chunks);
|
||||
_chunks.append(chunk);
|
||||
_updateQueue.append(chunk);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
|
|||
// Add skybox
|
||||
for (int orientation = 0; orientation < 5; orientation++)
|
||||
{
|
||||
ExplorerChunkSky* chunk = new ExplorerChunkSky(&_renderer, 500.0, (SkyboxOrientation)orientation);
|
||||
ExplorerChunkSky* chunk = new ExplorerChunkSky(_renderer, 500.0, (SkyboxOrientation)orientation);
|
||||
_chunks.append(chunk);
|
||||
_updateQueue.append(chunk);
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ WidgetExplorer::~WidgetExplorer()
|
|||
delete _chunks[i];
|
||||
}
|
||||
waterDeleteDefinition(&_water);
|
||||
rendererDelete(_renderer);
|
||||
}
|
||||
|
||||
void WidgetExplorer::startThreads()
|
||||
|
@ -390,7 +391,7 @@ void WidgetExplorer::paintGL()
|
|||
double frame_time;
|
||||
|
||||
cameraValidateDefinition(&_current_camera, 1);
|
||||
_renderer.camera_location = _current_camera.location;
|
||||
_renderer->camera_location = _current_camera.location;
|
||||
|
||||
start_time = QTime::currentTime();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ private:
|
|||
CameraDefinition _current_camera;
|
||||
CameraDefinition* _base_camera;
|
||||
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
bool _updated;
|
||||
|
||||
QVector<BaseExplorerChunk*> _chunks;
|
||||
|
|
|
@ -19,7 +19,7 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain):
|
|||
|
||||
_terrain = terrain;
|
||||
_renderer = rendererCreate();
|
||||
TerrainRendererClass.bind(_renderer.terrain, _terrain);
|
||||
TerrainRendererClass.bind(_renderer, _terrain);
|
||||
_vertices = new _VertexInfo[HEIGHTMAP_RESOLUTION * HEIGHTMAP_RESOLUTION];
|
||||
|
||||
_dirty = true;
|
||||
|
@ -49,7 +49,7 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, TerrainDefinition* terrain):
|
|||
|
||||
WidgetHeightMap::~WidgetHeightMap()
|
||||
{
|
||||
rendererDelete(&_renderer);
|
||||
rendererDelete(_renderer);
|
||||
noiseDeleteGenerator(_brush_noise);
|
||||
delete[] _vertices;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ private:
|
|||
|
||||
private:
|
||||
TerrainDefinition* _terrain;
|
||||
Renderer _renderer;
|
||||
Renderer* _renderer;
|
||||
_VertexInfo* _vertices;
|
||||
|
||||
bool _dirty;
|
||||
|
|
|
@ -47,9 +47,11 @@ void basicGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 nor
|
|||
|
||||
light.direction = v3Scale(renderer->atmosphere->getSunDirection(renderer), -1.0);
|
||||
light.color = renderer->atmosphere->definition->sun_color;
|
||||
/*light.color.r *= 100.0;
|
||||
light.color.g *= 100.0;
|
||||
light.color.b *= 100.0;*/
|
||||
light.reflection = 1.0;
|
||||
light.filtered = 1;
|
||||
light.masked = 1;
|
||||
light.altered = 1;
|
||||
lightingPushLight(status, &light);
|
||||
|
||||
/* TODO Sample other directions */
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
/*********************** Constants ***********************/
|
||||
|
||||
#define WORLD_SCALING 0.05
|
||||
#define GROUND_OFFSET 10.0
|
||||
static const double Rg = 6360.0;
|
||||
static const double Rt = 6420.0;
|
||||
static const double RL = 6421.0;
|
||||
|
@ -1189,7 +1190,7 @@ void brunetonInit()
|
|||
|
||||
Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position)
|
||||
{
|
||||
Vector3 x = {0.0, Rg + (eye.y + WORLD_SCALING) * 0.01, 0.0};
|
||||
Vector3 x = {0.0, Rg + (max(eye.y, 0.0) + GROUND_OFFSET) * WORLD_SCALING, 0.0};
|
||||
Vector3 v = v3Normalize(direction);
|
||||
Vector3 s = v3Normalize(v3Sub(sun_position, x));
|
||||
|
||||
|
@ -1214,7 +1215,7 @@ Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color
|
|||
Vector3 direction = v3Scale(v3Sub(location, eye), WORLD_SCALING);
|
||||
Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), 149597870.0);
|
||||
|
||||
Vector3 x = {0.0, Rg + (eye.y + 10.0) * WORLD_SCALING, 0.0};
|
||||
Vector3 x = {0.0, Rg + (max(eye.y, 0.0) + GROUND_OFFSET) * WORLD_SCALING, 0.0};
|
||||
Vector3 v = v3Normalize(direction);
|
||||
Vector3 s = v3Normalize(v3Sub(sun_position, x));
|
||||
|
||||
|
@ -1237,3 +1238,36 @@ Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color
|
|||
|
||||
return groundColor; /* Eq (16) */
|
||||
}
|
||||
|
||||
void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque)
|
||||
{
|
||||
LightDefinition sun, irradiance;
|
||||
double muS;
|
||||
|
||||
double r0 = Rg + (max(lightingGetStatusLocation(status).y, 0.0) + GROUND_OFFSET) * WORLD_SCALING;
|
||||
Vector3 up = {0.0, 1.0, 0.0};
|
||||
Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), 149597870.0);
|
||||
Vector3 x = {0.0, r0, 0.0};
|
||||
Vector3 s = v3Normalize(v3Sub(sun_position, x));
|
||||
|
||||
muS = v3Dot(up, s);
|
||||
sun.color = _transmittanceWithShadow(r0, muS);
|
||||
sun.color.r *= 100.0;
|
||||
sun.color.g *= 100.0;
|
||||
sun.color.b *= 100.0;
|
||||
sun.direction = s;
|
||||
sun.reflection = 1.0;
|
||||
sun.altered = 1;
|
||||
|
||||
lightingPushLight(status, &sun);
|
||||
|
||||
irradiance.color = _irradiance(_irradianceTexture, r0, muS);
|
||||
irradiance.color.r *= 100.0;
|
||||
irradiance.color.g *= 100.0;
|
||||
irradiance.color.b *= 100.0;
|
||||
irradiance.direction = v3Scale(normal, -1.0);
|
||||
irradiance.reflection = 0.0;
|
||||
irradiance.altered = 0;
|
||||
|
||||
lightingPushLight(status, &irradiance);
|
||||
}
|
||||
|
|
|
@ -331,22 +331,24 @@ static void _deleteRenderer(AtmosphereRenderer* renderer)
|
|||
free(renderer);
|
||||
}
|
||||
|
||||
static void _bindRenderer(AtmosphereRenderer* renderer, AtmosphereDefinition* definition)
|
||||
static void _bindRenderer(Renderer* renderer, AtmosphereDefinition* definition)
|
||||
{
|
||||
AtmosphereRendererCache* cache = (AtmosphereRendererCache*)renderer->_internal_data;
|
||||
AtmosphereRendererCache* cache = (AtmosphereRendererCache*)renderer->atmosphere->_internal_data;
|
||||
|
||||
AtmosphereDefinitionClass.copy(definition, renderer->definition);
|
||||
AtmosphereDefinitionClass.copy(definition, renderer->atmosphere->definition);
|
||||
|
||||
renderer->getSkyColor = _getSkyColor;
|
||||
renderer->getLightingStatus = basicGetLightingStatus;
|
||||
renderer->atmosphere->getSkyColor = _getSkyColor;
|
||||
|
||||
switch (definition->model)
|
||||
{
|
||||
case ATMOSPHERE_MODEL_BRUNETON:
|
||||
renderer->applyAerialPerspective = brunetonApplyAerialPerspective;
|
||||
renderer->atmosphere->applyAerialPerspective = brunetonApplyAerialPerspective;
|
||||
/*renderer->atmosphere->getLightingStatus = brunetonGetLightingStatus;*/
|
||||
renderer->atmosphere->getLightingStatus = basicGetLightingStatus;
|
||||
break;
|
||||
default:
|
||||
renderer->applyAerialPerspective = basicApplyAerialPerspective;
|
||||
renderer->atmosphere->applyAerialPerspective = basicApplyAerialPerspective;
|
||||
renderer->atmosphere->getLightingStatus = basicGetLightingStatus;
|
||||
}
|
||||
|
||||
mutexAcquire(cache->lock);
|
||||
|
|
|
@ -149,13 +149,13 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
|
|||
}
|
||||
}
|
||||
|
||||
Renderer atmosphereCreatePreviewRenderer()
|
||||
Renderer* atmosphereCreatePreviewRenderer()
|
||||
{
|
||||
Renderer result = rendererCreate();
|
||||
Renderer* result = rendererCreate();
|
||||
|
||||
result.camera_location.x = 0.0;
|
||||
result.camera_location.y = 7.0;
|
||||
result.camera_location.z = 0.0;
|
||||
result->camera_location.x = 0.0;
|
||||
result->camera_location.y = 7.0;
|
||||
result->camera_location.z = 0.0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ void basicGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 nor
|
|||
void brunetonInit();
|
||||
Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position);
|
||||
Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base);
|
||||
void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque);
|
||||
|
||||
Color preethamGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ extern StandardRenderer AtmosphereRendererClass;
|
|||
|
||||
void atmosphereAutoPreset(AtmosphereDefinition* definition, AtmospherePreset preset);
|
||||
void atmosphereRenderSkydome(Renderer* renderer);
|
||||
Renderer atmosphereCreatePreviewRenderer();
|
||||
Renderer* atmosphereCreatePreviewRenderer();
|
||||
Color atmosphereGetPreview(Renderer* renderer, double x, double y, double heading);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -50,7 +50,7 @@ void autoGenRealisticLandscape(int seed)
|
|||
texture->material.base.r = 0.6;
|
||||
texture->material.base.g = 0.55;
|
||||
texture->material.base.b = 0.57;
|
||||
texture->material.reflection = 0.2;
|
||||
texture->material.reflection = 0.02;
|
||||
texture->material.shininess = 3.0;
|
||||
texture->thickness = 0.001;
|
||||
texture->slope_range = 0.001;
|
||||
|
@ -68,7 +68,7 @@ void autoGenRealisticLandscape(int seed)
|
|||
texture->material.base.r = 0.12;
|
||||
texture->material.base.g = 0.19;
|
||||
texture->material.base.b = 0.035;
|
||||
texture->material.reflection = 0.03;
|
||||
texture->material.reflection = 0.003;
|
||||
texture->material.shininess = 2.0;
|
||||
texture->thickness = 0.02;
|
||||
texture->slope_range = 0.03;
|
||||
|
|
|
@ -61,7 +61,7 @@ void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destinatio
|
|||
void cameraValidateDefinition(CameraDefinition* definition, int check_above)
|
||||
{
|
||||
WaterDefinition water;
|
||||
Renderer renderer;
|
||||
Renderer* renderer;
|
||||
double water_height, terrain_height, diff;
|
||||
Vector3 move;
|
||||
Matrix4 rotation;
|
||||
|
@ -74,8 +74,8 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
|
|||
waterDeleteDefinition(&water);
|
||||
|
||||
renderer = sceneryCreateStandardRenderer();
|
||||
terrain_height = renderer.terrain->getHeight(&renderer, definition->location.x, definition->location.z, 1) + 0.5;
|
||||
rendererDelete(&renderer);
|
||||
terrain_height = renderer->terrain->getHeight(renderer, definition->location.x, definition->location.z, 1) + 0.5;
|
||||
rendererDelete(renderer);
|
||||
|
||||
if (definition->location.y < water_height || definition->location.y < terrain_height)
|
||||
{
|
||||
|
|
|
@ -74,39 +74,39 @@ static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3
|
|||
return base;
|
||||
}
|
||||
|
||||
Renderer rendererCreate()
|
||||
Renderer* rendererCreate()
|
||||
{
|
||||
Renderer result;
|
||||
Renderer* result = malloc(sizeof(Renderer));
|
||||
RenderParams params = {1, 1, 1, 5};
|
||||
|
||||
result.render_quality = 5;
|
||||
result.render_width = 1;
|
||||
result.render_height = 1;
|
||||
result.render_interrupt = 0;
|
||||
result.render_progress = 0.0;
|
||||
result.is_rendering = 0;
|
||||
result.render_camera = cameraCreateDefinition();
|
||||
result.camera_location = result.render_camera.location;
|
||||
result.render_area = renderCreateArea();
|
||||
result->render_quality = 5;
|
||||
result->render_width = 1;
|
||||
result->render_height = 1;
|
||||
result->render_interrupt = 0;
|
||||
result->render_progress = 0.0;
|
||||
result->is_rendering = 0;
|
||||
result->render_camera = cameraCreateDefinition();
|
||||
result->camera_location = result->render_camera.location;
|
||||
result->render_area = renderCreateArea();
|
||||
|
||||
renderSetParams(result.render_area, params);
|
||||
renderSetParams(result->render_area, params);
|
||||
|
||||
result.addRenderProgress = _addRenderProgress;
|
||||
result.getPrecision = _getPrecision;
|
||||
result.projectPoint = _projectPoint;
|
||||
result.unprojectPoint = _unprojectPoint;
|
||||
result.pushTriangle = _pushTriangle;
|
||||
result.pushQuad = _pushQuad;
|
||||
result->addRenderProgress = _addRenderProgress;
|
||||
result->getPrecision = _getPrecision;
|
||||
result->projectPoint = _projectPoint;
|
||||
result->unprojectPoint = _unprojectPoint;
|
||||
result->pushTriangle = _pushTriangle;
|
||||
result->pushQuad = _pushQuad;
|
||||
|
||||
result.rayWalking = _rayWalking;
|
||||
result.getWaterHeightInfo = _getWaterHeightInfo;
|
||||
result.applyTextures = _applyTextures;
|
||||
result.applyClouds = _applyClouds;
|
||||
result->rayWalking = _rayWalking;
|
||||
result->getWaterHeightInfo = _getWaterHeightInfo;
|
||||
result->applyTextures = _applyTextures;
|
||||
result->applyClouds = _applyClouds;
|
||||
|
||||
result.lighting = lightingManagerCreate();
|
||||
result->lighting = lightingManagerCreate();
|
||||
|
||||
result.atmosphere = AtmosphereRendererClass.create();
|
||||
result.terrain = TerrainRendererClass.create();
|
||||
result->atmosphere = AtmosphereRendererClass.create();
|
||||
result->terrain = TerrainRendererClass.create();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -119,6 +119,8 @@ void rendererDelete(Renderer* renderer)
|
|||
TerrainRendererClass.destroy(renderer->terrain);
|
||||
|
||||
renderDeleteArea(renderer->render_area);
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
|
||||
|
|
|
@ -48,7 +48,7 @@ struct Renderer
|
|||
void* customData[10];
|
||||
};
|
||||
|
||||
Renderer rendererCreate();
|
||||
Renderer* rendererCreate();
|
||||
void rendererDelete(Renderer* renderer);
|
||||
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update);
|
||||
void rendererStart(Renderer* renderer, RenderParams params);
|
||||
|
|
|
@ -224,25 +224,25 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
|
|||
return v3Norm(v3Sub(cameraUnproject(&renderer->render_camera, renderer, projected), location)); // / (double)render_quality;
|
||||
}
|
||||
|
||||
Renderer sceneryCreateStandardRenderer()
|
||||
Renderer* sceneryCreateStandardRenderer()
|
||||
{
|
||||
Renderer result;
|
||||
Renderer* result;
|
||||
|
||||
result = rendererCreate();
|
||||
|
||||
cameraCopyDefinition(&_camera, &result.render_camera);
|
||||
result.camera_location = _camera.location;
|
||||
cameraCopyDefinition(&_camera, &result->render_camera);
|
||||
result->camera_location = _camera.location;
|
||||
|
||||
result.rayWalking = _rayWalking;
|
||||
result.getWaterHeightInfo = _getWaterHeightInfo;
|
||||
result.applyTextures = _applyTextures;
|
||||
result.applyClouds = _applyClouds;
|
||||
result.projectPoint = _projectPoint;
|
||||
result.unprojectPoint = _unprojectPoint;
|
||||
result.getPrecision = _getPrecision;
|
||||
result->rayWalking = _rayWalking;
|
||||
result->getWaterHeightInfo = _getWaterHeightInfo;
|
||||
result->applyTextures = _applyTextures;
|
||||
result->applyClouds = _applyClouds;
|
||||
result->projectPoint = _projectPoint;
|
||||
result->unprojectPoint = _unprojectPoint;
|
||||
result->getPrecision = _getPrecision;
|
||||
|
||||
AtmosphereRendererClass.bind(result.atmosphere, _atmosphere);
|
||||
TerrainRendererClass.bind(result.terrain, _terrain);
|
||||
AtmosphereRendererClass.bind(result, _atmosphere);
|
||||
TerrainRendererClass.bind(result, _terrain);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ void sceneryGetTextures(TexturesDefinition* textures);
|
|||
void scenerySetWater(WaterDefinition* water);
|
||||
void sceneryGetWater(WaterDefinition* water);
|
||||
|
||||
Renderer sceneryCreateStandardRenderer();
|
||||
Renderer* sceneryCreateStandardRenderer();
|
||||
void sceneryRenderFirstPass(Renderer* renderer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -193,36 +193,27 @@ static RayCastingResult _castRay(Renderer* renderer, Vector3 start, Vector3 dire
|
|||
return result;
|
||||
}
|
||||
|
||||
static LightDefinition _fakeAlterLight(Renderer* renderer, LightDefinition* light, Vector3 at)
|
||||
{
|
||||
UNUSED(renderer);
|
||||
UNUSED(at);
|
||||
|
||||
return *light;
|
||||
}
|
||||
|
||||
static LightDefinition _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
|
||||
static int _alterLight(LightDefinition* light, Vector3 location, Renderer* renderer)
|
||||
{
|
||||
TerrainDefinition* definition = renderer->terrain->definition;
|
||||
LightDefinition result = *light;
|
||||
Vector3 inc_vector, direction_to_light;
|
||||
double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length;
|
||||
|
||||
direction_to_light = v3Scale(light->direction, -1.0);
|
||||
if ((fabs(direction_to_light.x) < 0.0001 && fabs(direction_to_light.z) < 0.0001) || definition->height < 0.001)
|
||||
{
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
else if (direction_to_light.y < 0.05)
|
||||
{
|
||||
result.color = COLOR_BLACK;
|
||||
return result;
|
||||
light->color = COLOR_BLACK;
|
||||
return 1;
|
||||
}
|
||||
else if (direction_to_light.y < 0.0000)
|
||||
{
|
||||
result.color.r *= (0.05 + direction_to_light.y) / 0.05;
|
||||
result.color.g *= (0.05 + direction_to_light.y) / 0.05;
|
||||
result.color.b *= (0.05 + direction_to_light.y) / 0.05;
|
||||
light->color.r *= (0.05 + direction_to_light.y) / 0.05;
|
||||
light->color.g *= (0.05 + direction_to_light.y) / 0.05;
|
||||
light->color.b *= (0.05 + direction_to_light.y) / 0.05;
|
||||
}
|
||||
|
||||
inc_factor = (double)renderer->render_quality;
|
||||
|
@ -268,16 +259,16 @@ static LightDefinition _alterLight(Renderer* renderer, LightDefinition* light, V
|
|||
|
||||
if (light_factor <= 0.0)
|
||||
{
|
||||
result.color = COLOR_BLACK;
|
||||
return result;
|
||||
light->color = COLOR_BLACK;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.color.r *= light_factor;
|
||||
result.color.g *= light_factor;
|
||||
result.color.b *= light_factor;
|
||||
light->color.r *= light_factor;
|
||||
light->color.g *= light_factor;
|
||||
light->color.b *= light_factor;
|
||||
|
||||
return result;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,13 +306,15 @@ static void _deleteRenderer(TerrainRenderer* renderer)
|
|||
free(renderer);
|
||||
}
|
||||
|
||||
static void _bindRenderer(TerrainRenderer* renderer, TerrainDefinition* definition)
|
||||
static void _bindRenderer(Renderer* renderer, TerrainDefinition* definition)
|
||||
{
|
||||
TerrainDefinitionClass.copy(definition, renderer->definition);
|
||||
TerrainDefinitionClass.copy(definition, renderer->terrain->definition);
|
||||
|
||||
renderer->castRay = _castRay;
|
||||
renderer->getHeight = _getHeight;
|
||||
renderer->getFinalColor = _getFinalColor;
|
||||
renderer->terrain->castRay = _castRay;
|
||||
renderer->terrain->getHeight = _getHeight;
|
||||
renderer->terrain->getFinalColor = _getFinalColor;
|
||||
|
||||
lightingManagerRegisterFilter(renderer->lighting, (FuncLightingAlterLight)_alterLight, renderer);
|
||||
}
|
||||
|
||||
StandardRenderer TerrainRendererClass = {
|
||||
|
|
|
@ -18,15 +18,15 @@ static Color _applyTextures(Renderer* renderer, Vector3 location, double precisi
|
|||
return texturesGetColor(&_textures, renderer, location.x, location.z, precision);
|
||||
}
|
||||
|
||||
Renderer terrainCreatePreviewRenderer()
|
||||
Renderer* terrainCreatePreviewRenderer()
|
||||
{
|
||||
Renderer result = rendererCreate();
|
||||
Renderer* result = rendererCreate();
|
||||
|
||||
result.render_quality = 3;
|
||||
result.applyTextures = _applyTextures;
|
||||
result.camera_location.x = 0.0;
|
||||
result.camera_location.y = 50.0;
|
||||
result.camera_location.z = 0.0;
|
||||
result->render_quality = 3;
|
||||
result->applyTextures = _applyTextures;
|
||||
result->camera_location.x = 0.0;
|
||||
result->camera_location.y = 50.0;
|
||||
result->camera_location.z = 0.0;
|
||||
|
||||
if (!_inited)
|
||||
{
|
||||
|
|
|
@ -52,7 +52,7 @@ void terrainAutoPreset(TerrainDefinition* definition, TerrainPreset preset);
|
|||
void terrainRenderSurface(Renderer* renderer);
|
||||
double terrainGetGridHeight(TerrainDefinition* definition, int x, int z, int with_painting);
|
||||
|
||||
Renderer terrainCreatePreviewRenderer();
|
||||
Renderer* terrainCreatePreviewRenderer();
|
||||
Color terrainGetPreviewColor(Renderer* renderer, double x, double z, double detail);
|
||||
|
||||
typedef struct
|
||||
|
|
|
@ -237,6 +237,14 @@ static double _uncharted2Tonemap(double x)
|
|||
|
||||
Color colorProfileApply(ColorProfile* profile, Color pixel)
|
||||
{
|
||||
/*pixel.r *= 0.4;
|
||||
pixel.g *= 0.4;
|
||||
pixel.b *= 0.4;
|
||||
pixel.r = pixel.r < 1.413 ? pow(pixel.r * 0.38317, 1.0 / 2.2) : 1.0 - exp(-pixel.r);
|
||||
pixel.g = pixel.g < 1.413 ? pow(pixel.g * 0.38317, 1.0 / 2.2) : 1.0 - exp(-pixel.g);
|
||||
pixel.b = pixel.b < 1.413 ? pow(pixel.b * 0.38317, 1.0 / 2.2) : 1.0 - exp(-pixel.b);
|
||||
return pixel;*/
|
||||
|
||||
double exposure_bias = 2.0;
|
||||
double W = 11.2;
|
||||
double white_scale = 1.0 / _uncharted2Tonemap(W);
|
||||
|
|
|
@ -46,6 +46,17 @@ void lightingManagerDelete(LightingManager* filter)
|
|||
|
||||
void lightingManagerRegisterFilter(LightingManager* filter, FuncLightingAlterLight callback, void* data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < filter->callbacks_count; i++)
|
||||
{
|
||||
if (filter->callbacks[i].filter == callback)
|
||||
{
|
||||
filter->callbacks[i].data = data;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (filter->callbacks_count < MAX_CALLBACK_COUNT)
|
||||
{
|
||||
filter->callbacks[filter->callbacks_count].filter = callback;
|
||||
|
@ -80,13 +91,16 @@ void lightingPushLight(LightStatus* status, LightDefinition* light)
|
|||
LightingManager* manager = status->manager;
|
||||
LightDefinition final = *light;
|
||||
|
||||
for (i = 0; i < manager->callbacks_count; i++)
|
||||
if (light->altered)
|
||||
{
|
||||
LightFilterCallback callback = manager->callbacks[i];
|
||||
LightDefinition temp = final;
|
||||
if (callback.filter(&temp, status->location, callback.data))
|
||||
for (i = 0; i < manager->callbacks_count; i++)
|
||||
{
|
||||
final = temp;
|
||||
LightFilterCallback callback = manager->callbacks[i];
|
||||
LightDefinition temp = final;
|
||||
if (callback.filter(&temp, status->location, callback.data))
|
||||
{
|
||||
final = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,14 +124,14 @@ Color lightingApplyStatus(LightStatus* status, Vector3 normal, SurfaceMaterial*
|
|||
final.b += result.b;
|
||||
}
|
||||
|
||||
return result;
|
||||
return final;
|
||||
}
|
||||
|
||||
Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 location, Vector3 normal, SurfaceMaterial* material)
|
||||
{
|
||||
Color result, light_color;
|
||||
double diffuse, specular, normal_norm;
|
||||
Vector3 view, reflect, direction_inv;
|
||||
double normal_norm;
|
||||
Vector3 direction_inv;
|
||||
|
||||
light_color = light->color;
|
||||
direction_inv = v3Scale(light->direction, -1.0);
|
||||
|
@ -129,46 +143,60 @@ Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 locatio
|
|||
}
|
||||
normal = v3Normalize(normal);
|
||||
|
||||
diffuse = v3Dot(direction_inv, normal);
|
||||
result = COLOR_BLACK;
|
||||
|
||||
/* diffused light */
|
||||
double diffuse = v3Dot(direction_inv, normal) / M_PI;
|
||||
if (diffuse > 0.0)
|
||||
{
|
||||
if (material->shininess > 0.0 && light->reflection > 0.0)
|
||||
{
|
||||
view = v3Normalize(v3Sub(location, eye));
|
||||
reflect = v3Sub(direction_inv, v3Scale(normal, 2.0 * v3Dot(direction_inv, normal)));
|
||||
|
||||
specular = v3Dot(reflect, view);
|
||||
if (specular > 0.0)
|
||||
{
|
||||
specular = pow(specular, material->shininess) * material->reflection;
|
||||
}
|
||||
else
|
||||
{
|
||||
specular = 0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
specular = 0.0;
|
||||
}
|
||||
result.r += diffuse * material->base.r * light_color.r;
|
||||
result.g += diffuse * material->base.g * light_color.g;
|
||||
result.b += diffuse * material->base.b * light_color.b;
|
||||
}
|
||||
else
|
||||
|
||||
/* specular reflection */
|
||||
if (material->reflection > 0.0 && light->reflection > 0.0)
|
||||
{
|
||||
diffuse = 0.0;
|
||||
specular = 0.0;
|
||||
Vector3 view = view = v3Normalize(v3Sub(location, eye));
|
||||
Vector3 reflect = v3Sub(direction_inv, v3Scale(normal, 2.0 * v3Dot(direction_inv, normal)));
|
||||
double specular = v3Dot(reflect, view);
|
||||
if (specular > 0.0)
|
||||
{
|
||||
specular = pow(specular, material->shininess) * material->reflection;
|
||||
result.r += specular * light_color.r;
|
||||
result.g += specular * light_color.g;
|
||||
result.b += specular * light_color.b;
|
||||
}
|
||||
}
|
||||
|
||||
specular *= normal_norm * light->reflection;
|
||||
diffuse = 1.0 - normal_norm + diffuse * normal_norm;
|
||||
|
||||
result.r = material->base.r * diffuse * light_color.r + specular * light_color.r;
|
||||
result.g = material->base.g * diffuse * light_color.g + specular * light_color.g;
|
||||
result.b = material->base.b * diffuse * light_color.b + specular * light_color.b;
|
||||
result.a = material->base.a;
|
||||
/* specular reflection with fresnel effect */
|
||||
/*if (material->reflection > 0.0 && light->reflection > 0.0)
|
||||
{
|
||||
Vector3 view = v3Normalize(v3Sub(location, eye));
|
||||
Vector3 h = v3Normalize(v3Sub(direction_inv, view));
|
||||
double fresnel = 0.02 + 0.98 * pow(1.0 - v3Dot(v3Scale(view, -1.0), h), 5.0);
|
||||
double refl = v3Dot(h, normal);
|
||||
if (refl > 0.0)
|
||||
{
|
||||
double waterBrdf = fresnel * pow(refl, material->shininess);
|
||||
if (waterBrdf > 0.0)
|
||||
{
|
||||
refl = material->reflection * waterBrdf * light->reflection;
|
||||
result.r += refl * light_color.r;
|
||||
result.g += refl * light_color.g;
|
||||
result.b += refl * light_color.b;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector3 lightingGetStatusLocation(LightStatus* status)
|
||||
{
|
||||
return status->location;
|
||||
}
|
||||
|
||||
void materialSave(PackStream* stream, SurfaceMaterial* material)
|
||||
{
|
||||
colorSave(stream, &material->base);
|
||||
|
|
|
@ -21,8 +21,7 @@ typedef struct
|
|||
Vector3 direction; /* Global direction of the light */
|
||||
Color color; /* Main color of the light */
|
||||
double reflection; /* Reflected factor of the light (for specular lighting) */
|
||||
int filtered; /* Should the light be filtered (by atmosphere, water...) */
|
||||
int masked; /* Should the light be masked (cast shadows..) */
|
||||
int altered; /* Should the light be filtered or masked (by atmosphere, water, ground, clouds...) */
|
||||
} LightDefinition;
|
||||
|
||||
typedef int (*FuncLightingAlterLight)(LightDefinition* light, Vector3 at, void* data);
|
||||
|
@ -38,6 +37,7 @@ LightStatus* lightingCreateStatus(LightingManager* manager, Vector3 location, Ve
|
|||
void lightingDeleteStatus(LightStatus* status);
|
||||
void lightingPushLight(LightStatus* status, LightDefinition* light);
|
||||
Color lightingApplyStatus(LightStatus* status, Vector3 normal, SurfaceMaterial* material);
|
||||
Vector3 lightingGetStatusLocation(LightStatus* status);
|
||||
|
||||
Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 location, Vector3 normal, SurfaceMaterial* material);
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
|
|||
|
||||
definition->depth_color.a = 1.0;
|
||||
definition->material.base.a = 1.0;
|
||||
definition->material.reflection = 1.0;
|
||||
definition->material.reflection = 0.4;
|
||||
definition->material.shininess = 16.0;
|
||||
definition->foam_material.base.r = 0.8;
|
||||
definition->foam_material.base.g = 0.8;
|
||||
|
|
Loading…
Reference in a new issue