Added /atmosphere/humidity control

This commit is contained in:
Michaël Lemaire 2015-08-24 01:19:19 +02:00
parent 625507e11d
commit c199bef7f2
9 changed files with 73 additions and 33 deletions

View file

@ -8,6 +8,7 @@ AtmosphereDefinition::AtmosphereDefinition(DefinitionNode* parent):
DefinitionNode(parent, "atmosphere", "atmosphere") DefinitionNode(parent, "atmosphere", "atmosphere")
{ {
daytime = new FloatNode(this, "daytime"); daytime = new FloatNode(this, "daytime");
humidity = new FloatNode(this, "humidity");
} }
AtmosphereDefinition::~AtmosphereDefinition() AtmosphereDefinition::~AtmosphereDefinition()
@ -22,7 +23,6 @@ void AtmosphereDefinition::save(PackStream* stream) const
sun_color.save(stream); sun_color.save(stream);
stream->write(&sun_radius); stream->write(&sun_radius);
stream->write(&dome_lighting); stream->write(&dome_lighting);
stream->write(&humidity);
stream->write(&moon_radius); stream->write(&moon_radius);
stream->write(&moon_theta); stream->write(&moon_theta);
stream->write(&moon_phi); stream->write(&moon_phi);
@ -45,7 +45,6 @@ void AtmosphereDefinition::load(PackStream* stream)
sun_color.load(stream); sun_color.load(stream);
stream->read(&sun_radius); stream->read(&sun_radius);
stream->read(&dome_lighting); stream->read(&dome_lighting);
stream->read(&humidity);
stream->read(&moon_radius); stream->read(&moon_radius);
stream->read(&moon_theta); stream->read(&moon_theta);
stream->read(&moon_phi); stream->read(&moon_phi);
@ -78,7 +77,6 @@ void AtmosphereDefinition::copy(DefinitionNode* _destination) const
destination->sun_color = sun_color; destination->sun_color = sun_color;
destination->sun_radius = sun_radius; destination->sun_radius = sun_radius;
destination->dome_lighting = dome_lighting; destination->dome_lighting = dome_lighting;
destination->humidity = humidity;
destination->moon_radius = moon_radius; destination->moon_radius = moon_radius;
destination->moon_theta = moon_theta; destination->moon_theta = moon_theta;
destination->moon_phi = moon_phi; destination->moon_phi = moon_phi;
@ -125,7 +123,6 @@ void AtmosphereDefinition::applyPreset(AtmospherePreset preset)
moon_radius = 1.0; moon_radius = 1.0;
moon_theta = 0.3; moon_theta = 0.3;
moon_phi = 0.5; moon_phi = 0.5;
humidity = 0.1;
model = ATMOSPHERE_MODEL_BRUNETON; model = ATMOSPHERE_MODEL_BRUNETON;
@ -133,27 +130,29 @@ void AtmosphereDefinition::applyPreset(AtmospherePreset preset)
{ {
case ATMOSPHERE_PRESET_CLEAR_DAY: case ATMOSPHERE_PRESET_CLEAR_DAY:
setDayTime(15); setDayTime(15);
humidity->setValue(0.1);
dome_lighting = 0.2; dome_lighting = 0.2;
break; break;
case ATMOSPHERE_PRESET_CLEAR_SUNSET: case ATMOSPHERE_PRESET_CLEAR_SUNSET:
setDayTime(17, 45); setDayTime(17, 45);
humidity->setValue(0.1);
dome_lighting = 0.3; dome_lighting = 0.3;
sun_radius = 0.03; sun_radius = 0.03;
break; break;
case ATMOSPHERE_PRESET_HAZY_MORNING: case ATMOSPHERE_PRESET_HAZY_MORNING:
setDayTime(8, 30); setDayTime(8, 30);
humidity->setValue(0.4);
dome_lighting = 0.25; dome_lighting = 0.25;
humidity = 0.4;
break; break;
case ATMOSPHERE_PRESET_FOGGY: case ATMOSPHERE_PRESET_FOGGY:
setDayTime(15); setDayTime(15);
humidity->setValue(0.7);
dome_lighting = 0.1; dome_lighting = 0.1;
humidity = 0.7;
break; break;
case ATMOSPHERE_PRESET_STORMY: case ATMOSPHERE_PRESET_STORMY:
setDayTime(15); setDayTime(15);
humidity->setValue(0.9);
dome_lighting = 0.05; dome_lighting = 0.05;
humidity = 0.9;
break; break;
default: default:
; ;

View file

@ -46,6 +46,7 @@ public:
virtual void copy(DefinitionNode* destination) const override; virtual void copy(DefinitionNode* destination) const override;
inline FloatNode *propDayTime() const {return daytime;} inline FloatNode *propDayTime() const {return daytime;}
inline FloatNode *propHumidity() const {return humidity;}
/** /**
* Set the daytime from a 0.0-1.0 value. * Set the daytime from a 0.0-1.0 value.
@ -65,7 +66,7 @@ public:
public: public:
AtmosphereModel model; AtmosphereModel model;
double humidity;
Color sun_color; Color sun_color;
double sun_radius; double sun_radius;
double dome_lighting; double dome_lighting;
@ -77,6 +78,7 @@ public:
std::vector<Star> stars; std::vector<Star> stars;
private: private:
FloatNode *humidity;
FloatNode *daytime; FloatNode *daytime;
}; };

View file

@ -8,9 +8,11 @@
AtmosphereModeler::AtmosphereModeler(MainModelerWindow *main) AtmosphereModeler::AtmosphereModeler(MainModelerWindow *main)
{ {
prop_daytime = new FloatPropertyBind(main, "atmosphere_daytime", "value", main->getScenery()->getAtmosphere()->propDayTime()); prop_daytime = new FloatPropertyBind(main, "atmosphere_daytime", "value", main->getScenery()->getAtmosphere()->propDayTime());
prop_humidity = new FloatPropertyBind(main, "atmosphere_humidity", "value", main->getScenery()->getAtmosphere()->propHumidity());
} }
AtmosphereModeler::~AtmosphereModeler() AtmosphereModeler::~AtmosphereModeler()
{ {
delete prop_daytime; delete prop_daytime;
delete prop_humidity;
} }

View file

@ -14,6 +14,7 @@ public:
private: private:
FloatPropertyBind *prop_daytime; FloatPropertyBind *prop_daytime;
FloatPropertyBind *prop_humidity;
}; };
} }

View file

@ -13,6 +13,12 @@ BaseSection {
picture: "images/icon_atmosphere_daytime.png" picture: "images/icon_atmosphere_daytime.png"
hovertext: qsTr("Change the time of day") hovertext: qsTr("Change the time of day")
} }
ToolbarButton {
id: tool_humidity
picture: "images/icon_atmosphere_humidity.png"
hovertext: qsTr("Humidity factor in the air")
}
} }
PanelAtmosphereDaytime { PanelAtmosphereDaytime {
@ -21,6 +27,13 @@ BaseSection {
enabled: false enabled: false
} }
PanelSimpleFloat {
id: panel_humidity
anchors.left: toolbar.right
enabled: false
objectName: "atmosphere_humidity"
}
states: [ states: [
State { State {
name: "DayTime" name: "DayTime"
@ -29,6 +42,14 @@ BaseSection {
target: panel_daytime target: panel_daytime
enabled: true enabled: true
} }
},
State {
name: "Humidity"
when: tool_humidity.selected
PropertyChanges {
target: panel_humidity
enabled: true
}
} }
] ]
} }

View file

@ -0,0 +1,19 @@
import QtQuick 2.0
// Simple panel with a single float slider
BasePanel {
id: panel
property alias objectName: slider.objectName
property alias minimumValue: slider.minimumValue
property alias maximumValue: slider.maximumValue
width: 40
BaseSlider {
id: slider
minimumValue: 0
maximumValue: 1
orientation: Qt.Vertical
anchors.fill: parent
anchors.margins: 10
}
}

View file

@ -15,20 +15,13 @@ BaseSection {
} }
} }
BasePanel { PanelSimpleFloat {
id: panel_water_level id: panel_water_level
width: 40
anchors.left: toolbar.right
enabled: false enabled: false
anchors.left: toolbar.right
BaseSlider { minimumValue: -1
objectName: "water_height" maximumValue: 1
minimumValue: -1 objectName: "water_height"
maximumValue: 1
orientation: Qt.Vertical
anchors.fill: parent
anchors.margins: 10
}
} }
states: [ states: [

View file

@ -42,5 +42,6 @@
<file>WaterSection.qml</file> <file>WaterSection.qml</file>
<file>BaseSection.qml</file> <file>BaseSection.qml</file>
<file>AtmosphereSection.qml</file> <file>AtmosphereSection.qml</file>
<file>PanelSimpleFloat.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -33,7 +33,7 @@ static inline void _applyWeatherEffects(AtmosphereDefinition* definition, Atmosp
} }
double distance = result->distance; double distance = result->distance;
double max_distance = 100.0 - 90.0 * definition->humidity; double max_distance = 100.0 - 90.0 * definition->propHumidity()->getValue();
double distancefactor, dayfactor; double distancefactor, dayfactor;
if (distance > max_distance) if (distance > max_distance)
@ -44,33 +44,35 @@ static inline void _applyWeatherEffects(AtmosphereDefinition* definition, Atmosp
/* TODO Get day lighting from model */ /* TODO Get day lighting from model */
dayfactor = _getDayFactor(definition->propDayTime()->getValue()); dayfactor = _getDayFactor(definition->propDayTime()->getValue());
double humidity = definition->propHumidity()->getValue();
/* Fog masking */ /* Fog masking */
if (definition->humidity > 0.3) if (humidity > 0.3)
{ {
result->mask.r = result->mask.g = result->mask.b = (10.0 - 8.0 * definition->humidity) * dayfactor; result->mask.r = result->mask.g = result->mask.b = (10.0 - 8.0 * humidity) * dayfactor;
result->mask.a = distancefactor * (definition->humidity - 0.3) / 0.7; result->mask.a = distancefactor * (humidity - 0.3) / 0.7;
} }
/* Scattering tweaking */ /* Scattering tweaking */
if (definition->humidity < 0.15) if (humidity < 0.15)
{ {
/* Limit scattering on ultra clear day */ /* Limit scattering on ultra clear day */
double force = (0.15 - definition->humidity) / 0.15; double force = (0.15 - humidity) / 0.15;
result->inscattering.limitPower(100.0 - 90.0 * pow(force, 0.1)); result->inscattering.limitPower(100.0 - 90.0 * pow(force, 0.1));
} }
else else
{ {
/* Scattering boost */ /* Scattering boost */
double force = 1.2 * (definition->humidity < 0.5 ? sqrt((definition->humidity - 0.15) / 0.35) : 1.0 - (definition->humidity - 0.5) / 0.5); double force = 1.2 * (humidity < 0.5 ? sqrt((humidity - 0.15) / 0.35) : 1.0 - (humidity - 0.5) / 0.5);
result->inscattering.r *= 1.0 + force * distancefactor * (definition->humidity - 0.15) / 0.85; result->inscattering.r *= 1.0 + force * distancefactor * (humidity - 0.15) / 0.85;
result->inscattering.g *= 1.0 + force * distancefactor * (definition->humidity - 0.15) / 0.85; result->inscattering.g *= 1.0 + force * distancefactor * (humidity - 0.15) / 0.85;
result->inscattering.b *= 1.0 + force * distancefactor * (definition->humidity - 0.15) / 0.85; result->inscattering.b *= 1.0 + force * distancefactor * (humidity - 0.15) / 0.85;
} }
/* Attenuation */ /* Attenuation */
result->attenuation.r *= 1.0 - 0.4 * distancefactor * definition->humidity; result->attenuation.r *= 1.0 - 0.4 * distancefactor * humidity;
result->attenuation.g *= 1.0 - 0.4 * distancefactor * definition->humidity; result->attenuation.g *= 1.0 - 0.4 * distancefactor * humidity;
result->attenuation.b *= 1.0 - 0.4 * distancefactor * definition->humidity; result->attenuation.b *= 1.0 - 0.4 * distancefactor * humidity;
result->updateFinal(); result->updateFinal();
} }