Re: Realistic water scene node
Posted: Mon Mar 17, 2014 1:01 pm
Did you read my post? You need to adjust the clip plane
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
Code: Select all
void RealisticWaterSceneNode::OnAnimate(u32 timeMs)
{
ISceneNode::OnAnimate(timeMs);
_time = timeMs;
//fixes glitches with incomplete refraction
const f32 CLIP_PLANE_OFFSET_Y = 250.0f;//5.0f
if (IsVisible)
{
setVisible(false); //hide the water
//refraction
_videoDriver->setRenderTarget(_refractionMap, true, true); //render to refraction
//refraction clipping plane
core::plane3d<f32> refractionClipPlane(0, RelativeTranslation.Y + CLIP_PLANE_OFFSET_Y, 0, 0, -1, 0); //refraction clip plane
_videoDriver->setClipPlane(0, refractionClipPlane, true);
_sceneManager->drawAll(); //draw the scene
//reflection
_videoDriver->setRenderTarget(_reflectionMap, true, true); //render to reflection
//get current camera
scene::ICameraSceneNode* currentCamera = _sceneManager->getActiveCamera();
//set FOV anf far value from current camera
_camera->setFarValue(currentCamera->getFarValue());
_camera->setFOV(currentCamera->getFOV());
core::vector3df position = currentCamera->getAbsolutePosition();
position.Y = -position.Y + 2 * RelativeTranslation.Y; //position of the water
_camera->setPosition(position);
core::vector3df target = currentCamera->getTarget();
//invert Y position of current camera
target.Y = -target.Y + 2 * RelativeTranslation.Y;
_camera->setTarget(target);
//set the reflection camera
_sceneManager->setActiveCamera(_camera);
//reflection clipping plane
core::plane3d<f32> reflectionClipPlane(0, RelativeTranslation.Y - CLIP_PLANE_OFFSET_Y, 0, 0, 1, 0);
_videoDriver->setClipPlane(0, reflectionClipPlane, true);
_sceneManager->drawAll(); //draw the scene
//disable clip plane
_videoDriver->enableClipPlane(0, false);
//set back old render target
_videoDriver->setRenderTarget(0, false, true);
//set back the active camera
_sceneManager->setActiveCamera(currentCamera);
setVisible(true); //show it again
}
}
Your image isn't appearing, but I found the redirect to the actual image for anyone interested:diho wrote:What causes this:
-Diho
Code: Select all
RealisticWaterSceneNode *water = new RealisticWaterSceneNode(smgr, 102400.0f, 102400.0f);
smgr->getRootSceneNode()->addChild(water);
water->setPosition(spawnPoint);
Strange.. I just comment out one single DrawAll() call (first one), and keep just second one, and do have instead of 14 FPS, 24 FPS, and everything working as before.Maybe because Irrlicht didn't have multi render targets when it was coded (wasn't in Irrlicht 1.8 I think).