HomeWildfire Games

Fix red squares on some maps when using HQ water effects
AuditedrP22310

Description

Fix red squares on some maps when using HQ water effects

This fixes an oversight in rp22297.

Reported By: gameboy

Differential Revision: https://code.wildfiregames.com/D1919

Event Timeline

This commit now has outstanding concerns.May 28 2019, 6:07 PM

actually it is water refraction effect causing it so now I am not sure if it exactly the same thing but it is red

Silier accepted this commit.EditedJun 3 2019, 3:07 PM

This is making my reported problem only more visible (refraction water effect). Adding screenshot before rP22297 . (Still dont know which revision cause it)

All concerns with this commit have now been addressed.Jun 3 2019, 3:07 PM
aeonios added a subscriber: aeonios.Jun 5 2019, 7:00 AM
In rP22310#33575, @Angen wrote:

actually it is water refraction effect causing it so now I am not sure if it exactly the same thing but it is red

Well, red water problems are a longstanding issue. It occurs when it tries to draw areas outside of the water during refraction, and appears at certain angles for reasons that aren't easy to explain but probably have to do with the hack used to produce refraction.

I noticed that red water issues got a lot worse after wraitii introduced a patch which interpolates between the base water image and a blurred version based on water depth. The way he did that really didn't make very good sense to begin with (should have just used a downscaled image rather than blurring in the shader), it's slow, and it causes other issues.

To be fair water has always been a pain to work with, as I know all too well.

In rP22310#33575, @Angen wrote:

actually it is water refraction effect causing it so now I am not sure if it exactly the same thing but it is red

Well, red water problems are a longstanding issue. It occurs when it tries to draw areas outside of the water during refraction, and appears at certain angles for reasons that aren't easy to explain but probably have to do with the hack used to produce refraction.

I noticed that red water issues got a lot worse after wraitii introduced a patch which interpolates between the base water image and a blurred version based on water depth. The way he did that really didn't make very good sense to begin with (should have just used a downscaled image rather than blurring in the shader), it's slow, and it causes other issues.

To be fair water has always been a pain to work with, as I know all too well.

Do you have a way to fix that ?

@vladislavbelov @wraitii

wraitii added a comment.EditedJun 5 2019, 10:09 AM

Well, red water problems are a longstanding issue. It occurs when it tries to draw areas outside of the water during refraction, and appears at certain angles for reasons that aren't easy to explain but probably have to do with the hack used to produce refraction.

There are cases where we also clip incorrectly (scissoring) and then we end up not re-drawing some area of the refraction texture we should be redrawing, which is annoying.

Indeed, since we're just rendering to a flat texture and then distorting that, introducing distortions forces one to have some hack for the fact that we'll sample from undrawn areas (which have been red for a while as that makes mistakes obvious... I could change that to some shade of blue and it'd be less visible).

I noticed that red water issues got a lot worse after wraitii introduced a patch which interpolates between the base water image and a blurred version based on water depth. The way he did that really didn't make very good sense to begin with (should have just used a downscaled image rather than blurring in the shader), it's slow, and it causes other issues.

I'm interested in more detail here. It's probably slower than downscaling, though iirc we ran into a limit with regards to the # of sampler here. That code could probably be removed though. I never noticed it really making the red-ness worse however.

vladislavbelov added a comment.EditedJun 5 2019, 2:20 PM

Well, red water problems are a longstanding issue. It occurs when it tries to draw areas outside of the water during refraction, and appears at certain angles for reasons that aren't easy to explain but probably have to do with the hack used to produce refraction.

Partially because of scissoring #2692, but also we have inaccurate refraction projection (inaccurate in relation to the real refraction angles). We may calculate it more carefully.

Indeed, since we're just rendering to a flat texture and then distorting that, introducing distortions forces one to have some hack for the fact that we'll sample from undrawn areas (which have been red for a while as that makes mistakes obvious... I could change that to some shade of blue and it'd be less visible).

Yeah, the single flat texture rendered from one point isn't enough to make a refraction from all possible angles.

In my experience AAA titles usually do not render "correct" refractions. They just use the same texture as for the whole scene (without additional pass), but clip it by height, distort and make a masking of leaking, instead of correct color picking.

Partially because of scissoring #2692, but also we have inaccurate refraction projection (inaccurate in relation to the real refraction angles). We may calculate it more carefully.

There really isn't a better way of doing that. Any given approximation of refraction isn't going to be much different from what we've got.

Scissoring is basically the reason for red-water issues though.

In my experience AAA titles usually do not render "correct" refractions. They just use the same texture as for the whole scene (without additional pass), but clip it by height, distort and make a masking of leaking, instead of correct color picking.

See, I probably would have implemented that already if I understood how they distort the image in a single pass without copying anything over. AFAIK if you read from and write to the same pixels in a pass then there's no way to guarantee sane results. Unless each pixel uses an independent read-write without requiring data from other pixels, unlike what we're doing here. If we did it that way we could eliminate the refraction map and just draw everything in one pass at full resolution.

Not that there aren't potential issues with doing things that way, but at least we'd be dealing with solvable problems in that case, and it would absolutely solve all the red water issues.

There really isn't a better way of doing that. Any given approximation of refraction isn't going to be much different from what we've got.

Yeah, that's what I'm talking about. It's just a little improvement. Though all these flat refraction maps are workarounds.

See, I probably would have implemented that already if I understood how they distort the image in a single pass without copying anything over.

AFAIK GTA 5 uses second pass to cut the only refracted area, add a depth color and distort it. HITMAN also does a blur a bit depending on depth.

AFAIK if you read from and write to the same pixels in a pass then there's no way to guarantee sane results.

True.