Jump to content

Water Rendering


Recommended Posts

Speaking as the maintainer of the water code:

Seems like you managed to fix the weird inverted normal Issue I had which made specular wrong and I never bothered to fix. By this point I expect you have noticed I'm using real reflections for the skybox and distorting a transparent "reflection map" for objects that are near.

FYI the "artifacts" when you orient the wind north are dependent on graphic cards. It never happened for me on Intel GMA and I could never fix it because of that.

Make sure to test your code with all textures types and all waviness settings as there is a lot of room for mistakes there.

Likewise, the Red color that appears at low angle is WorkingAsDesigned and is there because of the distortion code. With the shader tries to get refraction texels that are "above water" pixel and contain garbage data. I detected this in the shader by checking the red component against the other one (the "horrible hack") and choosing the original undistorted texel in this case. However in some cases even that is insufficient. SO if you just remove the hack you're only going to break it further.

The red comes from the C++ code, the refraction texture is cleared with (255,0,0) before drawing the refraction. So when you fetch a pixel that's not rendered (above water) you get full red, which is why it happens on the edges of the map.

The proper fix for that problem is not trivial.

 

Also FYI the shore waves took me months of thinking to get somewhat right. I do not believe they are recomputed every frame, though, if they are it's an insane bug on my part. IIRC I create polygons by trying to follow the shore, but I never got it to work really well.

 

Edit: Oh yeah also I see you removed my comment about reflections being wrong at low angles far away, but the problem is still there. Just as an FYI, I still believe my "default to sky color" is the right way to go about this, but there is one thing to notice: since the normal map gets entirely blurry, the normal of the water plane becomes (0,1,0) ie straight vertical. But in real-life, you see the sky more because of the wave ripples. See my attached diagram. So that may be another thing to go after.

diagram.png

  • Like 2
Link to comment
Share on other sites

The fact that pixels outside of the water plane are cleared to red is helpful in figuring that out. I'll have to tinker with that now that I know the cause.

 

I was probably mistaken about it recalculating the shore line every frame. Shore waves are kind of expensive but probably for other reasons.

 

Also, why does the normal map become blurry? I didn't see any particular evidence of lod being used, although it might be, but the water plane should be taking the surface normals directly from the normal map (and normalized vectors are distance and angle independent). Also note that if the angle between the view vector and the surface normal is small (ie looking at the side of a wave) what you -should- get is more refraction and less reflection anyway. The old fresnel function was also kind of bad, being nearly linear when reflections should be more confined to grazing angles.

 

Another issue I found was that the addition of small waves on top of the large ones creates high frequency artifacts in the refractions (particularly with ocean waves). Removing them did not noticeably reduce wave details, but did remove the high freq noise. The small-wave-noise also made it look like the water was rushing along in a current rather than just being waves in a static body of water, and is a lot more noticeable with a high-res refraction map.

Link to comment
Share on other sites

Yeah, I'm aware of that last issue, but you're really free to change it if you think it looks better.

About the normal map point: The textures used at low angle, even with a lot of anisotropic filtering, end up being blurred at low angles, or are very "sharp" which looks even worse (basically either left or right here). You need at least 16x anisotropic filtering to keep it acceptable, and even then it's never really enough.

Also I might have done the linear fresnel thing on purpose: we as humans are used to seeing reflections on water, as we tend to look at water at a low angle. Looking at water from above with no reflections at all looks kind of odd, so I artificially made my water too reflective. You're right that looking at the side of a wave means more refraction, but because of the problem in my diagram above instead code usually shows reflections, which is basically entirely wrong.

 

Feel free to ask any other question.

  • Like 2
Link to comment
Share on other sites

13 hours ago, wraitii said:

Yeah, I'm aware of that last issue, but you're really free to change it if you think it looks better.

About the normal map point: The textures used at low angle, even with a lot of anisotropic filtering, end up being blurred at low angles, or are very "sharp" which looks even worse (basically either left or right here). You need at least 16x anisotropic filtering to keep it acceptable, and even then it's never really enough.

Also I might have done the linear fresnel thing on purpose: we as humans are used to seeing reflections on water, as we tend to look at water at a low angle. Looking at water from above with no reflections at all looks kind of odd, so I artificially made my water too reflective. You're right that looking at the side of a wave means more refraction, but because of the problem in my diagram above instead code usually shows reflections, which is basically entirely wrong.

 

Feel free to ask any other question.

