paysages : Explorer texturing (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@324 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-05-09 11:39:03 +00:00 committed by ThunderK
parent b34a2cc59d
commit 69ff124eaa
6 changed files with 97 additions and 26 deletions

View file

@ -1,10 +1,12 @@
????-??-?? Technology Preview 2 ????-??-?? Technology Preview 2
------------------------------- -------------------------------
* Previews scaling is now logarithmic (slower when zoomed). * Previews scaling is now logarithmic (slower when zoomed).
* Previews drawing now takes advantage of multiple CPUs. * Previews drawing now takes advantage of multiple CPU cores.
* New texture model (perpendicular displacement and thickness). * New texture model (perpendicular displacement and thickness).
* Added clouds hardness to light. * Added clouds hardness to light.
* Version management in saved files. * Version management in saved files.
* Added ground texture and sun location in 3D explorer.
* 3D explorer now takes advantage of multiple CPU cores.
2012-04-20 Technology Preview 1 2012-04-20 Technology Preview 1
------------------------------- -------------------------------

7
TODO
View file

@ -17,12 +17,13 @@ Technology Preview 2 :
=> Improve curve rendering => Improve curve rendering
=> Add axis labels => Add axis labels
- Improve 3d explorer - Improve 3d explorer
=> Store computed vertices in memory, using chunks => Improve priority rendering (prioritize on screen chunks)
=> Compute the ground texture by chunk => Restore LOD and intelligent poly count
=> Interrupt chunk rendering when quitting dialog
=> Don't display the water if it's below all ground => Don't display the water if it's below all ground
=> Add the sun position
=> Try to overcome the near frustum cutting => Try to overcome the near frustum cutting
=> Disable texture reflection of light (dependant on camera location) => Disable texture reflection of light (dependant on camera location)
=> Add toggles (for water...)
- Water and terrain LOD moves with the camera, fix it like in the wanderer. - Water and terrain LOD moves with the camera, fix it like in the wanderer.
- Pause previews drawing of main window when a dialog is opened. - Pause previews drawing of main window when a dialog is opened.
- Interrupt preview chunk renderings that will be discarded at commit, or that are no more visible. - Interrupt preview chunk renderings that will be discarded at commit, or that are no more visible.

View file

@ -25,13 +25,13 @@ WandererChunk::WandererChunk(Renderer* renderer, double x, double z, double size
_tessellation_current_size = 0; _tessellation_current_size = 0;
_tessellation_step = _size / (double)_tessellation_max_size; _tessellation_step = _size / (double)_tessellation_max_size;
_texture_max_size = 32; _texture_max_size = 128;
_texture_current_size = 0; _texture_current_size = 0;
_texture = new QImage(1, 1, QImage::Format_ARGB32); _texture = new QImage(1, 1, QImage::Format_ARGB32);
_texture_id = 0; _texture_id = 0;
_texture_changed = false; _texture_changed = false;
maintain(VECTOR_ZERO); maintain();
} }
WandererChunk::~WandererChunk() WandererChunk::~WandererChunk()
@ -82,10 +82,38 @@ void WandererChunk::render(QGLWidget* widget)
} }
} }
bool WandererChunk::maintain(Vector3 camera_location) void WandererChunk::updatePriority(Vector3 camera_location)
{
// Compute new priority
_lock_data.lock();
if (_tessellation_current_size == _tessellation_max_size && _texture_current_size == _texture_max_size)
{
_ideal_priority = -1000.0;
}
else
{
double distance = v3Norm(v3Sub(camera_location, getCenter()));
distance = distance < 0.1 ? 0.1 : distance;
_ideal_tessellation = (int)ceil(120.0 - distance / 3.0);
_ideal_priority = _ideal_tessellation - _texture_current_size;
if (_texture_current_size == 1)
{
_ideal_priority += 100.0;
}
else if (distance < 15.0 && _texture_current_size < _texture_max_size)
{
_ideal_priority += 75.0;
}
else if (distance < 30.0 && _texture_current_size < _texture_max_size / 2)
{
_ideal_priority += 50.0;
}
}
_lock_data.unlock();
}
bool WandererChunk::maintain()
{ {
bool result;
if (_tessellation_current_size < _tessellation_max_size || _texture_current_size < _texture_max_size) if (_tessellation_current_size < _tessellation_max_size || _texture_current_size < _texture_max_size)
{ {
// Improve heightmap resolution // Improve heightmap resolution
@ -135,22 +163,12 @@ bool WandererChunk::maintain(Vector3 camera_location)
_lock_data.unlock(); _lock_data.unlock();
} }
result = true; return true;
} }
else else
{ {
result = false; return false;
} }
// Compute new priority
_lock_data.lock();
double distance = v3Norm(v3Sub(camera_location, getCenter()));
distance = distance < 0.1 ? 0.1 : distance;
_ideal_tessellation = (int)ceil(120.0 - distance / 3.0);
_ideal_priority = _ideal_tessellation - _texture_current_size;
_lock_data.unlock();
return result;
} }
Vector3 WandererChunk::getCenter() Vector3 WandererChunk::getCenter()

