FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Simulation, Artificial Life
(Moderator: REAS)
   First stab at water
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: First stab at water  (Read 2337 times)
flight404

WWW Email
First stab at water
« on: Nov 10th, 2003, 6:52pm »

Okay, admittedly, since I am using no mention of sine or cosine, this isn't really a water test but rather a noise test.  However, since I DID color it with oceanic hues, I am going to call it water and there is little you can do to stop me.
 
http://www.flight404.com/p5/waterTest1/
 
The original purpose of this sketch was to create a landscape for a 3D meandering-object avoidance-steering thing, but got side tracked because noise() is just so damn fun.
 
Disable the source code link because the code is a side-effect of another project.  When I get a chance to clean it up and modularize it, I will post but for now, Toxi's noise previews are cleanly coded and commented!
 
http://www.toxi.co.uk/p5/perlin/
 
 
toxi

WWW
Re: First stab at water
« Reply #1 on: Nov 10th, 2003, 7:12pm »

he's back!!!
 
nicely done, it's not quite "the perfect storm", but i like it! how about introducing white foam/spray particles at the positions where the wavefronts are changing rapidly. you could do this by storing all height values in an array and for each position computing the difference to the value in the previous frame. if it's over a certain threshold you spawn a few particles with a very short lifespan. could look awesome!!
 
have you seen this?
you should check out their OSX software: TweakWaves
 

http://toxi.co.uk/
flight404

WWW Email
Re: First stab at water
« Reply #2 on: Nov 10th, 2003, 9:04pm »

Nice.  Those waves look great.
 
As for my waves, I plan on cleaning up the code a bit and making it a little more customizable.  I will try your foam/spray idea while I am at it.  Want to incorporate some sine and cosine input as well to make it a little more wave-like and a little less noise-like.
 
Also want to deal with reflection of light in a more believable fashion.  Right now, it is merely hinted at with the far side of the wave showing up brighter than the near side of the wave.
 
naztafari

WWW
Re: First stab at water
« Reply #3 on: Nov 10th, 2003, 9:10pm »

Sweet!
 

-Naz
http://www.object404.com
Glen Murphy

WWW Email
Re: First stab at water
« Reply #4 on: Nov 11th, 2003, 9:46am »

Awesome.
 
It'd be nice if you fixed the camera angle at a shallow angle, as it loses the effect at more vertical perspectives.
 
flight404

WWW Email
Re: First stab at water
« Reply #5 on: Nov 11th, 2003, 8:50pm »

Agreed, Glen.  It looks much more believable side-on.  But since i still plan on mucking with it, i wanted to be able to see more of a top view as well to make sure things are working properly.  Eventually, the view will be established by the position of the vehicle on the water (soon) but need to figure out how to deal with the 3D clipping problem.
 
Questions about the best way to handle this project:
 
1. is there a good naming convention to deal with the four points which comprise each square of the water surface?  I am currently using something like x,y   x2,y   x2,y2   x,y2   which sucks because it is hard to remember what is what.  Each of these points has its own z point and other information and wondering how others deal with this problem.
 
2. instead of making the water surface at the same time i make the calculations, would it make more sense to put all the information into an array and then use that info to draw the surface?  I assume this might be a better way especially if I plan on including more environmental variables like wind speed and direction and wave height.  That way, I could keep modifying the point information within the array and then finally draw it.  Would there be a performance hit?
 
3. is there a planned fix for the 3D clipping?
 
4. okay, this one is hard to phrase.  I am making each square of water by analyzing the four corner points and drawing two right triangles.
4a. Should I stick with triangles or could I use beginShape(QUADS).  Since each of the corner points exists at a different z-depth, can quads still be used?  I tried experimenting with it but wasn't able to figure out how it was working (if at all).
4b. Since I am using the two triangle method, what is a good way to determine what properties the two different triangles has?  Currently, triangle 2 of square 1 has the same color info as triangle 1 of square 2 (which can be seen by the presence of parallelograms comprising the surface of the water instead of triangles).
 
4b(continued).  For example, since each point has a different z value, should I have to average the three z values of each triangle and use that new z average to give the triangle its color value?  Is there a more reasonable way that doesn't involve averaging?
 
Sorry if this post is hard to decipher.  Uncharted territory for me so I don't know the proper lingo yet.
 
 
 
thanks for the input and information.
 
r
« Last Edit: Nov 11th, 2003, 8:58pm by flight404 »  
REAS


WWW
Re: First stab at water
« Reply #6 on: Nov 11th, 2003, 10:02pm »

3D clipping fix has been planned for two years, but should be working shortly.  
 
toxi

WWW
Re: First stab at water
« Reply #7 on: Nov 12th, 2003, 2:14pm »

hey rob, sorry haven't got time to go into much detail right now, but i quickly rewrote my perlin terrain demo so that it looks more like water. so please have a look at the source there, it should answer *some* of your questions:
 
http://www.toxi.co.uk/p5/water/
 
re: triangle colours, you know that you can specify a different colour for each vertex. the colours are then interpolated across the triangle when it's rendered and produces very smooth results.
 
re:3d clipping, as you can see you can get away with having a static camera, but still achieve some kind of movement. in this case this is done by moving along the noise Z-axis to create the wave/ripples animation and along the noise space Y-axis to create the effect of waves slowly coming towards you.
 
hope that helps!
 

http://toxi.co.uk/
Bijeoma

myloveiloved
Re: First stab at water
« Reply #8 on: Nov 12th, 2003, 6:04pm »

wow toxi that looks nice
 
flight404

WWW Email
Re: First stab at water
« Reply #9 on: Nov 12th, 2003, 8:04pm »

