clouds_walking: Restored cloud previews

This commit is contained in:
Michaël Lemaire 2013-06-02 21:49:48 +02:00
parent 1ede3de8d5
commit b6376deeca
7 changed files with 124 additions and 63 deletions

View file

@ -1,5 +1,6 @@
#include "formclouds.h"
#include "rendering/clouds/clo_preview.h"
#include "rendering/tools/color.h"
#include "rendering/tools/euclid.h"
#include "rendering/scenery.h"
@ -12,24 +13,22 @@ class PreviewCloudsCoverage:public BasePreview
public:
PreviewCloudsCoverage(QWidget* parent, CloudsLayerDefinition* layer):BasePreview(parent)
{
_renderer = cloudsCreatePreviewCoverageRenderer();
_renderer = cloudsPreviewCoverageCreateRenderer();
_3d = true;
_original_layer = layer;
_preview_definition = (CloudsDefinition*)CloudsDefinitionClass.create();
addToggle("3d", tr("Perspective"), true);
configScaling(100.0, 1000.0, 20.0, 200.0);
}
~PreviewCloudsCoverage()
{
CloudsDefinitionClass.destroy(_preview_definition);
rendererDelete(_renderer);
}
protected:
Color getColor(double x, double y)
{
return cloudsGetPreviewCoverage(_renderer, x, y, scaling, _3d);
return cloudsPreviewCoverageGetPixel(_renderer, x, y, scaling, _3d);
}
virtual void toggleChangeEvent(QString key, bool value)
{
@ -41,15 +40,12 @@ protected:
}
void updateData()
{
layersDeleteLayer(_preview_definition->layers, 0);
layersAddLayer(_preview_definition->layers, _original_layer);
CloudsRendererClass.bind(_renderer, _preview_definition);
cloudsPreviewCoverageBindLayer(_renderer, _original_layer);
}
private:
Renderer* _renderer;
CloudsLayerDefinition* _original_layer;
CloudsDefinition* _preview_definition;
bool _3d;
};
@ -59,27 +55,28 @@ public:
PreviewCloudsColor(QWidget* parent, CloudsLayerDefinition* layer):BasePreview(parent)
{
_original_layer = layer;
_preview_definition = (CloudsDefinition*)CloudsDefinitionClass.create();
_renderer = cloudsCreatePreviewColorRenderer();
_renderer = cloudsPreviewMaterialCreateRenderer();
configScaling(0.5, 2.0, 0.1, 2.0);
}
~PreviewCloudsColor()
{
rendererDelete(_renderer);
}
protected:
Color getColor(double x, double y)
{
return cloudsGetPreviewColor(_renderer, x, y);
return cloudsPreviewMaterialGetPixel(_renderer, x, y);
}
void updateData()
{
layersDeleteLayer(_preview_definition->layers, 0);
layersAddLayer(_preview_definition->layers, _original_layer);
CloudsRendererClass.bind(_renderer, _preview_definition);
cloudsPreviewMaterialBindLayer(_renderer, _original_layer);
}
private:
Renderer* _renderer;
CloudsLayerDefinition* _original_layer;
CloudsDefinition* _preview_definition;
};
/**************** Form ****************/

View file

@ -1,2 +0,0 @@
#include "clo_lighting.h"

View file

