Separated texture layer results for previews

This commit is contained in:
Michaël Lemaire 2013-08-28 16:03:22 +02:00
parent 7cd74b2c8a
commit 05c0a58875
5 changed files with 74 additions and 41 deletions

View file

@ -147,22 +147,6 @@ void FreeFormHelper::setPresetButton(QPushButton* button)
connect(button, SIGNAL(clicked()), this, SLOT(processPresetClicked())); connect(button, SIGNAL(clicked()), this, SLOT(processPresetClicked()));
} }
void FreeFormHelper::processPresetClicked()
{
bool ok;
QString item = QInputDialog::getItem(_form_widget, tr("Choose a preset"), tr("Preset settings : "), _presets, 0, false, &ok);
if (ok && !item.isEmpty())
{
int preset = _presets.indexOf(item);
if (preset >= 0)
{
emit presetSelected(preset);
emit needLocalRefreshing();
}
}
}
void FreeFormHelper::openDialog(QDialog* dialog) void FreeFormHelper::openDialog(QDialog* dialog)
{ {
if (dialog->exec()) if (dialog->exec())
@ -296,3 +280,19 @@ void FreeFormHelper::processDecimalChange(double value)
processDataChange(); processDataChange();
} }
} }
void FreeFormHelper::processPresetClicked()
{
bool ok;
QString item = QInputDialog::getItem(_form_widget, tr("Choose a preset"), tr("Preset settings : "), _presets, 0, false, &ok);
if (ok && !item.isEmpty())
{
int preset = _presets.indexOf(item);
if (preset >= 0)
{
emit presetSelected(preset);
processDataChange();
}
}
}

View file

@ -106,6 +106,7 @@ void MainTexturesForm::selectLayer(int layer)
ui->preview_texture->setEnabled(true); ui->preview_texture->setEnabled(true);
preview_layer_coverage->setLayer(layer); preview_layer_coverage->setLayer(layer);
preview_layer_look->setLayer(layer);
ui->preview_coverage->redraw(); ui->preview_coverage->redraw();
ui->preview_texture->redraw(); ui->preview_texture->redraw();

View file