View file

@ -12,7 +12,8 @@ public:
WandererChunk(Renderer* renderer, double x, double z, double size); WandererChunk(Renderer* renderer, double x, double z, double size);
~WandererChunk(); ~WandererChunk();
bool maintain(Vector3 camera_location); bool maintain();
void updatePriority(Vector3 camera_location);
void render(QGLWidget* widget); void render(QGLWidget* widget);
Vector3 getCenter(); Vector3 getCenter();

View file

@ -45,6 +45,26 @@ private:
static QVector<ChunkMaintenanceThread*> _threads; static QVector<ChunkMaintenanceThread*> _threads;
static double _getTerrainHeight(Renderer* renderer, double x, double z)
{
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
}
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
}
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
return lightingApplyToSurface((LightingDefinition*)renderer->customData[2], renderer, location, normal, material);
}
static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light)
{
return terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light_color, at_location, light_location, direction_to_light);
}
WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera): WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
QGLWidget(parent) QGLWidget(parent)
{ {
@ -58,8 +78,24 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera):
sceneryGetWater(&_water); sceneryGetWater(&_water);
_sky = skyCreateDefinition(); _sky = skyCreateDefinition();
sceneryGetSky(&_sky); sceneryGetSky(&_sky);
_terrain = terrainCreateDefinition();
sceneryGetTerrain(&_terrain);
_textures = texturesCreateDefinition();
sceneryGetTextures(&_textures);
_lighting = lightingCreateDefinition();
sceneryGetLighting(&_lighting);
_renderer = rendererCreate();
_renderer.render_quality = 3;
_renderer.customData[0] = &_terrain;
_renderer.customData[1] = &_textures;
_renderer.customData[2] = &_lighting;
_renderer.customData[3] = &_water;
_renderer.applyTextures = _applyTextures;
_renderer.getTerrainHeight = _getTerrainHeight;
_renderer.applyLightingToSurface = _applyLightingToSurface;
_renderer.maskLight = _maskLight;
_renderer = sceneryCreateStandardRenderer();
_updated = false; _updated = false;
int chunks = 16; int chunks = 16;
@ -102,7 +138,7 @@ void WidgetWanderer::startThreads()
_alive = true; _alive = true;
nbcore = QThread::idealThreadCount() - 1; nbcore = QThread::idealThreadCount();
if (nbcore < 1) if (nbcore < 1)
{ {
nbcore = 1; nbcore = 1;
@ -152,7 +188,7 @@ void WidgetWanderer::performChunksMaintenance()
return; return;
} }
if (chunk->maintain(_current_camera.location)) if (chunk->maintain())
{ {
if (!_alive) if (!_alive)
{ {
@ -164,7 +200,6 @@ void WidgetWanderer::performChunksMaintenance()
_lock_chunks.lock(); _lock_chunks.lock();
_updateQueue.append(chunk); _updateQueue.append(chunk);
qSort(_updateQueue.begin(), _updateQueue.end(), _cmpChunks);
_lock_chunks.unlock(); _lock_chunks.unlock();
} }
@ -316,6 +351,14 @@ void WidgetWanderer::timerEvent(QTimerEvent *event)
_updated = false; _updated = false;
updateGL(); updateGL();
} }
for (int i = 0; i < _chunks.count(); i++)
{
_chunks[i]->updatePriority(_current_camera.location);
}
_lock_chunks.lock();
qSort(_updateQueue.begin(), _updateQueue.end(), _cmpChunks);
_lock_chunks.unlock();
} }
void WidgetWanderer::initializeGL() void WidgetWanderer::initializeGL()

View file

@ -7,6 +7,9 @@
#include "../lib_paysages/water.h" #include "../lib_paysages/water.h"
#include "../lib_paysages/renderer.h" #include "../lib_paysages/renderer.h"
#include "../lib_paysages/sky.h" #include "../lib_paysages/sky.h"
#include "../lib_paysages/terrain.h"
#include "../lib_paysages/textures.h"
#include "../lib_paysages/lighting.h"
class WidgetWanderer : public QGLWidget class WidgetWanderer : public QGLWidget
{ {
@ -49,6 +52,9 @@ private:
WaterDefinition _water; WaterDefinition _water;
SkyDefinition _sky; SkyDefinition _sky;
TerrainDefinition _terrain;
TexturesDefinition _textures;
LightingDefinition _lighting;
double _average_frame_time; double _average_frame_time;
int _quality; int _quality;