Opened 8 years ago

Closed 8 years ago

Last modified 8 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 8 years ago.
0ad_water.gif (1.9 MB ) - added by elexis 8 years ago.
sample
water.diff (17.7 KB ) - added by aeonios 8 years ago.
water_r.png (228.7 KB ) - added by Vladislav Belov 8 years ago.
water_r2.png (172.4 KB ) - added by Vladislav Belov 8 years ago.

Change History (23)

comment:1 by Niek, 8 years ago

Keywords: patch review added

comment:2 by wraitii, 8 years ago

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 by gameboy, 8 years ago

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

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

comment:4 by elexis, 8 years ago

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 by aeonios, 8 years ago

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

by fatherbushido, 8 years ago

Attachment: errors.txt added

comment:6 by fatherbushido, 8 years ago

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

comment:7 by aeonios, 8 years ago

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.

by elexis, 8 years ago

Attachment: 0ad_water.gif added

sample

comment:8 by elexis, 8 years ago

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

Options:

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!

http://trac.wildfiregames.com/raw-attachment/ticket/3781/0ad_water.gif

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

comment:9 by wraitii, 8 years ago

I still believe refractions are not strong enough.

comment:10 by aeonios, 8 years ago

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 by fabio, 8 years ago

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

by aeonios, 8 years ago

Attachment: water.diff added

comment:12 by aeonios, 8 years ago

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 by elexis, 8 years ago

Keywords: review added

comment:14 by Itms, 8 years ago

Milestone: Alpha 20Alpha 21

by Vladislav Belov, 8 years ago

Attachment: water_r.png added

by Vladislav Belov, 8 years ago

Attachment: water_r2.png added

comment:15 by Vladislav Belov, 8 years ago

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

http://trac.wildfiregames.com/raw-attachment/ticket/3781/water_r.png

http://trac.wildfiregames.com/raw-attachment/ticket/3781/water_r2.png

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

comment:16 by gameboy, 8 years ago

Please contact aeonios, he will solve these problems.

comment:17 by wraitii, 8 years ago

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 by wraitii, 8 years ago

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