Water is now always at y=0.0
This commit is contained in:
parent
33c5d89783
commit
25d9a95141
13 changed files with 32 additions and 87 deletions
|
@ -183,7 +183,7 @@ void Scenery::checkCameraAboveGround()
|
|||
{
|
||||
Vector3 camera_location = camera->getLocation();
|
||||
double terrain_height = terrain->getInterpolatedHeight(camera_location.x, camera_location.z, 1, 1) + 2.0;
|
||||
double water_height = terrain->getWaterHeight() + 1.5;
|
||||
double water_height = 1.5;
|
||||
if (camera_location.y < water_height || camera_location.y < terrain_height)
|
||||
{
|
||||
double diff = ((water_height > terrain_height) ? water_height : terrain_height) - camera_location.y;
|
||||
|
|
|
@ -107,7 +107,7 @@ double TerrainDefinition::getInterpolatedHeight(double x, double z, int scaled,
|
|||
|
||||
if (scaled)
|
||||
{
|
||||
return h * height * scaling;
|
||||
return (h - water_height) * height * scaling;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -127,11 +127,6 @@ HeightInfo TerrainDefinition::getHeightInfo()
|
|||
return result;
|
||||
}
|
||||
|
||||
double TerrainDefinition::getWaterHeight()
|
||||
{
|
||||
return water_height * height * scaling;
|
||||
}
|
||||
|
||||
unsigned long TerrainDefinition::getMemoryStats()
|
||||
{
|
||||
return height_map->getMemoryStats();
|
||||
|
|
|
@ -31,7 +31,6 @@ public:
|
|||
double getInterpolatedHeight(double x, double z, int scaled, int with_painting);
|
||||
unsigned long getMemoryStats();
|
||||
HeightInfo getHeightInfo();
|
||||
double getWaterHeight();
|
||||
|
||||
public:
|
||||
typedef enum
|
||||
|
|
|
@ -33,7 +33,6 @@ QGLWidget(parent)
|
|||
_water = true;
|
||||
_wireframe = true;
|
||||
_painted_area = true;
|
||||
_water_height = 0.0;
|
||||
|
||||
_average_frame_time = 0.0;
|
||||
|
||||
|
@ -78,7 +77,6 @@ void WidgetHeightMap::setTerrain(TerrainDefinition* terrain)
|
|||
|
||||
_renderer->getScenery()->setTerrain(_terrain);
|
||||
_renderer->prepare();
|
||||
_water_height = _renderer->getTerrainRenderer()->getWaterHeight() / _terrain->scaling;
|
||||
|
||||
revert();
|
||||
}
|
||||
|
@ -466,10 +464,11 @@ void WidgetHeightMap::paintGL()
|
|||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(0.2, 0.3, 0.7, 0.7);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(_target_x - 500.0, _water_height, _target_z - 500.0);
|
||||
glVertex3f(_target_x - 500.0, _water_height, _target_z + 500.0);
|
||||
glVertex3f(_target_x + 500.0, _water_height, _target_z + 500.0);
|
||||
glVertex3f(_target_x + 500.0, _water_height, _target_z - 500.0);
|
||||
double water_height = _terrain->water_height * _terrain->scaling * _terrain->height;
|
||||
glVertex3f(_target_x - 500.0, water_height, _target_z - 500.0);
|
||||
glVertex3f(_target_x - 500.0, water_height, _target_z + 500.0);
|
||||
glVertex3f(_target_x + 500.0, water_height, _target_z + 500.0);
|
||||
glVertex3f(_target_x + 500.0, water_height, _target_z - 500.0);
|
||||
glEnd();
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
|
|
@ -61,7 +61,6 @@ private:
|
|||
|
||||
bool _dirty;
|
||||
|
||||
double _water_height;
|
||||
bool _water;
|
||||
bool _wireframe;
|
||||
bool _painted_area;
|
||||
|
|
|
@ -37,9 +37,6 @@ void OpenGLWater::initialize()
|
|||
|
||||
void OpenGLWater::update()
|
||||
{
|
||||
double water_height = renderer->getWaterRenderer()->getHeightInfo().max_height;
|
||||
renderer->getSharedState()->set("waterHeight", water_height);
|
||||
|
||||
Color water_color = renderer->getScenery()->getWater()->material->_rgb;
|
||||
renderer->getSharedState()->set("waterColor", water_color);
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const float GROUND_OFFSET = 0.5;
|
||||
const float Rg = 6360.0;
|
||||
const float Rt = 6420.0;
|
||||
const float RL = 6421.0;
|
||||
|
@ -188,11 +187,8 @@ vec3 _getInscatterColor(inout vec3 x, inout float t, vec3 v, vec3 s, out float r
|
|||
|
||||
vec4 applyAerialPerspective(vec4 base)
|
||||
{
|
||||
float yoffset = GROUND_OFFSET - waterHeight;
|
||||
vec3 camera = vec3(cameraLocation.x, max(cameraLocation.y + yoffset, 0.0), cameraLocation.z);
|
||||
vec3 location = vec3(unprojected.x, max(unprojected.y + yoffset, 0.0), unprojected.z);
|
||||
vec3 x = vec3(0.0, Rg + camera.y * WORLD_SCALING, 0.0);
|
||||
vec3 v = normalize(location - camera);
|
||||
vec3 x = vec3(0.0, Rg + cameraLocation.y * WORLD_SCALING, 0.0);
|
||||
vec3 v = normalize(unprojected - cameraLocation);
|
||||
vec3 s = normalize(sunDirection * SUN_DISTANCE_SCALED - x);
|
||||
|
||||
if (v.y == 0.0)
|
||||
|
@ -202,7 +198,7 @@ vec4 applyAerialPerspective(vec4 base)
|
|||
|
||||
float r = length(x);
|
||||
float mu = dot(x, v) / r;
|
||||
float t = length(location - camera) * WORLD_SCALING;
|
||||
float t = length(unprojected - cameraLocation) * WORLD_SCALING;
|
||||
|
||||
vec3 attenuation;
|
||||
vec3 inscattering = _getInscatterColor(x, t, v, s, r, mu, attenuation);
|
||||
|
@ -212,9 +208,7 @@ vec4 applyAerialPerspective(vec4 base)
|
|||
|
||||
vec4 getSkyColor(vec3 location, vec3 direction)
|
||||
{
|
||||
float yoffset = GROUND_OFFSET - waterHeight;
|
||||
vec3 camera = vec3(location.x, max(location.y + yoffset, 0.0), location.z);
|
||||
vec3 x = vec3(0.0, Rg + camera.y * WORLD_SCALING, 0.0);
|
||||
vec3 x = vec3(0.0, Rg + location.y * WORLD_SCALING, 0.0);
|
||||
vec3 v = normalize(direction);
|
||||
vec3 s = normalize(sunDirection * SUN_DISTANCE_SCALED - x);
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@ varying vec3 unprojected;
|
|||
|
||||
void main(void)
|
||||
{
|
||||
unprojected = vec3(cameraLocation.x + vertex.x * 500.0, vertex.y + waterHeight, cameraLocation.z + vertex.z * 500.0);
|
||||
unprojected = vec3(cameraLocation.x + vertex.x * 500.0, 0.0, cameraLocation.z + vertex.z * 500.0);
|
||||
gl_Position = viewMatrix * vec4(unprojected, 1.0);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double scaling
|
|||
double height;
|
||||
|
||||
height = getTerrainRenderer()->getHeight(x, y, 1);
|
||||
if (height > getTerrainRenderer()->getWaterHeight())
|
||||
if (height > 0.0)
|
||||
{
|
||||
return getTerrainRenderer()->getFinalColor(Vector3(x, height, y), 0.000001);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
/*********************** Constants ***********************/
|
||||
|
||||
#define GROUND_OFFSET 0.5
|
||||
static const double Rg = 6360.0;
|
||||
static const double Rt = 6420.0;
|
||||
static const double RL = 6421.0;
|
||||
|
@ -1156,12 +1155,6 @@ AtmosphereModelBruneton::AtmosphereModelBruneton(SoftwareRenderer *parent):
|
|||
|
||||
AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3 &direction, const Vector3 &sun_position, const Color &base)
|
||||
{
|
||||
double yoffset = GROUND_OFFSET - parent->getWaterRenderer()->getHeightInfo().base_height;
|
||||
eye.y += yoffset;
|
||||
if (eye.y < 0.0)
|
||||
{
|
||||
eye.y = 0.0;
|
||||
}
|
||||
Vector3 x = {0.0, Rg + eye.y * WORLD_SCALING, 0.0};
|
||||
Vector3 v = direction.normalize();
|
||||
Vector3 s = sun_position.sub(x).normalize();
|
||||
|
@ -1192,17 +1185,6 @@ AtmosphereResult AtmosphereModelBruneton::applyAerialPerspective(Vector3 locatio
|
|||
Vector3 eye = parent->getCameraLocation(location);
|
||||
Vector3 sun_position = parent->getAtmosphereRenderer()->getSunDirection().scale(SUN_DISTANCE);
|
||||
|
||||
double yoffset = GROUND_OFFSET - parent->getWaterRenderer()->getHeightInfo().base_height;
|
||||
eye.y += yoffset;
|
||||
location.y += yoffset;
|
||||
if (eye.y < 0.0)
|
||||
{
|
||||
eye.y = 0.0;
|
||||
}
|
||||
if (location.y < 0.0)
|
||||
{
|
||||
location.y = 0.0;
|
||||
}
|
||||
Vector3 direction = location.sub(eye).scale(WORLD_SCALING);
|
||||
|
||||
Vector3 x = {0.0, Rg + eye.y * WORLD_SCALING, 0.0};
|
||||
|
@ -1238,23 +1220,16 @@ void AtmosphereModelBruneton::fillLightingStatus(LightStatus *status, const Vect
|
|||
LightComponent sun, irradiance;
|
||||
double muS;
|
||||
|
||||
double altitude = status->getLocation().y;
|
||||
double altitude = status->getLocation().y * WORLD_SCALING;
|
||||
|
||||
double yoffset = GROUND_OFFSET - parent->getWaterRenderer()->getHeightInfo().base_height;
|
||||
altitude += yoffset;
|
||||
if (altitude < 0.0)
|
||||
{
|
||||
altitude = 0.0;
|
||||
}
|
||||
|
||||
double r0 = Rg + altitude * WORLD_SCALING;
|
||||
double r0 = Rg + altitude;
|
||||
Vector3 up = {0.0, 1.0, 0.0};
|
||||
Vector3 sun_position = parent->getAtmosphereRenderer()->getSunDirection().scale(SUN_DISTANCE);
|
||||
Vector3 x = {0.0, r0, 0.0};
|
||||
Vector3 s = sun_position.sub(x).normalize();
|
||||
|
||||
muS = up.dotProduct(s);
|
||||
if (altitude * WORLD_SCALING > RL)
|
||||
if (altitude > RL)
|
||||
{
|
||||
sun.color = parent->getScenery()->getAtmosphere()->sun_color;
|
||||
}
|
||||
|
|
|
@ -201,9 +201,3 @@ bool TerrainRenderer::applyLightFilter(LightComponent &light, const Vector3 &at)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
double TerrainRenderer::getWaterHeight()
|
||||
{
|
||||
TerrainDefinition* terrain = parent->getScenery()->getTerrain();
|
||||
return terrain->water_height * terrain->height * terrain->scaling;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ public:
|
|||
virtual double getHeight(double x, double z, int with_painting);
|
||||
virtual TerrainResult getResult(double x, double z, int with_painting, int with_textures);
|
||||
virtual Color getFinalColor(const Vector3 &location, double precision);
|
||||
virtual double getWaterHeight();
|
||||
virtual bool applyLightFilter(LightComponent &light, const Vector3 &at) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -21,12 +21,12 @@ void WaterRenderer::update()
|
|||
{
|
||||
}
|
||||
|
||||
static inline double _getHeight(WaterDefinition* definition, double base_height, double x, double z)
|
||||
static inline double _getHeight(WaterDefinition* definition, double x, double z)
|
||||
{
|
||||
return base_height + definition->_waves_noise->get2DTotal(x, z);
|
||||
return definition->_waves_noise->get2DTotal(x, z);
|
||||
}
|
||||
|
||||
static inline Vector3 _getNormal(WaterDefinition* definition, double base_height, Vector3 base, double detail)
|
||||
static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail)
|
||||
{
|
||||
Vector3 back, right;
|
||||
double x, z;
|
||||
|
@ -35,12 +35,12 @@ static inline Vector3 _getNormal(WaterDefinition* definition, double base_height
|
|||
z = base.z;
|
||||
|
||||
back.x = x;
|
||||
back.y = _getHeight(definition, base_height, x, z + detail);
|
||||
back.y = _getHeight(definition, x, z + detail);
|
||||
back.z = z + detail;
|
||||
back = back.sub(base);
|
||||
|
||||
right.x = x + detail;
|
||||
right.y = _getHeight(definition, base_height, x + detail, z);
|
||||
right.y = _getHeight(definition, x + detail, z);
|
||||
right.z = z;
|
||||
right = right.sub(base);
|
||||
|
||||
|
@ -76,33 +76,31 @@ static inline Color _getFoamMask(SoftwareRenderer* renderer, WaterDefinition* de
|
|||
{
|
||||
Color result;
|
||||
double foam_factor, normal_diff, location_offset;
|
||||
double base_height;
|
||||
|
||||
base_height = renderer->getTerrainRenderer()->getWaterHeight();
|
||||
location_offset = 2.0 * detail;
|
||||
|
||||
foam_factor = 0.0;
|
||||
location.x += location_offset;
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, location, detail));
|
||||
if (normal_diff > foam_factor)
|
||||
{
|
||||
foam_factor = normal_diff;
|
||||
}
|
||||
location.x -= location_offset * 2.0;
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, location, detail));
|
||||
if (normal_diff > foam_factor)
|
||||
{
|
||||
foam_factor = normal_diff;
|
||||
}
|
||||
location.x += location_offset;
|
||||
location.z -= location_offset;
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, location, detail));
|
||||
if (normal_diff > foam_factor)
|
||||
{
|
||||
foam_factor = normal_diff;
|
||||
}
|
||||
location.z += location_offset * 2.0;
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
|
||||
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, location, detail));
|
||||
if (normal_diff > foam_factor)
|
||||
{
|
||||
foam_factor = normal_diff;
|
||||
|
@ -145,7 +143,7 @@ HeightInfo WaterRenderer::getHeightInfo()
|
|||
HeightInfo info;
|
||||
double noise_minvalue, noise_maxvalue;
|
||||
|
||||
info.base_height = parent->getTerrainRenderer()->getWaterHeight();
|
||||
info.base_height = 0.0;
|
||||
definition->_waves_noise->getRange(&noise_minvalue, &noise_maxvalue);
|
||||
info.min_height = info.base_height + noise_minvalue;
|
||||
info.max_height = info.base_height + noise_maxvalue;
|
||||
|
@ -155,7 +153,7 @@ HeightInfo WaterRenderer::getHeightInfo()
|
|||
|
||||
double WaterRenderer::getHeight(double x, double z)
|
||||
{
|
||||
return _getHeight(parent->getScenery()->getWater(), parent->getTerrainRenderer()->getWaterHeight(), x, z);
|
||||
return _getHeight(parent->getScenery()->getWater(), x, z);
|
||||
}
|
||||
|
||||
WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
|
||||
|
@ -165,12 +163,10 @@ WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
|
|||
RayCastingResult refracted;
|
||||
Vector3 location, normal, look_direction;
|
||||
Color color, foam;
|
||||
double base_height, detail, depth;
|
||||
|
||||
base_height = parent->getTerrainRenderer()->getWaterHeight();
|
||||
double detail, depth;
|
||||
|
||||
location.x = x;
|
||||
location.y = _getHeight(definition, base_height, x, z);
|
||||
location.y = _getHeight(definition, x, z);
|
||||
location.z = z;
|
||||
result.location = location;
|
||||
|
||||
|
@ -180,7 +176,7 @@ WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
|
|||
detail = 0.00001;
|
||||
}
|
||||
|
||||
normal = _getNormal(definition, base_height, location, detail);
|
||||
normal = _getNormal(definition, location, detail);
|
||||
look_direction = location.sub(parent->getCameraLocation(location)).normalize();
|
||||
|
||||
/* Reflection */
|
||||
|
@ -242,14 +238,12 @@ bool WaterRenderer::applyLightFilter(LightComponent &light, const Vector3 &at)
|
|||
{
|
||||
WaterDefinition* definition = parent->getScenery()->getWater();
|
||||
double factor;
|
||||
double base_height;
|
||||
|
||||
base_height = parent->getTerrainRenderer()->getWaterHeight();
|
||||
if (at.y < base_height)
|
||||
if (at.y < 0.0)
|
||||
{
|
||||
if (light.direction.y <= -0.00001)
|
||||
{
|
||||
factor = (base_height - at.y) / (-light.direction.y * definition->lighting_depth);
|
||||
factor = -at.y / (-light.direction.y * definition->lighting_depth);
|
||||
if (factor > 1.0)
|
||||
{
|
||||
factor = 1.0;
|
||||
|
|
Loading…
Reference in a new issue