paysages : Textures WIP.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@549 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-04-12 20:11:29 +00:00 committed by ThunderK
parent 06841dfe89
commit 72d1791718
10 changed files with 84 additions and 94 deletions

1
TODO
View file

@ -14,6 +14,7 @@ Technology Preview 2 :
- Translations.
Technlogy Preview 3 :
- Start using unit testing.
- Improve terrain 3D editor:
=> Add a map preview with edit area highlighted.
=> Allow zooming and simplified camera control.

View file

@ -8,6 +8,14 @@ ifeq (${BUILDMODE},release)
CC_FLAGS += -O3 -DNDEBUG -Wno-unused-variable -Wno-unused-but-set-variable
endif
ifneq (,${LIBS})
CC_FLAGS += $(shell pkg-config --cflags ${LIBS})
CC_LDFLAGS += $(shell pkg-config --libs ${LIBS})
endif
CC_FLAGS += -fPIC -Wall
CC_LDFLAGS += -fPIC
all:prepare ${RESULT}
prepare:

View file

@ -2,5 +2,3 @@ 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

@ -97,6 +97,11 @@ private:
FormTextures::FormTextures(QWidget *parent):
BaseFormLayer(parent)
{
addAutoPreset(tr("Rock"));
addAutoPreset(tr("Grass"));
addAutoPreset(tr("Sand"));
addAutoPreset(tr("Snow"));
_definition = (TexturesDefinition*)TexturesDefinitionClass.create();
_layer = (TexturesLayerDefinition*)texturesGetLayerType().callback_create();
@ -105,13 +110,13 @@ FormTextures::FormTextures(QWidget *parent):
addPreview(_previewCoverage, tr("Coverage preview"));
addPreview(_previewColor, tr("Lighted sample"));
/*addInputNoise(tr("Surface noise"), _layer->bump_noise);
addInputDouble(tr("Surface noise height"), &_layer->bump_height, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Surface noise scaling"), &_layer->bump_scaling, 0.003, 0.3, 0.003, 0.03);
addInputDouble(tr("Displacement height"), &_layer->displacement_height, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Displacement scaling"), &_layer->displacement_scaling, 0.003, 0.3, 0.003, 0.03);
addInputMaterial(tr("Material"), &_layer->material);
addInputCurve(tr("Coverage by altitude"), _supp.height_curve, -20.0, 20.0, 0.0, 1.0, tr("Terrain altitude"), tr("Texture coverage"));
addInputCurve(tr("Coverage by slope"), _supp.slope_curve, 0.0, 5.0, 0.0, 1.0, tr("Terrain slope"), tr("Texture coverage"));
addInputDouble(tr("Amplitude for slope coverage"), &_layer->slope_range, 0.001, 0.1, 0.001, 0.01);
/*addInputCurve(tr("Coverage by altitude"), _layer->terrain_zone->value_by_height, -20.0, 20.0, 0.0, 1.0, tr("Terrain altitude"), tr("Texture coverage"));
addInputCurve(tr("Coverage by slope"), _layer->terrain_zone->value_by_slope, 0.0, 5.0, 0.0, 1.0, tr("Terrain slope"), tr("Texture coverage"));*/
/*addInputDouble(tr("Amplitude for slope coverage"), &_layer->slope_range, 0.001, 0.1, 0.001, 0.01);
addInputDouble(tr("Layer thickness"), &_layer->thickness, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Transparency thickness"), &_layer->thickness_transparency, 0.0, 0.1, 0.001, 0.01);*/

View file

@ -14,7 +14,4 @@ ifneq (,${CHECK_OPENCL})
CC_FLAGS += -DHAVE_OPENCL=1
endif
CC_FLAGS += $(shell pkg-config --cflags ${LIBS})
CC_LDFLAGS += $(shell pkg-config --libs ${LIBS})
include ../common_post.mk

View file

@ -63,7 +63,7 @@ static void _layerValidateDefinition(TexturesLayerDefinition* definition)
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);
noiseNormalizeAmplitude(definition->_detail_noise, -0.005, 0.005, 0);
noiseValidate(definition->_detail_noise);
}
@ -74,16 +74,11 @@ static TexturesLayerDefinition* _layerCreateDefinition()
result = malloc(sizeof(TexturesLayerDefinition));
result->terrain_zone = zoneCreate();
result->displacement_scaling = 2.0;
result->displacement_height = 0.1;
result->displacement_offset = 0.0;
result->material.base = COLOR_WHITE;
result->material.reflection = 0.0;
result->material.shininess = 0.0;
result->_displacement_noise = noiseCreateGenerator();
result->_detail_noise = noiseCreateGenerator();
texturesLayerAutoPreset(result, TEXTURES_LAYER_PRESET_ROCK);
_layerValidateDefinition(result);
return result;

