Sunday, June 24, 2007

[GPU] Ocean simulation





I have been working on my ocean simulation again - It's been a lot of fun to 'resurect' this code.



The two main improvements are the addition of foam, and the 'sparkles' in areas reflecting the sun. I also added a very bad looking boat (ok, this will require more work ;-)

I was afraid adding foam would be difficult, but actually the simplest approach turned out quite well. The foam is a (toroidal) texture mapped onto the sea.

The texture I use is shown here - notice it is very dark - That's because I simply add its color to the sea color.



The foam layer is multiplied by a spatially varying control value. When the control value is 0 the foam is invisible, when 1 it is fully visible. The idea is to have foam appear where the sea surface becomes rough. To do this, I am simply using (1-sea_nrm.z) as the control value. It does work reasonably well. One improvement could be to 'blur' this control value a little bit, but the current approach seems sufficient.


Last trick: To avoid obvious repetitions, I in fact add two versions of the foam texture with different scaling values. (eg. One is repeating every 2.7 units, the other every 3.14 units).


The second improvement is the addition of 'sparkles' of light. If you've been lucky enough to witness great sunset on the sea, you may have noticed all these small 'random' light sparkles in the distance. These are due to small waves reflecting the sun light directly into your eyes. I was hoping that adding sparkles would give a better impression of detail in the distance. (Especially because we do lose detail in the distance due to filtering of higher-frequency waves).



The sparkles are generated in a post-processing step. First, I render the scene in a render target. I use this texture to compute a 'probability' for sparkle appearance. Basically, sparkles are likely to appear in areas reflecting the sun light.





Second, I render the sparkles in another render target. I use a random number generator and compare its output to the probability of appearance. If the random number is large enough a white pixel is output. Otherwise a black pixel is written. Of course the generated random numbers vary with time.

This image shows the 'sparkle' layer which is directly added to the final result. I was quite happy with the result - even though it is perfectible. I think it is quite successful in increasing the impression of detail on the ocean surface.

To conclude, here is the final result. Hopefully you can see the sparkles even at this resolution.



Next I am planning to add the reflection of the boat in the sea and implement some more credible boat dynamics (not sure about this one - will depend on the gameplay).

Of course I'd like to improve the boat model / rendering. My plan (in a world with no time constraints) would be to create a boat race - or a 'boat-war' game. So if you are a modeler please send me your best creations ;-)

Saturday, June 23, 2007

[system] Transfering my blog

I am transfering my blog to blogspot ...
This is a first post to try it out.

Cheers -

Wednesday, November 22, 2006

[game] BubblePool

BubblePool is a small game prototype (no cool graphics, no sound, just pure gameplay). It is a pool-like game with strange rules :-) Download it from [removed].

Saturday, October 21, 2006

[tools] Adding cygwin to explorer context menu

Cygwin shells are a nice replacement for the standard Win32 console.
However, I had no convenient way of opening a Cygwin console at a given location, in the spirit of the 'Open Command Line Here' XP powertoy.
After playing with bash/rxvt I found a way to do this. Replace your C:\cygwin\cygwin.bat with the following lines:

@echo offC:\cygwin\bin\bash --login -i -c 'cd "`cygpath %1`";rxvt -title \"%1\" -fg white -bg black'
Then open an explorer window (assuming Windows XP), go into Tools -> Folder options, File types, select (NONE) Folder, click on 'Advanced', 'New', give an action name such as 'Open Cygwin shell here' and select C:\Cygwin\cygwin.bat as the program to be launched.

If everything went as planned, you should now have a working 'Open Cygwin shell here' line in your context menu for folders.

Note: I am using rxvt to enable support for escape codes. I am looking for a way to have working escape codes in a Win32 console. If you know how, please drop me an email :-)

Wednesday, August 9, 2006

[GPU/Cg] tips of the day

For those using Cg and D3D, there is a trap in the API.
Using the following Cg(Fx) code:
uniform sampler2D Tex = sampler_state {MinFilter = Linear;MipFilter = Linear;MagFilter = Linear;};

The Tex parameter must be set with cgD3D9SetTextureParameter and not with cgD3D9SetTexture, even though according to the current documentation cgD3D9SetTexture is the one to be used for samplers. When using it, Cg returns an error ...
Quick edit: cgD3D9SetupSampler can also be used. It does both cgD3D9SetTextureParameter and cgSetSamplerState.

Tuesday, May 23, 2006

[game] The end of modding ?

The recent ESRB rating change of Oblivion sounds like a very bad news for the moddoing community. It seems the ESRB has decided to judge the rating of a game according to user-created content; a bit like judging whether your web browser is suitable for children based on content it could display.

While I agree that user-created content raises some questions about children protection, I don't see why Bethesda (or any other company making moddable games, for that matter) would be held responsible for this content. The content has first to be downloaded from somewhere: a web site. It is not available form the start. It is not distributed by the company (to my knowledge). So, it is very much like downloading mature content from the web: The browser software displaying it is not responsible for the content; whoever puts the content online is.

There is no difference between a moddable game and a video player or web browser: All are displaying content. Whether the downloaded content is suitable or not for children is not the responsability of the company making the software. While this is obvious for a video player, the bad understanding of what a game and a moddable software are just prevent most people to see this.

If things continue this way, I am afraid most game companies will start to remove modding tools -- And that will be a huge loss to the community (How many players started to learn coding by modding games ?).

Tuesday, February 28, 2006

[tools] GroupBar

I like to open many windows at once. As a consequence my Desktop is often crowded and it might be difficult to navigate among this forest of windows. Fortunately, a group at Microsoft Research has worked on this problem and released the GroupBar (download from here).

You can group windows together, hide/show groups in one click, and even save groups across sessions. It's really simple to use and it is a great addition to the windows desktop!