1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-02-24 07:22:58 +01:00

fix water noise function (ripples)

This commit is contained in:
XProger 2019-01-30 04:23:06 +03:00
parent 72e26d6b21
commit 12ce8db50e
3 changed files with 17 additions and 10 deletions

View File

@ -696,7 +696,7 @@ struct WaterCache {
vec2 s(item.size.x * DETAIL * 2.0f, item.size.z * DETAIL * 2.0f);
game->setShader(Core::passWater, Shader::WATER_SIMULATE);
Core::active.shader->setParam(uParam, vec4(0.995f, 1.0f, randf() * 0.5f, randf() * 0.5f));
Core::active.shader->setParam(uParam, vec4(0.995f, 1.0f, randf() * 0.5f, Core::params.x));
Core::active.shader->setParam(uTexParam, vec4(1.0f / item.data[0]->width, 1.0f / item.data[0]->height, s.x / item.data[0]->width, s.y / item.data[0]->height));
Core::active.shader->setParam(uRoomSize, vec4(1.0f / item.mask->origWidth, 1.0f / item.mask->origHeight, float(item.mask->origWidth) / item.mask->width, float(item.mask->origHeight) / item.mask->height));

View File

@ -660,11 +660,11 @@ namespace Core {
ditherTex = new Texture(8, 8, FMT_LUMINANCE, OPT_REPEAT | OPT_NEAREST, &ditherData);
// generate noise texture
uint8 *noiseData = new uint8[SQR(NOISE_TEX_SIZE)];
for (int i = 0; i < SQR(NOISE_TEX_SIZE); i++) {
uint8 *noiseData = new uint8[SQR(NOISE_TEX_SIZE) * 4];
for (int i = 0; i < SQR(NOISE_TEX_SIZE) * 4; i++) {
noiseData[i] = rand() % 255;
}
noiseTex = new Texture(NOISE_TEX_SIZE, NOISE_TEX_SIZE, FMT_LUMINANCE, OPT_REPEAT, noiseData);
noiseTex = new Texture(NOISE_TEX_SIZE, NOISE_TEX_SIZE, FMT_RGBA, OPT_REPEAT, noiseData);
delete[] noiseData;

View File

@ -114,6 +114,7 @@ vec3 calcNormal(vec2 tc, float base) {
return f + f0 * (1.0 - f);
}
#ifdef WATER_DROP
vec4 drop() {
vec2 v = texture2D(sNormal, vTexCoord).xy;
@ -123,14 +124,21 @@ vec3 calcNormal(vec2 tc, float base) {
return vec4(v, 0.0, 0.0);
}
#endif
#ifdef WATER_SIMULATE
float noise3(vec3 x) { // https://www.shadertoy.com/view/XslGRr
vec3 p = floor(x);
vec3 f = fract(x);
f = f * f * (3.0 - 2.0 * f);
vec2 uv = (p.xy + vec2(37.0, 17.0) * p.z) + f.xy;
vec2 rg = texture2D(sDiffuse, (uv + 0.5) / 32.0).yx;
return mix(rg.x, rg.y, f.z) * 2.0 - 1.0;
}
vec4 simulate() {
vec2 tc = vTexCoord;
if (texture2D(sMask, vMaskCoord).a < 0.5)
return vec4(0.0);
vec2 v = texture2D(sNormal, tc).xy; // height, speed
vec3 d = vec3(uTexParam.xy, 0.0);
@ -143,8 +151,8 @@ vec3 calcNormal(vec2 tc, float base) {
const float vis = 0.995;
v.y += (average - v.x) * vel;
v.y *= vis;
float noise = texture2D(sDiffuse, tc + uParam.zw * 0.5).x;
v.x += v.y + (noise * 2.0 - 1.0) * 0.00025;
v.x += v.y + noise3(vec3(tc * 32.0, uParam.w)) * 0.00025;
v *= texture2D(sMask, vMaskCoord).a;
return vec4(v.xy, 0.0, 0.0);
}
@ -161,7 +169,6 @@ vec3 calcNormal(vec2 tc, float base) {
#endif
#ifdef WATER_RAYS
float boxIntersect(vec3 rayPos, vec3 rayDir, vec3 center, vec3 hsize) {
center -= rayPos;
vec3 bMin = (center - hsize) / rayDir;