paysages: Added water depth color.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@198 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2011-12-19 20:59:39 +00:00 committed by ThunderK
parent 35e9d5d0bf
commit 501ccd10ba
7 changed files with 156 additions and 42 deletions

View file

@ -975,7 +975,7 @@ A small entropy will make the noise repeat more often.</property>
<property name="border_width">5</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<property name="n_rows">4</property>
<property name="n_rows">6</property>
<property name="n_columns">2</property>
<child>
<object class="GtkLabel" id="label20">
@ -1050,7 +1050,7 @@ A small entropy will make the noise repeat more often.</property>
<object class="GtkLabel" id="label23">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Base color</property>
<property name="label" translatable="yes">Surface color</property>
</object>
<packing>
<property name="left_attach">0</property>
@ -1092,6 +1092,65 @@ A small entropy will make the noise repeat more often.</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label28">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Depth color</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label32">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Depth limit</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="water_color_depth">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<property name="use_action_appearance">False</property>
<property name="title" translatable="yes">Choose a main water color</property>
<property name="rgba">rgb(0,0,0)</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkScale" id="water_transparency_depth">
<property name="width_request">250</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="round_digits">2</property>
<property name="digits">2</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>

View file

@ -170,12 +170,17 @@ void autoGenRealisticLandscape(int seed)
/* Water */
water.height = 0.0;
water.transparency = 0.4;
water.reflection = 0.5;
water.transparency = 0.5;
water.reflection = 0.3;
water.transparency_depth = 6.0;
water.main_color.r = 0.1;
water.main_color.g = 0.3;
water.main_color.b = 0.4;
water.main_color.a = 1.0;
water.depth_color.r = 0.0;
water.depth_color.g = 0.2;
water.depth_color.b = 0.3;
water.depth_color.a = 1.0;
water.height_noise = noiseCreateGenerator();
noiseGenerateBaseNoise(water.height_noise, 262144);
noiseAddLevelsSimple(water.height_noise, 2, 0.2, 0.015);

View file

@ -206,4 +206,5 @@ ColorGradation colorGradationLoad(FILE* f)
result.parts[i].col = colorLoad(f);
}
return result;
}

View file

@ -127,6 +127,12 @@ static void _cbReflectionChanged(GtkRange* range, gpointer data)
guiPreviewRedraw(_preview_render);
}
static void _cbTransparencyDepthChanged(GtkRange* range, gpointer data)
{
_definition.transparency_depth = gtk_range_get_value(range);
guiPreviewRedraw(_preview_render);
}
static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data)
{
GdkRGBA col;
@ -141,6 +147,20 @@ static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data)
guiPreviewRedraw(_preview_coverage);
}
static void _cbColorDepthChanged(GtkColorButton* colorbutton, gpointer data)
{
GdkRGBA col;
gtk_color_button_get_rgba(colorbutton, &col);
_definition.depth_color.r = col.red;
_definition.depth_color.g = col.green;
_definition.depth_color.b = col.blue;
_definition.depth_color.a = 1.0;
guiPreviewRedraw(_preview_render);
guiPreviewRedraw(_preview_coverage);
}
static void _cbRevertConfig(GtkWidget* widget, gpointer data)
{
GdkRGBA col;
@ -150,11 +170,17 @@ static void _cbRevertConfig(GtkWidget* widget, gpointer data)
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_height")), _definition.height);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_transparency")), _definition.transparency);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_reflection")), _definition.reflection);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_transparency_depth")), _definition.transparency_depth);
col.red = _definition.main_color.r;
col.green = _definition.main_color.g;
col.blue = _definition.main_color.b;
col.alpha = 1.0;
gtk_color_button_set_rgba(GTK_COLOR_BUTTON(GET_WIDGET("water_color")), &col);
col.red = _definition.depth_color.r;
col.green = _definition.depth_color.g;
col.blue = _definition.depth_color.b;
col.alpha = 1.0;
gtk_color_button_set_rgba(GTK_COLOR_BUTTON(GET_WIDGET("water_color_depth")), &col);
guiPreviewRedraw(_preview_render);
guiPreviewRedraw(_preview_coverage);
@ -179,12 +205,15 @@ void guiWaterInit()
gtk_range_set_range(GTK_RANGE(GET_WIDGET("water_height")), -20.0, 20.0);
gtk_range_set_range(GTK_RANGE(GET_WIDGET("water_transparency")), 0.0, 1.0);
gtk_range_set_range(GTK_RANGE(GET_WIDGET("water_reflection")), 0.0, 1.0);
gtk_range_set_range(GTK_RANGE(GET_WIDGET("water_transparency_depth")), 0.0, 100.0);
/* Config signals */
g_signal_connect(GET_WIDGET("water_height"), "value-changed", G_CALLBACK(_cbHeightChanged), NULL);
g_signal_connect(GET_WIDGET("water_transparency"), "value-changed", G_CALLBACK(_cbTransparencyChanged), NULL);
g_signal_connect(GET_WIDGET("water_transparency_depth"), "value-changed", G_CALLBACK(_cbTransparencyDepthChanged), NULL);
g_signal_connect(GET_WIDGET("water_reflection"), "value-changed", G_CALLBACK(_cbReflectionChanged), NULL);
g_signal_connect(GET_WIDGET("water_color"), "color-set", G_CALLBACK(_cbColorChanged), NULL);
g_signal_connect(GET_WIDGET("water_color_depth"), "color-set", G_CALLBACK(_cbColorDepthChanged), NULL);
/* Previews */
_preview_coverage = guiPreviewNew(GTK_IMAGE(GET_WIDGET("water_preview_coverage")));