Rock on, Toxi.  Once again, you humble me.  Not only is your code about 1/3 as long as mine, but you dont see any facet triangles and you can pan left and right.  Good stuff.
 
I actually have the z-noise y-axis movement effect on mine but it is at a much slower speed so it is nearly unnoticable.  But what i eventually want is for the camera to bob and change angle depending on the angle of the wave on which it sits.  In that case, would I have to wait for a 3D clipping fix (or provide one of my own).
 
TrianglesStrip ? ! ? !   Nice.  Has that been there all along?
 
And having each vertex have its color information... wonderful.  Thank you for pointing that out.
 
yay
« Last Edit: Nov 12th, 2003, 8:05pm by flight404 »  
madmerv
Guest
Email
3d Landscape Generation
« Reply #10 on: Nov 12th, 2003, 9:04pm »

// Vector-based Landscape Renderer (Example 2)  
// by merv http://www.madmerv.com
 
// Draw a 3d landscape based on 2 images.
// Dimensions must be divisible by 2 (for best results).
// Both images must share the same dimensions.
 
// Image1: Color Map
// Image2: Height Map
 
// Created 10 November 2003
 
float xmag, ymag = 0;
float newXmag, newYmag = 0;  
float xyzscale = 1;
float delta = 0.01;
int xRes = 640;
int yRes = 480;
int xcount;
int ycount;
 
BImage img;
BImage bump;
float vsize = .075;  // distance between vertices
 
void svertex( float x, float y, float z, color c )
{
     fill( c );
     vertex( x*xyzscale, y*xyzscale, z*xyzscale );
}
  
void setup()  
{  
  size(xRes, yRes);  
  noStroke();  
  colorMode(RGB, 1);  
}  
 
void loop()  
{  
  int count;
  
  background(0, 0, .2);
  
  img = loadImage("marsfacetex.jpg");
  bump = loadImage("marsfacebmp.gif");    
 
//  img = loadImage("texturesm.gif");
//  bump = loadImage("bumpsm.gif");
 
  push();  
 
  translate(width/2, height/2, -30);  
  
  newXmag = mouseX/float(width) * TWO_PI;
  newYmag = mouseY/float(height) * TWO_PI;
  
  float diff = xmag-newXmag;
  if (abs(diff) >  0.01) { xmag -= diff/4.0; }
  
  diff = ymag-newYmag;
  if (abs(diff) >  0.01) { ymag -= diff/4.0; }
  
  rotateX(-ymag);  
  rotateY(-xmag);  
  
  scale(50);
 
  if ((xyzscale >= 3) || (xyzscale <= 0.4)) {
    delta = -delta;
  }
    xyzscale = xyzscale + delta;
 
//  beginShape(QUADS);
//  prism( 0, 0, 0, 1, 1, 1 );
//  endShape();
 
  int dimx = img.width;
  int dimx2 = img.width/2;
  int dimy = img.height;
  int dimy2 = img.height/2;
  color xy1, xy2, xy3, xy4;
      
  for ( xcount = -(dimx2);  xcount < dimx2-1; xcount=xcount+1 ) {    
  for ( ycount = -(dimy2);  ycount < dimy2-1; ycount=ycount+1 ) {
  
  beginShape(QUADS);
  float vheight;
 
 // if i use this next line instead of the following, also does not work:
 // xy2 = red(bump.pixels[(xcount+bump.width/2)+(bump.width*(ycount+bump.height/2))]);
  xy1 = bump.pixels[(xcount+dimx2)+(dimx*(ycount+dimy2))];
  xy2 = bump.pixels[(xcount+1+dimx2)+(dimx*(ycount+dimy2))];
  xy3 = bump.pixels[(xcount+dimx2)+(dimx*(ycount+1+dimy2))];
  xy4 = bump.pixels[(xcount+1+dimx2)+(dimx*(ycount+1+dimy2))];
 
  vheight = ((xy1 % 256)/32);
  vheight = min(vsize,vheight);  
  svertex( vsize*xcount, vsize*ycount, vsize*vheight,
  img.pixels[(xcount+dimx2)+(dimx*(ycount+dimy2))] );  
 
  vheight = ((xy3 % 256)/32);
  vheight = min(vsize,vheight);  
  svertex( vsize*xcount, vsize*ycount + vsize, vsize*vheight,
  img.pixels[(xcount+dimx2)+(dimx*(ycount+1+dimy2))] );    
 
  vheight = ((xy4 % 256)/32);
  vheight = min(vsize,vheight);  
  svertex( vsize*xcount + vsize, vsize*ycount + vsize, vsize*vheight,
  img.pixels[(xcount+1+dimx2)+(dimx*(ycount+1+dimy2))] );      
      
  vheight = ((xy2 % 256)/32);
  vheight = min(vsize,vheight);    
  svertex( vsize*xcount + vsize, vsize*ycount, vsize*vheight,
  img.pixels[(xcount+1+dimx2)+(dimx*(ycount+dimy2))] );  
 
      
 
  endShape();
  }
  }
  
  
  pop();  
}  
« Last Edit: Nov 12th, 2003, 9:05pm by madmerv »  
flight404

WWW Email
Re: First stab at water
« Reply #11 on: Nov 12th, 2003, 10:03pm »

Two things, Madmerv...
 
1. Care to elucidate as to why you are pasting this code into this forum?  Any info or descriptions would be nice.
 
2. Can you provide sample images that can be used to test this code or perhaps point us to images which might lead to nice results?
 
 
benelek

35160983516098 WWW Email
Re: First stab at water
« Reply #12 on: Nov 13th, 2003, 2:05pm »

or even upload the applet to your website, and link to it...
 
Pages: 1 

« Previous topic | Next topic »