Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rain Simulation in Open GL

243 views
Skip to first unread message

Simon Goodall

unread,
Feb 17, 2006, 10:58:34 AM2/17/06
to
Hi,
I've been trying to make a rain simulator using point sprites. Using the
point sprite extension with the auto-generated texture co-ordinates works
nicely. However I have two issues I would like some help with.

Firstly, I would like to be able to rotate my sprites according to a wind
speed variable. I tried using glRotate on the z axis to rotate the texture
matrix, however this had no effect. I guess the auto generated coordinates
(from the point_sprite extension) override any texture matrix settings.
How can I rotate my point sprite? The auto generated texture coords
generated can be turned off, but how can you then specify the texture
coordinates? glTexCoord presumably won't work as four corners need to be
specified for a single point. I also tried to use glTexGen, but didn't
have much luck there either (although i'm not sure that i did the right
thing.)
Is this possible, or do i need to use a regular glQuad to be able to do
this.

The second issue is in making rain splashes happen in the right places.
I've been using glOrtho and rand() to render the rain drops to random x/y
locations in 2D. For rain splashes, they need to be restricted, to hitting
actual objects and not empty space. I have been added a Z component to the
x/y position of the splash and depth tested it. This now only renders
splashes on areas that have has the depth buffer value set (so all objects
and not on the sky) however I would like to further restrict this so that
far away objects so not get the splash (think a seeing a splash on a
distant mountain).

here is some example code

// Render 3-D scene and set the depth buffer glDepthFunc == GL_LEQUAL

// Setup 2-D rendering
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix glOrtho(0, m_width,
0 , m_height, -1, 1); // Set Up An Ortho Screen
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity();

//
each rain splash pos
float x = rand / RAND_MAX * m_width
float y = rand / RAND_MAX * m_height
float z = rand / RAND_MAX * -1.0 // Needs to be -1.0 or less otherwise no
rain splashes

glDepthFunc(GL_GEQUAL);

// Render the rain splashes.

psva...@yahoo.com

unread,
Feb 19, 2006, 4:25:58 AM2/19/06
to
In the point sprite extention the tex coordinate of each point is
calculated based
on the size of the point. This is why texture matrix values have no
effect.

Maybe varying the texture alpha value to change the shape of the
raindrop as a function
of wind speed might be of use. Can you explain what effect you are
trying to achieve when
you say you want raindrops to be rotated as a function of wind speed.

Another interesting area you can look is point size attenuation with
depth. This might
give you the result where in you do not want the splashes. with
distance.

Valins

Simon Goodall

unread,
Feb 19, 2006, 7:15:06 AM2/19/06
to

psva...@yahoo.com wrote:
> In the point sprite extention the tex coordinate of each point is
> calculated based
> on the size of the point. This is why texture matrix values have no
> effect.
>
> Maybe varying the texture alpha value to change the shape of the
> raindrop as a function
> of wind speed might be of use. Can you explain what effect you are
> trying to achieve when
> you say you want raindrops to be rotated as a function of wind speed.

Currently I have a texture with a straight vertical line. I was hoping
to be able to rotate it with wind speed such that in the extreme case,
it would be rendered horizontally.

>
> Another interesting area you can look is point size attenuation with
> depth. This might
> give you the result where in you do not want the splashes. with
> distance.

Yes it does sound like an interesting idea. However I am rendering my
rain with glOrtho set. The attenutation seems to work from the bottom
left corner of the screen, such that most of the "rain" is gone by the
center of the screen. Perhaps there is another way to work this?

Simon
>
> Valins
>

psva...@yahoo.com

unread,
Feb 20, 2006, 8:41:40 AM2/20/06
to
Well point size attenuation should work
something like this
derived point size=1/function(d,d**2).
d being the distance from the eye to the world coordinates of the
point.

Now since you have changed the view volume you might see strange
results.

Is it possible for you to use the scene view volume to generate random
points in
the scene.

Another trick you could use is to make splashes get generated on the
nearby surfaces.
ie on the nearby surface geometry vertex place a rectangular billboard
to show
the splashes. If you can use some different kinds of textures and
choose your
vertices judicially you could get a good enuff effect.

After all its all about fooling the eye :).
Valins

0 new messages