paysages3d/src/render/opengl/shaders/noise.frag

26 lines
760 B
GLSL
Raw Normal View History

2014-01-21 20:41:15 +00:00
uniform sampler2D simplexSampler;
vec3 noiseNormal2d(float[4] data, vec2 location, float detail)
2014-01-21 20:41:15 +00:00
{
vec3 normal = vec3(0.0, 0.0, 0.0);
float scaling = data[0];
float height = data[1];
float step_scaling = data[2];
float step_height = data[3];
while (height > detail)
2014-01-21 20:41:15 +00:00
{
// TODO offsets
2016-01-04 19:26:40 +00:00
// TODO parametrized texture scaling
2016-01-12 18:36:25 +00:00
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;
height *= step_height;
2014-01-21 20:41:15 +00:00
}
return normalize(normal);
}