i want to create the effect that my bitmap is the surface of water and when the mouse moves over it, it will create ripples and waves. does any one have such an algorithm?
Posted on 2004-03-26 22:03:22 by Qages
Yes there is

HE Game has such an effect on its in game menu

Bassically you have to do a fire/blur but using a history, ie add the values of the previouse frame calculations... so one can tell that water is a fire with history and no ascension ;)

Below code extract from HE shows how to calculate curent water frame.
After this you will need a way to show the effect on screenn, I suggest using one of this:
- a refraction algorithm (looks better)
- a displacement (faster)
- a bump map ?

For a start just modify the color using the amplitude of the watter as a base.
This way you can see the algorithm working and later on tweak it to look good.

BTW there are many articles on the net about how to do this fire and water simulations ;)



.data
water_phase dd 0

.data?
align 4
water_buffer_this dd water_dx*water_dy dup(?)
water_buffer_new_old dd water_dx*water_dy dup(?)

.code


;**********************************
;
; water update status
;
;**********************************

Water_update:
;============================
; get buffer pointers
;============================
mov esi,offset water_buffer_new_old
add esi,water_dx*4-8

mov edi,offset water_buffer_this
add edi,water_dx*4-8

;========================
; increment phase
;========================
mov eax,[water_phase]
inc eax
and eax,01h
mov [water_phase],eax

;==============================
; swap pointers to make
; this=>old
; new=>this
;==============================
jz water_no_switch
xchg edi,esi

water_no_switch:

;===============================
; init y counter
; minus 2 blank lines
; top most and bottom most lines
;===============================
mov edx,water_dy-2


water_loop_y:
;=================================
;init x counter
; minus 2 blank columns
; left most and right most columns
;=================================
mov ecx,water_dx-2

add esi,8
add edi,8

water_loop_x:

;======================================
; 1
; get 1 0 1 of THIS buffer
; 1
;======================================
mov eax,[edi - 4*water_dx]
add eax,[edi + 4*water_dx]
add eax,[edi - 4]
add eax,[edi + 4]


;==========================
; 1/2
;==========================
sar eax,1

;============================
; substract old (t-1) value
;============================
sub eax,[esi]

;==============================
; for damp , calc 1/16 of value
;==============================
mov ebx,eax
sar ebx,5

;=============================
; do the dampening
;=============================
sub eax,ebx

water_cool_down:
;==============================
; store new value into NEW/OLD
;==============================
mov [esi],eax

add edi,4
add esi,4

dec ecx
jnz water_loop_x

dec edx
jnz water_loop_y

ret

Posted on 2004-03-27 07:38:40 by BogdanOntanu
Neat effect! Having trouble with painting the wave-map. Found some refracting algorithms, but please explain what you mean by Bump-Maps and Displacement.
Posted on 2004-04-10 14:13:57 by The Dude of Dudes
Refracting is good (at least for watter) but it might be slower

Displacement:
------------------
Just take the value of the wave amplitude in a location and use it as a displacement(offset +/- x,y) in the bitmap and paint the pixel at the displacement location instead of pixel at x,y .

Looks like a refraction or a "predator" like effect -- but is pretty fast

Bump Map:
-------------
Consider a source of light somewhere on top of bitmap. Calculate the "slope"/"normal" of bitmap in a x,y location by the difference from x and x-1, x and x+1 , y and y+1 , y and y-1. Find the angle of normal vector with the light vector and use that to decide the lightning on that spot:90 degrees gets full light while others angles get lower light intensity. Move the light arround the bitmap.

There are many shortcuts for faster calculation as this in not a full 3D calculation just an optimized version for this special case. Check the net for samples (there are so many)

The resulting effect looks like a "bump map" ie a surface that has small and many identations in/out of it.

BTW. Above dampening is 1/32 and not 1/16 i guess
Posted on 2004-04-11 01:12:43 by BogdanOntanu
Played around with BogdanOntanu's algo a little and ended up with this.

The routine will look for a bitmap named 'bitmap.bmp' in current directory and use it as a backdrop. If 'bitmap.bmp' does not exist it will use a blank screen. Move the mouse to make the waves, left and right clicks reduce and increase 'splash size' respectively. It's a little slow, could definately use some optimizing. Anyways, it's just for fun.
Posted on 2004-04-12 20:23:44 by The Dude of Dudes
dude,

