Water: distortions
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user