Refactored noise shader
This commit is contained in:
parent
25d9a95141
commit
e79692bb5d
5 changed files with 20 additions and 8 deletions
|
@ -27,6 +27,7 @@ void OpenGLWater::initialize()
|
||||||
program->addFragmentSource("bruneton");
|
program->addFragmentSource("bruneton");
|
||||||
program->addFragmentSource("tonemapping");
|
program->addFragmentSource("tonemapping");
|
||||||
program->addFragmentSource("fadeout");
|
program->addFragmentSource("fadeout");
|
||||||
|
program->addFragmentSource("noise");
|
||||||
program->addFragmentSource("water");
|
program->addFragmentSource("water");
|
||||||
|
|
||||||
setVertex(0, -1.0f, 0.0f, -1.0f);
|
setVertex(0, -1.0f, 0.0f, -1.0f);
|
||||||
|
|
|
@ -87,4 +87,5 @@ OTHER_FILES += \
|
||||||
shaders/tonemapping.frag \
|
shaders/tonemapping.frag \
|
||||||
shaders/terrain.frag \
|
shaders/terrain.frag \
|
||||||
shaders/terrain.vert \
|
shaders/terrain.vert \
|
||||||
shaders/fadeout.frag
|
shaders/fadeout.frag \
|
||||||
|
shaders/noise.frag
|
||||||
|
|
15
src/render/opengl/shaders/noise.frag
Normal file
15
src/render/opengl/shaders/noise.frag
Normal 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);
|
||||||
|
}
|
|
@ -9,5 +9,6 @@
|
||||||
<file>terrain.frag</file>
|
<file>terrain.frag</file>
|
||||||
<file>terrain.vert</file>
|
<file>terrain.vert</file>
|
||||||
<file>fadeout.frag</file>
|
<file>fadeout.frag</file>
|
||||||
|
<file>noise.frag</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
uniform vec4 waterColor;
|
uniform vec4 waterColor;
|
||||||
uniform sampler2D simplexSampler;
|
|
||||||
uniform float waterReflection;
|
uniform float waterReflection;
|
||||||
|
|
||||||
vec4 applyLighting(vec3 location, vec3 normal, vec4 color, float shininess)
|
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)
|
void main(void)
|
||||||
{
|
{
|
||||||
vec3 normal = vec3(0.0, 0.0, 0.0);
|
vec3 normal = noiseNormal2d(unprojected.xz, 0.001);
|
||||||
for (float scaling = 1.0; scaling < 400.0; scaling *= 1.5)
|
|
||||||
{
|
|
||||||
normal += texture2D(simplexSampler, unprojected.xz * 0.01 * scaling).xyz;
|
|
||||||
}
|
|
||||||
normal = normalize(normal);
|
|
||||||
|
|
||||||
gl_FragColor = applyLighting(unprojected, normal, waterColor, 100.0);
|
gl_FragColor = applyLighting(unprojected, normal, waterColor, 100.0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue