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:
parent
e99633f7c4
commit
06841dfe89
18 changed files with 213 additions and 96 deletions
1
TODO
1
TODO
|
@ -7,7 +7,6 @@ Technology Preview 2 :
|
||||||
=> Restore cloud lighting
|
=> Restore cloud lighting
|
||||||
=> Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)).
|
=> Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)).
|
||||||
- Finish texture refactoring.
|
- Finish texture refactoring.
|
||||||
=> Push displaced polygons, but keep undisplaced coordinates for second pass.
|
|
||||||
=> Add detail texture.
|
=> Add detail texture.
|
||||||
=> Displacement on 3d explorer and previews.
|
=> Displacement on 3d explorer and previews.
|
||||||
=> Optimize ray marching (for tracing and shadows), using base terrain and displacement power.
|
=> Optimize ray marching (for tracing and shadows), using base terrain and displacement power.
|
||||||
|
|
31
cli/Makefile
31
cli/Makefile
|
@ -1,27 +1,10 @@
|
||||||
BUILDMODE=debug
|
include ../common_pre.mk
|
||||||
BUILDPATH=../build/${BUILDMODE}
|
|
||||||
SOURCES=$(wildcard *.c)
|
|
||||||
OBJECTS=${SOURCES:%.c=obj/%.o}
|
|
||||||
HEADERS=$(wildcard ../lib_paysages/shared/*.h ../lib_paysages/*.h *.h)
|
|
||||||
RESULT=${BUILDPATH}/paysages-cli
|
|
||||||
CC_FLAGS=-g -pg -Wall
|
|
||||||
CC_LDFLAGS=-L${BUILDPATH} -lpaysages
|
|
||||||
|
|
||||||
all:prepare ${RESULT}
|
OBJPATH = ${BUILDPATH}/cli
|
||||||
|
RESULT = ${BUILDPATH}/paysages-cli
|
||||||
|
SOURCES += $(wildcard *.c)
|
||||||
|
HEADERS += $(wildcard *.h)
|
||||||
|
|
||||||
prepare:
|
CC_LDFLAGS += -L${BUILDPATH} -lpaysages
|
||||||
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
|
|
||||||
|
|
||||||
|
include ../common_post.mk
|
||||||
|
|
27
common_post.mk
Normal file
27
common_post.mk
Normal 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
6
common_pre.mk
Normal 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
|
|
@ -85,34 +85,35 @@ QMainWindow(parent)
|
||||||
QToolBar* toolbar;
|
QToolBar* toolbar;
|
||||||
|
|
||||||
tabs = new QTabWidget(this);
|
tabs = new QTabWidget(this);
|
||||||
|
tabs->setIconSize(QSize(32, 32));
|
||||||
|
|
||||||
form = new FormTerrain(tabs);
|
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);
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormTextures(tabs);
|
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);
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormWater(tabs);
|
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);
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormAtmosphere(tabs);
|
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);
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormClouds(tabs);
|
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);
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
_form_render = new FormRender(tabs);
|
_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);
|
_forms.append(_form_render);
|
||||||
|
|
||||||
toolbar = new QToolBar(this);
|
toolbar = new QToolBar(this);
|
||||||
|
|
|
@ -3,9 +3,9 @@ CONFIG += qt
|
||||||
QT += core gui opengl
|
QT += core gui opengl
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += .
|
INCLUDEPATH += .
|
||||||
OBJECTS_DIR = ./obj/$$BUILDMODE/
|
|
||||||
MOC_DIR = ./moc/$$BUILDMODE/
|
|
||||||
DESTDIR = ../build/$$BUILDMODE/
|
DESTDIR = ../build/$$BUILDMODE/
|
||||||
|
OBJECTS_DIR = $$DESTDIR/gui_qt/
|
||||||
|
MOC_DIR = $$DESTDIR/gui_qt/moc
|
||||||
CONFIG -= release
|
CONFIG -= release
|
||||||
CONFIG += $$BUILDMODE
|
CONFIG += $$BUILDMODE
|
||||||
|
|
||||||
|
|
BIN
images/tab_atmosphere.png
Normal file
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
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
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
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
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
BIN
images/tab_water.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
|
@ -1,12 +1,12 @@
|
||||||
BUILDMODE = debug
|
include ../common_pre.mk
|
||||||
BUILDPATH = ../build/${BUILDMODE}
|
|
||||||
OBJPATH = ./obj/${BUILDMODE}
|
OBJPATH = ${BUILDPATH}/lib_paysages
|
||||||
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)
|
|
||||||
RESULT = ${BUILDPATH}/libpaysages.so
|
RESULT = ${BUILDPATH}/libpaysages.so
|
||||||
LIBS = glib-2.0 gthread-2.0 IL ILU
|
SOURCES += $(wildcard *.c atmosphere/*.c clouds/*.c terrain/*.c textures/*.c water/*.c tools/*.c shared/*.c)
|
||||||
CC_FLAGS = -Wall -fPIC -DHAVE_GLIB=1
|
|
||||||
|
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)
|
CHECK_OPENCL = $(shell pkg-config --modversion --silence-errors OpenCL)
|
||||||
ifneq (,${CHECK_OPENCL})
|
ifneq (,${CHECK_OPENCL})
|
||||||
|
@ -15,32 +15,6 @@ ifneq (,${CHECK_OPENCL})
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CC_FLAGS += $(shell pkg-config --cflags ${LIBS})
|
CC_FLAGS += $(shell pkg-config --cflags ${LIBS})
|
||||||
CC_LDFLAGS = $(shell pkg-config --libs ${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
|
|
||||||
|
|
||||||
|
include ../common_post.mk
|
||||||
|
|
|
@ -57,6 +57,19 @@ Renderer* terrainCreatePreviewRenderer()
|
||||||
result->getCameraLocation = _getCameraLocation;
|
result->getCameraLocation = _getCameraLocation;
|
||||||
result->atmosphere->getLightingStatus = _getLightingStatus;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,11 @@ static void _layerValidateDefinition(TexturesLayerDefinition* definition)
|
||||||
noiseAddLevelsSimple(definition->_displacement_noise, 4, 1.0, -1.0, 1.0, 0.0);
|
noiseAddLevelsSimple(definition->_displacement_noise, 4, 1.0, -1.0, 1.0, 0.0);
|
||||||
noiseNormalizeAmplitude(definition->_displacement_noise, -1.0, 1.0, 0);
|
noiseNormalizeAmplitude(definition->_displacement_noise, -1.0, 1.0, 0);
|
||||||
noiseValidate(definition->_displacement_noise);
|
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()
|
static TexturesLayerDefinition* _layerCreateDefinition()
|
||||||
|
@ -77,6 +82,7 @@ static TexturesLayerDefinition* _layerCreateDefinition()
|
||||||
result->material.shininess = 0.0;
|
result->material.shininess = 0.0;
|
||||||
|
|
||||||
result->_displacement_noise = noiseCreateGenerator();
|
result->_displacement_noise = noiseCreateGenerator();
|
||||||
|
result->_detail_noise = noiseCreateGenerator();
|
||||||
|
|
||||||
_layerValidateDefinition(result);
|
_layerValidateDefinition(result);
|
||||||
|
|
||||||
|
@ -87,6 +93,7 @@ static void _layerDeleteDefinition(TexturesLayerDefinition* definition)
|
||||||
{
|
{
|
||||||
zoneDelete(definition->terrain_zone);
|
zoneDelete(definition->terrain_zone);
|
||||||
noiseDeleteGenerator(definition->_displacement_noise);
|
noiseDeleteGenerator(definition->_displacement_noise);
|
||||||
|
noiseDeleteGenerator(definition->_detail_noise);
|
||||||
free(definition);
|
free(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +106,7 @@ static void _layerCopyDefinition(TexturesLayerDefinition* source, TexturesLayerD
|
||||||
destination->material = source->material;
|
destination->material = source->material;
|
||||||
|
|
||||||
noiseCopy(source->_displacement_noise, destination->_displacement_noise);
|
noiseCopy(source->_displacement_noise, destination->_displacement_noise);
|
||||||
|
noiseCopy(source->_detail_noise, destination->_detail_noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _layerSave(PackStream* stream, TexturesLayerDefinition* layer)
|
static void _layerSave(PackStream* stream, TexturesLayerDefinition* layer)
|
||||||
|
@ -110,6 +118,7 @@ static void _layerSave(PackStream* stream, TexturesLayerDefinition* layer)
|
||||||
materialSave(stream, &layer->material);
|
materialSave(stream, &layer->material);
|
||||||
|
|
||||||
noiseSaveGenerator(stream, layer->_displacement_noise);
|
noiseSaveGenerator(stream, layer->_displacement_noise);
|
||||||
|
noiseSaveGenerator(stream, layer->_detail_noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _layerLoad(PackStream* stream, TexturesLayerDefinition* layer)
|
static void _layerLoad(PackStream* stream, TexturesLayerDefinition* layer)
|
||||||
|
@ -121,6 +130,7 @@ static void _layerLoad(PackStream* stream, TexturesLayerDefinition* layer)
|
||||||
materialLoad(stream, &layer->material);
|
materialLoad(stream, &layer->material);
|
||||||
|
|
||||||
noiseLoadGenerator(stream, layer->_displacement_noise);
|
noiseLoadGenerator(stream, layer->_displacement_noise);
|
||||||
|
noiseLoadGenerator(stream, layer->_detail_noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerType texturesGetLayerType()
|
LayerType texturesGetLayerType()
|
||||||
|
|
|
@ -47,7 +47,7 @@ typedef struct
|
||||||
TexturesMergeMode merge_mode;*/
|
TexturesMergeMode merge_mode;*/
|
||||||
|
|
||||||
NoiseGenerator* _displacement_noise;
|
NoiseGenerator* _displacement_noise;
|
||||||
/*NoiseGenerator* _detail_noise;*/
|
NoiseGenerator* _detail_noise;
|
||||||
/*Curve* _local_slope_condition;*/
|
/*Curve* _local_slope_condition;*/
|
||||||
} TexturesLayerDefinition;
|
} TexturesLayerDefinition;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ typedef struct
|
||||||
Layers* layers;
|
Layers* layers;
|
||||||
} TexturesDefinition;
|
} TexturesDefinition;
|
||||||
|
|
||||||
typedef struct
|
/*typedef struct
|
||||||
{
|
{
|
||||||
double global_presence;
|
double global_presence;
|
||||||
double local_presence;
|
double local_presence;
|
||||||
|
@ -64,14 +64,14 @@ typedef struct
|
||||||
Vector3 displaced_normal;
|
Vector3 displaced_normal;
|
||||||
Color color;
|
Color color;
|
||||||
Color cancelled_color;
|
Color cancelled_color;
|
||||||
} TexturesLayerResult;
|
} TexturesLayerResult;*/
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Vector3 base_location;
|
Vector3 base_location;
|
||||||
Vector3 base_normal;
|
Vector3 base_normal;
|
||||||
int layer_count;
|
/*int layer_count;
|
||||||
TexturesLayerResult layers[TEXTURES_MAX_LAYERS];
|
TexturesLayerResult layers[TEXTURES_MAX_LAYERS];*/
|
||||||
Vector3 final_location;
|
Vector3 final_location;
|
||||||
Color final_color;
|
Color final_color;
|
||||||
} TexturesResult;
|
} TexturesResult;
|
||||||
|
|
|
@ -4,26 +4,80 @@
|
||||||
#include "../tools.h"
|
#include "../tools.h"
|
||||||
#include "../renderer.h"
|
#include "../renderer.h"
|
||||||
|
|
||||||
/******************** Fake ********************/
|
/******************** Tools ********************/
|
||||||
static Vector3 _fakeDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
|
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;
|
static Vector3 _getDetailNormal(Renderer* renderer, Vector3 base_location, Vector3 base_normal, TexturesLayerDefinition* layer)
|
||||||
result.base_location.y = 0.0;
|
{
|
||||||
result.base_location.z = z;
|
Vector3 result;
|
||||||
result.base_normal = VECTOR_UP;
|
double offset = 0.01;
|
||||||
result.layer_count = 0;
|
|
||||||
result.final_location = result.base_location;
|
|
||||||
result.final_color = COLOR_WHITE;
|
|
||||||
|
|
||||||
|
/* 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,27 +104,76 @@ static Vector3 _realDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
|
||||||
return v3Add(terrain.location, v3Scale(v3Normalize(terrain.normal), offset));
|
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)
|
static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z)
|
||||||
{
|
{
|
||||||
|
TexturesDefinition* textures = renderer->textures->definition;
|
||||||
TexturesResult result;
|
TexturesResult result;
|
||||||
|
|
||||||
/* Displacement */
|
/* Displacement */
|
||||||
TerrainResult terrain = renderer->terrain->getResult(renderer, x, z, 1, 1);
|
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 */
|
/* Find presence of each layer */
|
||||||
SurfaceMaterial temp;
|
TexturesIntermediaryResult layers_info[TEXTURES_MAX_LAYERS];
|
||||||
temp.base.r = 0.6;
|
int i, n;
|
||||||
temp.base.g = 0.55;
|
n = layersCount(textures->layers);
|
||||||
temp.base.b = 0.57;
|
for (i = 0; i < n; i++)
|
||||||
temp.reflection = 0.02;
|
{
|
||||||
temp.shininess = 3.0;
|
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_location = terrain.location;
|
||||||
result.base_normal = terrain.normal;
|
result.base_normal = terrain.normal;
|
||||||
result.final_location = terrain.location;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the base presence factor of a layer, not accounting for other layers.
|
* Get the base presence factor of a layer, not accounting for other layers.
|
||||||
|
|
Loading…
Reference in a new issue