View file

@ -192,8 +192,8 @@ void skyRender(RenderProgressCallback callback)
Color col;
Vector3 direction;
res_i = render_quality * 20;
res_j = render_quality * 10;
res_i = render_quality * 40;
res_j = render_quality * 20;
step_i = M_PI * 2.0 / (double)res_i;
step_j = M_PI / (double)res_j;

View file

@ -49,6 +49,8 @@ void waterSave(FILE* f)
{
toolsSaveDouble(f, _definition.height);
colorSave(_definition.main_color, f);
colorSave(_definition.depth_color, f);
toolsSaveDouble(f, _definition.transparency_depth);
toolsSaveDouble(f, _definition.transparency);
toolsSaveDouble(f, _definition.reflection);
noiseSave(_definition.height_noise, f);
@ -58,6 +60,8 @@ void waterLoad(FILE* f)
{
_definition.height = toolsLoadDouble(f);
_definition.main_color = colorLoad(f);
_definition.depth_color = colorLoad(f);
_definition.transparency_depth = toolsLoadDouble(f);
_definition.transparency = toolsLoadDouble(f);
_definition.reflection = toolsLoadDouble(f);
noiseLoad(_definition.height_noise, f);
@ -164,9 +168,10 @@ static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
WaterResult waterGetColorCustom(Vector3 location, Vector3 look, WaterDefinition* definition, WaterQuality* quality, WaterEnvironment* environment)
{
WaterResult result;
RayCastingResult refracted;
Vector3 normal;
Color color;
double shadowed, detail;
double shadowed, detail, depth;
if (definition == NULL)
{
@ -196,7 +201,20 @@ WaterResult waterGetColorCustom(Vector3 location, Vector3 look, WaterDefinition*
normal = _getNormal(definition, location, detail);
look = v3Normalize(look);
result.reflected = environment->reflection_function(location, _reflectRay(look, normal)).hit_color;
result.refracted = environment->refraction_function(location, _refractRay(look, normal)).hit_color;
refracted = environment->refraction_function(location, _refractRay(look, normal));
depth = v3Norm(v3Sub(location, refracted.hit_location));
if (depth > definition->transparency_depth)
{
result.refracted = definition->depth_color;
}
else
{
depth /= definition->transparency_depth;
result.refracted.r = refracted.hit_color.r * (1.0 - depth) + definition->depth_color.r * depth;
result.refracted.g = refracted.hit_color.g * (1.0 - depth) + definition->depth_color.g * depth;
result.refracted.b = refracted.hit_color.b * (1.0 - depth) + definition->depth_color.b * depth;
result.refracted.a = 1.0;
}
color.r = definition->main_color.r * (1.0 - definition->transparency) + result.reflected.r * definition->reflection + result.refracted.r * definition->transparency;
color.g = definition->main_color.g * (1.0 - definition->transparency) + result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;

View file

@ -10,6 +10,8 @@ typedef struct
double transparency;
double reflection;
Color main_color;
Color depth_color;
double transparency_depth;
NoiseGenerator* height_noise;
} WaterDefinition;