ho3/resources/shaders/water.fragment

55 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2024-06-06 13:25:38 +00:00
uniform samplerCube Env;
uniform sampler2D NormalMap;
uniform vec3 CamPos;
uniform float WaterTimer;
2024-06-08 20:24:26 +00:00
varying vec2 texCoord;
varying vec3 vertexPos;
2024-06-06 13:25:38 +00:00
varying vec3 camVec;
void main()
{
2024-06-08 20:24:26 +00:00
vec3 camVec2 = normalize(camVec);
2024-06-08 22:09:17 +00:00
/*camVec2.y = -camVec2.y;
2024-06-08 20:24:26 +00:00
vec4 reflectColor = textureCube(Env, camVec2);
gl_FragColor = vec4(reflectColor.xyz, 1.0f);
2024-06-08 22:09:17 +00:00
*/
2024-06-08 20:24:26 +00:00
2024-06-06 13:25:38 +00:00
mat3 rot;
rot[0] = vec3(0.0,0.0,1.0);
rot[1] = vec3(1.0,0.0,0.0);
rot[2] = vec3(0.0,1.0,0.0);
float sinx = 0.025*sin(WaterTimer+texCoord.x*5);
vec3 NVec1 = texture2D(NormalMap, vec2(-WaterTimer*0.04 + texCoord.x + sinx, -WaterTimer*0.04 + texCoord.y - sinx)).rgb;
vec3 NVec2 = texture2D(NormalMap, vec2( WaterTimer*0.04 + texCoord.y - sinx, -WaterTimer*0.04 + (1.0-texCoord.x) + sinx)).rgb;
NVec1 = (NVec1 -0.5) * 2.0;
NVec2 = (NVec2 -0.5) * 2.0;
vec3 NVec = NVec1 + NVec2;
vec3 NVecReflect = normalize(rot * (NVec1 + NVec2) + vec3(0,8,0));
vec3 NVecRefract = normalize(rot * (NVec1 + NVec2));
2024-06-08 20:24:26 +00:00
vec3 dir1 = reflect((camVec2),NVecReflect);
//vec3 dir2 = refract((camVec2),NVecRefract,0.9);
vec3 dir2 = reflect((camVec2),NVecReflect);
2024-06-06 13:25:38 +00:00
dir2.y = - dir2.y;
vec4 reflectColor = textureCube(Env, dir1);
vec4 refractColor = textureCube(Env, dir2);
2024-06-08 22:09:17 +00:00
vec4 texColor = reflectColor*0.5 + refractColor*0.5;
2024-06-06 13:25:38 +00:00
2024-06-08 22:09:17 +00:00
gl_FragColor = vec4(texColor.xyz, 1.0f);
2024-06-08 20:24:26 +00:00
2024-06-06 13:25:38 +00:00
}