View file

@ -2,34 +2,83 @@
void texturesAutoPreset(TexturesDefinition* definition, TexturesPreset preset)
{
int layer;
TexturesLayerDefinition* layer;
layersClear(definition->layers);
if (preset == TEXTURES_PRESET_IRELAND)
{
layer = layersAddLayer(definition->layers, NULL);
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_ROCK);
layersSetName(definition->layers, 0, "Ground");
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_GRASS);
layersSetName(definition->layers, 1, "Grass");
}
else if (preset == TEXTURES_PRESET_ALPS)
{
/* TODO */
}
else if (preset == TEXTURES_PRESET_CANYON)
{
/* TODO */
}
}
void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerPreset preset)
{
noiseRandomizeOffsets(definition->_displacement_noise);
noiseRandomizeOffsets(definition->_detail_noise);
zoneClear(definition->terrain_zone);
switch (preset)
{
case TEXTURES_LAYER_PRESET_ROCK:
definition->displacement_height = 0.1;
definition->displacement_scaling = 2.0;
definition->displacement_offset = 0.0;
definition->material.base.r = 0.6;
definition->material.base.g = 0.55;
definition->material.base.b = 0.57;
definition->material.reflection = 0.02;
definition->material.shininess = 3.0;
break;
case TEXTURES_LAYER_PRESET_GRASS:
zoneAddHeightRangeQuick(definition->terrain_zone, 1.0, -6.0, -5.0, 3.0, 15.0);
zoneAddSlopeRangeQuick(definition->terrain_zone, 1.0, 0.0, 0.0, 0.05, 0.4);
definition->displacement_height = 0.0;
definition->displacement_scaling = 1.0;
definition->displacement_offset = 0.0;
definition->material.base.r = 0.12;
definition->material.base.g = 0.19;
definition->material.base.b = 0.035;
definition->material.reflection = 0.003;
definition->material.shininess = 2.0;
break;
case TEXTURES_LAYER_PRESET_SAND:
zoneAddHeightRangeQuick(definition->terrain_zone, 1.0, -5.5, -4.5, -4.0, -3.0);
zoneAddSlopeRangeQuick(definition->terrain_zone, 1.0, 0.0, 0.0, 0.15, 0.3);
definition->displacement_height = 0.0;
definition->displacement_scaling = 1.0;
definition->displacement_offset = 0.0;
definition->material.base.r = 0.30;
definition->material.base.g = 0.28;
definition->material.base.b = 0.02;
definition->material.reflection = 0.008;
definition->material.shininess = 6.0;
break;
case TEXTURES_LAYER_PRESET_SNOW:
zoneAddHeightRangeQuick(definition->terrain_zone, 1.0, 4.0, 5.0, 100.0, 100.0);
zoneAddSlopeRangeQuick(definition->terrain_zone, 1.0, 0.0, 0.0, 0.2, 1.0);
definition->displacement_height = 0.0;
definition->displacement_scaling = 1.0;
definition->displacement_offset = 0.0;
definition->material.base.r = 1.0;
definition->material.base.g = 1.0;
definition->material.base.b = 1.0;
definition->material.reflection = 0.25;
definition->material.shininess = 0.6;
break;
default:
break;
@ -37,60 +86,3 @@ void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerP
texturesGetLayerType().callback_validate(definition);
}
#if 0
textures = texturesCreateDefinition();
layer = layersAddLayer(textures.layers, NULL);
layersSetName(textures.layers, layer, "Ground");
texture = layersGetLayer(textures.layers, layer);
noiseClearLevels(texture->bump_noise);
noiseRandomizeOffsets(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, -0.5, 0.5, 0.5);
texture->bump_height = 0.01;
texture->bump_scaling = 0.045;
texture->material.base.r = 0.6;
texture->material.base.g = 0.55;
texture->material.base.b = 0.57;
texture->material.reflection = 0.02;
texture->material.shininess = 3.0;
texture->thickness = 0.001;
texture->slope_range = 0.001;
texture->thickness_transparency = 0.0;
layer = layersAddLayer(textures.layers, NULL);
layersSetName(textures.layers, layer, "Grass");
texture = layersGetLayer(textures.layers, layer);
zoneAddHeightRangeQuick(texture->zone, 1.0, -6.0, -5.0, 3.0, 15.0);
zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.05, 0.4);
noiseClearLevels(texture->bump_noise);
noiseRandomizeOffsets(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 5, 1.0, -0.2, 0.2, 0.5);
noiseAddLevelsSimple(texture->bump_noise, 2, 0.03, -0.04, 0.04, 0.5);
texture->bump_height = 0.002;
texture->bump_scaling = 0.03;
texture->material.base.r = 0.12;
texture->material.base.g = 0.19;
texture->material.base.b = 0.035;
texture->material.reflection = 0.003;
texture->material.shininess = 2.0;
texture->thickness = 0.02;
texture->slope_range = 0.03;
texture->thickness_transparency = 0.005;
/*texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
zoneAddHeightRangeQuick(texture->zone, 1.0, 4.0, 5.0, 100.0, 100.0);
zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.2, 1.0);
noiseGenerateBaseNoise(texture->bump_noise, 102400);
noiseClearLevels(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 6, 1.0, 1.0);
texture->bump_height = 0.002;
texture->bump_scaling = 0.03;
texture->material.base.r = 1.0;
texture->material.base.g = 1.0;
texture->material.base.b = 1.0;
texture->material.reflection = 0.25;
texture->material.shininess = 0.6;
texture->thickness = 0.05;
texture->slope_range = 0.3;
texture->thickness_transparency = 0.015;*/
scenerySetTextures(&textures);
texturesDeleteDefinition(&textures);
#endif

