diff --git a/src/gamedata/WaterModule.cpp b/src/gamedata/WaterModule.cpp index 12eb8ad..b10ce9e 100644 --- a/src/gamedata/WaterModule.cpp +++ b/src/gamedata/WaterModule.cpp @@ -233,7 +233,7 @@ WaterModule::WaterModule(flecs::world &ecs) texture_unit2->setTextureFiltering( Ogre::FT_MAG, Ogre::FO_LINEAR); texture_unit2->setTextureFiltering( - Ogre::FT_MIP, Ogre::FO_NONE); + Ogre::FT_MIP, Ogre::FO_LINEAR); #if 0 bool success = Ogre::RTShader::ShaderGenerator::getSingletonPtr() @@ -267,6 +267,7 @@ WaterModule::WaterModule(flecs::world &ecs) .getByName("Water/Above"); mat->load(); #endif + mat->load(); mat->setReceiveShadows(false); /* auto mat2 = diff --git a/water/water.frag b/water/water.frag index a77ff40..5093e92 100644 --- a/water/water.frag +++ b/water/water.frag @@ -6,14 +6,21 @@ SAMPLER2D(noiseMap, 1); #if NEW_WATER_SHADER MAIN_PARAMETERS IN(vec4 clipSpace, TEXCOORD0) +IN(vec2 textureCoords, TEXCOORD1) MAIN_DECLARATION { - // vec2 ndc = gl_FragCoord.xy / viewportSize.xy; vec2 ndc = clipSpace.xy / clipSpace.w / 2.0 + vec2(0.5, 0.5); - vec2 reflectionUV = vec2(ndc.x, 1.0 - ndc.y) * 0.5; - vec2 refractionUV = vec2(ndc.x, 1.0 - ndc.y) * 0.5 + vec2(0.5, 0.0); - vec4 reflectionColour = texture2D(reflectMap, reflectionUV); - vec4 refractionColour = texture2D(reflectMap, refractionUV); + vec2 distortion1 = texture2D(noiseMap, textureCoords).rg * 2.0 - vec2(1.0, 1.0); + vec2 distortion2 = texture2D(noiseMap, textureCoords * 5.0 + vec2(10202.0, 221.0)).rg * 2.0 - vec2(1.0, 1.0); + vec2 distortion3 = texture2D(noiseMap, textureCoords * 10.0 + vec2(1302.0, 721.0)).rg * 2.0 - vec2(1.0, 1.0); + vec2 reflectionUV = (vec2(ndc.x, 1.0 - ndc.y) + distortion1 * 0.035 + distortion2 * 0.02 + distortion3 * 0.01); + vec2 refractionUV = (vec2(ndc.x, 1.0 - ndc.y) + distortion1 * 0.035 + distortion2 * 0.02 + distortion3 * 0.01); + reflectionUV.x = clamp(reflectionUV.x, 0.001, 0.999); + reflectionUV.y = clamp(reflectionUV.y, 0.001, 0.999); + refractionUV.x = clamp(refractionUV.x, 0.001, 0.999); + refractionUV.y = clamp(refractionUV.y, 0.001, 0.999); + vec4 reflectionColour = texture2D(reflectMap, reflectionUV * 0.5); + vec4 refractionColour = texture2D(reflectMap, refractionUV * 0.5 + vec2(0.5, 0.0)); gl_FragColor = mix(reflectionColour, refractionColour, 0.5); } #else diff --git a/water/water.program b/water/water.program index fdd227e..5e9c6a6 100644 --- a/water/water.program +++ b/water/water.program @@ -91,6 +91,8 @@ fragment_program Water/water_fp glsl glsles glslang hlsl source water.frag default_params { + param_named reflectMap int 0 + param_named noiseMap int 1 } preprocessor_defines NEW_WATER_SHADER } diff --git a/water/water.vert b/water/water.vert index 8e8bf9b..70f07c7 100644 --- a/water/water.vert +++ b/water/water.vert @@ -28,13 +28,17 @@ uniform mat4 projectionMatrix; uniform mat4 viewMatrix; uniform mat4 modelMatrix; ) +const float tiling = 0.012; MAIN_PARAMETERS IN(vec4 position, POSITION) OUT(vec4 clipSpace, TEXCOORD0) +OUT(vec2 textureCoords, TEXCOORD1) MAIN_DECLARATION { clipSpace = projectionMatrix * viewMatrix * modelMatrix * vec4(position.xyz, 1.0); + vec4 worldPos = modelMatrix * vec4(position.xyz, 1.0); gl_Position = clipSpace; + textureCoords = vec2(worldPos.x / 2.0 + 0.5, worldPos.z / 2.0 + 0.5) * tiling; } #else