Hi, I noticed that my custom clip planes, which work as expected when rendering EMT_SOLID and other engine default materials, don’t work anymore when using a material created from addHighLevelShaderMaterialFromFiles(). Nothing gets clipped.
Any idea what the issue might be?
I’m running opengl, can’t test it on D3D. Irrlicht Trunk although not the most up to date. Also verified that it’s not an issue with render targets.
Clip planes and shader materials
-
Rusty Rooster
- Posts: 14
- Joined: Thu May 24, 2018 6:43 pm
- Location: USA
Re: Clip planes and shader materials
It uses glClipPlane which indeed only seems to be for the fixed function pipeline.
I found this discussion, maybe it helps: https://community.khronos.org/t/glclipp ... /108078/19
I haven't worked with those yet myself, so I would also have to experiment first.
If you only need depth clipping (probably not, but just in case...), you can use real planes. Like following code I used in some navigation node to clip the back half of circles away:
Obvious downside is that you can't easily reset this (it just fills the z-buffer).
I found this discussion, maybe it helps: https://community.khronos.org/t/glclipp ... /108078/19
I haven't worked with those yet myself, so I would also have to experiment first.
If you only need depth clipping (probably not, but just in case...), you can use real planes. Like following code I used in some navigation node to clip the back half of circles away:
Code: Select all
// Create plane for clipping
const f32 clipSize = (TORUS_MAJOR_RADIUS+TORUS_MINOR_RADIUS)*2.1f;
scene::IMesh * clipMesh = SceneManager->getGeometryCreator()->createPlaneMesh(core::dimension2df(clipSize,clipSize));
if ( clipMesh )
{
core::matrix4 m;
m.setRotationDegrees(core::vector3df(-90.f, 0.f, 0.f) );
meshManip->transform(clipMesh, m);
// fully transparent but fills the z-buffer
video::SMaterial& clipMaterial = clipMesh->getMeshBuffer(0)->getMaterial();
clipMaterial.Lighting = false;
#if 1 // disable to see how the clip-plane looks like
clipMaterial.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
clipMaterial.ZWriteEnable = video::EZW_ON;
meshManip->setVertexColorAlpha(clipMesh, 0);
#endif
ClipNode = SceneManager->addMeshSceneNode(clipMesh, this, 0);
clipMesh->drop();
// Selector as the clipped away parts also have selectors which are now invisible and shouldn't be hit
scene::ITriangleSelector* s = SceneManager->createTriangleSelector(clipMesh, ClipNode);
ClipNode->setTriangleSelector(s);
s->drop();
ClipNode->setVisible(false); // should never render itself, as we have to ensure it's rendered before handles, so we render it's mesh manually in render()
}
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
Rusty Rooster
- Posts: 14
- Joined: Thu May 24, 2018 6:43 pm
- Location: USA
Re: Clip planes and shader materials
Thanks CuteAlien. Indeed, when using shaders one has to feed any clipping information to the gpu via the vertex shader:
Then in the program just call enableClipPlane(0,true)
Code: Select all
vec4 plane0 = vec4(1,1,0,0);
gl_ClipDistance[0] = dot(plane0, mWorld * gl_Vertex);
//this clips in world coordinates