paysages : WIP.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@531 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-03-03 17:05:30 +00:00 committed by ThunderK
parent a78fecdae7
commit 445d59a4be
9 changed files with 58 additions and 34 deletions

2
TODO
View file

@ -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.

View file

@ -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++;
}

View file

@ -51,6 +51,7 @@ public:
protected:
virtual void updateData();
virtual void cameraEvent();
virtual Color getColor(double x, double y);
void configHdrToneMapping(bool active);

View file

@ -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)
{

View file

@ -12,7 +12,6 @@
void autoGenRealisticLandscape(int seed)
{
WaterDefinition water;
TexturesDefinition textures;
TextureLayerDefinition* texture;
int layer;

View file

@ -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;

View file

@ -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)

View file

@ -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)

View file

@ -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,9 +229,26 @@ 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);
look_direction = v3Normalize(v3Sub(location, renderer->getCameraLocation(renderer, location)));
/* Reflection */
if (definition->reflection == 0.0)
{
result.reflected = COLOR_BLACK;
}
else
{
result.reflected = renderer->rayWalking(renderer, location, _reflectRay(look_direction, normal), 1, 0, 1, 1).hit_color;
}
/* 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)
{
@ -245,18 +262,19 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z)
result.refracted.b = refracted.hit_color.b * (1.0 - depth) + definition->depth_color.b * depth;
result.refracted.a = 1.0;
}
}
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;
/* Lighting from environment */
color = renderer->applyLightingToSurface(renderer, location, normal, &definition->material);
material = definition->material;
material.base = color;
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;
_applyFoam(definition, location, normal, detail, &material);
/* Merge with foam */
// _applyFoam(definition, location, normal, detail, &material);
color = renderer->applyLightingToSurface(renderer, location, normal, &material);
/* Bring color to the camera */
color = renderer->applyMediumTraversal(renderer, location, color);
result.base = definition->material.base;