@ -1,30 +0,0 @@
#ifndef _PAYSAGES_CLOUDS_LIGHTING_H_
#define _PAYSAGES_CLOUDS_LIGHTING_H_
#include "public.h"
#include "../tools/euclid.h"
/**
* Cloud lighting helpers.
*/
#ifdef __cplusplus
extern "C"
{
#endif
/*
* Bind fake lighting functions to a renderer.
*/
void cloudsBindFakeLightingToRenderer(CloudsRenderer* renderer);
/*
* Bind real lighting functions to a renderer.
*/
void cloudsBindRealLightingToRenderer(CloudsRenderer* renderer);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -18,7 +18,7 @@ Color _fakeApplyLightingToSurface(Renderer* renderer, Vector3 location, Vector3
return COLOR_WHITE;
}
Renderer* cloudsCreatePreviewCoverageRenderer()
Renderer* cloudsPreviewCoverageCreateRenderer()
{
Renderer* result = rendererCreate();
result->render_quality = 5;
@ -26,7 +26,15 @@ Renderer* cloudsCreatePreviewCoverageRenderer()
return result;
}
Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling, int perspective)
void cloudsPreviewCoverageBindLayer(Renderer* renderer, CloudsLayerDefinition* layer)
{
CloudsDefinition* definition = (CloudsDefinition*)CloudsDefinitionClass.create();
layersAddLayer(definition->layers, layer);
CloudsRendererClass.bind(renderer, definition);
CloudsDefinitionClass.destroy(definition);
}
Color cloudsPreviewCoverageGetPixel(Renderer* renderer, double x, double y, double scaling, int perspective)
{
if (perspective)
{
@ -55,25 +63,91 @@ Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double sc
}
}
Renderer* cloudsCreatePreviewColorRenderer()
static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque)
{
LightDefinition light;
UNUSED(renderer);
UNUSED(normal);
UNUSED(opaque);
light.color.r = 1.0;
light.color.g = 1.0;
light.color.b = 1.0;
light.direction.x = -1.0;
light.direction.y = -0.5;
light.direction.z = 1.0;
light.direction = v3Normalize(light.direction);
light.altered = 1;
light.reflection = 0.0;
lightingPushLight(status, &light);
light.color.r = 0.2;
light.color.g = 0.2;
light.color.b = 0.2;
light.direction.x = 1.0;
light.direction.y = -0.5;
light.direction.z = -1.0;
light.direction = v3Normalize(light.direction);
light.altered = 0;
light.reflection = 0.0;
lightingPushLight(status, &light);
}
Renderer* cloudsPreviewMaterialCreateRenderer()
{
Renderer* result = rendererCreate();
result->render_quality = 8;
result->atmosphere->getLightingStatus = _getLightingStatus;
return result;
}
Color cloudsGetPreviewColor(Renderer* renderer, double x, double y)
static double _getDensity(Renderer* renderer, CloudsLayerDefinition* layer, Vector3 location)
{
UNUSED(renderer);
UNUSED(layer);
double distance = v3Norm(location);
if (distance > 1.0)
{
return 0.0;
}
else if (distance < 0.8)
{
return 1.0;
}
else
{
return (1.0 - distance) / 0.2;
}
}
void cloudsPreviewMaterialBindLayer(Renderer* renderer, CloudsLayerDefinition* layer)
{
CloudsDefinition* definition = (CloudsDefinition*)CloudsDefinitionClass.create();
layersAddLayer(definition->layers, layer);
CloudsRendererClass.bind(renderer, definition);
CloudsDefinitionClass.destroy(definition);
layer = layersGetLayer(renderer->clouds->definition->layers, 0);
layer->lower_altitude = -1.0;
layer->thickness = 2.0;
renderer->clouds->getLayerDensity = _getDensity;
}
Color cloudsPreviewMaterialGetPixel(Renderer* renderer, double x, double y)
{
Vector3 start, end;
double thickness = 0.5;
double thickness = 2.0;
start.x = x * thickness * 0.5;
start.y = -y * thickness * 0.5;
start.z = thickness * 0.5;
start.z = y * thickness * 0.5;
start.y = thickness * 0.5;
end.x = start.x;
end.y = start.y;
end.z = -start.z;
end.z = start.z;
end.y = -start.y;
return renderer->clouds->getColor(renderer, COLOR_BLUE, start, end);
}

View file

@ -0,0 +1,28 @@
#ifndef _PAYSAGES_CLOUDS_PREVIEW_H_
#define _PAYSAGES_CLOUDS_PREVIEW_H_
#include "public.h"
#include "../tools/euclid.h"
/**
* Cloud preview helpers.
*/
#ifdef __cplusplus
extern "C"
{
#endif
Renderer* cloudsPreviewCoverageCreateRenderer();
void cloudsPreviewCoverageBindLayer(Renderer* renderer, CloudsLayerDefinition* layer);
Color cloudsPreviewCoverageGetPixel(Renderer* renderer, double x, double y, double scaling, int perspective);
Renderer* cloudsPreviewMaterialCreateRenderer();
void cloudsPreviewMaterialBindLayer(Renderer* renderer, CloudsLayerDefinition* layer);
Color cloudsPreviewMaterialGetPixel(Renderer* renderer, double x, double y);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -185,7 +185,7 @@ static Color _getColor(Renderer* renderer, Color base, Vector3 start, Vector3 en
/* Apply aerial perspective approximation */
/* TODO This should be done at cloud entry */
base = renderer->applyMediumTraversal(renderer, ostart, base);
base = renderer->atmosphere->applyAerialPerspective(renderer, ostart, base).final;
}
}

View file

@ -80,12 +80,6 @@ LayerType cloudsGetLayerType();
void cloudsAutoPreset(CloudsDefinition* definition, CloudsPreset preset);
void cloudsLayerAutoPreset(CloudsLayerDefinition* definition, CloudsLayerPreset preset);
Renderer* cloudsCreatePreviewCoverageRenderer();
Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling, int perspective);
Renderer* cloudsCreatePreviewColorRenderer();
Color cloudsGetPreviewColor(Renderer* renderer, double x, double y);
#ifdef __cplusplus
}
#endif