Wave Crests & Water Rendering Questions
by Case Western (#0004) · in Torque Game Engine · 11/30/2005 (12:08 pm) · 6 replies
I'd like to modify the rendering of the water blocks in Torque to display a set of white-crested waves, much like those in Wind Waker:

My idea is to represent the crests as square planes that have a wave texture applied to them:
and make the wave "swell" by scaling the plane in the Y direction starting with a scale of 0, scaling up to a maximum of 1.0 of their size, and then back down to 0.0. The wave crests will always face toward the camera.
My wave render algorithm:
1) Have a maximum number of active wave crests (say 10) that can be displayed on the water's surface at one time
2) Have a list of active wave crests (list may be between 0 - 10 crests in length)
3) Create an array that contains all vertices of the water's surface that are visible and at least some fixed distance away from the camera
4) Choose a random number of wave crests (between the number of active crests and 10) to add to the water's surface during this frame
5) Choose random vertices from the array in step 3 and make those the positions of the wave crests to be added this frame
6) Remove any waves from the list of active wave crests that have gone through their entire "swell cycle" once
7) Advance the swell of the remaining wave crests by some increment
8) Render all of the remaining wave crests, making sure they face the camera
9) Call this algorithm at the bottom of fluid::render(), right before section marked "Cleanup from all Phases"
My questions:
1) How exactly are fluids/water blocks rendered? I'm new to the engine and having trouble understanding this.
2) How do I obtain the right set of vertices for the water's surface in step 3? I figured that I would get these by iterating through the vertices stored in m_pVertex of the fluid class, but where is the size of this array stored, and will this list of vertices correspond to the set of vertices that are used to handle the mesh that the water is ultimately rendered with? I ask this because I notice that when I increase the scale of a water block that I've created, I notice that it has more triangles than the unscaled version, and also, sections of the water's surface that the camera is close to have more triangles (I assume for level of detail). I guess my question could be rephrased: is m_pVertex the list of vertices before or after these triangles are added for the scaling and level of detail?
3) It looks to me that the vertices for fluids are shared amongst all fluids in the current game. Why? Is this so that all water in the world stays at the same height?
Any help is appreciated, thanks.
Mike

My idea is to represent the crests as square planes that have a wave texture applied to them:
and make the wave "swell" by scaling the plane in the Y direction starting with a scale of 0, scaling up to a maximum of 1.0 of their size, and then back down to 0.0. The wave crests will always face toward the camera.My wave render algorithm:
1) Have a maximum number of active wave crests (say 10) that can be displayed on the water's surface at one time
2) Have a list of active wave crests (list may be between 0 - 10 crests in length)
3) Create an array that contains all vertices of the water's surface that are visible and at least some fixed distance away from the camera
4) Choose a random number of wave crests (between the number of active crests and 10) to add to the water's surface during this frame
5) Choose random vertices from the array in step 3 and make those the positions of the wave crests to be added this frame
6) Remove any waves from the list of active wave crests that have gone through their entire "swell cycle" once
7) Advance the swell of the remaining wave crests by some increment
8) Render all of the remaining wave crests, making sure they face the camera
9) Call this algorithm at the bottom of fluid::render(), right before section marked "Cleanup from all Phases"
My questions:
1) How exactly are fluids/water blocks rendered? I'm new to the engine and having trouble understanding this.
2) How do I obtain the right set of vertices for the water's surface in step 3? I figured that I would get these by iterating through the vertices stored in m_pVertex of the fluid class, but where is the size of this array stored, and will this list of vertices correspond to the set of vertices that are used to handle the mesh that the water is ultimately rendered with? I ask this because I notice that when I increase the scale of a water block that I've created, I notice that it has more triangles than the unscaled version, and also, sections of the water's surface that the camera is close to have more triangles (I assume for level of detail). I guess my question could be rephrased: is m_pVertex the list of vertices before or after these triangles are added for the scaling and level of detail?
3) It looks to me that the vertices for fluids are shared amongst all fluids in the current game. Why? Is this so that all water in the world stays at the same height?
Any help is appreciated, thanks.
Mike
About the author
#2
I'm sorry I can't be of much help, I really haven't even started looking at the water code yet :(
12/01/2005 (5:40 am)
If you get this working, I would be interested in knowing how you did it. :)I'm sorry I can't be of much help, I really haven't even started looking at the water code yet :(
#3
Here's a screen shot:
A couple things I need to work on to make this better are the following:
1) More efficiently accumulate vertices of the fluid to place the crests at
2) Sort the crest list by distance so that crests further away don't end up overlapping new closer crests
3) Fix a little problem causing a white line to appear at the bottom of the crest (I think this might be caused by AAing?)
4) Perhaps randomly choose when to advance the wave swelling because at slow swell rates, the waves all seem to swell together
Don't ask me to explain how fluids are rendered because I'm still a little confused about how the quad tree works to build the fluid surface. In time I might figure it out...
Mike Lukas
12/05/2005 (8:17 pm)
So after many accidents and much experimentation, I got a preliminary version of the wave crests working! Here's a screen shot:
A couple things I need to work on to make this better are the following:
1) More efficiently accumulate vertices of the fluid to place the crests at
2) Sort the crest list by distance so that crests further away don't end up overlapping new closer crests
3) Fix a little problem causing a white line to appear at the bottom of the crest (I think this might be caused by AAing?)
4) Perhaps randomly choose when to advance the wave swelling because at slow swell rates, the waves all seem to swell together
Don't ask me to explain how fluids are rendered because I'm still a little confused about how the quad tree works to build the fluid surface. In time I might figure it out...
Mike Lukas
#4
12/05/2005 (8:46 pm)
One thing you should definetely do is get different jpgs all the crests kind of look the same and the ones in wind waker are a bit more squat which looks a bit better. You might not be worrying about the details now but I thought I would throw that out there nice work though!
#5
12/05/2005 (8:46 pm)
Definately a start! which i could help. But i know nothing.
#6
Yeah I plan on changing the wave texture to something a little more squashed like Wind Waker's. I think I can solve the problem of all the waves looking the same by randomly choosing when to start a wave's swell with a certain probability per frame . This should make the wave sizes vary a little more. I thought that randomly choosing a random number of waves to add during the current frame would work nicely but that doesn't seem to be enough.
12/06/2005 (11:01 am)
@Master TrebYeah I plan on changing the wave texture to something a little more squashed like Wind Waker's. I think I can solve the problem of all the waves looking the same by randomly choosing when to start a wave's swell with a certain probability per frame . This should make the wave sizes vary a little more. I thought that randomly choosing a random number of waves to add during the current frame would work nicely but that doesn't seem to be enough.
Torque Owner Vashner