Water with depth in Unity Indie

First of all, hi everyone, I’m new here. Just downloaded the trial of Unity a few days ago, and I must say it blew me away!

So, without further ado, here goes my first try at doing something worthwile:

Water in Unity Indie that has depth that changes with the point of view. It’s obviously far away from water you can do with RenderToTexture functionality, but hey, not everyone can afford Unity Pro and it’s way better than simple transparent water :slight_smile:

It’s more impressive in motion, I’ll try to attach a demo application so you can check it out.

If anyone’s interested, I’m glad to share some details and scripts, but the explanation of the technique used is a bit on the lengthy side so I won’t type it out if noone cares anyway :slight_smile:

EDIT: you can try it out here:
http://approject.comxa.com/

If that fails, download here:
http://www.megaupload.com/?d=WRD4UV1I

Mouse Scroll to zoom, keys 1 and 2 switch between standard transparent and depthmapped water.

Note that the color calculation part of the two shaders is identical (with the same crappy artifacts :slight_smile: ), the difference is in the alpha calculation only.

I’d love to see it in action. :slight_smile: Could you try some sort of archive other than rar?

Tried zip, but still no luck, so I went ahead and uploaded it to megaupload:
http://www.megaupload.com/?d=AYVXYWY2

That’s not very interesting to Mac users, of which there are many here…you might want to upload a web player instead (which works on Mac + Windows and is smaller).

–Eric

Oops, sorry about that, I kindof forgot about the Mac. Hmm, I don’t have my own webspace, seems like it’s time to go hunt for a free one on the tubes… Any tips?

EDIT: here we go: http://approject.comxa.com/
Mouse Scroll to zoom, keys 1 and 2 switch between standard transparent and depthmapped water.
Note that the color calculation part of the two shaders is identical (with the same crappy artifacts :slight_smile: ), the difference is in the alpha calculation only.

Looked fantastic. :slight_smile:

Great work.

Actually I meant to zip the .html+.unityweb file together and upload the zip file. I tried the website link, but I guess they are suspicious of .unityweb files, and it’s not working. :wink: Of course, you could always upload a Mac build too (make it a Universal Binary). But the .unityweb file is cross-platform and takes up the least space.

–Eric

Heh, so many ways to go, yet so few of them lead somewhere :smile:
Megaupload link for web player: http://www.megaupload.com/?d=WRD4UV1I

Yay, that works. :slight_smile: Cool effect…even if you’re using Pro water, that would make a better fallback than the standard water (for old machines, or if you just want more speed).

–Eric

Thank you!

Thanks. I guess it could work well as a fallback, although it takes a bit more work to set up than just switching a shader.

Really great looking water you have there. Three thumbs up!

That looks really good! I’m sure a lot of people would like to see the source, or know how this it’s done. I do at least. :slight_smile:

Thanks for the compliments!

There’s two parts to the technique: a precomputation of a “depth map” done by an editor script, and a shader which utilizes the depth map to compute the depth of the water along the current viewing direction.

The precomputation script is in principle similar to lightmapping (in fact I wrote it by modifying Talzor’s awesome PixelLightMapper script - thanks Talzor!). It casts a bunch of rays in four major directions from every texel, and after some weighted averaging stores the depths in the four channels of an RGBA texture.

The shader then makes somewhat of an educated guess about the water depth along the viewing direction by weighting the depth values in the depth map with the dot product of the view direction and the major direction corresponding to that channel in the texture.

That’s the gist of it, I hope I wasn’t too confusing :slight_smile: I’ll attach a package so you can check it out if you’d like to.

167229–6026–$depthmapped_water_163.unitypackage (1.74 MB)

Thanks for sharing this, I’m having trouble downloading the file “depthmapped_water.unitypackage” though…

Could it be zipped up or something first please?

Strange, it’s working here. I’ll try uploading a zip, don’t know if it will help any though.

167239–6027–$depthmapped_water_853.zip (1.74 MB)

The zipped version worked fine, thanks very much for taking the time to do that - appreciated

  • taking a look now… Cheers!

Hey, I took a look at the web preview, and thought that this looked wonderful. I downloaded the .unitypackage and installed it, everything imported just fine.

Now, I’m not sure if I’m doing this right, since I’m fairly new to Unity.

After I imported it, I got the Depthmapped water object into my scene, placed it where I wanted it, but it was invisible in the editor, and in the game. So I ran the depthmapper script from the GameObject menu, had it run on the water plane, and it gave me a depth map, though the depthmap it gave me was solid black, and the water plane is still invisible.

Any thoughts on what could be the cause? Thanks in advance.

wow, this is really cool!

Thanks for the downloads!

I habe the same problem as Nilore: I attached Depthmapped Water to the plane (which pretends to be Waterplane), but I don’t see anything. I know, my question sounds n00bisch, but I’m at the beginning of my Unity-Way, so I’ll be ultra happy if somebody could just give a small hint how to append this tool (which looks awesome in the demo) :slight_smile:

The web demo looks fantastic! Definitely a step up for non-Pro users. :slight_smile:

It looks like your Editor script has an error in it though. It throws this exception when generating a new depthmap:

TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000]
UnityEditor.HostView.Invoke (System.String methodName) 
UnityEditor.HostView.OnGUI ()    at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000]
UnityEditor.ScriptableWizard.OnGUI () 
UnityEngine.Texture2D.SetPixels (UnityEngine.Color[] colors, Int32 miplevel) [0x00000]
UnityEngine.Texture2D.SetPixels (UnityEngine.Color[] colors) [0x00000]
DepthMapper.OnWizardCreate ()   (at Assets\Depthmapped Water\Editor\DepthMapper.cs:65)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]

Looks like the issue is coming from something about the System.Globalization.CultureInfo. I didn’t see any mention of that in the code itself, so I’m not sure why it’s mentioned here, but there ya go. Thanks for showing as the demo though. It restored my faith in Unity Free’s water.