paysages: Fixed specular lighting and clouds reflection on water.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@238 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-26 18:20:19 +00:00 committed by ThunderK
parent 912166fdba
commit d5d9ae219f
10 changed files with 28 additions and 20 deletions

View file

@ -72,7 +72,7 @@ public:
}; };
DialogRender::DialogRender(QWidget *parent): DialogRender::DialogRender(QWidget *parent):
QDialog(parent) QDialog(parent, Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint)
{ {
pixbuf = new QImage(1, 1, QImage::Format_ARGB32); pixbuf = new QImage(1, 1, QImage::Format_ARGB32);
_current_dialog = this; _current_dialog = this;

View file

@ -41,8 +41,7 @@ class PreviewTerrainColor:public Preview
public: public:
PreviewTerrainColor(QWidget* parent):Preview(parent) PreviewTerrainColor(QWidget* parent):Preview(parent)
{ {
// TODO Use custom renderer _renderer = rendererGetFake();
_renderer = sceneryGetStandardRenderer(3);
_preview_definition = terrainCreateDefinition(); _preview_definition = terrainCreateDefinition();
} }
protected: protected:

View file

@ -107,6 +107,7 @@ void autoGenRealisticLandscape(int seed)
noiseAddLevelSimple(cloud->noise, 50.0 / 800.0, 0.001); noiseAddLevelSimple(cloud->noise, 50.0 / 800.0, 0.001);
noiseAddLevelSimple(cloud->noise, 50.0 / 1000.0, 0.0005); noiseAddLevelSimple(cloud->noise, 50.0 / 1000.0, 0.0005);
scenerySetClouds(&clouds); scenerySetClouds(&clouds);
cloudsDeleteDefinition(&clouds);
/* Water */ /* Water */
water = waterCreateDefinition(); water = waterCreateDefinition();

View file

@ -422,7 +422,7 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
material.base = base; material.base = base;
material.reflection = 0.3; material.reflection = 0.3;
material.shininess = 0.1; material.shininess = 2.0;
return renderer->applyLightingToSurface(renderer, position, normal, material); return renderer->applyLightingToSurface(renderer, position, normal, material);
} }

View file

