paysages : Added detail textures + improved makefiles + gui tab icons.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@548 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-04-11 14:38:40 +00:00 committed by ThunderK
parent e99633f7c4
commit 06841dfe89
18 changed files with 213 additions and 96 deletions

1
TODO
View file

@ -7,7 +7,6 @@ Technology Preview 2 :
=> Restore cloud lighting
=> Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)).
- Finish texture refactoring.
=> Push displaced polygons, but keep undisplaced coordinates for second pass.
=> Add detail texture.
=> Displacement on 3d explorer and previews.
=> Optimize ray marching (for tracing and shadows), using base terrain and displacement power.

View file

@ -1,27 +1,10 @@
BUILDMODE=debug
BUILDPATH=../build/${BUILDMODE}
SOURCES=$(wildcard *.c)
OBJECTS=${SOURCES:%.c=obj/%.o}
HEADERS=$(wildcard ../lib_paysages/shared/*.h ../lib_paysages/*.h *.h)
include ../common_pre.mk
OBJPATH = ${BUILDPATH}/cli
RESULT = ${BUILDPATH}/paysages-cli
CC_FLAGS=-g -pg -Wall
CC_LDFLAGS=-L${BUILDPATH} -lpaysages
SOURCES += $(wildcard *.c)
HEADERS += $(wildcard *.h)
all:prepare ${RESULT}
prepare:
mkdir -p ./obj
mkdir -p ${BUILDPATH}
clean:
rm -f ${OBJECTS}
rm -f ${RESULT}
obj/%.o:%.c ${HEADERS}
${CC} -c ${CC_FLAGS} $< -o $@
${RESULT}:${OBJECTS}
${CC} $^ ${CC_LDFLAGS} -o $@
.PHONY:all clean prepare
CC_LDFLAGS += -L${BUILDPATH} -lpaysages
include ../common_post.mk

27
common_post.mk Normal file
View file

@ -0,0 +1,27 @@
OBJECTS = ${SOURCES:%.c=${OBJPATH}/%.o}
ifeq (${BUILDMODE},debug)
CC_FLAGS += -g -pg
CC_LDFLAGS += -g -pg
endif
ifeq (${BUILDMODE},release)
CC_FLAGS += -O3 -DNDEBUG -Wno-unused-variable -Wno-unused-but-set-variable
endif
all:prepare ${RESULT}
prepare:
mkdir -p ${BUILDPATH}
clean:
rm -f ${OBJECTS}
rm -f ${RESULT}
${OBJPATH}/%.o:%.c ${HEADERS}
mkdir -p `dirname $@`
${CC} -c ${CC_FLAGS} $< -o $@
${RESULT}:${OBJECTS}
${CC} $^ ${CC_LDFLAGS} -o $@
.PHONY:all clean prepare

6
common_pre.mk Normal file
View file

@ -0,0 +1,6 @@
PATH_LIB_PAYSAGES = ../lib_paysages
BUILDMODE = debug
BUILDPATH = ../build/${BUILDMODE}
HEADERS = $(${PATH_LIB_PAYSAGES}/atmosphere/*.h ${PATH_LIB_PAYSAGES}/clouds/*.h ${PATH_LIB_PAYSAGES}/terrain/*.h ${PATH_LIB_PAYSAGES}/textures/*.h ${PATH_LIB_PAYSAGES}/water/*.h ${PATH_LIB_PAYSAGES}/tools/*.h ${PATH_LIB_PAYSAGES}/shared/*.h)
CC_FLAGS = -Wall -fPIC

View file

@ -85,34 +85,35 @@ QMainWindow(parent)
QToolBar* toolbar;
tabs = new QTabWidget(this);
tabs->setIconSize(QSize(32, 32));
form = new FormTerrain(tabs);
tabs->addTab(form, tr("Terrain"));
tabs->addTab(form, QIcon("images/tab_terrain.png"), tr("Terrain"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormTextures(tabs);
tabs->addTab(form, tr("Textures"));
tabs->addTab(form, QIcon("images/tab_textures.png"), tr("Textures"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormWater(tabs);
tabs->addTab(form, tr("Water"));
tabs->addTab(form, QIcon("images/tab_water.png"), tr("Water"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormAtmosphere(tabs);
tabs->addTab(form, tr("Atmosphere"));
tabs->addTab(form, QIcon("images/tab_atmosphere.png"), tr("Atmosphere"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormClouds(tabs);
tabs->addTab(form, tr("Clouds"));
tabs->addTab(form, QIcon("images/tab_clouds.png"), tr("Clouds"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
_form_render = new FormRender(tabs);
tabs->addTab(_form_render, tr("Render"));
tabs->addTab(_form_render, QIcon("images/tab_render.png"), tr("Render"));
_forms.append(_form_render);
toolbar = new QToolBar(this);

View file

@ -3,9 +3,9 @@ CONFIG += qt
QT += core gui opengl
DEPENDPATH += .
INCLUDEPATH += .
OBJECTS_DIR = ./obj/$$BUILDMODE/
MOC_DIR = ./moc/$$BUILDMODE/
DESTDIR = ../build/$$BUILDMODE/
OBJECTS_DIR = $$DESTDIR/gui_qt/
MOC_DIR = $$DESTDIR/gui_qt/moc
CONFIG -= release
CONFIG += $$BUILDMODE

BIN
images/tab_atmosphere.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
images/tab_clouds.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
images/tab_render.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
images/tab_terrain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
images/tab_textures.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
images/tab_water.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -1,12 +1,12 @@
BUILDMODE = debug
BUILDPATH = ../build/${BUILDMODE}
OBJPATH = ./obj/${BUILDMODE}
SOURCES = $(wildcard *.c atmosphere/*.c clouds/*.c terrain/*.c textures/*.c water/*.c tools/*.c shared/*.c)
OBJECTS = ${SOURCES:%.c=${OBJPATH}/%.o}
HEADERS = $(wildcard *.h atmosphere/*.h clouds/*.h terrain/*.h textures/*.h water/*.h tools/*.h shared/*.h)
include ../common_pre.mk
OBJPATH = ${BUILDPATH}/lib_paysages
RESULT = ${BUILDPATH}/libpaysages.so
LIBS = glib-2.0 gthread-2.0 IL ILU
CC_FLAGS = -Wall -fPIC -DHAVE_GLIB=1
SOURCES += $(wildcard *.c atmosphere/*.c clouds/*.c terrain/*.c textures/*.c water/*.c tools/*.c shared/*.c)
LIBS += glib-2.0 gthread-2.0 IL ILU
CC_FLAGS += -DHAVE_GLIB=1
CC_LDFLAGS += -shared
CHECK_OPENCL = $(shell pkg-config --modversion --silence-errors OpenCL)
ifneq (,${CHECK_OPENCL})
@ -15,32 +15,6 @@ ifneq (,${CHECK_OPENCL})
endif
CC_FLAGS += $(shell pkg-config --cflags ${LIBS})
CC_LDFLAGS = $(shell pkg-config --libs ${LIBS})
ifeq (${BUILDMODE},debug)
CC_FLAGS += -g -pg
CC_LDFLAGS += -g -pg
endif
ifeq (${BUILDMODE},release)
CC_FLAGS += -O3 -DNDEBUG -Wno-unused-variable -Wno-unused-but-set-variable
endif
all:prepare ${RESULT}
prepare:
mkdir -p ${OBJPATH}
mkdir -p ${BUILDPATH}
clean:
rm -f ${OBJECTS}
rm -f ${RESULT}
${OBJPATH}/%.o:%.c ${HEADERS}
mkdir -p `dirname $@`
${CC} -c ${CC_FLAGS} $< -o $@
${RESULT}:${OBJECTS}
${CC} $^ -shared ${CC_LDFLAGS} -o $@
.PHONY:all clean prepare
CC_LDFLAGS += $(shell pkg-config --libs ${LIBS})
include ../common_post.mk

View file

@ -57,6 +57,19 @@ Renderer* terrainCreatePreviewRenderer()
result->getCameraLocation = _getCameraLocation;
result->atmosphere->getLightingStatus = _getLightingStatus;
TexturesDefinition* textures;
textures = TexturesDefinitionClass.create();
TexturesLayerDefinition* layer = layersGetLayer(textures->layers, layersAddLayer(textures->layers, NULL));
layer->displacement_height = 0.0;
layer->material.base = COLOR_WHITE;
layer->material.reflection = 0.05;
layer->material.shininess = 2.0;
noiseClearLevels(layer->_detail_noise);
TexturesRendererClass.bind(result, textures);
TexturesDefinitionClass.destroy(textures);
return result;
}

View file

@ -60,6 +60,11 @@ static void _layerValidateDefinition(TexturesLayerDefinition* definition)
noiseAddLevelsSimple(definition->_displacement_noise, 4, 1.0, -1.0, 1.0, 0.0);
noiseNormalizeAmplitude(definition->_displacement_noise, -1.0, 1.0, 0);
noiseValidate(definition->_displacement_noise);
noiseClearLevels(definition->_detail_noise);
noiseAddLevelsSimple(definition->_detail_noise, 4, 0.1, -1.0, 1.0, 0.0);
noiseNormalizeAmplitude(definition->_detail_noise, -0.01, 0.01, 0);
noiseValidate(definition->_detail_noise);
}
static TexturesLayerDefinition* _layerCreateDefinition()
@ -77,6 +82,7 @@ static TexturesLayerDefinition* _layerCreateDefinition()
result->material.shininess = 0.0;
result->_displacement_noise = noiseCreateGenerator();
result->_detail_noise = noiseCreateGenerator();
_layerValidateDefinition(result);
@ -87,6 +93,7 @@ static void _layerDeleteDefinition(TexturesLayerDefinition* definition)
{
zoneDelete(definition->terrain_zone);
noiseDeleteGenerator(definition->_displacement_noise);
noiseDeleteGenerator(definition->_detail_noise);
free(definition);
}
@ -99,6 +106,7 @@ static void _layerCopyDefinition(TexturesLayerDefinition* source, TexturesLayerD
destination->material = source->material;
noiseCopy(source->_displacement_noise, destination->_displacement_noise);
noiseCopy(source->_detail_noise, destination->_detail_noise);
}
static void _layerSave(PackStream* stream, TexturesLayerDefinition* layer)
@ -110,6 +118,7 @@ static void _layerSave(PackStream* stream, TexturesLayerDefinition* layer)
materialSave(stream, &layer->material);
noiseSaveGenerator(stream, layer->_displacement_noise);
noiseSaveGenerator(stream, layer->_detail_noise);
}
static void _layerLoad(PackStream* stream, TexturesLayerDefinition* layer)
@ -121,6 +130,7 @@ static void _layerLoad(PackStream* stream, TexturesLayerDefinition* layer)
materialLoad(stream, &layer->material);
noiseLoadGenerator(stream, layer->_displacement_noise);
noiseLoadGenerator(stream, layer->_detail_noise);
}
LayerType texturesGetLayerType()

View file

@ -47,7 +47,7 @@ typedef struct
TexturesMergeMode merge_mode;*/
NoiseGenerator* _displacement_noise;
/*NoiseGenerator* _detail_noise;*/
NoiseGenerator* _detail_noise;
/*Curve* _local_slope_condition;*/
} TexturesLayerDefinition;
@ -56,7 +56,7 @@ typedef struct
Layers* layers;
} TexturesDefinition;
typedef struct
/*typedef struct
{
double global_presence;
double local_presence;
@ -64,14 +64,14 @@ typedef struct
Vector3 displaced_normal;
Color color;
Color cancelled_color;
} TexturesLayerResult;
} TexturesLayerResult;*/
typedef struct
{
Vector3 base_location;
Vector3 base_normal;
int layer_count;
TexturesLayerResult layers[TEXTURES_MAX_LAYERS];
/*int layer_count;
TexturesLayerResult layers[TEXTURES_MAX_LAYERS];*/
Vector3 final_location;
Color final_color;
} TexturesResult;

