From 445d59a4bec63add5ea9e016ecf91513fbac07b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 3 Mar 2013 17:05:30 +0000 Subject: [PATCH] paysages : WIP. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@531 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 2 +- gui_qt/basepreview.cpp | 5 +++ gui_qt/basepreview.h | 1 + gui_qt/formwater.cpp | 15 +++++---- lib_paysages/auto.c | 1 - lib_paysages/camera.c | 1 - lib_paysages/render.c | 3 +- lib_paysages/tools/lighting.c | 2 +- lib_paysages/water/render.c | 62 ++++++++++++++++++++++------------- 9 files changed, 58 insertions(+), 34 deletions(-) diff --git a/TODO b/TODO index b1c6ce5..aee4b50 100644 --- a/TODO +++ b/TODO @@ -23,7 +23,7 @@ Technology Preview 2 : - Fix rendering when inside a cloud layer, with other upper or lower layers. - Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)). - Top-down previews and explorer renderings should be camera independant. -- Sun radius is too small. +- Translations. Technlogy Preview 3 : - Fully move layer management from BaseForm to BaseFormLayer. diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index 67c2763..d558585 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -438,6 +438,10 @@ void BasePreview::updateData() { } +void BasePreview::cameraEvent() +{ +} + Color BasePreview::getColor(double, double) { return COLOR_BLACK; @@ -692,6 +696,7 @@ void BasePreview::updateScaling() void BasePreview::updateChunks() { + cameraEvent(); _drawing_manager->updateChunks(this); _revision++; } diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index e717b08..398d22b 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -51,6 +51,7 @@ public: protected: virtual void updateData(); + virtual void cameraEvent(); virtual Color getColor(double x, double y); void configHdrToneMapping(bool active); diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index bfc0c45..ea50605 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -69,12 +69,13 @@ public: _renderer->atmosphere->getLightingStatus = _getLightingStatus; _renderer->rayWalking = _rayWalking; _renderer->customData[0] = this; + //cameraSetTarget(&_renderer->render_camera, 0.0, 0.0, 0.0); configScaling(10.0, 1000.0, 10.0, 250.0); //configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0); addChoice("bg", tr("Background"), QStringList(tr("None")) << tr("Grid") << tr("Sinusoid"), 2); - addToggle("light", tr("Lighting"), true); + addToggle("light", tr("Light reflection"), true); } int _background; bool _lighting_enabled; @@ -84,7 +85,6 @@ protected: Vector3 eye, look; double target_x, target_z; - // TODO Camera location eye.x = 0.0; eye.y = scaling; eye.z = -10.0 * scaling; @@ -108,10 +108,14 @@ protected: return _renderer->water->getResult(_renderer, target_x, target_z).final; } + void cameraEvent() + { + cameraSetLocation(&_renderer->render_camera, 0.0, scaling, -10.0 * scaling); + } void updateData() { WaterRendererClass.bind(_renderer, _definition); - _water.height = 0.0; + _renderer->water->definition->height = 0.0; } void choiceChangeEvent(const QString& key, int position) { @@ -132,7 +136,6 @@ protected: private: Renderer* _renderer; - WaterDefinition _water; static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int) { @@ -172,11 +175,11 @@ private: static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3, int) { LightDefinition light; - PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[2]; + PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[0]; light.color = COLOR_WHITE; light.direction.x = 0.0; light.direction.y = -0.4794; - light.direction.z = 0.8776; + light.direction.z = -0.8776; light.altered = 0; if (preview->_lighting_enabled) { diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 9eade6e..94e6ee9 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -12,7 +12,6 @@ void autoGenRealisticLandscape(int seed) { - WaterDefinition water; TexturesDefinition textures; TextureLayerDefinition* texture; int layer; diff --git a/lib_paysages/camera.c b/lib_paysages/camera.c index 6d6406c..846e5b6 100644 --- a/lib_paysages/camera.c +++ b/lib_paysages/camera.c @@ -61,7 +61,6 @@ void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destinatio void cameraValidateDefinition(CameraDefinition* definition, int check_above) { - WaterDefinition water; Renderer* renderer; double water_height, terrain_height, diff; Vector3 move; diff --git a/lib_paysages/render.c b/lib_paysages/render.c index 657f6b6..c365438 100644 --- a/lib_paysages/render.c +++ b/lib_paysages/render.c @@ -283,11 +283,10 @@ static inline Color _getFinalPixel(RenderArea* area, int x, int y) result.g += col.g / (double)(area->params.antialias * area->params.antialias); result.b += col.b / (double)(area->params.antialias * area->params.antialias); - result = colorProfileApply(area->hdr_mapping, result); } } - return result; + return colorProfileApply(area->hdr_mapping, result); } static void _processDirtyPixels(RenderArea* area) diff --git a/lib_paysages/tools/lighting.c b/lib_paysages/tools/lighting.c index d4bd245..c543950 100644 --- a/lib_paysages/tools/lighting.c +++ b/lib_paysages/tools/lighting.c @@ -158,7 +158,7 @@ Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 locatio /* specular reflection */ if (material->reflection > 0.0 && light->reflection > 0.0) { - Vector3 view = view = v3Normalize(v3Sub(location, eye)); + Vector3 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) diff --git a/lib_paysages/water/render.c b/lib_paysages/water/render.c index 3b5bb05..fc354b4 100644 --- a/lib_paysages/water/render.c +++ b/lib_paysages/water/render.c @@ -6,7 +6,6 @@ #include "../renderer.h" static HeightInfo _FAKE_HEIGHT_INFO = {0.0, 0.0, 0.0}; -static WaterResult _FAKE_RESULT = {}; /******************** Fake ********************/ static HeightInfo _fakeGetHeightInfo(Renderer* renderer) @@ -27,6 +26,8 @@ static WaterResult _fakeGetResult(Renderer* renderer, double x, double z) { WaterResult result; + UNUSED(renderer); + result.location.x = x; result.location.y = 0.0; result.location.z = z; @@ -212,9 +213,8 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z) WaterDefinition* definition = renderer->water->definition; WaterResult result; RayCastingResult refracted; - Vector3 location, normal, look; + Vector3 location, normal, look_direction; Color color; - SurfaceMaterial material; double detail, depth; location.x = x; @@ -229,34 +229,52 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z) } normal = _getNormal(definition, location, detail); - look = v3Normalize(renderer->getCameraDirection(renderer, location)); - 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) + look_direction = v3Normalize(v3Sub(location, renderer->getCameraLocation(renderer, location))); + + /* Reflection */ + if (definition->reflection == 0.0) { - result.refracted = definition->depth_color; + result.reflected = COLOR_BLACK; } else { - depth /= definition->transparency_depth; - result.refracted.r = refracted.hit_color.r * (1.0 - depth) + definition->depth_color.r * depth; - result.refracted.g = refracted.hit_color.g * (1.0 - depth) + definition->depth_color.g * depth; - result.refracted.b = refracted.hit_color.b * (1.0 - depth) + definition->depth_color.b * depth; - result.refracted.a = 1.0; + result.reflected = renderer->rayWalking(renderer, location, _reflectRay(look_direction, normal), 1, 0, 1, 1).hit_color; } - color.r = definition->material.base.r * (1.0 - definition->transparency) + result.reflected.r * definition->reflection + result.refracted.r * definition->transparency; - color.g = definition->material.base.g * (1.0 - definition->transparency) + result.reflected.g * definition->reflection + result.refracted.g * definition->transparency; - color.b = definition->material.base.b * (1.0 - definition->transparency) + result.reflected.b * definition->reflection + result.refracted.b * definition->transparency; - color.a = 1.0; + /* Transparency/refraction */ + if (definition->transparency == 0.0) + { + result.refracted = COLOR_BLACK; + } + else + { + refracted = renderer->rayWalking(renderer, location, _refractRay(look_direction, normal), 1, 0, 1, 1); + depth = v3Norm(v3Sub(location, refracted.hit_location)); + if (depth > definition->transparency_depth) + { + result.refracted = definition->depth_color; + } + else + { + depth /= definition->transparency_depth; + result.refracted.r = refracted.hit_color.r * (1.0 - depth) + definition->depth_color.r * depth; + result.refracted.g = refracted.hit_color.g * (1.0 - depth) + definition->depth_color.g * depth; + result.refracted.b = refracted.hit_color.b * (1.0 - depth) + definition->depth_color.b * depth; + result.refracted.a = 1.0; + } + } - material = definition->material; - material.base = color; + /* Lighting from environment */ + color = renderer->applyLightingToSurface(renderer, location, normal, &definition->material); - _applyFoam(definition, location, normal, detail, &material); + color.r += result.reflected.r * definition->reflection + result.refracted.r * definition->transparency; + color.g += result.reflected.g * definition->reflection + result.refracted.g * definition->transparency; + color.b += result.reflected.b * definition->reflection + result.refracted.b * definition->transparency; - color = renderer->applyLightingToSurface(renderer, location, normal, &material); + /* Merge with foam */ +// _applyFoam(definition, location, normal, detail, &material); + + /* Bring color to the camera */ color = renderer->applyMediumTraversal(renderer, location, color); result.base = definition->material.base;