@ -23,6 +23,7 @@ void lightingInit()
_LIGHT_NULL.direction.y = 1.0; _LIGHT_NULL.direction.y = 1.0;
_LIGHT_NULL.direction.z = 0.0; _LIGHT_NULL.direction.z = 0.0;
_LIGHT_NULL.color = COLOR_BLACK; _LIGHT_NULL.color = COLOR_BLACK;
_LIGHT_NULL.reflection = 0.0;
_LIGHT_NULL.filtered = 0; _LIGHT_NULL.filtered = 0;
_LIGHT_NULL.masked = 0; _LIGHT_NULL.masked = 0;
_LIGHT_NULL.amplitude = 0.0; _LIGHT_NULL.amplitude = 0.0;
@ -38,6 +39,7 @@ void lightingSave(FILE* f, LightingDefinition* definition)
{ {
v3Save(definition->lights[i].direction, f); v3Save(definition->lights[i].direction, f);
colorSave(definition->lights[i].color, f); colorSave(definition->lights[i].color, f);
toolsSaveDouble(f, definition->lights[i].reflection);
toolsSaveInt(f, definition->lights[i].filtered); toolsSaveInt(f, definition->lights[i].filtered);
toolsSaveInt(f, definition->lights[i].masked); toolsSaveInt(f, definition->lights[i].masked);
toolsSaveDouble(f, definition->lights[i].amplitude); toolsSaveDouble(f, definition->lights[i].amplitude);
@ -54,6 +56,7 @@ void lightingLoad(FILE* f, LightingDefinition* definition)
{ {
definition->lights[i].direction = v3Load(f); definition->lights[i].direction = v3Load(f);
definition->lights[i].color = colorLoad(f); definition->lights[i].color = colorLoad(f);
definition->lights[i].reflection = toolsLoadDouble(f);
definition->lights[i].filtered = toolsLoadInt(f); definition->lights[i].filtered = toolsLoadInt(f);
definition->lights[i].masked = toolsLoadInt(f); definition->lights[i].masked = toolsLoadInt(f);
definition->lights[i].amplitude = toolsLoadDouble(f); definition->lights[i].amplitude = toolsLoadDouble(f);
@ -166,20 +169,20 @@ static Color _applyLightCustom(LightDefinition* definition, Renderer* renderer,
} }
normal = v3Normalize(normal); normal = v3Normalize(normal);
view = v3Normalize(v3Sub(location, renderer->camera_location));
reflect = v3Sub(v3Scale(normal, 2.0 * v3Dot(direction_inv, normal)), direction_inv);
diffuse = v3Dot(direction_inv, normal); diffuse = v3Dot(direction_inv, normal);
diffuse = pow(diffuse * 0.5 + 0.5, 2.0); //diffuse = pow(diffuse * 0.5 + 0.5, 2.0);
//diffuse = (diffuse * 0.5 + 0.5); diffuse = diffuse * 0.5 + 0.5;
if (diffuse > 0.0) if (diffuse > 0.0)
{ {
if (material.shininess > 0.0) if (material.shininess > 0.0 && definition->reflection > 0.0)
{ {
view = v3Normalize(v3Sub(location, renderer->camera_location));
reflect = v3Sub(direction_inv, v3Scale(normal, 2.0 * v3Dot(direction_inv, normal)));
specular = v3Dot(reflect, view) * material.reflection; specular = v3Dot(reflect, view) * material.reflection;
if (specular > 0.0) if (specular > 0.0)
{ {
specular = pow(specular, material.shininess * 10.0 + 1.0); specular = pow(specular, material.shininess);
} }
else else
{ {
@ -197,12 +200,12 @@ static Color _applyLightCustom(LightDefinition* definition, Renderer* renderer,
specular = 0.0; specular = 0.0;
} }
specular *= normal_norm; specular *= normal_norm * definition->reflection;
diffuse = 1.0 - normal_norm + diffuse * normal_norm; diffuse = 1.0 - normal_norm + diffuse * normal_norm;
result.r = material.base.r * diffuse * light.r + material.base.r * specular * light.r; result.r = material.base.r * diffuse * light.r + specular * light.r;
result.g = material.base.g * diffuse * light.g + material.base.g * specular * light.g; result.g = material.base.g * diffuse * light.g + specular * light.g;
result.b = material.base.b * diffuse * light.b + material.base.b * specular * light.b; result.b = material.base.b * diffuse * light.b + specular * light.b;
result.a = material.base.a; result.a = material.base.a;
return result; return result;

View file

@ -15,6 +15,7 @@ typedef struct
{ {
Vector3 direction; /* Global direction of the light */ Vector3 direction; /* Global direction of the light */
Color color; /* Main color of the light */ Color color; /* Main color of the light */
double reflection; /* Reflected factor of the light (for specular lighting) */
int filtered; /* Should the light be filtered (by atmosphere, water...) */ int filtered; /* Should the light be filtered (by atmosphere, water...) */
int masked; /* Should the light be masked (cast shadows..) */ int masked; /* Should the light be masked (cast shadows..) */
double amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */ double amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */

View file

@ -232,11 +232,13 @@ static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vecto
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds) static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
{ {
RayCastingResult result; RayCastingResult result;
Color sky_color;
if (!terrainProjectRay(&_terrain, renderer, location, direction, &result.hit_location, &result.hit_color)) if (!terrainProjectRay(&_terrain, renderer, location, direction, &result.hit_location, &result.hit_color))
{ {
result.hit_color = skyGetColor(&_sky, renderer, location, direction); sky_color = skyGetColor(&_sky, renderer, location, direction);
/* TODO hit_location */ result.hit_location = v3Add(location, v3Scale(direction, 1000.0));
result.hit_color = renderer->applyClouds(renderer, sky_color, location, result.hit_location);
} }
result.hit = 1; result.hit = 1;

View file

@ -99,6 +99,7 @@ int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)
/* Light from the sun */ /* Light from the sun */
lights[0].direction = v3Scale(sun_direction, -1.0); lights[0].direction = v3Scale(sun_direction, -1.0);
lights[0].color = colorGradationGet(&sky->sun_color, sky->daytime); lights[0].color = colorGradationGet(&sky->sun_color, sky->daytime);
lights[0].reflection = 1.0;
lights[0].filtered = 1; lights[0].filtered = 1;
lights[0].masked = 1; lights[0].masked = 1;
lights[0].amplitude = 0.0; lights[0].amplitude = 0.0;
@ -113,6 +114,7 @@ int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)
lights[1].color.r *= 0.4; lights[1].color.r *= 0.4;
lights[1].color.g *= 0.4; lights[1].color.g *= 0.4;
lights[1].color.b *= 0.4; lights[1].color.b *= 0.4;
lights[1].reflection = 0.0;
lights[1].filtered = 1; lights[1].filtered = 1;
lights[1].masked = 0; lights[1].masked = 0;
lights[1].amplitude = M_PI / 2.0; lights[1].amplitude = M_PI / 2.0;

View file

@ -221,7 +221,7 @@ Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* render
{ {
material.base = definition->color; material.base = definition->color;
material.reflection = 0.1; material.reflection = 0.1;
material.shininess = 0.1; material.shininess = 4.0;
result = renderer->applyLightingToSurface(renderer, location, normal, material); result = renderer->applyLightingToSurface(renderer, location, normal, material);
result.a = coverage; result.a = coverage;

View file

@ -199,8 +199,8 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
color.a = 1.0; color.a = 1.0;
material.base = color; material.base = color;
material.reflection = 0.8; material.reflection = 1.0;
material.shininess = 0.6; material.shininess = 12.0;
color = renderer->applyLightingToSurface(renderer, location, normal, material); color = renderer->applyLightingToSurface(renderer, location, normal, material);
color = renderer->applyAtmosphere(renderer, location, color); color = renderer->applyAtmosphere(renderer, location, color);