I see what you mean about normal maps now. That would indeed be a limitation of normal maps since the water surface technically remains flat, but the reason I removed the comment is simply because I've never seen any visually disturbing artifacts as a result of that. It might occur on huge maps, but I've never actually seen any of those, either (not that I've seen every map for that matter).

 

The linear fresnel thing did indeed include reasoning, but I always found it to be visually disturbing. On the other hand I do see what you mean, since the water surface becomes invisible without any reflections at all (and irl the effective view angle would be distorted by lens effects). A more 'correct' solution would be to utilize a bias term in the fresnel approximation, which is what I ended up doing. The fresnel function I'm using currently looks like this:

 

fresnel = clamp(((pow(1.1 - ndotv, 3.0)) * 1.5), 0.2, 1.0);

where 3 is the power, 1.5 is the scale and 0.2 is applied as a bias through clamp. It ends up looking like this:

screenshot0006.thumb.png.7c884f07975db73

 

Actually I do have a relevant question. For some reason fish display 'ghost refractions' that aren't fully opaque even though the fish are. You can see it especially in the bottom right of this screenshot:

screenshot0007.thumb.png.4cbf289fd0d8816

I think that's probably the culprit of 'off-colored-fish' issues that people have reported, but I'm not sure why it only happens for fish and not terrain.

 

EDIT: Nevermind,  the discoloration is a problem with depth, and I'm not sure how to fix that properly. Basically it uses the depth of the fish but the texture of something else due to the displacement.

Edited by aeonios
  • Like 1
Link to comment
Share on other sites

Well, I figured out why that is. It's because 'water depth' is an approximation and not an accurate method for creating refractions. If the difference between the depth of the fish and the depth of the terrain behind them is large you end up with fish-shaped distortions. That's one of those 'only ray tracing can do that properly' effects, but I think I've got it to the point where it's pretty good nonetheless.

Link to comment
Share on other sites

3 hours ago, aeonios said:

Well, I figured out why that is. It's because 'water depth' is an approximation and not an accurate method for creating refractions. If the difference between the depth of the fish and the depth of the terrain behind them is large you end up with fish-shaped distortions. That's one of those 'only ray tracing can do that properly' effects, but I think I've got it to the point where it's pretty good nonetheless.

Yup, you're entirely right. I tried some stuffs to fix that but it just added more problems. I'm quite interested in your patch, looks good.

Re normal maps: there are no visual artifacts. There's only a visual "issue" that you see flat reflections instead of seeing what you should see (a mix of water color and sky). Check out this picture, we see very little reflection in the distance, as the water isn't flat. Compare with this. And in-game in the attached picture. It only ever happens at low angles, but it looks very bad on cinematic shots.

Capture d’écran 2016-02-12 à 07.59.58.png

  • Like 2
Link to comment
Share on other sites

17 minutes ago, niektb said:

I was wondering, from a scenario designer POV, how does this affect the 'murkiness' option in Atlas?

Not at all. At first I thought there was some problem with excessive murkiness, but I found out later that it was just the map settings. In the end I left it the same, and murkiness isn't affected by the changes in refraction.

Link to comment
Share on other sites

1 hour ago, gameboy said:
  • But you realized so beautiful surface reflection effect, why I use the patch you have no such effect?

1. Did you rebuild pyrogenesis with the patched files?

2. If you did you have to have the right angle in relation to the sun to see the sun reflection. This is true without the patch as well.

  • Like 1
Link to comment
Share on other sites

Yeah this color-fade effect isn't handled very well.

 

I think another direction to work on is to base reflections more intelligently on normals. If the reflection vector ends up being "straight up" there should definitely not be a reflection of a nearby object from the map.

 

About depth: I find the idea of a logarithm very interesting.

  • Like 1
Link to comment
Share on other sites

wrt color, I think part of the issue is that colors in the real world are generally less saturated than the colors in game art. That was also the reason why I cut the intensity of sky reflections in half. I think another issue is that there's no map level control over shadow color. The shadows in that photo are very dark, but the ones in game are much brighter.

 

1 hour ago, wraitii said:

I think another direction to work on is to base reflections more intelligently on normals. If the reflection vector ends up being "straight up" there should definitely not be a reflection of a nearby object from the map.

That only occurs if the nearby object is blocking the view of the sky. Reflection distortions just tend to make the objects look wavier rather than breaking up the reflections like what water tends to do more, but I don't see a way of fixing that reasonably.

1 hour ago, wraitii said:

About depth: I find the idea of a logarithm very interesting.

log is one of those useful slowly increasing functions. :P Getting refractions to look good everywhere is still a challenge I'm working on though.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...