Simple lua script for water reflection

Hier können mit Artweaver erstellte Bilder präsentiert werden - Here you can show pictures created with Artweaver.
Beiträge: 9
Registriert: Mi Jan 31, 2007 8:31 pm

Simple lua script for water reflection

Beitragvon Singerxy » Mi Aug 06, 2008 1:30 am

I reproduced my previous lua script for water reflection and wish to trigger more discussion on the wonderful artweaver with lua.

Code: Alles auswählen

-- threshold filter

ywavelength = 0.01
yamplitude = 50
rangefactor = 0.5
xwavelength = 10
xcenter = 0.5
y0 = height/2
x0 = width*xcenter

for y=0, y0-1 do
  for x=0, width-1 do
    tempy = y/y0
    x1 = (1-tempy) * yamplitude * math.sin(tempy * tempy * rangefactor /ywavelength)
    x2 = (1-tempy)*(1-tempy) * yamplitude * math.sin((x-x0) * rangefactor / xwavelength)
    h,s,l = get_hsl (x+x1+x2,y)
    l = (1+tempy)*l
    set_hsl (x,height-y,h,s,l)

Sorry I seldom comment the code. I will explain the idea. Through a rough math modeling, I determine several factors should be take count into as the graph shows.
H1, the object height,
H2, view point height

Something missed from the graph, the wave propogation normal to the plane of drawing.

Also note that view field is important

All of above can be converted into angular factor or ratio factor, I don't plan to put effort to this.

Through some simplified maths, I conclude the view angle or wavelength will increase roughly as square of a distance factor. Therefore I applied the square in a sin to create a periodic ---- this is very rough, because the axis is also changed

The other effect I applied is to applied an offset from the center, applied to x2.

Then a lightness increment, which I should add control parameter

I removed the y dimensional distortion in the model to reduce the control parameters (previously I need to control 11 parameters).

I know the algorithm is not perfect. I'd like to discuss with your guys on that.
2008-08-05_181036.png (9.06 KiB) 6997 mal betrachtet

Beiträge: 14
Registriert: Mi Mai 17, 2006 6:36 pm

Beitragvon staigerman » So Aug 24, 2008 11:35 pm

very nice.

we have seen anotehr lua script that can also be used for water reflection. It is a little more suited for 'disturbed' water. I bet using the two together will make for great effects.

See - this was done with Marco Pontello's 'Sliders'. The reflection itself was done pre-emptively in Dogwaffle. Easy enough to do the same in ArtWeaver.

See more about Sliders here:

I guess the next step is to combine the two scripts.


Beiträge: 14
Registriert: Mi Mai 17, 2006 6:36 pm

get_ / set_ hsl or hsv ?

Beitragvon staigerman » Mo Aug 25, 2008 3:15 am

hue saturation lightness, hsl... or is it hsv, hue saturation value?

When I run the script above, using DogLua's lua system in Dogwaffle, it stops at line 17 with get_hsl

when I change it to get_hsv instead, it works.

Is there really a function called get_hsl or is that a typo?

dito with line 19: set_hsl should be set_hsv ?


Zurück zu „Gallery“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste