From 14d8b29666c297affe110398174ae66d8a1ee933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 3 Feb 2016 22:30:46 +0100 Subject: [PATCH] WIP on clouds --- src/definition/SurfaceMaterial.cpp | 4 ---- src/definition/SurfaceMaterial.h | 1 - src/definition/TextureLayerDefinition.cpp | 2 -- src/definition/VegetationModelDefinition.cpp | 2 -- src/definition/WaterDefinition.cpp | 3 --- src/render/software/CloudBasicLayerRenderer.cpp | 10 ++++++---- src/render/software/clouds/BaseCloudsModel.cpp | 3 ++- 7 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/definition/SurfaceMaterial.cpp b/src/definition/SurfaceMaterial.cpp index 306f4c1..c48e731 100644 --- a/src/definition/SurfaceMaterial.cpp +++ b/src/definition/SurfaceMaterial.cpp @@ -59,8 +59,4 @@ void SurfaceMaterial::copy(SurfaceMaterial *destination) const { destination->hardness = hardness; destination->reflection = reflection; destination->shininess = shininess; - destination->validate(); -} - -void SurfaceMaterial::validate() { } diff --git a/src/definition/SurfaceMaterial.h b/src/definition/SurfaceMaterial.h index 0b89557..843535b 100644 --- a/src/definition/SurfaceMaterial.h +++ b/src/definition/SurfaceMaterial.h @@ -20,7 +20,6 @@ class DEFINITIONSHARED_EXPORT SurfaceMaterial { void save(PackStream *stream) const; void load(PackStream *stream); void copy(SurfaceMaterial *destination) const; - void validate(); public: Color *base; diff --git a/src/definition/TextureLayerDefinition.cpp b/src/definition/TextureLayerDefinition.cpp index f43c9bc..4f84db3 100644 --- a/src/definition/TextureLayerDefinition.cpp +++ b/src/definition/TextureLayerDefinition.cpp @@ -30,8 +30,6 @@ TextureLayerDefinition::~TextureLayerDefinition() { void TextureLayerDefinition::validate() { DefinitionNode::validate(); - material->validate(); - // Update zone height range if (auto scenery = getScenery()) { TerrainDefinition *terrain = scenery->getTerrain(); diff --git a/src/definition/VegetationModelDefinition.cpp b/src/definition/VegetationModelDefinition.cpp index a0a5703..fad75d3 100644 --- a/src/definition/VegetationModelDefinition.cpp +++ b/src/definition/VegetationModelDefinition.cpp @@ -13,13 +13,11 @@ VegetationModelDefinition::VegetationModelDefinition(DefinitionNode *parent) : D solid_material->reflection = 0.002; solid_material->shininess = 1.0; solid_material->hardness = 0.3; - solid_material->validate(); foliage_material = new SurfaceMaterial(Color(0.4, 0.8, 0.45)); foliage_material->reflection = 0.007; foliage_material->shininess = 2.0; foliage_material->hardness = 0.2; - foliage_material->validate(); randomize(); } diff --git a/src/definition/WaterDefinition.cpp b/src/definition/WaterDefinition.cpp index 0f13b5d..1c17f72 100644 --- a/src/definition/WaterDefinition.cpp +++ b/src/definition/WaterDefinition.cpp @@ -103,9 +103,6 @@ void WaterDefinition::validate() { foam_material->reflection = 0.1; foam_material->shininess = 1.5; foam_material->hardness = 0.2; - - material->validate(); - foam_material->validate(); } void WaterDefinition::applyPreset(WaterPreset preset, RandomGenerator &random) { diff --git a/src/render/software/CloudBasicLayerRenderer.cpp b/src/render/software/CloudBasicLayerRenderer.cpp index 7b4e350..6d3b9a8 100644 --- a/src/render/software/CloudBasicLayerRenderer.cpp +++ b/src/render/software/CloudBasicLayerRenderer.cpp @@ -171,17 +171,19 @@ Color CloudBasicLayerRenderer::getColor(BaseCloudsModel *model, const Vector3 &e double transparency_depth = (ymax - ymin); SurfaceMaterial material(COLOR_WHITE.scaled(8.0)); - material.ambient = 0.8; material.hardness = 0.0; - material.reflection = 0.2; material.shininess = 3.0; - material.validate(); segment_count = findSegments(model, start, direction, 30, transparency_depth, max_length, &inside_length, &total_length, segments, 0.001); for (i = segment_count - 1; i >= 0; i--) { const Vector3 &location = segments[i].start; - col = parent->applyLightingToSurface(location, model->getNormal(location, 1.0), material); + Vector3 normal = model->getNormal(location, 1.0); + + material.ambient = 1.0 - normal.getNorm() * 0.2; + material.reflection = 0.2 * normal.getNorm(); + + col = parent->applyLightingToSurface(location, normal.normalize(), material); col.a = (segments[i].length >= transparency_depth) ? 1.0 : (segments[i].length / transparency_depth); result.mask(col); diff --git a/src/render/software/clouds/BaseCloudsModel.cpp b/src/render/software/clouds/BaseCloudsModel.cpp index 4210acd..ff38bed 100644 --- a/src/render/software/clouds/BaseCloudsModel.cpp +++ b/src/render/software/clouds/BaseCloudsModel.cpp @@ -1,5 +1,6 @@ #include "BaseCloudsModel.h" +#include "Maths.h" #include "CloudLayerDefinition.h" #include "Vector3.h" @@ -46,5 +47,5 @@ Vector3 BaseCloudsModel::getNormal(const Vector3 &location, double quality) cons normal = normal.add(_getPseudoNormal(this, location, VECTOR_WEST, base_density, precision)); normal = normal.add(_getPseudoNormal(this, location, VECTOR_NORTH, base_density, precision)); normal = normal.add(_getPseudoNormal(this, location, VECTOR_SOUTH, base_density, precision)); - return normal.normalize(); + return normal.normalize().scale(Maths::smoothstep(0.0, 1.0, normal.getNorm())); }