Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#3781 closed enhancement (fixed)

[PATCH] Improved Water Rendering

Reported by: aeonios Owned by: wraitii
Priority: Nice to Have Milestone: Alpha 21
Component: Core engine Keywords: patch
Cc: Patch:

Description (last modified by elexis)

-Increases reflection and refraction texture sizes. -Changes the refraction function to be less extreme and to work better over a larger range of water depths. -Improves the reflection/fresnel function so that reflections fall off more naturally. -Reduces the intensity of sky reflections because the color is too extreme otherwise. -Reduces the distortion intensity for reflections to a more natural level.

-Cleans up the code a bit, removes old commented-out stuff and adds/improves comments in a few places.

Attachments (5)

errors.txt (857 bytes) - added by fatherbushido 4 years ago.
0ad_water.gif (1.9 MB) - added by elexis 4 years ago.
water.diff (17.7 KB) - added by aeonios 4 years ago.
water_r.png (228.7 KB) - added by Vladislav Belov 3 years ago.
water_r2.png (172.4 KB) - added by Vladislav Belov 3 years ago.

Change History (23)

comment:1 Changed 4 years ago by Niek

Keywords: patch review added

comment:2 Changed 4 years ago by wraitii

Code seems OK at first glance, I'll review the changes later, but there is one thing I'd suggest you go back on: refractions can actually benefit from a downscaled texture as it applies a rudimentary "blurring" effect, which looks better.

comment:3 Changed 4 years ago by gameboy

I have tested it, but I don't see the effect of the water and the sun on your image. why?

Last edited 4 years ago by gameboy (previous) (diff)

comment:4 Changed 4 years ago by elexis

When testing #3697, we also tested this patch, since it is included in attachment:trade-v2.3.patch:ticket:3697. All three of us got errors and water that was rendered completely black. It apparently has something to do with the user.cfg (likely the one of a19).

comment:5 Changed 4 years ago by aeonios

If you don't provide the error log then there's nothing I can do about it. :|

Changed 4 years ago by fatherbushido

Attachment: errors.txt added

comment:6 Changed 4 years ago by fatherbushido

aeonios : you won't get the errors while replaying ? I join the errors i got in console.

comment:7 Changed 4 years ago by aeonios

hmm.. that looks like the patch is not being applied properly, or perhaps was not created properly. The variable it's saying was not declared definitely has a declaration and is only used within the ifdef where it was declared, so a garbled file seems most likely. I have no idea why that would happen though.

Changed 4 years ago by elexis

Attachment: 0ad_water.gif added


comment:8 Changed 4 years ago by elexis

Description: modified (diff)
Keywords: review removed
  • With the latest patch after compiling:
ERROR: Failed to compile shader 'shaders/glsl/water_high.fs':
Fragment shader failed to compile with the following errors:
ERROR: 0:260: error(#143) Undeclared identifier: refColor
ERROR: 0:260: error(#202) No matching overloaded function found: mix
ERROR: 0:260: error(#160) Cannot convert from: "const float" to: "highp 3-component vector of vec3"
ERROR: 0:331: error(#143) Undeclared identifier: alphaCoeff
ERROR: error(#273) 4 compilation errors.  No code generated


waterfancyeffects = "true"
waternormals = "false"
waterrealdepth = "false"
waterreflection = "false"
waterrefraction = "false"
watershadows = "true"
waterugly = "false"

Switching some functions (in particular water-refraction) triggers errors too.

  • Why do you change things like ReflectionTextureSize to RefTextureSize? (Could the error even have something to do with this?) Ref reads less descriptive than Reflection.
  • Comments should start with capital letters
  • But the effect looks impressive and it should be committed in my opinion!

Last edited 4 years ago by elexis (previous) (diff)

comment:9 Changed 4 years ago by wraitii

I still believe refractions are not strong enough.

comment:10 Changed 4 years ago by aeonios

Ah, ok those errors are real and occurred due to reflection and refraction being disabled. I need to double check some things but that should be fixable.

The reason why I changed it from ReflectionTextureSize? to RefTextureSize? is because there used to be two separate values, ReflectionTextureSize? and RefractionTextureSize?, which is also why it's now simply 'ref' as in REFlection and REFraction.

wrt refractions I agree. The problem is getting them to be strong enough under low waviness/depth without causing pinching artifacts under high waviness/depth. I may try using a constant distortion factor and see how that works.

comment:11 Changed 4 years ago by fabio

I can confirm fatherbushido errors when enabling everything but Refractions. This config make water completely disappear.

Changed 4 years ago by aeonios

Attachment: water.diff added

comment:12 Changed 4 years ago by aeonios

I fixed the issue with the shader breaking when refraction is disabled. It now also obeys water murk color settings when refraction is disabled as well.

Fixed comments. (except one that starts with a variable name)

I also changed the distortion factor to be constant rather than depth based. Distortions should now be more noticeable in low waviness (to a point) and seems to work well enough on gold oasis and greek acropolis. With high waviness it's not too extreme, and taking depth out of the equation should fix some of the issues with fish.

I also managed to reduce the severity and frequency of red water issues. I think the reason that happens is because the refraction map is not rendering the water plane properly from certain angles (zoomed in or from off map), which causes what should be terrain to instead appear as pure red (the clear color). Previously it also tried distorting in the opposite direction when encountering out-of-bounds pixels, but that didn't seem to improve anything. Now I have it use entirely undistorted coords instead, which seems to work a bit better. A proper fix should be possible but I have no idea how long it'll take to track down exactly what's wrong.

comment:13 Changed 4 years ago by elexis

Keywords: review added

comment:14 Changed 4 years ago by Itms

Milestone: Alpha 20Alpha 21

Changed 3 years ago by Vladislav Belov

Attachment: water_r.png added

Changed 3 years ago by Vladislav Belov

Attachment: water_r2.png added

comment:15 Changed 3 years ago by Vladislav Belov

About the last patch (all options are enabled, Cycladic Islands & Golden Island):

  • water looks too transparent (need dependence of depth)
  • reflection looks a bit strange
  • need to test, but for me it seems a lower performance
  • windows eols, few comment and indent issues

Last edited 3 years ago by Vladislav Belov (previous) (diff)

comment:16 Changed 3 years ago by gameboy

Please contact aeonios, he will solve these problems.

comment:17 Changed 3 years ago by wraitii

Owner: set to wraitii
Resolution: fixed
Status: newclosed

In 18443:

Improve water rendering, partly based on a patch by aeonios, including:
-increase the size of the refraction and reflection texture
-blur the refraction map depending on depth

Fixes #3781

comment:18 Changed 3 years ago by wraitii

Keywords: review removed
Note: See TracTickets for help on using tickets.