Smoothed water LOD in OpenGL

This commit is contained in:
Michaël Lemaire 2016-01-12 19:36:25 +01:00
parent c0a4e93c52
commit bf42b2bab8
2 changed files with 11 additions and 5 deletions

View file

@ -517,14 +517,14 @@ const Texture2D *NoiseFunctionSimplex::getNormalTexture() {
// TODO Make texture tileable // TODO Make texture tileable
double dx = to_double(x) / to_double(width); double dx = to_double(x) / to_double(width);
double dz = to_double(z) / to_double(height); double dz = to_double(z) / to_double(height);
double vcenter = noiseSimplexGet2DValue(scale * dx, scale * dz) - 0.5; double vcenter = noiseSimplexGet2DValue(scale * dx, scale * dz);
double vsouth = noiseSimplexGet2DValue(scale * dx, scale * dz + offset) - 0.5; double vsouth = noiseSimplexGet2DValue(scale * dx, scale * dz + offset);
double veast = noiseSimplexGet2DValue(scale * dx + offset, scale * dz) - 0.5; double veast = noiseSimplexGet2DValue(scale * dx + offset, scale * dz);
Vector3 normal = Geometry::getNormalFromTriangle( Vector3 normal = Geometry::getNormalFromTriangle(
Vector3(0.0, vcenter, 0.0), Vector3(0.0, vsouth, offset), Vector3(offset, veast, 0.0)); Vector3(0.0, vcenter, 0.0), Vector3(0.0, vsouth, offset), Vector3(offset, veast, 0.0));
_normalTexture->setPixel(x, z, Color(normal.x + 0.5, normal.y + 0.5, normal.z + 0.5)); _normalTexture->setPixel(x, z, Color(normal.x * 0.5 + 0.5, normal.y * 0.5 + 0.5, normal.z * 0.5 + 0.5));
} }
} }
} }

View file

@ -11,7 +11,13 @@ vec3 noiseNormal2d(float[4] data, vec2 location, float detail)
{ {
// TODO offsets // TODO offsets
// TODO parametrized texture scaling // TODO parametrized texture scaling
normal += texture(simplexSampler, location * scaling / 15.0).xyz - vec3(0.5); float factor;
if (height * step_height <= detail) {
factor = (height - detail) / (height - height * step_height);
} else {
factor = 1.0;
}
normal += (texture(simplexSampler, location * scaling / 15.0).xyz * 2.0 - 1.0) * factor;
scaling *= step_scaling; scaling *= step_scaling;
height *= step_height; height *= step_height;
} }