paysages: GUI for sky (WIP)

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@195 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2011-12-17 14:46:09 +00:00 committed by ThunderK
parent cb17818068
commit d61539e08d
6 changed files with 105 additions and 124 deletions

View file

@ -1173,6 +1173,7 @@ A small entropy will make the noise repeat more often.</property>
</child> </child>
<child> <child>
<object class="GtkImage" id="sky_colorgradient_sun"> <object class="GtkImage" id="sky_colorgradient_sun">
<property name="width_request">250</property>
<property name="height_request">20</property> <property name="height_request">20</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -1189,7 +1190,7 @@ A small entropy will make the noise repeat more often.</property>
<object class="GtkLabel" id="label30"> <object class="GtkLabel" id="label30">
<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">Sun apparent size</property> <property name="label" translatable="yes">Sun radius</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
@ -1228,6 +1229,7 @@ A small entropy will make the noise repeat more often.</property>
</child> </child>
<child> <child>
<object class="GtkImage" id="sky_colorgradient_zenith"> <object class="GtkImage" id="sky_colorgradient_zenith">
<property name="width_request">250</property>
<property name="height_request">20</property> <property name="height_request">20</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -1255,6 +1257,7 @@ A small entropy will make the noise repeat more often.</property>
</child> </child>
<child> <child>
<object class="GtkImage" id="sky_colorgradient_haze"> <object class="GtkImage" id="sky_colorgradient_haze">
<property name="width_request">250</property>
<property name="height_request">20</property> <property name="height_request">20</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -1338,7 +1341,7 @@ A small entropy will make the noise repeat more often.</property>
<property name="spacing">10</property> <property name="spacing">10</property>
<property name="layout_style">spread</property> <property name="layout_style">spread</property>
<child> <child>
<object class="GtkButton" id="water_apply1"> <object class="GtkButton" id="sky_apply">
<property name="label" translatable="yes">Apply</property> <property name="label" translatable="yes">Apply</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -1352,7 +1355,7 @@ A small entropy will make the noise repeat more often.</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="water_revert1"> <object class="GtkButton" id="sky_revert">
<property name="label" translatable="yes">Cancel</property> <property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -1427,6 +1430,9 @@ A small entropy will make the noise repeat more often.</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="model">clouds_layers_model</property> <property name="model">clouds_layers_model</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2"/>
</child>
<child> <child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3"> <object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="title" translatable="yes">Altitude</property> <property name="title" translatable="yes">Altitude</property>

View file

@ -184,6 +184,7 @@ void autoGenRealisticLandscape(int seed)
noiseDeleteGenerator(water.height_noise); noiseDeleteGenerator(water.height_noise);
/* Sky */ /* Sky */
sky.sun_color = colorGradationCreate();
sky.zenith_color = colorGradationCreate(); sky.zenith_color = colorGradationCreate();
colorGradationAddRgba(&sky.zenith_color, 0.2, 0.03, 0.03, 0.05, 1.0); colorGradationAddRgba(&sky.zenith_color, 0.2, 0.03, 0.03, 0.05, 1.0);
colorGradationAddRgba(&sky.zenith_color, 0.25, 0.25, 0.33, 0.37, 1.0); colorGradationAddRgba(&sky.zenith_color, 0.25, 0.25, 0.33, 0.37, 1.0);

View file

@ -29,6 +29,9 @@ void guiTerrainInit();
void guiWaterInit(); void guiWaterInit();
void guiWaterUpdate(); void guiWaterUpdate();
void guiSkyInit();
void guiSkyUpdate();
void guiCloudsInit(); void guiCloudsInit();
void guiCloudsUpdate(); void guiCloudsUpdate();

View file

@ -31,10 +31,10 @@ static void _cbLoad(GtkWidget* widget, gpointer data)
autoLoad(filename); autoLoad(filename);
g_free(filename); g_free(filename);
} }
/* Update all GUI */ /* Update all GUI */
guiUpdate(); guiUpdate();
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
} }
@ -85,6 +85,7 @@ void guiInit()
guiTerrainInit(); guiTerrainInit();
guiWaterInit(); guiWaterInit();
guiCloudsInit(); guiCloudsInit();
guiSkyInit();
} }
void guiStart() void guiStart()
@ -101,6 +102,7 @@ void guiUpdate()
{ {
guiWaterUpdate(); guiWaterUpdate();
guiCloudsUpdate(); guiCloudsUpdate();
guiSkyUpdate();
guiPreviewRedrawAll(); guiPreviewRedrawAll();
} }

View file

