WaterRenderPass and reflected / refracted Quads

Hey there!



I have a nice little skybox with an ocean view. Now i want to put the WaterRenderPass in there to make the water realtime (which works).



My problem is, that the water only reflects the part of the skybox that is above the water line (basically just the sky) and the part underneath (the water part of the skybox) is not reflected (or then its called refracted i guess). I managed to have it like I want it before, but somehow i cant get there anymore since 0.11.



I also tried to explicitly add the 6 Quads of the skybox to the reflectedNode Node instead of the whole skybox but that doesnt work either.



Refraction is turned on.



The skybox:





With water-effect:





I want the water-effect to refract/reflect the water part of the skybox (looked really really cool before).



Thx in advance,

Andy





some code:



  /**

  * Initializes the Theme. Builds the SceneGraph

  */

  @Override

  public void init(final StandardGame game, double camDistFromZero) {

    // remember the game, s.t.s. the OpenGL-thread

    this.game = game;

    // call init method of base class

    super.init(game, camDistFromZero);

   

    // create a light-node and a lensflare

    createLight();



    // build the skybox

    buildSkyBox();



    // Heads Up Display

//    createHUD();



    // set the default camera location and direction

    setDefaultCamera();



    // create a new BasicPassManager that manages the water effect

    pManager = new BasicPassManager();



    // the node that holds all Spatials that are reflected by the water

    Node reflectedNode = new Node(“reflectNode”);



    // reflect the skybox

    reflectedNode.attachChild(skybox);

    // reflectedNode.attachChild(skybox.getSide(Skybox.DOWN));

    // add the reflectedNode to the rootnode of the scenegraph

    rootNode.attachChild(reflectedNode);



    Camera cam = TaskQueueUtil.getCamera(game);



    // get a WaterRenderPass from the TaskQueueUtil (The OpenGL thread)

    waterEffectRenderPass = TaskQueueUtil.getWaterRenderPass(game);

    // setting to default value

    waterEffectRenderPass.setWaterPlane(new Plane(new Vector3f(0.0f, 1.0f, 0.0f), 0.0f));



    // the water quad on whicht the water will be rendered

    waterQuad = new Quad(“waterQuad”, 1, 1);

    // create FloatBuffer and set it

    FloatBuffer normBuf = waterQuad.getNormalBuffer(0);

    normBuf.clear();

    normBuf.put(0).put(1).put(0);

    normBuf.put(0).put(1).put(0);

    normBuf.put(0).put(1).put(0);

    normBuf.put(0).put(1).put(0);



    // set the quad we created before for the water as target

    waterEffectRenderPass.setWaterEffectOnSpatial(waterQuad);

    rootNode.attachChild(waterQuad);



    // set the reflectedNode as

    waterEffectRenderPass.setReflectedScene(reflectedNode);

    waterEffectRenderPass.setSkybox(skybox);

    pManager.add(waterEffectRenderPass);



    // create a new RenderPass

    RenderPass rootPass = new RenderPass();

    rootPass.add(rootNode);

    pManager.add(rootPass);



    // set background color

    GameTaskQueueManager.getManager().update(new Callable<Object>() {



      public Object call() throws Exception {

        game.getDisplay().getRenderer().setBackgroundColor(ColorRGBA.blue);

        return null;

      } // call

    }); // Callable<Object>



    // update the rootNode

    rootNode.updateRenderState();

  } // init

it uses the depth buffer to calculate how much should be seen from below the water surface(refracted). the normal way of using a skybox is to make it pretty small, centered around the camera and not writing to the depth buffer. if that's how you do it too you won't get any refraction from it…it's done like that cause it would look strange to see the bottom of an ocean where it's deep etc.

can't see how you create the renderpass but there's an option for turning on refraction just so you know(even if it doesnt work with your skybox)

MrCoder said:

if that's how you do it too you won't get any refraction from it...


yes, i do it like that too. the question is: how can i get the water from the skybox to refract too? create a quad with the texture i want to refract and place it just a little below the water surface?

that should work. not sure what you are aiming at though, seeing water below the water :slight_smile:

looking at your screenshot it looks strangely reflective(almost like a mirror), have you tried playing the the start and end color params?

to make the water look more like your skybox i would need to add a few more settings to the waterrenderpass(and shader)…i'll put that on my todo list!

MrCoder said:

that should work. not sure what you are aiming at though, seeing water below the water :)


I'll paste a screenshot when its done.  :wink:

MrCoder said:

looking at your screenshot it looks strangely reflective(almost like a mirror), have you tried playing the the start and end color params?


adding

    waterEffectRenderPass.setWaterColorStart(new ColorRGBA(0.0f, 0.0f, 1.0f, 1.0f));
    waterEffectRenderPass.setWaterColorEnd(new ColorRGBA(0.0f, 0.5f, 1.0f, 1.0f));

didn't change anything.  :?

MrCoder said:

to make the water look more like your skybox i would need to add a few more settings to the waterrenderpass(and shader)...i'll put that on my todo list!


Cool 8)!!! thxal in advance
dhdd said:

adding

i somehow think that it looks different because the sky is just that one blue color in my case. the TestQuadWater looks just like you see it on the screenshots. then again, 3-4 different colors in that skybox.



i integrated the water by c&p of the TestQuadWater example plus the passManager (since i do not extend SimplePassGame).



i double-checked and the setTextureCoords(…) and setVertexCoords(…) are invoked every update()



Question: is it enough to just set the start- and end-color without some kind of update other then passManager.updatePasses(tpf); in the update-method?



thx, Andy

yeah, that's passed to the shader in the rendercall…if you wan't to try out some settings a bit easier you can add these lines to your code



        JFrame frame = WaterPassEditor.makeFrame(waterEffectRenderPass);
        frame.setVisible(true);



and see if something happens when you change colors etc. the start and end colors are the colors to blend to when the water normal is pointing towards the camera.

I've noticed that on Ubuntu and Mac I am not getting the refraction.  Perhaps this is a depth buffer/fbo issue.

could be…do you see the refracted box below the surface in testquadwater?

Not on Ubuntu…  I will have to check on mac later.

do you see the refracted box below the surface in testquadwater?


Im using Ubuntu with a radeon x1400 and I am seeing the refraction of the box below the surface

i am using ubuntu with | GeForce 7600 GS | and i only see the reflections and not the refractions with TestQuadWater … funny thing is: i am certain that i did see it before and my configuration has not changed …



so my statement before that it looks like it should is wrong  :oops:



Using the jFrame to change the colors didn't change the water either.



… damn …

could be that jme switched from pbuffer's to fbo's … are your drivers updated? if they are, there's some issue with ubuntu as renanse said…

MrCoder said:

could be that jme switched from pbuffer's to fbo's ... are your drivers updated? if they are, there's some issue with ubuntu as renanse said...


hey there!

1. that is one of the problems. the sysadmin said i mustn't update my nvidia-driver for it will screw up the X-server  :x ... so: screw refraction, i have to achieve smth with just reflection  ;)
2. i played with some different colored objects beneath and upon the water surface, refraction simply doesn't work and reflection is (as you said before) like a mirror. black stuff is reflected on the water in just the same black (as it is with other colors). only the water movement makes it a little 'waterly'  :wink:

MrCoder (or anyone else for that matter), you would be my hero if you could help me somehow, as a release date is getting near and my boss has a gun to my head  :|

even if the refraction doesnt work, it's still strange you don't see any change when changing the colors…not sure what that can be