From c6be386a5916b42e7ae280fff03dd723169a5000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 18 Sep 2013 17:10:34 +0200 Subject: [PATCH] Switch to HSL color space for material definition --- src/editing/lighting/DialogMaterialEditor.cpp | 10 +- src/editing/lighting/DialogMaterialEditor.ui | 72 ++++---- src/editing/lighting/SmallPreviewHues.cpp | 14 +- src/editing/widgetexplorer.cpp | 2 +- src/rendering/clouds/clo_definition.c | 2 + src/rendering/clouds/clo_presets.c | 5 +- src/rendering/scenery.c | 1 + src/rendering/terrain/ter_preview.c | 2 +- src/rendering/textures/tex_definition.c | 2 + src/rendering/textures/tex_presets.c | 16 +- src/rendering/tools/color.c | 161 ++++++++++++++---- src/rendering/tools/color.h | 15 ++ src/rendering/tools/lighting.c | 29 +++- src/rendering/tools/lighting.h | 8 +- src/rendering/water/wat_definition.c | 3 + src/rendering/water/wat_presets.c | 13 +- src/rendering/water/wat_render.c | 2 +- 17 files changed, 254 insertions(+), 103 deletions(-) diff --git a/src/editing/lighting/DialogMaterialEditor.cpp b/src/editing/lighting/DialogMaterialEditor.cpp index 113564c..fc57691 100644 --- a/src/editing/lighting/DialogMaterialEditor.cpp +++ b/src/editing/lighting/DialogMaterialEditor.cpp @@ -17,18 +17,21 @@ preview_lighted(&edited) form_helper->addPreview(ui->preview_lighted, &preview_lighted); - form_helper->addDoubleInputSlider(ui->slider_hue, &edited.hue); - form_helper->addDoubleInputSlider(ui->slider_diffuse, &edited.diffuse); + form_helper->addDoubleInputSlider(ui->slider_hue, &edited.base.h); + form_helper->addDoubleInputSlider(ui->slider_lightness, &edited.base.l); + form_helper->addDoubleInputSlider(ui->slider_saturation, &edited.base.s); + form_helper->addDoubleInputSlider(ui->slider_hardness, &edited.hardness); form_helper->addDoubleInputSlider(ui->slider_reflection, &edited.reflection); form_helper->addDoubleInputSlider(ui->slider_specularity, &edited.shininess); + form_helper->addDoubleInputSlider(ui->slider_receive_shadows, &edited.receive_shadows); form_helper->setRevertButton(ui->button_revert); form_helper->startManaging(); - ui->preview_color->setColor(&edited.base); + ui->preview_color->setColor(&edited._rgb); connect(ui->button_apply, SIGNAL(clicked()), this, SLOT(accept())); connect(ui->button_cancel, SIGNAL(clicked()), this, SLOT(reject())); @@ -48,6 +51,7 @@ bool DialogMaterialEditor::getMaterial(QWidget* parent, SurfaceMaterial* materia void DialogMaterialEditor::refreshFromLocalData() { + materialValidate(&edited); ui->preview_color->update(); } diff --git a/src/editing/lighting/DialogMaterialEditor.ui b/src/editing/lighting/DialogMaterialEditor.ui index 9c13a87..dd0c870 100644 --- a/src/editing/lighting/DialogMaterialEditor.ui +++ b/src/editing/lighting/DialogMaterialEditor.ui @@ -9,7 +9,7 @@ 0 0 - 1090 + 1091 627 @@ -58,34 +58,6 @@ - - - - Diffuse factor - - - - - - - Hardness to light - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - @@ -121,6 +93,48 @@ + + + + Colorfulness (saturation) + + + + + + + Qt::Horizontal + + + + + + + Diffuse factor (lightness) + + + + + + + Qt::Horizontal + + + + + + + Hardness to light + + + + + + + Qt::Horizontal + + + diff --git a/src/editing/lighting/SmallPreviewHues.cpp b/src/editing/lighting/SmallPreviewHues.cpp index 0270814..d4283e7 100644 --- a/src/editing/lighting/SmallPreviewHues.cpp +++ b/src/editing/lighting/SmallPreviewHues.cpp @@ -10,5 +10,17 @@ SmallPreviewHues::SmallPreviewHues(QWidget* parent) : DrawingWidget(parent) void SmallPreviewHues::doDrawing(QPainter* painter) { - painter->fillRect(rect(), Qt::blue); + int x; + ColorHSL colhsl; + + colhsl.s = 1.0; + colhsl.l = 0.5; + colhsl.a = 1.0; + + for (x = 0; x < width(); x++) + { + colhsl.h = (double)x / (double)(width() - 1); + painter->setPen(colorToQColor(colorFromHSL(colhsl))); + painter->drawLine(x, 0, x, height() - 1); + } } diff --git a/src/editing/widgetexplorer.cpp b/src/editing/widgetexplorer.cpp index 3f5f60a..22a3fd1 100644 --- a/src/editing/widgetexplorer.cpp +++ b/src/editing/widgetexplorer.cpp @@ -414,7 +414,7 @@ void WidgetExplorer::paintGL() // Render water double water_height = _renderer->terrain->getWaterHeight(_renderer); glDisable(GL_TEXTURE_2D); - glColor3f(water->material.base.r, water->material.base.g, water->material.base.b); + glColor3f(water->material._rgb.r, water->material._rgb.g, water->material._rgb.b); glBegin(GL_QUADS); glVertex3f(camera_location.x - 500.0, water_height, camera_location.z - 500.0); glVertex3f(camera_location.x - 500.0, water_height, camera_location.z + 500.0); diff --git a/src/rendering/clouds/clo_definition.c b/src/rendering/clouds/clo_definition.c index 7ebcc37..dd59100 100644 --- a/src/rendering/clouds/clo_definition.c +++ b/src/rendering/clouds/clo_definition.c @@ -117,6 +117,8 @@ void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition) noiseNormalizeAmplitude(definition->_coverage_noise, -1.0, 3.0, 0); noiseNormalizeAmplitude(definition->_shape_noise, -0.5, 0.5, 0); noiseNormalizeAmplitude(definition->_edge_noise, -0.5, 0.5, 0); + + materialValidate(&definition->material); } CloudsLayerDefinition* cloudsLayerCreateDefinition() diff --git a/src/rendering/clouds/clo_presets.c b/src/rendering/clouds/clo_presets.c index ed1981c..e63a91f 100644 --- a/src/rendering/clouds/clo_presets.c +++ b/src/rendering/clouds/clo_presets.c @@ -26,10 +26,7 @@ void cloudsLayerAutoPreset(CloudsLayerDefinition* definition, CloudsLayerPreset noiseRandomizeOffsets(definition->_edge_noise); noiseRandomizeOffsets(definition->_shape_noise); - definition->material.base.r = 0.7; - definition->material.base.g = 0.7; - definition->material.base.b = 0.7; - definition->material.base.a = 1.0; + definition->material.base = colorToHSL(colorFromValues(0.7, 0.7, 0.7, 1.0)); switch (preset) { diff --git a/src/rendering/scenery.c b/src/rendering/scenery.c index 1f5dfb5..0492f1b 100644 --- a/src/rendering/scenery.c +++ b/src/rendering/scenery.c @@ -3,6 +3,7 @@ #include #include "tools/color.h" #include "tools/euclid.h" +#include "terrain/ter_raster.h" #include "render.h" #include "system.h" diff --git a/src/rendering/terrain/ter_preview.c b/src/rendering/terrain/ter_preview.c index 189ee28..f4618f0 100644 --- a/src/rendering/terrain/ter_preview.c +++ b/src/rendering/terrain/ter_preview.c @@ -61,7 +61,7 @@ Renderer* terrainCreatePreviewRenderer() textures = TexturesDefinitionClass.create(); TexturesLayerDefinition* layer = layersGetLayer(textures->layers, layersAddLayer(textures->layers, NULL)); layer->displacement_height = 0.0; - layer->material.base = COLOR_WHITE; + layer->material.base = colorToHSL(COLOR_WHITE); layer->material.reflection = 0.05; layer->material.shininess = 2.0; noiseClearLevels(layer->_detail_noise); diff --git a/src/rendering/textures/tex_definition.c b/src/rendering/textures/tex_definition.c index 6e3b21c..49da2b4 100644 --- a/src/rendering/textures/tex_definition.c +++ b/src/rendering/textures/tex_definition.c @@ -65,6 +65,8 @@ static void _layerValidateDefinition(TexturesLayerDefinition* definition) noiseAddLevelsSimple(definition->_detail_noise, 7, 0.01, -1.0, 1.0, 0.0); noiseNormalizeAmplitude(definition->_detail_noise, -0.008, 0.008, 0); noiseValidate(definition->_detail_noise); + + materialValidate(&definition->material); } static TexturesLayerDefinition* _layerCreateDefinition() diff --git a/src/rendering/textures/tex_presets.c b/src/rendering/textures/tex_presets.c index 006c050..5bf607b 100644 --- a/src/rendering/textures/tex_presets.c +++ b/src/rendering/textures/tex_presets.c @@ -44,9 +44,7 @@ void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerP definition->displacement_height = 0.3; 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.base = colorToHSL(colorFromValues(0.6, 0.55, 0.57, 1.0)); definition->material.reflection = 0.006; definition->material.shininess = 6.0; break; @@ -56,9 +54,7 @@ void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerP 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.base = colorToHSL(colorFromValues(0.12, 0.19, 0.035, 1.0)); definition->material.reflection = 0.001; definition->material.shininess = 4.0; break; @@ -68,9 +64,7 @@ void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerP 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.base = colorToHSL(colorFromValues(0.30, 0.28, 0.02, 1.0)); definition->material.reflection = 0.008; definition->material.shininess = 6.0; break; @@ -80,9 +74,7 @@ void texturesLayerAutoPreset(TexturesLayerDefinition* definition, TexturesLayerP 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.base = colorToHSL(colorFromValues(1.0, 1.0, 1.0, 1.0)); definition->material.reflection = 0.25; definition->material.shininess = 0.6; break; diff --git a/src/rendering/tools/color.c b/src/rendering/tools/color.c index 4b2b5cd..4ce8bc4 100644 --- a/src/rendering/tools/color.c +++ b/src/rendering/tools/color.c @@ -32,34 +32,46 @@ void colorLoad(PackStream* stream, Color* col) packReadDouble(stream, &col->a); } +Color colorFromValues(double r, double g, double b, double a) +{ + Color result; + + result.r = r; + result.g = g; + result.b = b; + result.a = a; + + return result; +} + unsigned int colorTo32BitRGBA(Color* col) { - return (((unsigned int)(col->a * 255.0)) << 24) | (((unsigned int)(col->b * 255.0)) << 16) | (((unsigned int)(col->g * 255.0)) << 8) | ((unsigned int)(col->r * 255.0)); + return (((unsigned int) (col->a * 255.0)) << 24) | (((unsigned int) (col->b * 255.0)) << 16) | (((unsigned int) (col->g * 255.0)) << 8) | ((unsigned int) (col->r * 255.0)); } unsigned int colorTo32BitBGRA(Color* col) { - return (((unsigned int)(col->a * 255.0)) << 24) | (((unsigned int)(col->r * 255.0)) << 16) | (((unsigned int)(col->g * 255.0)) << 8) | ((unsigned int)(col->b * 255.0)); + return (((unsigned int) (col->a * 255.0)) << 24) | (((unsigned int) (col->r * 255.0)) << 16) | (((unsigned int) (col->g * 255.0)) << 8) | ((unsigned int) (col->b * 255.0)); } unsigned int colorTo32BitARGB(Color* col) { - return (((unsigned int)(col->b * 255.0)) << 24) | (((unsigned int)(col->g * 255.0)) << 16) | (((unsigned int)(col->r * 255.0)) << 8) | ((unsigned int)(col->a * 255.0)); + return (((unsigned int) (col->b * 255.0)) << 24) | (((unsigned int) (col->g * 255.0)) << 16) | (((unsigned int) (col->r * 255.0)) << 8) | ((unsigned int) (col->a * 255.0)); } unsigned int colorTo32BitABGR(Color* col) { - return (((unsigned int)(col->r * 255.0)) << 24) | (((unsigned int)(col->g * 255.0)) << 16) | (((unsigned int)(col->b * 255.0)) << 8) | ((unsigned int)(col->a * 255.0)); + return (((unsigned int) (col->r * 255.0)) << 24) | (((unsigned int) (col->g * 255.0)) << 16) | (((unsigned int) (col->b * 255.0)) << 8) | ((unsigned int) (col->a * 255.0)); } Color colorFrom32BitRGBA(unsigned int col) { Color result; - result.r = ((double)(col & 0x000000FF)) / 255.0; - result.g = ((double)((col & 0x0000FF00) >> 8)) / 255.0; - result.b = ((double)((col & 0x00FF0000) >> 16)) / 255.0; - result.a = ((double)((col & 0xFF000000) >> 24)) / 255.0; + result.r = ((double) (col & 0x000000FF)) / 255.0; + result.g = ((double) ((col & 0x0000FF00) >> 8)) / 255.0; + result.b = ((double) ((col & 0x00FF0000) >> 16)) / 255.0; + result.a = ((double) ((col & 0xFF000000) >> 24)) / 255.0; return result; } @@ -68,10 +80,10 @@ Color colorFrom32BitBGRA(unsigned int col) { Color result; - result.b = ((double)(col & 0x000000FF)) / 255.0; - result.g = ((double)((col & 0x0000FF00) >> 8)) / 255.0; - result.r = ((double)((col & 0x00FF0000) >> 16)) / 255.0; - result.a = ((double)((col & 0xFF000000) >> 24)) / 255.0; + result.b = ((double) (col & 0x000000FF)) / 255.0; + result.g = ((double) ((col & 0x0000FF00) >> 8)) / 255.0; + result.r = ((double) ((col & 0x00FF0000) >> 16)) / 255.0; + result.a = ((double) ((col & 0xFF000000) >> 24)) / 255.0; return result; } @@ -80,10 +92,10 @@ Color colorFrom32BitARGB(unsigned int col) { Color result; - result.a = ((double)(col & 0x000000FF)) / 255.0; - result.r = ((double)((col & 0x0000FF00) >> 8)) / 255.0; - result.g = ((double)((col & 0x00FF0000) >> 16)) / 255.0; - result.b = ((double)((col & 0xFF000000) >> 24)) / 255.0; + result.a = ((double) (col & 0x000000FF)) / 255.0; + result.r = ((double) ((col & 0x0000FF00) >> 8)) / 255.0; + result.g = ((double) ((col & 0x00FF0000) >> 16)) / 255.0; + result.b = ((double) ((col & 0xFF000000) >> 24)) / 255.0; return result; } @@ -92,10 +104,10 @@ Color colorFrom32BitABGR(unsigned int col) { Color result; - result.a = ((double)(col & 0x000000FF)) / 255.0; - result.b = ((double)((col & 0x0000FF00) >> 8)) / 255.0; - result.g = ((double)((col & 0x00FF0000) >> 16)) / 255.0; - result.r = ((double)((col & 0xFF000000) >> 24)) / 255.0; + result.a = ((double) (col & 0x000000FF)) / 255.0; + result.b = ((double) ((col & 0x0000FF00) >> 8)) / 255.0; + result.g = ((double) ((col & 0x00FF0000) >> 16)) / 255.0; + result.r = ((double) ((col & 0xFF000000) >> 24)) / 255.0; return result; } @@ -203,7 +215,7 @@ struct ColorProfile { double minvalue; double maxvalue; - Color (*mapper)(Color col, double exposure); + Color(*mapper)(Color col, double exposure); double exposure; }; @@ -211,7 +223,7 @@ ColorProfile* colorProfileCreate() { ColorProfile* profile; - profile = malloc(sizeof(ColorProfile)); + profile = malloc(sizeof (ColorProfile)); colorProfileSetToneMapping(profile, TONE_MAPPING_UNCHARTED, 2.0); colorProfileClear(profile); @@ -233,7 +245,7 @@ static inline double _uncharted2Tonemap(double x) double E = 0.02; double F = 0.30; - return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; + return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F; } static Color _toneMappingUncharted(Color pixel, double exposure) @@ -272,14 +284,14 @@ void colorProfileSetToneMapping(ColorProfile* profile, ToneMappingOperator tonem { switch (tonemapper) { - case TONE_MAPPING_REIHNARD: - profile->mapper = _toneMappingReinhard; - break; - case TONE_MAPPING_UNCHARTED: - profile->mapper = _toneMappingUncharted; - break; - default: - profile->mapper = _toneMappingClamp; + case TONE_MAPPING_REIHNARD: + profile->mapper = _toneMappingReinhard; + break; + case TONE_MAPPING_UNCHARTED: + profile->mapper = _toneMappingUncharted; + break; + default: + profile->mapper = _toneMappingClamp; } profile->exposure = exposure; } @@ -335,7 +347,7 @@ ColorGradation* colorGradationCreate() { ColorGradation* result; - result = malloc(sizeof(ColorGradation)); + result = malloc(sizeof (ColorGradation)); result->red = curveCreate(); result->green = curveCreate(); result->blue = curveCreate(); @@ -441,3 +453,88 @@ Color colorGradationGet(ColorGradation* gradation, double value) return result; } +/******************************** HSL Color Space ********************************/ +static double _hue2rgb(double p, double q, double t) +{ + if (t < 0.0) t += 1; + if (t > 1.0) t -= 1; + if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t; + if (t < 1.0 / 2.0) return q; + if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0; + return p; +} + +Color colorFromHSL(ColorHSL col) +{ + Color result; + + if (col.s == 0) + { + result.r = result.g = result.b = col.l; + } + else + { + double q = col.l < 0.5 ? col.l * (1.0 + col.s) : col.l + col.s - col.l * col.s; + double p = 2 * col.l - q; + result.r = _hue2rgb(p, q, col.h + 1.0 / 3.0); + result.g = _hue2rgb(p, q, col.h); + result.b = _hue2rgb(p, q, col.h - 1.0 / 3.0); + } + + result.a = col.a; + + return result; +} + +ColorHSL colorToHSL(Color col) +{ + ColorHSL result; + double min, max; + + max = col.r > col.g ? col.r : col.g; + max = col.b > max ? col.b : max; + + min = col.r < col.g ? col.r : col.g; + min = col.b < min ? col.b : min; + + result.h = result.s = result.l = (max + min) / 2.0; + + if (max == min) + { + result.h = result.s = 0.0; + } + else + { + double d = max - min; + result.s = result.l > 0.5 ? d / (2.0 - max - min) : d / (max + min); + if (max == col.r) + { + result.h = (col.g - col.b) / d + (col.g < col.b ? 6.0 : 0); + } + else if (max == col.g) + { + result.h = (col.b - col.r) / d + 2.0; + } + else + { + result.h = (col.r - col.g) / d + 4.0; + } + result.h /= 6.0; + } + + result.a = col.a; + + return result; +} + +ColorHSL colorHSLFromValues(double h, double s, double l, double a) +{ + ColorHSL result; + + result.h = h; + result.s = s; + result.l = l; + result.a = a; + + return result; +} diff --git a/src/rendering/tools/color.h b/src/rendering/tools/color.h index b6185ba..fb10505 100644 --- a/src/rendering/tools/color.h +++ b/src/rendering/tools/color.h @@ -27,6 +27,7 @@ extern Color COLOR_GREY; /* Color */ void colorSave(PackStream* stream, Color* col); void colorLoad(PackStream* stream, Color* col); +Color colorFromValues(double r, double g, double b, double a); unsigned int colorTo32BitRGBA(Color* col); unsigned int colorTo32BitBGRA(Color* col); @@ -90,6 +91,20 @@ void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r Color colorGradationGet(ColorGradation* gradation, double value); +/* HSL color space */ +typedef struct +{ + double h; + double s; + double l; + double a; +} ColorHSL; + +Color colorFromHSL(ColorHSL col); +ColorHSL colorToHSL(Color col); + +ColorHSL colorHSLFromValues(double h, double s, double l, double a); + #ifdef __cplusplus } #endif diff --git a/src/rendering/tools/lighting.c b/src/rendering/tools/lighting.c index 8c1f771..a941e6c 100644 --- a/src/rendering/tools/lighting.c +++ b/src/rendering/tools/lighting.c @@ -162,9 +162,9 @@ Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 locatio diffuse = (diffuse + (1.0 - normal_norm)) / (1.0 + (1.0 - normal_norm)); if (diffuse > 0.0) { - result.r += diffuse * material->base.r * light_color.r; - result.g += diffuse * material->base.g * light_color.g; - result.b += diffuse * material->base.b * light_color.b; + result.r += diffuse * material->_rgb.r * light_color.r; + result.g += diffuse * material->_rgb.g * light_color.g; + result.b += diffuse * material->_rgb.b * light_color.b; } /* specular reflection */ @@ -215,14 +215,33 @@ Vector3 lightingGetStatusLocation(LightStatus* status) void materialSave(PackStream* stream, SurfaceMaterial* material) { - colorSave(stream, &material->base); + packWriteDouble(stream, &material->base.h); + packWriteDouble(stream, &material->base.l); + packWriteDouble(stream, &material->base.s); + + packWriteDouble(stream, &material->hardness); packWriteDouble(stream, &material->reflection); packWriteDouble(stream, &material->shininess); + + packWriteDouble(stream, &material->receive_shadows); } void materialLoad(PackStream* stream, SurfaceMaterial* material) { - colorLoad(stream, &material->base); + packReadDouble(stream, &material->base.h); + packReadDouble(stream, &material->base.l); + packReadDouble(stream, &material->base.s); + + packReadDouble(stream, &material->hardness); packReadDouble(stream, &material->reflection); packReadDouble(stream, &material->shininess); + + packReadDouble(stream, &material->receive_shadows); + + materialValidate(material); +} + +void materialValidate(SurfaceMaterial* material) +{ + material->_rgb = colorFromHSL(material->base); } diff --git a/src/rendering/tools/lighting.h b/src/rendering/tools/lighting.h index f4c22b9..712c06a 100644 --- a/src/rendering/tools/lighting.h +++ b/src/rendering/tools/lighting.h @@ -11,16 +11,15 @@ extern "C" { typedef struct { - double hue; - double diffuse; - double hardness; + ColorHSL base; + double hardness; double reflection; double shininess; double receive_shadows; - Color base; + Color _rgb; } SurfaceMaterial; typedef struct @@ -51,6 +50,7 @@ Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 locatio void materialSave(PackStream* stream, SurfaceMaterial* material); void materialLoad(PackStream* stream, SurfaceMaterial* material); +void materialValidate(SurfaceMaterial* material); #ifdef __cplusplus } diff --git a/src/rendering/water/wat_definition.c b/src/rendering/water/wat_definition.c index b798759..f6ab384 100644 --- a/src/rendering/water/wat_definition.c +++ b/src/rendering/water/wat_definition.c @@ -16,6 +16,9 @@ static void _validateDefinition(WaterDefinition* definition) } noiseSetFunctionParams(definition->_waves_noise, NOISE_FUNCTION_SIMPLEX, -definition->turbulence, 0.0); noiseValidate(definition->_waves_noise); + + materialValidate(&definition->material); + materialValidate(&definition->foam_material); } static WaterDefinition* _createDefinition() diff --git a/src/rendering/water/wat_presets.c b/src/rendering/water/wat_presets.c index f23786e..26839bb 100644 --- a/src/rendering/water/wat_presets.c +++ b/src/rendering/water/wat_presets.c @@ -9,9 +9,7 @@ void waterAutoPreset(WaterDefinition* definition, WaterPreset preset) definition->transparency = 0.5; definition->reflection = 0.4; definition->transparency_depth = 4.0; - definition->material.base.r = 0.08; - definition->material.base.g = 0.15; - definition->material.base.b = 0.2; + definition->material.base = colorToHSL(colorFromValues(0.08, 0.15, 0.2, 1.0)); definition->depth_color.r = 0.0; definition->depth_color.g = 0.1; definition->depth_color.b = 0.1; @@ -27,9 +25,7 @@ void waterAutoPreset(WaterDefinition* definition, WaterPreset preset) definition->transparency = 0.4; definition->reflection = 0.35; definition->transparency_depth = 3.0; - definition->material.base.r = 0.05; - definition->material.base.g = 0.18; - definition->material.base.b = 0.2; + definition->material.base = colorToHSL(colorFromValues(0.05, 0.18, 0.2, 1.0)); definition->depth_color.r = 0.0; definition->depth_color.g = 0.18; definition->depth_color.b = 0.15; @@ -45,10 +41,7 @@ void waterAutoPreset(WaterDefinition* definition, WaterPreset preset) definition->material.base.a = 1.0; definition->material.reflection = 1.0; definition->material.shininess = 16.0; - definition->foam_material.base.r = 0.8; - definition->foam_material.base.g = 0.8; - definition->foam_material.base.b = 0.8; - definition->foam_material.base.a = 1.0; + definition->foam_material.base = colorToHSL(colorFromValues(0.8, 0.8, 0.8, 1.0)); definition->foam_material.reflection = 0.1; definition->foam_material.shininess = 1.5; diff --git a/src/rendering/water/wat_render.c b/src/rendering/water/wat_render.c index e6eeba1..bb93a32 100644 --- a/src/rendering/water/wat_render.c +++ b/src/rendering/water/wat_render.c @@ -291,7 +291,7 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z) /* Bring color to the camera */ color = renderer->applyMediumTraversal(renderer, location, color); - result.base = definition->material.base; + result.base = definition->material._rgb; result.final = color; return result;