WaterTextureEffect Question

Started by ToddMcF2002, May 10, 2007, 04:10:52 PM

Previous topic - Next topic

ToddMcF2002

I've been playing around with WaterTextureEffect.  The confusion I have is over the intensity and when to call applyEffect.

If I set the "intensity" to 2000 (is this duration in milliseconds???) and applyEffect every 1000 ms there is cumulative effect and after about 30 seconds it is "rippling" alot.

If I set the intensity to 1000 and applyEffect every 1000 ms not a heck of alot of rippling happens, just small pockets.

Is the intensity in milliseconds?  Should I overlap the applyEffect or am I misusing this class?


EgonOlsen

Intensity isn't based on time. It's like the docs state: The higher the value, the longer the ripples last. I can't remember reasonable values for intensity as this class is so damn old that i almost forgot everything about it. Just find a value that fits. But keep in mind that applying the effect too often hurts performance in OpenGL mode because it requires a texture upload every time.

ToddMcF2002

I've settled on 100ms updates to the textures and I think its reasonable - also I'll share the texture.

I was messing around with different JPG's and its amazing the difference in effect.  Do you have a texture you could post that looked good for you?  I'm trying to figure out just how good this can look.  It reminds me of the old algorithmic textures in the original UnrealEd.

In short... I like it!

EgonOlsen

No idea about what will be a suitable texture for it. I've never used this effect myself. I've written it as a test case for the ITextureEffect-implementation and included it because i thought "why not...?". If you are interested in modifying it, here's the code:


public class WaterTextureEffect implements ITextureEffect, java.io.Serializable{

   private int[] buffer1;
   private int[] buffer2;
   private int width=0;
   private int height=0;
   private byte shifter=0;
   private int ripples=0;

   public WaterTextureEffect(int intensity) {
      ripples=intensity;
   }

   public void init(Texture tex) {
      buffer1=new int[tex.getArraySize()];
      buffer2=new int[tex.getArraySize()];
      width=tex.getWidth();
      height=tex.getHeight();
      shifter=tex.shifter;
   }

   public void apply(int[] dest, int[] source) {

      int pos=(int) (Math.random()*width*height);
      buffer1[pos]=ripples;

      int end=height<<shifter-width;
      for (int i=width; i<end; i++) {
         pos=(((buffer1[i-1]+
                buffer1[i+1]+
                buffer1[i-width]+
                buffer1[i+width])>>1)-buffer2[i]);

         buffer2[i]=pos-(pos>>5);
      }

      end=height<<shifter;
      int size=width*height;

      for (int i=width; i<size; i++) {

         int offsetX=buffer2[i-1]-buffer2[i+1];
         int offsetY=buffer2[i-width]-buffer2[i+width];

         int first=i+offsetX+(offsetY<<shifter);

         if (first<0) {
            first=0;
         } else {
            if (first>size) {
               first=size;
            }
         }

         dest[i]=source[first];

      }
      int[] tmp=buffer1;
      buffer1=buffer2;
      buffer2=tmp;
   }
}


ToddMcF2002

Egon,

Are there any effects you can add to a texture without replacing the texture and causing a hardware caching?  Such as scrolling, rotating etc.

Thank you for posting the code BTW.  I never would have guessed it was so short!


EgonOlsen

You can create a lot of special effects by playing around with the texture coords, which can be changed by using the PolygonManager.