Files
ogre-prototype/water/water.frag
2025-07-07 00:16:48 +03:00

33 lines
1.0 KiB
GLSL

OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
#include <OgreUnifiedShader.h>
// SAMPLER2D(noiseMap, 0);
SAMPLER2D(reflectMap, 0);
// SAMPLER2D(refractMap, 1);
OGRE_UNIFORMS(
uniform float renderTargetFlipping;
uniform vec4 viewportSize;
uniform f32vec4 cameraPosition;
)
MAIN_PARAMETERS
IN(f32vec3 positionWS, TEXCOORD0)
IN(f32vec3 vnormal, TEXCOORD1)
MAIN_DECLARATION
{
float flip = -renderTargetFlipping;
vec2 screenUV = gl_FragCoord.xy / viewportSize.xy;
#if !defined(OGRE_HLSL) && !defined(VULKAN)
screenUV.y = 1.0 - screenUV.y * 0.6 - 0.2;
#else
screenUV.y = screenUV.y * 0.6 + 0.2;
#endif
float depth = saturate(length(positionWS - cameraPosition.xyz) * 0.01);
vec4 reflectionColour = texture2D(reflectMap, screenUV * vec2(0.5, 1.0));
vec4 refractionColour = texture2D(reflectMap, screenUV * vec2(0.5, 1.0) + vec2(0.5, 0.0));
vec4 result = mix(mix(reflectionColour, refractionColour, 0.5), vec4(0.0, 1.0, 1.0, 1.0), depth);
float mul = dot(vec3(0.0, 1.0, 0.0), vnormal);
result = result * mul;
result.a = 1.0;
gl_FragColor = result;
}