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:
parent
35e9d5d0bf
commit
501ccd10ba
7 changed files with 156 additions and 42 deletions
|
@ -975,7 +975,7 @@ A small entropy will make the noise repeat more often.</property>
|
||||||
<property name="border_width">5</property>
|
<property name="border_width">5</property>
|
||||||
<property name="row_spacing">5</property>
|
<property name="row_spacing">5</property>
|
||||||
<property name="column_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>
|
<property name="n_columns">2</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="label20">
|
<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">
|
<object class="GtkLabel" id="label23">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="label" translatable="yes">Base color</property>
|
<property name="label" translatable="yes">Surface color</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">0</property>
|
<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>
|
<property name="height">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</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>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
|
|
@ -170,12 +170,17 @@ void autoGenRealisticLandscape(int seed)
|
||||||
|
|
||||||
/* Water */
|
/* Water */
|
||||||
water.height = 0.0;
|
water.height = 0.0;
|
||||||
water.transparency = 0.4;
|
water.transparency = 0.5;
|
||||||
water.reflection = 0.5;
|
water.reflection = 0.3;
|
||||||
|
water.transparency_depth = 6.0;
|
||||||
water.main_color.r = 0.1;
|
water.main_color.r = 0.1;
|
||||||
water.main_color.g = 0.3;
|
water.main_color.g = 0.3;
|
||||||
water.main_color.b = 0.4;
|
water.main_color.b = 0.4;
|
||||||
water.main_color.a = 1.0;
|
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();
|
water.height_noise = noiseCreateGenerator();
|
||||||
noiseGenerateBaseNoise(water.height_noise, 262144);
|
noiseGenerateBaseNoise(water.height_noise, 262144);
|
||||||
noiseAddLevelsSimple(water.height_noise, 2, 0.2, 0.015);
|
noiseAddLevelsSimple(water.height_noise, 2, 0.2, 0.015);
|
||||||
|
|
|
@ -206,4 +206,5 @@ ColorGradation colorGradationLoad(FILE* f)
|
||||||
result.parts[i].col = colorLoad(f);
|
result.parts[i].col = colorLoad(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ static RayCastingResult _rayCastFromWater(Vector3 start, Vector3 direction)
|
||||||
{
|
{
|
||||||
RayCastingResult result;
|
RayCastingResult result;
|
||||||
double x, y;
|
double x, y;
|
||||||
|
|
||||||
result.hit = 1;
|
result.hit = 1;
|
||||||
if (direction.z < 0.0001)
|
if (direction.z < 0.0001)
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ static RayCastingResult _rayCastFromWater(Vector3 start, Vector3 direction)
|
||||||
{
|
{
|
||||||
x = start.x + direction.x * (0.0 - start.z) / direction.z;
|
x = start.x + direction.x * (0.0 - start.z) / direction.z;
|
||||||
y = start.y + direction.y * (0.0 - start.z) / direction.z;
|
y = start.y + direction.y * (0.0 - start.z) / direction.z;
|
||||||
|
|
||||||
if (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0))
|
if (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0))
|
||||||
{
|
{
|
||||||
result.hit_color = COLOR_WHITE;
|
result.hit_color = COLOR_WHITE;
|
||||||
|
@ -35,7 +35,7 @@ static RayCastingResult _rayCastFromWater(Vector3 start, Vector3 direction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* TODO hit_location */
|
/* TODO hit_location */
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ static Color _cbPreviewCoverage(SmallPreview* preview, double x, double y, doubl
|
||||||
{
|
{
|
||||||
Color result;
|
Color result;
|
||||||
double height;
|
double height;
|
||||||
|
|
||||||
height = terrainGetHeight(x, y);
|
height = terrainGetHeight(x, y);
|
||||||
if (height <= _definition.height)
|
if (height <= _definition.height)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ static Color _cbPreviewCoverage(SmallPreview* preview, double x, double y, doubl
|
||||||
{
|
{
|
||||||
result.r = result.g = result.b = terrainGetHeightNormalized(x, y);
|
result.r = result.g = result.b = terrainGetHeightNormalized(x, y);
|
||||||
result.a = 1.0;
|
result.a = 1.0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ static Color _cbPreviewRender(SmallPreview* preview, double x, double y, double
|
||||||
WaterDefinition definition;
|
WaterDefinition definition;
|
||||||
WaterEnvironment environment;
|
WaterEnvironment environment;
|
||||||
WaterQuality quality;
|
WaterQuality quality;
|
||||||
|
|
||||||
eye.x = 0.0;
|
eye.x = 0.0;
|
||||||
eye.y = scaling;
|
eye.y = scaling;
|
||||||
eye.z = -10.0 * scaling;
|
eye.z = -10.0 * scaling;
|
||||||
|
@ -72,12 +72,12 @@ static Color _cbPreviewRender(SmallPreview* preview, double x, double y, double
|
||||||
look.y = -y * 0.01 / scaling - 0.3;
|
look.y = -y * 0.01 / scaling - 0.3;
|
||||||
look.z = 1.0;
|
look.z = 1.0;
|
||||||
look = v3Normalize(look);
|
look = v3Normalize(look);
|
||||||
|
|
||||||
if (look.y > -0.0001)
|
if (look.y > -0.0001)
|
||||||
{
|
{
|
||||||
return _rayCastFromWater(eye, look).hit_color;
|
return _rayCastFromWater(eye, look).hit_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
location.x = eye.x - look.x * eye.y / look.y;
|
location.x = eye.x - look.x * eye.y / look.y;
|
||||||
location.y = 0.0;
|
location.y = 0.0;
|
||||||
location.z = eye.z - look.z * eye.y / look.y;
|
location.z = eye.z - look.z * eye.y / look.y;
|
||||||
|
@ -94,7 +94,7 @@ static Color _cbPreviewRender(SmallPreview* preview, double x, double y, double
|
||||||
environment.toggle_fog = 0;
|
environment.toggle_fog = 0;
|
||||||
environment.toggle_shadows = 0;
|
environment.toggle_shadows = 0;
|
||||||
quality.force_detail = 0.0001;
|
quality.force_detail = 0.0001;
|
||||||
|
|
||||||
return waterGetColorCustom(location, look, &definition, &quality, &environment).final;
|
return waterGetColorCustom(location, look, &definition, &quality, &environment).final;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ static void _cbEditNoise(GtkWidget* widget, gpointer data)
|
||||||
|
|
||||||
static void _cbHeightChanged(GtkRange* range, gpointer data)
|
static void _cbHeightChanged(GtkRange* range, gpointer data)
|
||||||
{
|
{
|
||||||
_definition.height = gtk_range_get_value(range);
|
_definition.height = gtk_range_get_value(range);
|
||||||
guiPreviewRedraw(_preview_coverage);
|
guiPreviewRedraw(_preview_coverage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,16 +127,36 @@ static void _cbReflectionChanged(GtkRange* range, gpointer data)
|
||||||
guiPreviewRedraw(_preview_render);
|
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)
|
static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data)
|
||||||
{
|
{
|
||||||
GdkRGBA col;
|
GdkRGBA col;
|
||||||
|
|
||||||
gtk_color_button_get_rgba(colorbutton, &col);
|
gtk_color_button_get_rgba(colorbutton, &col);
|
||||||
_definition.main_color.r = col.red;
|
_definition.main_color.r = col.red;
|
||||||
_definition.main_color.g = col.green;
|
_definition.main_color.g = col.green;
|
||||||
_definition.main_color.b = col.blue;
|
_definition.main_color.b = col.blue;
|
||||||
_definition.main_color.a = 1.0;
|
_definition.main_color.a = 1.0;
|
||||||
|
|
||||||
|
guiPreviewRedraw(_preview_render);
|
||||||
|
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_render);
|
||||||
guiPreviewRedraw(_preview_coverage);
|
guiPreviewRedraw(_preview_coverage);
|
||||||
}
|
}
|
||||||
|
@ -144,18 +164,24 @@ static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data)
|
||||||
static void _cbRevertConfig(GtkWidget* widget, gpointer data)
|
static void _cbRevertConfig(GtkWidget* widget, gpointer data)
|
||||||
{
|
{
|
||||||
GdkRGBA col;
|
GdkRGBA col;
|
||||||
|
|
||||||
waterCopyDefinition(waterGetDefinition(), &_definition);
|
waterCopyDefinition(waterGetDefinition(), &_definition);
|
||||||
|
|
||||||
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_height")), _definition.height);
|
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_transparency")), _definition.transparency);
|
||||||
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_reflection")), _definition.reflection);
|
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.red = _definition.main_color.r;
|
||||||
col.green = _definition.main_color.g;
|
col.green = _definition.main_color.g;
|
||||||
col.blue = _definition.main_color.b;
|
col.blue = _definition.main_color.b;
|
||||||
col.alpha = 1.0;
|
col.alpha = 1.0;
|
||||||
gtk_color_button_set_rgba(GTK_COLOR_BUTTON(GET_WIDGET("water_color")), &col);
|
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_render);
|
||||||
guiPreviewRedraw(_preview_coverage);
|
guiPreviewRedraw(_preview_coverage);
|
||||||
}
|
}
|
||||||
|
@ -169,23 +195,26 @@ static void _cbApplyConfig(GtkWidget* widget, gpointer data)
|
||||||
void guiWaterInit()
|
void guiWaterInit()
|
||||||
{
|
{
|
||||||
_definition = waterCreateDefinition();
|
_definition = waterCreateDefinition();
|
||||||
|
|
||||||
/* Buttons */
|
/* Buttons */
|
||||||
g_signal_connect(GET_WIDGET("water_noise_edit"), "clicked", G_CALLBACK(_cbEditNoise), NULL);
|
g_signal_connect(GET_WIDGET("water_noise_edit"), "clicked", G_CALLBACK(_cbEditNoise), NULL);
|
||||||
g_signal_connect(GET_WIDGET("water_apply"), "clicked", G_CALLBACK(_cbApplyConfig), NULL);
|
g_signal_connect(GET_WIDGET("water_apply"), "clicked", G_CALLBACK(_cbApplyConfig), NULL);
|
||||||
g_signal_connect(GET_WIDGET("water_revert"), "clicked", G_CALLBACK(_cbRevertConfig), NULL);
|
g_signal_connect(GET_WIDGET("water_revert"), "clicked", G_CALLBACK(_cbRevertConfig), NULL);
|
||||||
|
|
||||||
/* Configs */
|
/* Configs */
|
||||||
gtk_range_set_range(GTK_RANGE(GET_WIDGET("water_height")), -20.0, 20.0);
|
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_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_reflection")), 0.0, 1.0);
|
||||||
|
gtk_range_set_range(GTK_RANGE(GET_WIDGET("water_transparency_depth")), 0.0, 100.0);
|
||||||
|
|
||||||
/* Config signals */
|
/* Config signals */
|
||||||
g_signal_connect(GET_WIDGET("water_height"), "value-changed", G_CALLBACK(_cbHeightChanged), NULL);
|
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"), "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_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"), "color-set", G_CALLBACK(_cbColorChanged), NULL);
|
||||||
|
g_signal_connect(GET_WIDGET("water_color_depth"), "color-set", G_CALLBACK(_cbColorDepthChanged), NULL);
|
||||||
|
|
||||||
/* Previews */
|
/* Previews */
|
||||||
_preview_coverage = guiPreviewNew(GTK_IMAGE(GET_WIDGET("water_preview_coverage")));
|
_preview_coverage = guiPreviewNew(GTK_IMAGE(GET_WIDGET("water_preview_coverage")));
|
||||||
guiPreviewConfigScaling(_preview_coverage, 0.01, 1.0, 0.05);
|
guiPreviewConfigScaling(_preview_coverage, 0.01, 1.0, 0.05);
|
||||||
|
|
|
@ -192,8 +192,8 @@ void skyRender(RenderProgressCallback callback)
|
||||||
Color col;
|
Color col;
|
||||||
Vector3 direction;
|
Vector3 direction;
|
||||||
|
|
||||||
res_i = render_quality * 20;
|
res_i = render_quality * 40;
|
||||||
res_j = render_quality * 10;
|
res_j = render_quality * 20;
|
||||||
step_i = M_PI * 2.0 / (double)res_i;
|
step_i = M_PI * 2.0 / (double)res_i;
|
||||||
step_j = M_PI / (double)res_j;
|
step_j = M_PI / (double)res_j;
|
||||||
|
|
||||||
|
|
52
src/water.c
52
src/water.c
|
@ -13,13 +13,13 @@ static WaterEnvironment _environment;
|
||||||
static RayCastingResult _reflectionFunction(Vector3 start, Vector3 direction)
|
static RayCastingResult _reflectionFunction(Vector3 start, Vector3 direction)
|
||||||
{
|
{
|
||||||
RayCastingResult result;
|
RayCastingResult result;
|
||||||
|
|
||||||
if (!terrainProjectRay(start, direction, &result.hit_location, &result.hit_color))
|
if (!terrainProjectRay(start, direction, &result.hit_location, &result.hit_color))
|
||||||
{
|
{
|
||||||
result.hit_color = skyProjectRay(start, direction);
|
result.hit_color = skyProjectRay(start, direction);
|
||||||
/* TODO hit_location */
|
/* TODO hit_location */
|
||||||
}
|
}
|
||||||
|
|
||||||
result.hit = 1;
|
result.hit = 1;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,18 @@ static RayCastingResult _reflectionFunction(Vector3 start, Vector3 direction)
|
||||||
static RayCastingResult _refractionFunction(Vector3 start, Vector3 direction)
|
static RayCastingResult _refractionFunction(Vector3 start, Vector3 direction)
|
||||||
{
|
{
|
||||||
RayCastingResult result;
|
RayCastingResult result;
|
||||||
|
|
||||||
result.hit = terrainProjectRay(start, direction, &result.hit_location, &result.hit_color);
|
result.hit = terrainProjectRay(start, direction, &result.hit_location, &result.hit_color);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waterInit()
|
void waterInit()
|
||||||
{
|
{
|
||||||
_definition = waterCreateDefinition();
|
_definition = waterCreateDefinition();
|
||||||
|
|
||||||
/* TODO quality */
|
/* TODO quality */
|
||||||
|
|
||||||
_environment.reflection_function = _reflectionFunction;
|
_environment.reflection_function = _reflectionFunction;
|
||||||
_environment.refraction_function = _refractionFunction;
|
_environment.refraction_function = _refractionFunction;
|
||||||
_environment.toggle_fog = 1;
|
_environment.toggle_fog = 1;
|
||||||
|
@ -49,6 +49,8 @@ void waterSave(FILE* f)
|
||||||
{
|
{
|
||||||
toolsSaveDouble(f, _definition.height);
|
toolsSaveDouble(f, _definition.height);
|
||||||
colorSave(_definition.main_color, f);
|
colorSave(_definition.main_color, f);
|
||||||
|
colorSave(_definition.depth_color, f);
|
||||||
|
toolsSaveDouble(f, _definition.transparency_depth);
|
||||||
toolsSaveDouble(f, _definition.transparency);
|
toolsSaveDouble(f, _definition.transparency);
|
||||||
toolsSaveDouble(f, _definition.reflection);
|
toolsSaveDouble(f, _definition.reflection);
|
||||||
noiseSave(_definition.height_noise, f);
|
noiseSave(_definition.height_noise, f);
|
||||||
|
@ -58,6 +60,8 @@ void waterLoad(FILE* f)
|
||||||
{
|
{
|
||||||
_definition.height = toolsLoadDouble(f);
|
_definition.height = toolsLoadDouble(f);
|
||||||
_definition.main_color = colorLoad(f);
|
_definition.main_color = colorLoad(f);
|
||||||
|
_definition.depth_color = colorLoad(f);
|
||||||
|
_definition.transparency_depth = toolsLoadDouble(f);
|
||||||
_definition.transparency = toolsLoadDouble(f);
|
_definition.transparency = toolsLoadDouble(f);
|
||||||
_definition.reflection = toolsLoadDouble(f);
|
_definition.reflection = toolsLoadDouble(f);
|
||||||
noiseLoad(_definition.height_noise, f);
|
noiseLoad(_definition.height_noise, f);
|
||||||
|
@ -66,10 +70,10 @@ void waterLoad(FILE* f)
|
||||||
WaterDefinition waterCreateDefinition()
|
WaterDefinition waterCreateDefinition()
|
||||||
{
|
{
|
||||||
WaterDefinition result;
|
WaterDefinition result;
|
||||||
|
|
||||||
result.height = -1000.0;
|
result.height = -1000.0;
|
||||||
result.height_noise = noiseCreateGenerator();
|
result.height_noise = noiseCreateGenerator();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +85,7 @@ void waterDeleteDefinition(WaterDefinition definition)
|
||||||
void waterCopyDefinition(WaterDefinition source, WaterDefinition* destination)
|
void waterCopyDefinition(WaterDefinition source, WaterDefinition* destination)
|
||||||
{
|
{
|
||||||
NoiseGenerator* noise;
|
NoiseGenerator* noise;
|
||||||
|
|
||||||
noise = destination->height_noise;
|
noise = destination->height_noise;
|
||||||
*destination = source;
|
*destination = source;
|
||||||
destination->height_noise = noise;
|
destination->height_noise = noise;
|
||||||
|
@ -101,7 +105,7 @@ WaterDefinition waterGetDefinition()
|
||||||
void waterSetQuality(WaterQuality quality)
|
void waterSetQuality(WaterQuality quality)
|
||||||
{
|
{
|
||||||
_quality = quality;
|
_quality = quality;
|
||||||
|
|
||||||
_quality.detail_boost = (_quality.detail_boost < 0.1) ? 0.1 : _quality.detail_boost;
|
_quality.detail_boost = (_quality.detail_boost < 0.1) ? 0.1 : _quality.detail_boost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +143,7 @@ static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, doub
|
||||||
static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
|
static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
|
||||||
{
|
{
|
||||||
double c;
|
double c;
|
||||||
|
|
||||||
c = v3Dot(normal, v3Scale(incoming, -1.0));
|
c = v3Dot(normal, v3Scale(incoming, -1.0));
|
||||||
return v3Add(incoming, v3Scale(normal, 2.0 * c));
|
return v3Add(incoming, v3Scale(normal, 2.0 * c));
|
||||||
}
|
}
|
||||||
|
@ -147,7 +151,7 @@ static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
|
||||||
static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
|
static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
|
||||||
{
|
{
|
||||||
double c1, c2, f;
|
double c1, c2, f;
|
||||||
|
|
||||||
f = 1.0 / 1.33;
|
f = 1.0 / 1.33;
|
||||||
c1 = v3Dot(normal, v3Scale(incoming, -1.0));
|
c1 = v3Dot(normal, v3Scale(incoming, -1.0));
|
||||||
c2 = sqrt(1.0 - pow(f, 2.0) * (1.0 - pow(c1, 2.0)));
|
c2 = sqrt(1.0 - pow(f, 2.0) * (1.0 - pow(c1, 2.0)));
|
||||||
|
@ -164,10 +168,11 @@ static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
|
||||||
WaterResult waterGetColorCustom(Vector3 location, Vector3 look, WaterDefinition* definition, WaterQuality* quality, WaterEnvironment* environment)
|
WaterResult waterGetColorCustom(Vector3 location, Vector3 look, WaterDefinition* definition, WaterQuality* quality, WaterEnvironment* environment)
|
||||||
{
|
{
|
||||||
WaterResult result;
|
WaterResult result;
|
||||||
|
RayCastingResult refracted;
|
||||||
Vector3 normal;
|
Vector3 normal;
|
||||||
Color color;
|
Color color;
|
||||||
double shadowed, detail;
|
double shadowed, detail, depth;
|
||||||
|
|
||||||
if (definition == NULL)
|
if (definition == NULL)
|
||||||
{
|
{
|
||||||
definition = &_definition;
|
definition = &_definition;
|
||||||
|
@ -196,13 +201,26 @@ WaterResult waterGetColorCustom(Vector3 location, Vector3 look, WaterDefinition*
|
||||||
normal = _getNormal(definition, location, detail);
|
normal = _getNormal(definition, location, detail);
|
||||||
look = v3Normalize(look);
|
look = v3Normalize(look);
|
||||||
result.reflected = environment->reflection_function(location, _reflectRay(look, normal)).hit_color;
|
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.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;
|
color.g = definition->main_color.g * (1.0 - definition->transparency) + result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;
|
||||||
color.b = definition->main_color.b * (1.0 - definition->transparency) + result.reflected.b * definition->reflection + result.refracted.b * definition->transparency;
|
color.b = definition->main_color.b * (1.0 - definition->transparency) + result.reflected.b * definition->reflection + result.refracted.b * definition->transparency;
|
||||||
color.a = 1.0;
|
color.a = 1.0;
|
||||||
|
|
||||||
if (environment->toggle_shadows)
|
if (environment->toggle_shadows)
|
||||||
{
|
{
|
||||||
shadowed = terrainGetShadow(location, sun_direction_inv);
|
shadowed = terrainGetShadow(location, sun_direction_inv);
|
||||||
|
@ -311,7 +329,7 @@ void waterRender(RenderProgressCallback callback)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < chunk_count - 1; i++)
|
for (i = 0; i < chunk_count - 1; i++)
|
||||||
{
|
{
|
||||||
_renderQuad(cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size);
|
_renderQuad(cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size);
|
||||||
|
|
|
@ -10,6 +10,8 @@ typedef struct
|
||||||
double transparency;
|
double transparency;
|
||||||
double reflection;
|
double reflection;
|
||||||
Color main_color;
|
Color main_color;
|
||||||
|
Color depth_color;
|
||||||
|
double transparency_depth;
|
||||||
NoiseGenerator* height_noise;
|
NoiseGenerator* height_noise;
|
||||||
} WaterDefinition;
|
} WaterDefinition;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue