Refactored noise shader

This commit is contained in:
Michaël Lemaire 2014-01-21 21:41:15 +01:00
parent 25d9a95141
commit e79692bb5d
5 changed files with 20 additions and 8 deletions

View file

@ -27,6 +27,7 @@ void OpenGLWater::initialize()
program->addFragmentSource("bruneton");
program->addFragmentSource("tonemapping");
program->addFragmentSource("fadeout");
program->addFragmentSource("noise");
program->addFragmentSource("water");
setVertex(0, -1.0f, 0.0f, -1.0f);

View file

@ -87,4 +87,5 @@ OTHER_FILES += \
shaders/tonemapping.frag \
shaders/terrain.frag \
shaders/terrain.vert \
shaders/fadeout.frag
shaders/fadeout.frag \
shaders/noise.frag

View file

@ -0,0 +1,15 @@
uniform float noiseInitScaling;
uniform float noiseInitHeight;
uniform float noiseStepScaling;
uniform float noiseStepHeight;
uniform sampler2D simplexSampler;
vec3 noiseNormal2d(vec2 location, float detail)
{
vec3 normal = vec3(0.0, 0.0, 0.0);
for (float scaling = 1.0; scaling < 400.0; scaling *= 1.5)
{
normal += texture2D(simplexSampler, location * 0.01 * scaling).xyz;
}
return normalize(normal);
}

View file

@ -9,5 +9,6 @@
<file>terrain.frag</file>
<file>terrain.vert</file>
<file>fadeout.frag</file>
<file>noise.frag</file>
</qresource>
</RCC>

View file

@ -1,5 +1,4 @@
uniform vec4 waterColor;
uniform sampler2D simplexSampler;
uniform float waterReflection;
vec4 applyLighting(vec3 location, vec3 normal, vec4 color, float shininess)
@ -25,12 +24,7 @@ vec4 applyLighting(vec3 location, vec3 normal, vec4 color, float shininess)
void main(void)
{
vec3 normal = vec3(0.0, 0.0, 0.0);
for (float scaling = 1.0; scaling < 400.0; scaling *= 1.5)
{
normal += texture2D(simplexSampler, unprojected.xz * 0.01 * scaling).xyz;
}
normal = normalize(normal);
vec3 normal = noiseNormal2d(unprojected.xz, 0.001);
gl_FragColor = applyLighting(unprojected, normal, waterColor, 100.0);