View file

@ -4,26 +4,80 @@
#include "../tools.h"
#include "../renderer.h"
/******************** Fake ********************/
static Vector3 _fakeDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
/******************** Tools ********************/
static inline Vector3 _getNormal4(Vector3 center, Vector3 north, Vector3 east, Vector3 south, Vector3 west)
{
UNUSED(renderer);
/* TODO This is duplicated in terrain/main.c */
Vector3 dnorth, deast, dsouth, dwest, normal;
return terrain.location;
dnorth = v3Sub(north, center);
deast = v3Sub(east, center);
dsouth = v3Sub(south, center);
dwest = v3Sub(west, center);
normal = v3Cross(deast, dnorth);
normal = v3Add(normal, v3Cross(dsouth, deast));
normal = v3Add(normal, v3Cross(dwest, dsouth));
normal = v3Add(normal, v3Cross(dnorth, dwest));
return v3Normalize(normal);
}
static TexturesResult _fakeApplyToTerrain(Renderer* renderer, double x, double z)
static inline Vector3 _getNormal2(Vector3 center, Vector3 east, Vector3 south)
{
TexturesResult result;
/* TODO This is duplicated in terrain/main.c */
return v3Normalize(v3Cross(v3Sub(south, center), v3Sub(east, center)));
}
result.base_location.x = x;
result.base_location.y = 0.0;
result.base_location.z = z;
result.base_normal = VECTOR_UP;
result.layer_count = 0;
result.final_location = result.base_location;
result.final_color = COLOR_WHITE;
static Vector3 _getDetailNormal(Renderer* renderer, Vector3 base_location, Vector3 base_normal, TexturesLayerDefinition* layer)
{
Vector3 result;
double offset = 0.01;
/* Find guiding vectors in the appoximated local plane */
Vector3 dx, dy;
Vector3 pivot;
if (base_normal.y > 0.95)
{
pivot = VECTOR_NORTH;
}
else
{
pivot = VECTOR_UP;
}
dx = v3Normalize(v3Cross(base_normal, pivot));
dy = v3Cross(base_normal, dx);
/* Apply detail noise locally */
Vector3 center, north, east, south, west;
center = v3Add(base_location, v3Scale(base_normal, texturesGetTriplanarNoise(layer->_detail_noise, base_location, base_normal)));
east = v3Add(base_location, v3Scale(dx, offset));
east = v3Add(east, v3Scale(base_normal, texturesGetTriplanarNoise(layer->_detail_noise, east, base_normal)));
south = v3Add(base_location, v3Scale(dy, offset));
south = v3Add(south, v3Scale(base_normal, texturesGetTriplanarNoise(layer->_detail_noise, south, base_normal)));
if (renderer->render_quality > 6)
{
west = v3Add(base_location, v3Scale(dx, -offset));
west = v3Add(west, v3Scale(base_normal, texturesGetTriplanarNoise(layer->_detail_noise, west, base_normal)));
north = v3Add(base_location, v3Scale(dy, -offset));
north = v3Add(north, v3Scale(base_normal, texturesGetTriplanarNoise(layer->_detail_noise, north, base_normal)));
result = _getNormal4(center, north, east, south, west);
}
else
{
result = _getNormal2(center, east, south);
}
if (v3Dot(result, base_normal) < 0.0)
{
result = v3Scale(result, -1.0);
}
return result;
}
@ -50,27 +104,76 @@ static Vector3 _realDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
return v3Add(terrain.location, v3Scale(v3Normalize(terrain.normal), offset));
}
typedef struct
{
TexturesLayerDefinition* layer;
double presence;
Color color;
} TexturesIntermediaryResult;
static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z)
{
TexturesDefinition* textures = renderer->textures->definition;
TexturesResult result;
/* Displacement */
TerrainResult terrain = renderer->terrain->getResult(renderer, x, z, 1, 1);
/* TODO Detail */
/* TODO Displaced textures had their presence already computed before, store that result and use it */
/* TEMP */
SurfaceMaterial temp;
temp.base.r = 0.6;
temp.base.g = 0.55;
temp.base.b = 0.57;
temp.reflection = 0.02;
temp.shininess = 3.0;
/* Find presence of each layer */
TexturesIntermediaryResult layers_info[TEXTURES_MAX_LAYERS];
int i, n;
n = layersCount(textures->layers);
for (i = 0; i < n; i++)
{
layers_info[i].layer = layersGetLayer(textures->layers, i);
layers_info[i].presence = texturesGetLayerBasePresence(layers_info[i].layer, terrain);
if (layers_info[i].presence > 0.0)
{
Vector3 normal = _getDetailNormal(renderer, terrain.location, terrain.normal, layers_info[i].layer);
layers_info[i].color = renderer->applyLightingToSurface(renderer, terrain.location, normal, &layers_info[i].layer->material);
}
}
result.base_location = terrain.location;
result.base_normal = terrain.normal;
result.final_location = terrain.location;
result.final_color = renderer->applyLightingToSurface(renderer, terrain.location, terrain.normal, &temp);
result.final_color = COLOR_GREEN;
for (i = 0; i < n; i++)
{
if (layers_info[i].presence > 0.0)
{
layers_info[i].color.a = layers_info[i].presence;
colorMask(&result.final_color, &layers_info[i].color);
}
}
return result;
}
/******************** Fake ********************/
static Vector3 _fakeDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
{
UNUSED(renderer);
return terrain.location;
}
static TexturesResult _fakeApplyToTerrain(Renderer* renderer, double x, double z)
{
UNUSED(renderer);
TexturesResult result;
result.base_location.x = x;
result.base_location.y = 0.0;
result.base_location.z = z;
result.base_normal = VECTOR_UP;
/*result.layer_count = 0;*/
result.final_location = result.base_location;
result.final_color = COLOR_WHITE;
return result;
}

View file

@ -1,6 +1,7 @@
#include "private.h"
#include <assert.h>
#include <math.h>
/*
* Get the base presence factor of a layer, not accounting for other layers.