Jump to content

Plane Clipping


Shadoh
 Share

Recommended Posts

I've scoured the site, and can't find how to implement Plane Clipping, I need this to create water reflections. It's simple to implement via OpenGL, infact the commands are below, can it please be wrapped in Leadwerks?

 

A quick side-question, can we actually call OpenGL commands ourself?

 

double plane[4] = {0.0, 1.0, 0.0, 0.0}; //water at y=0
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, plane);
RenderScene();
glDisable(GL_CLIP_PLANE0);

Link to comment
Share on other sites

I just had a stroke of genius :P

 

What I'll do as a temporary solution is render the scene ONLY with the water plane, then when I render the reflection camera I'll remove any pixels with less depth than the plane.

 

Pretty crappy work-around, but at-least it'll let me get a screenshot up :)

Link to comment
Share on other sites

Yes you can use discard like that, but then you need to change all object shader in use (the ones that are supposed to be clipped), which makes water making with plane reflection difficult for general easy usage.

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Just FYI here's what I have so far, the map is LakeTumbleson. And has over 200,000 trees. I can't easily remove the glitchy spots in the water where the sky is cutting out the reflection, that is until PlaneClipping is added.

 

As you can see it's very much a W.I.P and me and my team-mate are keeping the game quiet until we're sure we're going to finish it, this is mainly just a test to see what we can do at this stage.

 

EDIT: Yes, there are trees in the water, the tree generation system still needs some fine tuning lol

post-11564-0-61350400-1403911707_thumb.png

post-11564-0-72329300-1403912026_thumb.png

  • Upvote 2
Link to comment
Share on other sites

Plane clipping is part of the fixed-function pipeline that was removed in OpenGL 4. It can be done in a shader, though, as discussed.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I did something like this in 3.0 for the model shaders

 

vertex:

out vec3 clip_pos;
..
clip_pos = (entitymatrix*vec4(vertex_position, 1.0)).xyz;

 

frag:

in vec3 clip_pos;
uniform float water_height;
..
if (clip_pos.y < water_height) discard;

 

The thing is that you have to change all shaders that are in play or has the chance of being clipped, so making clipped workshop items etc will be a nightmare.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...