paysages: Don't render underwater terrain quads.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@251 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-29 17:53:12 +00:00 committed by ThunderK
parent 23586ee5f4
commit e5a64ebf9f
7 changed files with 46 additions and 7 deletions

View file

@ -3,6 +3,7 @@
#include "lighting.h" #include "lighting.h"
RayCastingResult _RAYCASTING_NULL = {0}; RayCastingResult _RAYCASTING_NULL = {0};
HeightInfo _WATER_HEIGHT_INFO = {-1000000.0, -1000000.0, -1000000.0};
static Color _filterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) static Color _filterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light)
{ {
@ -29,6 +30,11 @@ static double _getTerrainHeight(Renderer* renderer, double x, double z)
return 0.0; return 0.0;
} }
static HeightInfo _getWaterHeightInfo(Renderer* renderer)
{
return _WATER_HEIGHT_INFO;
}
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{ {
return COLOR_TRANSPARENT; return COLOR_TRANSPARENT;
@ -71,6 +77,7 @@ Renderer rendererGetFake()
result.applyLightingToSurface = _applyLightingToSurface; result.applyLightingToSurface = _applyLightingToSurface;
result.rayWalking = _rayWalking; result.rayWalking = _rayWalking;
result.getTerrainHeight = _getTerrainHeight; result.getTerrainHeight = _getTerrainHeight;
result.getWaterHeightInfo = _getWaterHeightInfo;
result.applyTextures = _applyTextures; result.applyTextures = _applyTextures;
result.applyAtmosphere = _applyAtmosphere; result.applyAtmosphere = _applyAtmosphere;
result.applyClouds = _applyClouds; result.applyClouds = _applyClouds;

View file

@ -23,6 +23,7 @@ struct Renderer
/* Scenery related */ /* Scenery related */
RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds); RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds);
double (*getTerrainHeight)(Renderer* renderer, double x, double z); double (*getTerrainHeight)(Renderer* renderer, double x, double z);
HeightInfo (*getWaterHeightInfo)(Renderer* renderer);
Color (*applyTextures)(Renderer* renderer, Vector3 location, double precision); Color (*applyTextures)(Renderer* renderer, Vector3 location, double precision);
Color (*applyAtmosphere)(Renderer* renderer, Vector3 location, Color base); Color (*applyAtmosphere)(Renderer* renderer, Vector3 location, Color base);
Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end); Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end);

View file

