Restored clouds rendering

This commit is contained in:
Michaël Lemaire 2013-12-18 22:09:35 +01:00
parent 3271b7ed5e
commit a3d2150349
2 changed files with 16 additions and 15 deletions

View file

@ -49,7 +49,7 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec
double ymin, ymax; double ymin, ymax;
int inside, segment_count; int inside, segment_count;
double current_total_length, current_inside_length; double current_total_length, current_inside_length;
double step_length, segment_length, remaining_length; double step_length, segment_length;
double noise_distance, last_noise_distance; double noise_distance, last_noise_distance;
Vector3 walker, step, segment_start; Vector3 walker, step, segment_start;
double render_precision; double render_precision;
@ -102,8 +102,8 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec
{ {
// entering the cloud // entering the cloud
inside = 1; inside = 1;
segment_length = step_length * noise_distance / (noise_distance - last_noise_distance); segment_length = 0.0;
segment_start = walker.add(direction.scale(-segment_length)); segment_start = walker;
current_inside_length += segment_length; current_inside_length += segment_length;
step = direction.scale(render_precision); step = direction.scale(render_precision);
} }
@ -113,12 +113,11 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec
if (inside) if (inside)
{ {
// exiting the cloud // exiting the cloud
remaining_length = step_length * last_noise_distance / (last_noise_distance - noise_distance); segment_length += step_length;
segment_length += remaining_length; current_inside_length += step_length;
current_inside_length += remaining_length;
out_segments->start = segment_start; out_segments->start = segment_start;
out_segments->end = walker.add(direction.scale(remaining_length - step_length)); out_segments->end = walker;
out_segments->length = segment_length; out_segments->length = segment_length;
out_segments++; out_segments++;
if (++segment_count >= max_segments) if (++segment_count >= max_segments)
@ -195,19 +194,20 @@ Color CloudBasicLayerRenderer::getColor(BaseCloudsModel *model, const Vector3 &e
bool CloudBasicLayerRenderer::alterLight(BaseCloudsModel *model, LightComponent* light, const Vector3 &, const Vector3 &location) bool CloudBasicLayerRenderer::alterLight(BaseCloudsModel *model, LightComponent* light, const Vector3 &, const Vector3 &location)
{ {
Vector3 start, end; Vector3 start, end, direction;
double inside_depth, total_depth, factor; double inside_depth, total_depth, factor;
CloudSegment segments[20]; CloudSegment segments[20];
start = location; start = location;
end = location.add(light->direction.scale(10000.0)); direction = light->direction.scale(-1.0);
end = location.add(direction.scale(10000.0));
if (not optimizeSearchLimits(model, &start, &end)) if (not optimizeSearchLimits(model, &start, &end))
{ {
return false; return false;
} }
double light_traversal = model->getLayer()->scaling * 1.3; double light_traversal = model->getLayer()->scaling * 1.3;
_findSegments(model, parent, start, light->direction, 0.1, 20, light_traversal, end.sub(start).getNorm(), &inside_depth, &total_depth, segments); _findSegments(model, parent, start, direction, 0.1, 20, light_traversal, end.sub(start).getNorm(), &inside_depth, &total_depth, segments);
if (light_traversal < 0.0001) if (light_traversal < 0.0001)
{ {
@ -222,7 +222,7 @@ bool CloudBasicLayerRenderer::alterLight(BaseCloudsModel *model, LightComponent*
} }
} }
double miminum_light = 0.2; double miminum_light = 0.3;
factor = 1.0 - (1.0 - miminum_light) * factor; factor = 1.0 - (1.0 - miminum_light) * factor;
light->color.r *= factor; light->color.r *= factor;

View file

@ -45,6 +45,7 @@ double CloudModelStratoCumulus::getDensity(const Vector3 &location) const
{ {
double val; double val;
double min_altitude, max_altitude; double min_altitude, max_altitude;
double noise_scaling = 12.0 * layer->scaling;
getAltitudeRange(&min_altitude, &max_altitude); getAltitudeRange(&min_altitude, &max_altitude);
@ -54,14 +55,14 @@ double CloudModelStratoCumulus::getDensity(const Vector3 &location) const
} }
else else
{ {
double x = location.x / (5.0 * layer->scaling); double x = location.x / noise_scaling;
double y = (location.y - min_altitude) / (5.0 * layer->scaling); double y = (location.y - min_altitude) / noise_scaling;
double z = location.z / (5.0 * layer->scaling); double z = location.z / noise_scaling;
//double coverage = layer->coverage * layer->_coverage_by_altitude->getValue((position.y - layer->altitude) / layer->scaling); //double coverage = layer->coverage * layer->_coverage_by_altitude->getValue((position.y - layer->altitude) / layer->scaling);
double coverage = layer->coverage; double coverage = layer->coverage;
val = 0.5 * noise->get3DTotal(x, y, z); val = 0.5 * noise->get3DTotal(x, y, z);
return val - 0.5 + coverage; return val - 0.9 + coverage;
} }
} }