Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Clipping on a wavy surface

Started by Pikkolini Feb 5, 2015 at 4:20 PM 3 replies 2.3k views
Original Post
Pikkolini
Pikkolini

Hello everyone,

I'm currently working on a water surface simulation and got some problems concerning the reflection.

I have a reflection camera which is mirrored in the water plane. If the water surface is a perfect flat plane you can specify a clipping plane and draw the rendered reflection texture directly on the water surface. Now I got the problem that my surface isn't flat. The deviation of the z coordinate of the surface from the perfect plane is calculated due to some uv-coordinates which are calculated on the cpu. How am I supposed to clip the reflection texture on that calculated surface?

The only idea I got is that I take the depth texture from the reflection camera, calculate the world position with the help of the depth texture, transform the world position in the model space of the water surface, calculate expensive the uv coordinates matching this world position, calculate the z deviation of the water surface at this point and compare the calculated z of the depth texture with the calculated z of the water surface.

This seems crazy to me besides I got some problems implementing this.

I am sure there must be a faster/easier solution. Can anyone help me? smile.png

BrentMorris
BrentMorris

I don't completely follow you! Are you saying that the wave geometry is showing up on the reflection, and you don't want it to be there? Or that the reflection from the surface isn't reflecting how you think it should be? A screenshot would be helpful to illustrate the issue.

stalef
stalef

If you can sample the water height in the reflection pass fragment shader (easy if you are using a heightmap for the surface) you can discard the fragment if it is below water.

Reitano
Reitano

You render the reflections assuming a planar mirror, and then you apply the resulting texture to a displaced surface. Unless you use raytracing, you will not get 100% correct results with this technique, although with a wise mix of approximations and tricks you can obtain plausible results. Highly displaced surfaces like water are problematic though.

Please send a screenshot so that we can understand the exact issue and give you some suggestions.

Pikkolini
Pikkolini

First of all here are two screenshots to display my problem:

[sharedmedia=gallery:images:6130]
[sharedmedia=gallery:images:6131]

In the first screenshot the wave is above the clipping plane. In the second screenshot the wave is under the clipping plane.

My general question would be: How can I make it look right?

I know that I have to translate the reflection texture to make it flush with the object. And I know that the reflection is either too much or too less clipped. My initial question is how can I solve the problem with the clipping?

I continued to work on this problem and now I am at the following point:

I tried to render the surface from the view of the reflection camera and test the depth of this image against the depth of the reflection texture. But what should I do if the depth test fails? There is no way how the shader can find out which color should be used as a replacement. Is another object behind the clipped object or is just the background behind the clipped object? I don't know.

I hope that I could make the topic a bit more clear and REALLY hope that somebody has an idea smile.png

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.