View file

@ -117,6 +117,14 @@ void zoneCopy(Zone* source, Zone* destination)
destination->circles_excluded_count = source->circles_excluded_count;
}
void zoneClear(Zone* zone)
{
curveClear(zone->value_by_height);
curveClear(zone->value_by_slope);
zone->circles_included_count = 0;
zone->circles_excluded_count = 0;
}
void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius)
{
Circle circle = {value, centerx, centerz, softradius, hardradius};

View file

@ -16,6 +16,8 @@ void zoneDelete(Zone* zone);
void zoneSave(PackStream* stream, Zone* zone);
void zoneLoad(PackStream* stream, Zone* zone);
void zoneCopy(Zone* source, Zone* destination);
void zoneClear(Zone* zone);
void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius);
void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double hardradius);

16
test.cl
View file

@ -1,16 +0,0 @@
__kernel void vector_add_gpu (__global const float* src_a,
__global const float* src_b,
__global float* res,
const int num)
{
/* get_global_id(0) returns the ID of the thread in execution.
As many threads are launched at the same time, executing the same kernel,
each one will receive a different ID, and consequently perform a different computation.*/
const int idx = get_global_id(0);
/* Now each work-item asks itself: "is my ID inside the vector's range?"
If the answer is YES, the work-item performs the corresponding computation*/
if (idx < num)
res[idx] = src_a[idx] + src_b[idx];
}