@ -11,167 +11,123 @@ static SkyDefinition _definition;
static Color _cbPreviewHorizon(SmallPreview* preview, double x, double y, double xoffset, double yoffset, double scaling) static Color _cbPreviewHorizon(SmallPreview* preview, double x, double y, double xoffset, double yoffset, double scaling)
{ {
Color result; Vector3 eye = {0.0, 0.0, 0.0};
double height; Vector3 look;
height = terrainGetHeight(x, y); look.x = x;
if (height <= _definition.height) look.y = -y;
{
return _definition.main_color;
}
else
{
result.r = result.g = result.b = terrainGetHeightNormalized(x, y);
result.a = 1.0;
return result;
}
}
static Color _cbPreviewRender(SmallPreview* preview, double x, double y, double xoffset, double yoffset, double scaling)
{
Vector3 eye, look, location;
WaterDefinition definition;
WaterEnvironment environment;
WaterQuality quality;
eye.x = 0.0;
eye.y = scaling;
eye.z = -10.0 * scaling;
look.x = x * 0.01 / scaling;
look.y = -y * 0.01 / scaling - 0.3;
look.z = 1.0; look.z = 1.0;
look = v3Normalize(look);
if (look.y > -0.0001) return skyGetColorCustom(eye, look, &_definition, NULL, NULL);
}
static inline void _updatePreview()
{
skyValidateDefinition(&_definition);
guiPreviewRedraw(_preview_horizon);
}
static void _redrawColorGradation(GtkImage* image, ColorGradation* gradation)
{
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 1, 8, 250, 20);
void* pixels = gdk_pixbuf_get_pixels(pixbuf);
int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
int x, y;
guint32* pixel;
Color col;
for (x = 0; x < 250; x++)
{ {
return _rayCastFromWater(eye, look).hit_color; for (y = 0; y < 20; y++)
{
pixel = (guint32*)(pixels + y * rowstride + x * 4);
col = colorGradationGet(gradation, (double)x / 250.0);
*pixel = (guint32)colorTo32BitRGBA(&col);
}
} }
location.x = eye.x - look.x * eye.y / look.y; gtk_image_set_from_pixbuf(image, pixbuf);
location.y = 0.0; gdk_pixbuf_unref(pixbuf);
location.z = eye.z - look.z * eye.y / look.y;
if (location.z > 0.0)
{
return _rayCastFromWater(eye, look).hit_color;
}
definition = _definition;
definition.height = 0.0;
environment.reflection_function = _rayCastFromWater;
environment.refraction_function = _rayCastFromWater;
environment.toggle_fog = 0;
environment.toggle_shadows = 0;
quality.force_detail = 0.0001;
return waterGetColorCustom(location, look, &definition, &quality, &environment).final;
} }
static void _cbEditNoiseDone(NoiseGenerator* generator) static void _cbDaytimeChanged(GtkRange* range, gpointer data)
{ {
noiseCopy(generator, _definition.height_noise); _definition.daytime = gtk_range_get_value(range);
guiPreviewRedraw(_preview_render); _updatePreview();
} }
static void _cbEditNoise(GtkWidget* widget, gpointer data) static void _cbSunSizeChanged(GtkRange* range, gpointer data)
{ {
guiNoiseEdit(_definition.height_noise, _cbEditNoiseDone); _definition.sun_radius = gtk_range_get_value(range);
_updatePreview();
} }
static void _cbHeightChanged(GtkRange* range, gpointer data) static void _cbHazeHeightChanged(GtkRange* range, gpointer data)
{ {
_definition.height = gtk_range_get_value(range); _definition.haze_height = gtk_range_get_value(range);
guiPreviewRedraw(_preview_coverage); _updatePreview();
} }
static void _cbTransparencyChanged(GtkRange* range, gpointer data) static void _cbHazeSmoothingChanged(GtkRange* range, gpointer data)
{ {
_definition.transparency = gtk_range_get_value(range); _definition.haze_smoothing = gtk_range_get_value(range);
guiPreviewRedraw(_preview_render); _updatePreview();
}
static void _cbReflectionChanged(GtkRange* range, gpointer data)
{
_definition.reflection = gtk_range_get_value(range);
guiPreviewRedraw(_preview_render);
}
static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data)
{
GdkRGBA col;
gtk_color_button_get_rgba(colorbutton, &col);
_definition.main_color.r = col.red;
_definition.main_color.g = col.green;
_definition.main_color.b = col.blue;
_definition.main_color.a = 1.0;
guiPreviewRedraw(_preview_render);
guiPreviewRedraw(_preview_coverage);
} }
static void _cbRevertConfig(GtkWidget* widget, gpointer data) static void _cbRevertConfig(GtkWidget* widget, gpointer data)
{ {
GdkRGBA col; skyCopyDefinition(skyGetDefinition(), &_definition);
waterCopyDefinition(waterGetDefinition(), &_definition); gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_daytime")), _definition.daytime);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_sun_size")), _definition.sun_radius);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_haze_height")), _definition.haze_height);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_haze_smoothing")), _definition.haze_smoothing);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_height")), _definition.height); _redrawColorGradation(GTK_IMAGE(GET_WIDGET("sky_colorgradient_sun")), &_definition.sun_color);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_transparency")), _definition.transparency); _redrawColorGradation(GTK_IMAGE(GET_WIDGET("sky_colorgradient_zenith")),& _definition.zenith_color);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_reflection")), _definition.reflection); _redrawColorGradation(GTK_IMAGE(GET_WIDGET("sky_colorgradient_haze")), &_definition.haze_color);
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);
guiPreviewRedraw(_preview_render); _updatePreview();
guiPreviewRedraw(_preview_coverage);
} }
static void _cbApplyConfig(GtkWidget* widget, gpointer data) static void _cbApplyConfig(GtkWidget* widget, gpointer data)
{ {
waterSetDefinition(_definition); skySetDefinition(_definition);
guiUpdate(); guiUpdate();
} }
void guiWaterInit() void guiSkyInit()
{ {
_definition = waterCreateDefinition(); _definition = skyCreateDefinition();
/* Buttons */ /* Buttons */
g_signal_connect(GET_WIDGET("water_noise_edit"), "clicked", G_CALLBACK(_cbEditNoise), NULL); g_signal_connect(GET_WIDGET("sky_apply"), "clicked", G_CALLBACK(_cbApplyConfig), NULL);
g_signal_connect(GET_WIDGET("water_apply"), "clicked", G_CALLBACK(_cbApplyConfig), NULL); g_signal_connect(GET_WIDGET("sky_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("sky_daytime")), 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("sky_sun_size")), 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("sky_haze_height")), 0.0, 1.0);
gtk_range_set_range(GTK_RANGE(GET_WIDGET("sky_haze_smoothing")), 0.0, 1.0);
/* Config signals */ /* Config signals */
g_signal_connect(GET_WIDGET("water_height"), "value-changed", G_CALLBACK(_cbHeightChanged), NULL); g_signal_connect(GET_WIDGET("sky_daytime"), "value-changed", G_CALLBACK(_cbDaytimeChanged), NULL);
g_signal_connect(GET_WIDGET("water_transparency"), "value-changed", G_CALLBACK(_cbTransparencyChanged), NULL); g_signal_connect(GET_WIDGET("sky_sun_size"), "value-changed", G_CALLBACK(_cbSunSizeChanged), NULL);
g_signal_connect(GET_WIDGET("water_reflection"), "value-changed", G_CALLBACK(_cbReflectionChanged), NULL); g_signal_connect(GET_WIDGET("sky_haze_height"), "value-changed", G_CALLBACK(_cbHazeHeightChanged), NULL);
g_signal_connect(GET_WIDGET("water_color"), "color-set", G_CALLBACK(_cbColorChanged), NULL); g_signal_connect(GET_WIDGET("sky_haze_smoothing"), "value-changed", G_CALLBACK(_cbHazeSmoothingChanged), NULL);
/* Previews */ /* Previews */
_preview_coverage = guiPreviewNew(GTK_IMAGE(GET_WIDGET("water_preview_coverage"))); _preview_horizon = guiPreviewNew(GTK_IMAGE(GET_WIDGET("sky_preview_horizon")));
guiPreviewConfigScaling(_preview_coverage, 0.01, 1.0, 0.05); guiPreviewConfigScaling(_preview_horizon, 0.01, 0.01, 0.0);
guiPreviewConfigScrolling(_preview_coverage, -1000.0, 1000.0, -1000.0, 1000.0); guiPreviewConfigScrolling(_preview_horizon, 0.0, 0.0, 0.0, 0.0);
guiPreviewSetViewport(_preview_coverage, 0.0, 0.0, 0.2); guiPreviewSetViewport(_preview_horizon, 0.0, 0.0, 0.01);
guiPreviewSetRenderer(_preview_coverage, _cbPreviewCoverage); guiPreviewSetRenderer(_preview_horizon, _cbPreviewHorizon);
_preview_render = guiPreviewNew(GTK_IMAGE(GET_WIDGET("water_preview_render")));
guiPreviewConfigScaling(_preview_render, 0.1, 1.0, 0.1);
guiPreviewConfigScrolling(_preview_render, -10.0, 10.0, -10.0, 10.0);
guiPreviewSetViewport(_preview_render, 0.0, 0.0, 0.5);
guiPreviewSetRenderer(_preview_render, _cbPreviewRender);
guiWaterUpdate(); guiSkyUpdate();
} }
void guiWaterUpdate() void guiSkyUpdate()
{ {
_cbRevertConfig(NULL, NULL); _cbRevertConfig(NULL, NULL);
} }

View file

@ -99,8 +99,21 @@ SkyDefinition skyGetDefinition()
Color skyGetColorCustom(Vector3 eye, Vector3 look, SkyDefinition* definition, SkyQuality* quality, SkyEnvironment* environment) Color skyGetColorCustom(Vector3 eye, Vector3 look, SkyDefinition* definition, SkyQuality* quality, SkyEnvironment* environment)
{ {
if (definition == NULL)
{
definition = &_definition;
}
if (quality == NULL)
{
quality = &_quality;
}
if (environment == NULL)
{
environment = &_environment;
}
look = v3Normalize(look); look = v3Normalize(look);
return colorGradationGet(&_definition._sky_gradation, look.y * 0.5 + 0.5); return colorGradationGet(&definition->_sky_gradation, look.y * 0.5 + 0.5);
} }
Color skyGetColor(Vector3 eye, Vector3 look) Color skyGetColor(Vector3 eye, Vector3 look)