Hi all,
I don’t know nothing about shaders and in a topic suggest me to make a custom shader, I hope someone of you could help me.
I need to realize a clipping plane, like the Near clip of the camera.
I have some geometry and I want a plane (or cube) that slice on it and hide all there is before (or inside if it is more simple)
Hmm… looks like a boolean operation is needed here and not a clipping shader.
I dont know though, if this can be achieved with a shader, but my guess would be, that you have to do the cut inside your 3D App and then export to Unity…
Here’s something quite simple limited I cook up (attached whole Unity project). Press Play or just move the Clipper cube around.
It has some limitations though:
It just clips whatever is behind the planes (does not “cap” the holes)
It only supports one directional light for illumination
…something else
The way it works is quite simple in fact: there’s a clipping texture, all white with black borders. Then a vertex shader computes UVs for that texture in such a way that they would relate to the clipping planes. Alpha testing is done in the shader on that texture. There’s a script attached to the clipper object that passes some matrices for the vertex shader.
Your work is appretiated, I don’t know how to thank you.
Your scene works perfectly, but I don’t know why, when I insert my models in your scene it doesn’t clip my models.
I Should add “VertexLitClip” material to my models to let it works.
There is another way with the other material?
I’ve always wanted realtime boolean effects (subtraction and intersection) in Untiy. Aras, is this theoretically possible to do in a Shader with arbitrary geometry?
I wonder too if this is now possible in 2.1 using a two pass process, render the normals of the clipped objects in the first pass and then process that render to look for any back facing normals those that are get rendered with the texture applied to the clipping plane.
Trying to work out some of the quirks of this to get it to work for a project i’m doing ->The original work behaves strangely when scaling the clipping object, and also I need 4 clip-planes.
To get 4 clip-planes i edited the texture to be square with a black border around the whole thing, but it doesn’t work as is with Aras’s clipping matrix setup so I replaced the box with an orthographic camera (non-active) and take the projectionMatrix from that. This gives me the four clip-planes, but unfortunately the clipping is not aligned to the camera projection and it also moves the opposite direction in y compared to the camera.
There’s a lot of things going on that I don’t have a clue about, e.g the shader clipping changes when changing the near and far clipplanes of the camera.
I’ll keep working on it and if anyone want’s to take a look I’ve attached a package of the thing.
I’ve been playing with this a bit and modified the original test to include basic capping. It only works for non intersecting closed objects but maybe still useful.
I’m sure someone with more knowledge of shaderLab could optimise this into a single pass at the moment I use 2 for simplicity.
I’ve been playing around with this examples trying to get them to behave the way I need for a project I’m working on.
If I understand right the code doesn’t actually use a clip planes, it uses a texture to emulate how a couple of clip planes would behave, right?
If so, is there a way to increase the precision of where the clip planes are placed so it starts clipping say at the origin of the volume or the exact side of it?
As I scale the volume this positions get offset, I’m thinking this is because of the stretching in the clip texture and the offset being where the black pixel starts.
Any way of just using a single clip plane instead of the clip texture?
I think if you took the example i did, which I reduced to just one clipping plane and then modified the texture so that the black to white transition was exactly in the center then the clip plane would exactly align with the center of the clipping box. That would allow you to precisely position it.
I just wanted to ask if there is a possible way to get just one plane which cuts sth. in half by just hiding the second part, but dynamic.
I looked at the results in this thread an tested them, but unfortunately these scripts/shaders don’t work as I want them to do… So I just had the urge feeling to ask you if and how I can modify the shader/script so that it does what I described above, just hides one half of an object at a given plane…