paysages : Added custom camera location on renderer for top-down previews.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@514 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-01-31 15:10:11 +00:00 committed by ThunderK
parent cc46102f9f
commit 324a01dca1
20 changed files with 90 additions and 50 deletions

View file

@ -16,7 +16,7 @@ ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrient
void ExplorerChunkSky::onRenderEvent(QGLWidget*)
{
double size = _box_size;
Vector3 camera = renderer()->camera_location;
Vector3 camera = renderer()->getCameraLocation(renderer(), VECTOR_ZERO);
glBegin(GL_QUADS);
switch(_orientation)

View file

@ -16,9 +16,7 @@ public:
{
_renderer = rendererCreate();
_renderer->applyTextures = _applyTextures;
_renderer->camera_location.x = 0.0;
_renderer->camera_location.y = 50.0;
_renderer->camera_location.z = 0.0;
_renderer->getCameraLocation = _getCameraLocation;
_textures = texturesCreateDefinition();
_water = waterCreateDefinition();
@ -82,6 +80,11 @@ private:
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
}
static Vector3 _getCameraLocation(Renderer* renderer, Vector3 location)
{
return v3Add(location, v3Scale(VECTOR_UP, 50.0));
}
static Color _applyAerialPerspective(Renderer*, Vector3, Color base)
{
return base;

View file

@ -18,7 +18,7 @@ public:
addOsd(QString("geolocation"));
configScaling(0.5, 200.0, 3.0, 50.0);
configScaling(20.0, 1000.0, 20.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:

View file

@ -27,7 +27,7 @@ public:
addOsd(QString("geolocation"));
configScaling(0.5, 200.0, 1.0, 50.0);
configScaling(20.0, 500.0, 20.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
~PreviewTexturesCoverage()
@ -70,9 +70,9 @@ public:
_renderer = rendererCreate();
_renderer->render_quality = 3;
_renderer->camera_location.x = 0.0;
_renderer->camera_location.y = 20.0;
_renderer->camera_location.z = 0.0;
_renderer->render_camera.location.x = 0.0;
_renderer->render_camera.location.y = 20.0;
_renderer->render_camera.location.z = 0.0;
_zone = zoneCreate();

View file

@ -27,7 +27,7 @@ public:
addOsd(QString("geolocation"));
addToggle("highlight", tr("Coverage highlight"), true);
configScaling(0.5, 200.0, 3.0, 50.0);
configScaling(20.0, 1000.0, 20.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:
@ -117,6 +117,7 @@ protected:
{
Vector3 eye, look, location;
// TODO Camera location
eye.x = 0.0;
eye.y = scaling;
eye.z = -10.0 * scaling;

View file

@ -22,9 +22,9 @@ 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->render_camera.location.x = 0.0;
_renderer->render_camera.location.x = 0.0;
_renderer->render_camera.location.z = 10.0;
}
SmallMaterialPreview::~SmallMaterialPreview()
@ -56,7 +56,7 @@ Color SmallMaterialPreview::getColor(double x, double y)
}
point = v3Normalize(point);
color = lightingApplyOneLight(&_light, _renderer->camera_location, point, point, _material);
color = lightingApplyOneLight(&_light, _renderer->getCameraLocation(_renderer, point), point, point, _material);
if (dist > 0.95)
{
color.a = (1.0 - dist) / 0.05;

View file

@ -397,7 +397,6 @@ void WidgetExplorer::paintGL()
double frame_time;
cameraValidateDefinition(&_current_camera, 1);
_renderer->camera_location = _current_camera.location;
start_time = QTime::currentTime();

View file

@ -6,7 +6,7 @@
Color basicApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base)
{
Vector3 direction = v3Sub(location, renderer->camera_location);
Vector3 direction = v3Sub(location, renderer->getCameraLocation(renderer, location));
double distance = v3Norm(direction);
AtmosphereDefinition* definition = renderer->atmosphere->definition;
double near = 10.0 - definition->humidity * 10.0;

View file

@ -1166,7 +1166,7 @@ Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3
Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base)
{
Vector3 eye = renderer->camera_location;
Vector3 eye = renderer->getCameraLocation(renderer, location);
Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), SUN_DISTANCE);
double yoffset = GROUND_OFFSET - renderer->getWaterHeightInfo(renderer).base_height;

View file

@ -120,10 +120,11 @@ static Color _fakeGetSkyColor(Renderer* renderer, Vector3 direction)
static Color _getSkyColor(Renderer* renderer, Vector3 direction)
{
AtmosphereDefinition* definition;
Vector3 sun_direction, sun_position;
Vector3 sun_direction, sun_position, camera_location;
Color sky_color, sun_color;
definition = renderer->atmosphere->definition;
camera_location = renderer->getCameraLocation(renderer, VECTOR_ZERO);
sun_direction = renderer->atmosphere->getSunDirection(renderer);
direction = v3Normalize(direction);
@ -133,10 +134,10 @@ static Color _getSkyColor(Renderer* renderer, Vector3 direction)
switch (definition->model)
{
case ATMOSPHERE_MODEL_BRUNETON:
sky_color = brunetonGetSkyColor(definition, renderer->camera_location, direction, sun_position);
sky_color = brunetonGetSkyColor(definition, camera_location, direction, sun_position);
break;
case ATMOSPHERE_MODEL_PREETHAM:
sky_color = preethamGetSkyColor(definition, renderer->camera_location, direction, sun_position);
sky_color = preethamGetSkyColor(definition, camera_location, direction, sun_position);
break;
default:
sky_color = COLOR_BLUE;
@ -145,7 +146,7 @@ static Color _getSkyColor(Renderer* renderer, Vector3 direction)
/* Get sun shape */
double sun_radius = definition->sun_radius * SUN_RADIUS_SCALED;
Vector3 hit1, hit2;
int hits = euclidRayIntersectSphere(renderer->camera_location, direction, sun_position, sun_radius, &hit1, &hit2);
int hits = euclidRayIntersectSphere(camera_location, direction, sun_position, sun_radius, &hit1, &hit2);
if (hits > 1)
{
double dist = v3Norm(v3Sub(hit2, hit1)) / sun_radius; /* distance between intersection points (relative to radius) */

View file

@ -148,9 +148,9 @@ Renderer* atmosphereCreatePreviewRenderer()
{
Renderer* result = rendererCreate();
result->camera_location.x = 0.0;
result->camera_location.y = 7.0;
result->camera_location.z = 0.0;
result->render_camera.location.x = 0.0;
result->render_camera.location.y = 7.0;
result->render_camera.location.z = 0.0;
return result;
}

View file

@ -8,16 +8,17 @@
static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
{
Vector3 direction;
Vector3 camera_location, direction;
Color result;
UNUSED(data);
direction = v3Sub(location, renderer->camera_location);
camera_location = renderer->getCameraLocation(renderer, location);
direction = v3Sub(location, camera_location);
/* TODO Don't compute result->color if it's fully covered by clouds */
result = renderer->atmosphere->getSkyColor(renderer, v3Normalize(direction));
result = renderer->clouds->getColor(renderer, result, renderer->camera_location, v3Add(renderer->camera_location, v3Scale(direction, 10.0)));
result = renderer->clouds->getColor(renderer, result, camera_location, v3Add(camera_location, v3Scale(direction, 10.0)));
return result;
}
@ -29,13 +30,15 @@ void atmosphereRenderSkydome(Renderer* renderer)
double step_i, step_j;
double current_i, current_j;
Vector3 vertex1, vertex2, vertex3, vertex4;
Vector3 direction;
Vector3 camera_location, direction;
res_i = renderer->render_quality * 40;
res_j = renderer->render_quality * 20;
step_i = M_PI * 2.0 / (double)res_i;
step_j = M_PI / (double)res_j;
camera_location = renderer->getCameraLocation(renderer, VECTOR_ZERO);
for (j = 0; j < res_j; j++)
{
if (!renderer->addRenderProgress(renderer, 0.0))
@ -52,22 +55,22 @@ void atmosphereRenderSkydome(Renderer* renderer)
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j);
vertex1 = v3Add(renderer->camera_location, direction);
vertex1 = v3Add(camera_location, direction);
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j);
vertex2 = v3Add(renderer->camera_location, direction);
vertex2 = v3Add(camera_location, direction);
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j + step_j);
vertex3 = v3Add(renderer->camera_location, direction);
vertex3 = v3Add(camera_location, direction);
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j + step_j);
vertex4 = v3Add(renderer->camera_location, direction);
vertex4 = v3Add(camera_location, direction);
/* TODO Triangles at poles */
renderer->pushQuad(renderer, vertex1, vertex4, vertex3, vertex2, _postProcessFragment, NULL);

View file

@ -245,7 +245,7 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
return renderer->applyLightingToSurface(renderer, location, normal, &definition->material);
lighting = lightingCreateStatus(renderer->lighting, location, renderer->camera_location);
lighting = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
renderer->atmosphere->getLightingStatus(renderer, lighting, normal, 0);
col1 = lightingApplyStatus(lighting, normal, &definition->material);
col2 = lightingApplyStatus(lighting, v3Scale(normal, -1.0), &definition->material);

View file

@ -4,9 +4,10 @@
#include "system.h"
#include "render.h"
#include "scenery.h"
#include "tools.h"
RayCastingResult _RAYCASTING_NULL = {0};
HeightInfo _WATER_HEIGHT_INFO = {0.0, 0.0, 0.0};
static RayCastingResult _RAYCASTING_NULL = {0};
static HeightInfo _WATER_HEIGHT_INFO = {0.0, 0.0, 0.0};
static void* _renderFirstPass(void* data)
{
@ -19,21 +20,40 @@ static void* _renderFirstPass(void* data)
static int _addRenderProgress(Renderer* renderer, double progress)
{
UNUSED(progress);
return !renderer->render_interrupt;
}
static Vector3 _getCameraLocation(Renderer* renderer, Vector3 target)
{
UNUSED(renderer);
UNUSED(target);
return renderer->render_camera.location;
}
static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
{
UNUSED(renderer);
UNUSED(target);
return renderer->render_camera.forward;
}
static double _getPrecision(Renderer* renderer, Vector3 location)
{
UNUSED(renderer);
UNUSED(location);
return 0.0;
}
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
{
UNUSED(renderer);
return point;
}
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
{
UNUSED(renderer);
return point;
}
@ -71,7 +91,7 @@ static Color _applyTextures(Renderer* renderer, Vector3 location, double precisi
Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material)
{
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->camera_location);
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
Color result = lightingApplyStatus(light, normal, material);
lightingDeleteStatus(light);
@ -90,12 +110,13 @@ Renderer* rendererCreate()
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);
result->addRenderProgress = _addRenderProgress;
result->getCameraLocation = _getCameraLocation;
result->getCameraDirection = _getCameraDirection;
result->getPrecision = _getPrecision;
result->projectPoint = _projectPoint;
result->unprojectPoint = _unprojectPoint;
@ -151,7 +172,6 @@ void rendererStart(Renderer* renderer, RenderParams params)
renderer->render_progress = 0.0;
cameraSetRenderSize(&renderer->render_camera, renderer->render_width, renderer->render_height);
renderer->camera_location = renderer->render_camera.location;
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
renderSetParams(renderer->render_area, params);

View file

@ -18,13 +18,14 @@ struct Renderer
int render_width;
int render_height;
CameraDefinition render_camera;
Vector3 camera_location;
/* Render related */
RenderArea* render_area;
double render_progress;
int render_interrupt;
int is_rendering;
Vector3 (*getCameraLocation)(Renderer* renderer, Vector3 target);
Vector3 (*getCameraDirection)(Renderer* renderer, Vector3 target);
double (*getPrecision)(Renderer* renderer, Vector3 location);
Vector3 (*projectPoint)(Renderer* renderer, Vector3 point);
Vector3 (*unprojectPoint)(Renderer* renderer, Vector3 point);

View file

@ -231,7 +231,6 @@ Renderer* sceneryCreateStandardRenderer()
result = rendererCreate();
cameraCopyDefinition(&_camera, &result->render_camera);
result->camera_location = _camera.location;
result->rayWalking = _rayWalking;
result->getWaterHeightInfo = _getWaterHeightInfo;

View file

@ -110,6 +110,9 @@ static double _getHeight(Renderer* renderer, double x, double z, int with_painti
static Color _fakeGetFinalColor(Renderer* renderer, Vector3 location, double precision)
{
UNUSED(renderer);
UNUSED(location);
UNUSED(precision);
return COLOR_GREEN;
}
@ -121,7 +124,7 @@ static Color _getFinalColor(Renderer* renderer, Vector3 location, double precisi
/* TODO Factorize this in scenery renderer */
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color);
color = renderer->clouds->getColor(renderer, color, renderer->camera_location, location);
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
return color;
}

View file

@ -49,16 +49,23 @@ static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3
lightingPushLight(status, &light);
}
static Vector3 _getCameraLocation(Renderer* renderer, Vector3 location)
{
UNUSED(renderer);
location.x -= 10.0;
location.y += 15.0;
location.z += 10.0;
return location;
}
Renderer* terrainCreatePreviewRenderer()
{
Renderer* result = rendererCreate();
result->render_quality = 3;
result->applyTextures = _applyTextures;
result->getCameraLocation = _getCameraLocation;
result->atmosphere->getLightingStatus = _getLightingStatus;
result->camera_location.x = 0.0;
result->camera_location.y = 50.0;
result->camera_location.z = 0.0;
if (!_inited)
{

View file

@ -47,8 +47,9 @@ static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, doubl
void terrainRenderSurface(Renderer* renderer)
{
int chunk_factor, chunk_count, i;
double cx = renderer->camera_location.x;
double cz = renderer->camera_location.z;
Vector3 cam = renderer->getCameraLocation(renderer, VECTOR_ZERO);
double cx = cam.x;
double cz = cam.z;
double min_chunk_size, visible_chunk_size;
double radius_int, radius_ext, chunk_size;
double water_height;

View file

@ -356,7 +356,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
color = renderer->applyLightingToSurface(renderer, location, normal, &material);
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color);
color = renderer->clouds->getColor(renderer, color, renderer->camera_location, location);
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
result.base = definition->material.base;
result.final = color;
@ -371,13 +371,14 @@ Color waterGetColor(WaterDefinition* definition, Renderer* renderer, Vector3 loc
static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
{
return waterGetColor((WaterDefinition*)data, renderer, location, v3Sub(location, renderer->camera_location));
return waterGetColor((WaterDefinition*)data, renderer, location, v3Sub(location, renderer->getCameraLocation(renderer, location)));
}
static Vector3 _getFirstPassVertex(WaterDefinition* definition, double x, double z, double precision)
{
Vector3 result;
UNUSED(precision);
result.x = x;
result.y = _getHeight(definition, x, z);
result.z = z;
@ -400,8 +401,9 @@ static void _renderQuad(WaterDefinition* definition, Renderer* renderer, double
void waterRender(WaterDefinition* definition, Renderer* renderer)
{
int chunk_factor, chunk_count, i;
double cx = renderer->camera_location.x;
double cz = renderer->camera_location.z;
Vector3 cam = renderer->getCameraLocation(renderer, VECTOR_ZERO);
double cx = cam.x;
double cz = cam.z;
double radius_int, radius_ext, base_chunk_size, chunk_size;
base_chunk_size = 2.0 / (double)renderer->render_quality;