@ -56,27 +56,25 @@ typedef struct
Layers* layers; Layers* layers;
} TexturesDefinition; } TexturesDefinition;
/*typedef struct typedef struct
{ {
double global_presence; TexturesLayerDefinition* layer;
double local_presence; double presence;
Vector3 displaced_location;
Vector3 displaced_normal;
Color color; Color 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;
typedef Vector3 (*FuncTexturesDisplaceTerrain)(Renderer* renderer, TerrainResult terrain); typedef Vector3 (*FuncTexturesDisplaceTerrain)(Renderer* renderer, TerrainResult terrain);
typedef double (*FuncTexturesGetBasePresence)(Renderer* renderer, int layer, TerrainResult terrain);
typedef TexturesResult (*FuncTexturesApplyToTerrain)(Renderer* renderer, double x, double z); typedef TexturesResult (*FuncTexturesApplyToTerrain)(Renderer* renderer, double x, double z);
typedef struct typedef struct
@ -84,6 +82,7 @@ typedef struct
TexturesDefinition* definition; TexturesDefinition* definition;
FuncTexturesDisplaceTerrain displaceTerrain; FuncTexturesDisplaceTerrain displaceTerrain;
FuncTexturesGetBasePresence getBasePresence;
FuncTexturesApplyToTerrain applyToTerrain; FuncTexturesApplyToTerrain applyToTerrain;
} TexturesRenderer; } TexturesRenderer;

View file

@ -40,9 +40,19 @@ Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double
return result; return result;
} }
static double _getPresenceFull(Renderer* renderer, int layer, TerrainResult terrain)
{
UNUSED(renderer);
UNUSED(layer);
UNUSED(terrain);
return 1.0;
}
void TexturesPreviewLayerLook_bind(Renderer* renderer, TexturesDefinition* definition) void TexturesPreviewLayerLook_bind(Renderer* renderer, TexturesDefinition* definition)
{ {
TexturesRendererClass.bind(renderer, definition); TexturesRendererClass.bind(renderer, definition);
renderer->textures->getBasePresence = _getPresenceFull;
} }
Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y, double scaling, int layer) Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y, double scaling, int layer)
@ -50,7 +60,15 @@ Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y,
UNUSED(scaling); UNUSED(scaling);
UNUSED(layer); UNUSED(layer);
return renderer->textures->applyToTerrain(renderer, x, y).final_color; TexturesResult result = renderer->textures->applyToTerrain(renderer, x, y);
if (layer >= 0 && layer < result.layer_count)
{
return result.layers[layer].color;
}
else
{
return COLOR_BLACK;
}
} }

View file

@ -104,12 +104,11 @@ 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 static double _realGetBasePresence(Renderer* renderer, int layer, TerrainResult terrain)
{ {
TexturesLayerDefinition* layer; TexturesLayerDefinition* layerdef = layersGetLayer(renderer->textures->definition->layers, layer);
double presence; return texturesGetLayerBasePresence(layerdef, terrain);
Color color; }
} TexturesIntermediaryResult;
static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z) static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z)
{ {
@ -122,19 +121,24 @@ static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z
/* TODO Displaced textures had their presence already computed before, store that result and use it */ /* TODO Displaced textures had their presence already computed before, store that result and use it */
/* Find presence of each layer */ /* Find presence of each layer */
TexturesIntermediaryResult layers_info[TEXTURES_MAX_LAYERS];
int i, n; int i, n;
n = layersCount(textures->layers); n = layersCount(textures->layers);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
layers_info[i].layer = layersGetLayer(textures->layers, i); TexturesLayerResult* info = result.layers + i;
layers_info[i].presence = texturesGetLayerBasePresence(layers_info[i].layer, terrain); info->layer = layersGetLayer(textures->layers, i);
if (layers_info[i].presence > 0.0) info->presence = renderer->textures->getBasePresence(renderer, i, terrain);
if (info->presence > 0.0)
{ {
Vector3 normal = _getDetailNormal(renderer, terrain.location, terrain.normal, layers_info[i].layer); Vector3 normal = _getDetailNormal(renderer, terrain.location, terrain.normal, info->layer);
layers_info[i].color = renderer->applyLightingToSurface(renderer, terrain.location, normal, &layers_info[i].layer->material); info->color = renderer->applyLightingToSurface(renderer, terrain.location, normal, &info->layer->material);
}
else
{
info->color = COLOR_TRANSPARENT;
} }
} }
result.layer_count = n;
result.base_location = terrain.location; result.base_location = terrain.location;
result.base_normal = terrain.normal; result.base_normal = terrain.normal;
@ -142,10 +146,10 @@ static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z
result.final_color = COLOR_GREEN; result.final_color = COLOR_GREEN;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
if (layers_info[i].presence > 0.0) if (result.layers[i].presence > 0.0)
{ {
layers_info[i].color.a = layers_info[i].presence; result.layers[i].color.a = result.layers[i].presence;
colorMask(&result.final_color, &layers_info[i].color); colorMask(&result.final_color, &result.layers[i].color);
} }
} }
@ -160,6 +164,15 @@ static Vector3 _fakeDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
return terrain.location; return terrain.location;
} }
static double _fakeGetBasePresence(Renderer* renderer, int layer, TerrainResult terrain)
{
UNUSED(renderer);
UNUSED(layer);
UNUSED(terrain);
return 1.0;
}
static TexturesResult _fakeApplyToTerrain(Renderer* renderer, double x, double z) static TexturesResult _fakeApplyToTerrain(Renderer* renderer, double x, double z)
{ {
UNUSED(renderer); UNUSED(renderer);
@ -170,7 +183,7 @@ static TexturesResult _fakeApplyToTerrain(Renderer* renderer, double x, double z
result.base_location.y = 0.0; result.base_location.y = 0.0;
result.base_location.z = z; result.base_location.z = z;
result.base_normal = VECTOR_UP; result.base_normal = VECTOR_UP;
/*result.layer_count = 0;*/ result.layer_count = 0;
result.final_location = result.base_location; result.final_location = result.base_location;
result.final_color = COLOR_WHITE; result.final_color = COLOR_WHITE;
@ -186,6 +199,7 @@ static TexturesRenderer* _createRenderer()
result->definition = TexturesDefinitionClass.create(); result->definition = TexturesDefinitionClass.create();
result->displaceTerrain = _fakeDisplaceTerrain; result->displaceTerrain = _fakeDisplaceTerrain;
result->getBasePresence = _fakeGetBasePresence;
result->applyToTerrain = _fakeApplyToTerrain; result->applyToTerrain = _fakeApplyToTerrain;
return result; return result;
@ -202,6 +216,7 @@ static void _bindRenderer(Renderer* renderer, TexturesDefinition* definition)
TexturesDefinitionClass.copy(definition, renderer->textures->definition); TexturesDefinitionClass.copy(definition, renderer->textures->definition);
renderer->textures->displaceTerrain = _realDisplaceTerrain; renderer->textures->displaceTerrain = _realDisplaceTerrain;
renderer->textures->getBasePresence = _realGetBasePresence;
renderer->textures->applyToTerrain = _realApplyToTerrain; renderer->textures->applyToTerrain = _realApplyToTerrain;
} }