@ -250,6 +250,11 @@ static double _getTerrainHeight(Renderer* renderer, double x, double z)
return terrainGetHeight(&_terrain, x, z); return terrainGetHeight(&_terrain, x, z);
} }
static HeightInfo _getWaterHeightInfo(Renderer* renderer)
{
return waterGetHeightInfo(&_water);
}
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{ {
return texturesGetColor(&_textures, renderer, location, precision); return texturesGetColor(&_textures, renderer, location, precision);
@ -306,6 +311,7 @@ Renderer sceneryGetStandardRenderer(int quality)
result.applyLightingToSurface = _applyLightingToSurface; result.applyLightingToSurface = _applyLightingToSurface;
result.rayWalking = _rayWalking; result.rayWalking = _rayWalking;
result.getTerrainHeight = _getTerrainHeight; result.getTerrainHeight = _getTerrainHeight;
result.getWaterHeightInfo = _getWaterHeightInfo;
result.applyTextures = _applyTextures; result.applyTextures = _applyTextures;
result.applyAtmosphere = _applyAtmosphere; result.applyAtmosphere = _applyAtmosphere;
result.applyClouds = _applyClouds; result.applyClouds = _applyClouds;

View file

@ -114,6 +114,13 @@ typedef struct
} RayCastingResult; } RayCastingResult;
typedef RayCastingResult (*RayCastingFunction)(Vector3 start, Vector3 direction); typedef RayCastingResult (*RayCastingFunction)(Vector3 start, Vector3 direction);
typedef struct
{
double min_height;
double max_height;
double base_height;
} HeightInfo;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -311,7 +311,7 @@ static Vertex _getFirstPassVertex(TerrainDefinition* definition, double x, doubl
return result; return result;
} }
static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, double x, double z, double size) static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, double x, double z, double size, double water_height)
{ {
Vertex v1, v2, v3, v4; Vertex v1, v2, v3, v4;
@ -319,7 +319,11 @@ static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, doubl
v2 = _getFirstPassVertex(definition, x, z + size, size); v2 = _getFirstPassVertex(definition, x, z + size, size);
v3 = _getFirstPassVertex(definition, x + size, z + size, size); v3 = _getFirstPassVertex(definition, x + size, z + size, size);
v4 = _getFirstPassVertex(definition, x + size, z, size); v4 = _getFirstPassVertex(definition, x + size, z, size);
renderPushQuad(renderer, &v1, &v2, &v3, &v4);
if (v1.location.y > water_height || v2.location.y > water_height || v3.location.y > water_height || v4.location.y > water_height)
{
renderPushQuad(renderer, &v1, &v2, &v3, &v4);
}
} }
double terrainGetHeight(TerrainDefinition* definition, double x, double z) double terrainGetHeight(TerrainDefinition* definition, double x, double z)
@ -352,6 +356,7 @@ void terrainRender(TerrainDefinition* definition, Renderer* renderer, RenderProg
double cz = renderer->camera_location.z; double cz = renderer->camera_location.z;
double min_chunk_size, visible_chunk_size; double min_chunk_size, visible_chunk_size;
double radius_int, radius_ext, chunk_size; double radius_int, radius_ext, chunk_size;
double water_height;
min_chunk_size = 0.1 / (double)renderer->render_quality; min_chunk_size = 0.1 / (double)renderer->render_quality;
visible_chunk_size = 0.05 / (double)renderer->render_quality; visible_chunk_size = 0.05 / (double)renderer->render_quality;
@ -361,7 +366,8 @@ void terrainRender(TerrainDefinition* definition, Renderer* renderer, RenderProg
radius_int = 0.0; radius_int = 0.0;
radius_ext = min_chunk_size; radius_ext = min_chunk_size;
chunk_size = min_chunk_size; chunk_size = min_chunk_size;
water_height = renderer->getWaterHeightInfo(renderer).max_height;
while (radius_ext < 1000.0) while (radius_ext < 1000.0)
{ {
@ -372,10 +378,10 @@ void terrainRender(TerrainDefinition* definition, Renderer* renderer, RenderProg
for (i = 0; i < chunk_count - 1; i++) for (i = 0; i < chunk_count - 1; i++)
{ {
_renderQuad(definition, renderer, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size); _renderQuad(definition, renderer, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size, water_height);
_renderQuad(definition, renderer, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size); _renderQuad(definition, renderer, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size, water_height);
_renderQuad(definition, renderer, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size); _renderQuad(definition, renderer, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size, water_height);
_renderQuad(definition, renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size); _renderQuad(definition, renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size, water_height);
} }
if (chunk_count % 64 == 0 && chunk_size / radius_int < visible_chunk_size) if (chunk_count % 64 == 0 && chunk_size / radius_int < visible_chunk_size)

View file

@ -136,6 +136,17 @@ static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
} }
} }
HeightInfo waterGetHeightInfo(WaterDefinition* definition)
{
HeightInfo info;
info.base_height = definition->height;
info.min_height = definition->height - noiseGetMaxValue(definition->waves_noise) * definition->waves_noise_height;
info.max_height = definition->height + noiseGetMaxValue(definition->waves_noise) * definition->waves_noise_height;
return info;
}
Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light) Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{ {
double factor; double factor;

View file

@ -43,6 +43,7 @@ void waterDeleteDefinition(WaterDefinition* definition);
void waterCopyDefinition(WaterDefinition* source, WaterDefinition* destination); void waterCopyDefinition(WaterDefinition* source, WaterDefinition* destination);
void waterValidateDefinition(WaterDefinition* definition); void waterValidateDefinition(WaterDefinition* definition);
HeightInfo waterGetHeightInfo(WaterDefinition* definition);
Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light); Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light);
WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer, Vector3 location, Vector3 look); WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer, Vector3 location, Vector3 look);
Color waterGetColor(WaterDefinition* definition, Renderer* renderer, Vector3 location, Vector3 look); Color waterGetColor(WaterDefinition* definition, Renderer* renderer, Vector3 location, Vector3 look);