Any examples of pretty, nonreflective, water?

Hey all,



I think using the WaterRenderPass is slowing my game down far too much. I'd be happy with having a nice translucent blue with some water-looking effects that doesn't actually reflect my entire scene. Are there any examples in JME that you can think of that would show me how to best achieve what I'm looking for? MrCoder said something about an alpha-transparency, but not sure what that means (maybe a transparent texture?).



Or perhaps there are ways to optimize the water to lower the quality of reflections? I'm familiar with MrCoder's technique of making a second, lower-quality terrain to reflect, but I'm just trying to get an idea of all my options.

No responses  :frowning: Anyway, we're about to implement trees and shrubbery and other things, so I've decided to take it upon myself to make a non-reflective water test, and I'll publish it in User-Code.



Currently stuck at getting the quad to be transparent but not blend colors with the grass behind it… Any ideas on this?

It is my impression that TestIsland defaults to a simple water implementation without shaders when your card doesn't support them. Perhaps you could look at that code and extract that part… Otherwise, there is also the YAMMO RPG project around here that does something similar for performance.

duenez said:

It is my impression that TestIsland defaults to a simple water implementation without shaders when your card doesn't support them. Perhaps you could look at that code and extract that part... Otherwise, there is also the YAMMO RPG project around here that does something similar for performance.


Searching for YAMMO RPG brings up a single thread--this one.

I've tried doing the things in =glass]this tutorial as well as =transparent]this one. The first tutorial isn't transparent at all, while the second mixes the colors and makes the water green (since the land under it is green).

All I want is for it to be translucent--I don't want color mixing, just for the ground under the water to be visible, and for the grass to be tinted blue instead of the other way around. Is this possible (in jme 1.0)?

If you want to use the WaterRenderPass you can try to reduce refraction/redlection quality or disable refraction.

I use it to do transparent water but I remove the depth texture to have transparent water.



If it's too slow you can try with a simple quad with alphaState and maybe a simple reflexion map, but it won't be so realistic. Or maybe using a mesh with lot of polygons making something like a surface water (using a noise in 3DSMax for exemple) and with a specular color.

Just as an example i added a simple transparent water quad to TestTerrain.







One thing to note is, you need to set the quads texture combine mode to REPLACE, because the rootNode already has a TextureState set (it wont be transparent if you don’t do that).

With the MaterialState the texture is tinted with blue and made Transparent.

With a nice Texture it can look pretty nice i think. (i used glass.jpg in the screenshot)



  private void createWaterPlane() {
      AlphaState as = display.getRenderer().createAlphaState();
      as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
      as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
      as.setTestFunction(AlphaState.TF_GREATER);
      as.setBlendEnabled(true);
     
      // tint the texture blue and make it transparent
      MaterialState ms = display.getRenderer().createMaterialState();
      ms.setSpecular(ColorRGBA.white.clone());
      ms.setDiffuse(new ColorRGBA(0.4f, 0.4f, 1f, 0.7f));
      ms.setShininess(128);
     
      TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      ts.setTexture(TextureManager.loadTexture(
          TestIsland.class.getClassLoader().getResource("jmetest/data/texture/water.png"),
          Texture.MM_LINEAR, Texture.FM_LINEAR));
     
      Quad q = new Quad("water plane", 500, 500);
      q.setModelBound(new BoundingBox());
      q.updateModelBound();
      q.getLocalRotation().fromAngleAxis(FastMath.DEG_TO_RAD*-90, Vector3f.UNIT_X);
      q.setLocalTranslation(0, 150, 0);
      rootNode.attachChild(q);
     
      // we don't want the rootNode's texture affect the quad
      q.setTextureCombineMode(TextureState.REPLACE);
     
      q.setRenderState(as);
      q.setRenderState(ms);
      q.setRenderState(ts);
  }

You could also add a spatial transformer to animate the water plane a little bit (up /down) maybe rotate it by a very small amount.

Of course it won't look realistic, but its good enough to get started i think :slight_smile:

Hi, you could also simply offset the texture by a small amount at each frame to get some movement effect …



Could give some nice results with the right texture.

even better with several textures moving at slightly different speeds

Yeah, MrCoder and I had been talking about taking 2 different water textures (I have both already) and making them move at slightly different speeds, then it will look as if the water is twinkling.

Using your settings for Alpha and Material states makes it solid. I don't understand why. It seems it is either solid or green-transparent…

did you set the TextureCombineMode to replace on your water quad ?

I did.

pitchonel said:

If you want to use the WaterRenderPass you can try to reduce refraction/redlection quality or disable refraction.
I use it to do transparent water but I remove the depth texture to have transparent water.

If it's too slow you can try with a simple quad with alphaState and maybe a simple reflexion map, but it won't be so realistic. Or maybe using a mesh with lot of polygons making something like a surface water (using a noise in 3DSMax for exemple) and with a specular color.


How do you do the first thing, with reducing quality or disabling refraction? I can't seem to find methods for either of those ( I am using JME 1.0 )

As for the second thing... that is what I'm trying to do now...

MrCoder suggested I "set the colors of the mesh to one with the alpha"



Soooo what's that mean?



It can't be this hard… I've got it to be transparent using the FlagRush tut's settings, I just need it to NOT blend colors…

in an expirement just using random numbers (lots of fun loops and such…)



I was able to find that this combination worked correctly…



src function 4

dst function 2

test function 4



So if you're creating something like this, that will work…ish… the transparency isn't nearly as transparent as I would prefer, but that's okay… I guess…

Okay. Figured everything out, looks pretty sweet, I'll be posting it on the forum soon in user-code. I will like here.

Trussell said:

pitchonel said:

If you want to use the WaterRenderPass you can try to reduce refraction/redlection quality or disable refraction.
I use it to do transparent water but I remove the depth texture to have transparent water.

If it's too slow you can try with a simple quad with alphaState and maybe a simple reflexion map, but it won't be so realistic. Or maybe using a mesh with lot of polygons making something like a surface water (using a noise in 3DSMax for exemple) and with a specular color.


How do you do the first thing, with reducing quality or disabling refraction? I can't seem to find methods for either of those ( I am using JME 1.0 )

As for the second thing... that is what I'm trying to do now...


You can reduce quality with setRenderScale() method wich divide the texture size of reflection/refraction rendered. RenderScale is also used in the constructor.

That method didn't do anything. I set it to 1, and I set it to 10000 and nothing happened.