without source, isnt very useful

ancev
Posted on 2004-04-13 01:06:17 by ancev
"dude, where's my source?" ;-)
No big deal anyway, there's heaps and stack of water effects out there - including ones that run+look very well on old computers, too.
Posted on 2004-04-13 03:13:23 by f0dder
i havent found any.
Posted on 2004-04-13 13:31:06 by Qages
Try something like http://www.google.com/search?q=water+effect+sourcecode , should be plenty :) - you might want to try http://www.google.com/search?q=water+effect+assembly+sourcecode , too. Yes, there's a lot of non-assembly there, but you have a text editor and an assembler, right? ^_^


PS: check http://win32asm.cjb.net , source codes, page 2...
Posted on 2004-04-13 14:45:30 by f0dder
The source has already been provided (courtesy BogdanOntanu). I just stuck it in some code that displayed the surfaces it creates. Thought some might like to see what his source did at a VERY basic level. I did anyways.
Posted on 2004-04-13 20:45:03 by The Dude of Dudes
Some observations:

1)the area is too big for any CPU to update the effect fast enough, smaler sizes as an option would help ;) Besides it calculates every little pixel.
BTW how big is it? , what size should we use for a backdrop BMP?

2)IMHO it uses a simple amplitude modifyer but while easy to programm that is pretty slow

3)Indeed it could use optimizations and it would be interesting (for me at least) to see how much this could be optimized in speed without any tricks like calculating every other row or such

4)There is a bug in that implemetation of The Dude of Dudes ie it reaches the marging and some sopts just keep water waves for ever -- that is because it calculates until the very margin-- but i have stated that you MUST avoid margin rows and columns and always consider them fixed values

5)there is no reflexion on the margins :-? Why? that makes the whole effect funny ... after all water wavwes reflect on their recipient margins. ... might be related to above ;)


I am interested i anybody has ideas and/or better faster implementations (but not precalculated like the example on Icz's site)

I still want them to:
- fill an area
-reflect on margins
-drag mouse to place droplets/trails

if possible...
Posted on 2004-04-14 00:07:52 by BogdanOntanu
I re-wrote the whole thing and came up with this. So here it is, source and all. I am still fairly new to WinAsm, and would appreciate any constructive criticism on how it is written and my use of the API.

On another note, please feel free to modify the code and play around with the settings. The window size, wave values, and damping are all easily changeable within the source code. Also, the translation of the wave map onto a bitmap is pretty basic (XOR). If someone would like to try their hand at implementing a refraction algorigthm, I'd love to see the results!

The area underneath the window is copied onto the window to provide a backdrop, so try running it on the Desktop.
Posted on 2004-04-18 20:03:24 by The Dude of Dudes
I did that effect in 3d, using the heightmap as a displacement map for a planar surface. With central differencing I generated per-vertex smoothed normals from the heightmap. You could use these normals for lighting and reflection/refraction.
You could do a simplified version of that in 2d. Just get the x and y displacements from the heightmap, and use those to perturb the texturecoordinates that you lookup from... Basically environment-mapped bumpmapping...
So instead of just doing this:

pixel = texel;

You do something like this:
dx = heightmap-heightmap;
dy = heightmap-heightmap;

pixel = texel;

This way you warp your texture around the 'bumps' in the surface. Quite simple, really? :)
Posted on 2004-05-17 16:46:29 by Scali
I made a 3d version of the ole 3d fire effect aswell, over the weekend...
And I noticed that I still had the water stuff online aswell, so I might aswell spam some URLs so you can see ;)

http://scali.eu.org/~bohemiq/Water.zip
http://scali.eu.org/~bohemiq/Water2.rar
http://scali.eu.org/~bohemiq/Fire4.rar
Posted on 2004-05-24 14:21:00 by Scali
Just tried a first idea to colour the fire, and I'm quite happy with the result, so here goes:
http://scali.eu.org/~bohemiq/Fire5.rar
Posted on 2004-05-24 16:29:49 by Scali