2013-11-13 19:07:35 +00:00
|
|
|
#include "WaterDefinition.h"
|
|
|
|
|
|
|
|
#include "PackStream.h"
|
2014-01-21 20:51:11 +00:00
|
|
|
#include "NoiseState.h"
|
2013-11-13 19:07:35 +00:00
|
|
|
#include "Color.h"
|
|
|
|
#include "SurfaceMaterial.h"
|
2015-09-08 21:52:34 +00:00
|
|
|
#include "IntNode.h"
|
2015-09-07 23:00:34 +00:00
|
|
|
#include "FloatNode.h"
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
WaterDefinition::WaterDefinition(DefinitionNode *parent) : DefinitionNode(parent, "water", "water") {
|
2015-09-08 21:52:34 +00:00
|
|
|
model = new IntNode(this, "model", -1);
|
2015-09-07 23:00:34 +00:00
|
|
|
reflection = new FloatNode(this, "reflection");
|
2015-10-15 15:52:03 +00:00
|
|
|
xoffset = new FloatNode(this, "xoffset");
|
|
|
|
zoffset = new FloatNode(this, "zoffset");
|
2015-09-07 23:00:34 +00:00
|
|
|
|
2013-11-13 19:07:35 +00:00
|
|
|
material = new SurfaceMaterial;
|
|
|
|
depth_color = new Color;
|
|
|
|
foam_material = new SurfaceMaterial;
|
2014-01-21 20:51:11 +00:00
|
|
|
noise_state = new NoiseState();
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2013-11-13 22:03:02 +00:00
|
|
|
transparency_depth = 0.0;
|
|
|
|
transparency = 0.0;
|
|
|
|
lighting_depth = 0.0;
|
|
|
|
scaling = 1.0;
|
|
|
|
waves_height = 0.0;
|
|
|
|
detail_height = 0.0;
|
|
|
|
turbulence = 0.0;
|
|
|
|
foam_coverage = 0.0;
|
2015-09-08 21:52:34 +00:00
|
|
|
|
|
|
|
model->addWatcher(this, true);
|
2013-11-13 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
WaterDefinition::~WaterDefinition() {
|
2013-11-13 19:07:35 +00:00
|
|
|
delete material;
|
|
|
|
delete depth_color;
|
|
|
|
delete foam_material;
|
2014-01-21 20:51:11 +00:00
|
|
|
delete noise_state;
|
2013-11-13 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void WaterDefinition::save(PackStream *stream) const {
|
2015-08-12 20:21:10 +00:00
|
|
|
DefinitionNode::save(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
material->save(stream);
|
2013-12-11 09:24:35 +00:00
|
|
|
depth_color->save(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
stream->write(&transparency_depth);
|
|
|
|
stream->write(&transparency);
|
|
|
|
stream->write(&lighting_depth);
|
|
|
|
|
|
|
|
stream->write(&scaling);
|
|
|
|
stream->write(&waves_height);
|
|
|
|
stream->write(&detail_height);
|
|
|
|
stream->write(&turbulence);
|
|
|
|
|
|
|
|
stream->write(&foam_coverage);
|
2013-12-25 18:45:56 +00:00
|
|
|
foam_material->save(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2014-01-21 20:51:11 +00:00
|
|
|
noise_state->save(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void WaterDefinition::load(PackStream *stream) {
|
2015-08-12 20:21:10 +00:00
|
|
|
DefinitionNode::load(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
material->load(stream);
|
2013-12-11 09:24:35 +00:00
|
|
|
depth_color->load(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
stream->read(&transparency_depth);
|
|
|
|
stream->read(&transparency);
|
|
|
|
stream->read(&lighting_depth);
|
|
|
|
|
|
|
|
stream->read(&scaling);
|
|
|
|
stream->read(&waves_height);
|
|
|
|
stream->read(&detail_height);
|
|
|
|
stream->read(&turbulence);
|
|
|
|
|
|
|
|
stream->read(&foam_coverage);
|
2013-12-25 18:45:56 +00:00
|
|
|
foam_material->load(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2014-01-21 20:51:11 +00:00
|
|
|
noise_state->load(stream);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
|
|
|
validate();
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void WaterDefinition::copy(DefinitionNode *_destination) const {
|
2015-08-12 20:21:10 +00:00
|
|
|
DefinitionNode::copy(_destination);
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
WaterDefinition *destination = (WaterDefinition *)_destination;
|
2013-11-13 19:07:35 +00:00
|
|
|
*destination->material = *material;
|
|
|
|
*destination->depth_color = *depth_color;
|
|
|
|
destination->transparency_depth = transparency_depth;
|
|
|
|
destination->transparency = transparency;
|
|
|
|
destination->lighting_depth = lighting_depth;
|
|
|
|
destination->scaling = scaling;
|
|
|
|
destination->waves_height = waves_height;
|
|
|
|
destination->detail_height = detail_height;
|
|
|
|
destination->turbulence = turbulence;
|
|
|
|
destination->foam_coverage = foam_coverage;
|
|
|
|
*destination->foam_material = *foam_material;
|
2014-01-21 20:51:11 +00:00
|
|
|
noise_state->copy(destination->noise_state);
|
2013-11-13 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void WaterDefinition::validate() {
|
2015-08-12 20:21:10 +00:00
|
|
|
DefinitionNode::validate();
|
2013-11-13 19:07:35 +00:00
|
|
|
|
2015-09-08 21:52:34 +00:00
|
|
|
depth_color->a = 1.0;
|
|
|
|
material->base->a = 1.0;
|
|
|
|
material->reflection = 1.0;
|
|
|
|
material->shininess = 16.0;
|
|
|
|
material->hardness = 0.3;
|
|
|
|
foam_material->setColor(0.8, 0.8, 0.8, 1.0);
|
|
|
|
foam_material->reflection = 0.1;
|
|
|
|
foam_material->shininess = 1.5;
|
|
|
|
foam_material->hardness = 0.2;
|
|
|
|
|
2013-12-25 18:45:56 +00:00
|
|
|
material->validate();
|
|
|
|
foam_material->validate();
|
2013-11-13 19:07:35 +00:00
|
|
|
}
|
2013-11-13 22:03:02 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void WaterDefinition::nodeChanged(const DefinitionNode *node, const DefinitionDiff *) {
|
|
|
|
if (node == model) {
|
2015-09-08 21:52:34 +00:00
|
|
|
noise_state->randomizeOffsets();
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
switch (model->getValue()) {
|
2015-09-08 21:52:34 +00:00
|
|
|
case 1:
|
|
|
|
transparency = 0.3;
|
|
|
|
reflection->setValue(0.07);
|
|
|
|
transparency_depth = 3.0;
|
|
|
|
material->setColor(0.05, 0.18, 0.2, 1.0);
|
|
|
|
depth_color->r = 0.0;
|
|
|
|
depth_color->g = 0.18;
|
|
|
|
depth_color->b = 0.15;
|
|
|
|
lighting_depth = 4.0;
|
|
|
|
scaling = 1.5;
|
|
|
|
waves_height = 1.0;
|
|
|
|
detail_height = 0.06;
|
|
|
|
turbulence = 0.3;
|
|
|
|
foam_coverage = 0.4;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
transparency = 0.5;
|
|
|
|
reflection->setValue(0.2);
|
|
|
|
transparency_depth = 4.0;
|
|
|
|
material->setColor(0.08, 0.15, 0.2, 1.0);
|
|
|
|
depth_color->r = 0.0;
|
|
|
|
depth_color->g = 0.1;
|
|
|
|
depth_color->b = 0.1;
|
|
|
|
lighting_depth = 6.0;
|
|
|
|
scaling = 1.0;
|
|
|
|
waves_height = 0.8;
|
|
|
|
detail_height = 0.05;
|
|
|
|
turbulence = 0.1;
|
|
|
|
foam_coverage = 0.15;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-13 22:03:02 +00:00
|
|
|
|
2015-12-10 18:40:39 +00:00
|
|
|
void WaterDefinition::applyPreset(WaterPreset preset, RandomGenerator &random) {
|
2015-11-09 21:30:46 +00:00
|
|
|
if (preset == WATER_PRESET_LAKE) {
|
2015-09-08 21:52:34 +00:00
|
|
|
model->setValue(0);
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (preset == WATER_PRESET_SEA) {
|
2015-09-08 21:52:34 +00:00
|
|
|
model->setValue(1);
|
2013-11-13 22:03:02 +00:00
|
|
|
}
|
|
|
|
}
|