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) It's possible? Could you help me? Thanks
Just one could be usefull I thought that adding the shader on the cube (fig. 2) it could be simple. Just to explain, I attached some picture of the resuls
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.
eheheh, right, but I need to move the plane in Unity and see the different cutting, I can't export all fases of the boolean operation
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? Thanks again You are my hero
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?
Did anyone manage to take this any further and get caps working on the ends? There's an interesting link here to some OpenGL libraries that do it, I wonder if this can be reproduced in unity? http://www.opencsg.org/ 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.
Hey Patrik, Just wanted to thank you for sharing :wink: The projection matrix is a little funky, but even in it's current state this is really cool to use for some interesting effects. Ethan
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...
I think it's worth linking the other cross-section thread: http://forum.unity3d.com/viewtopic.php?t=36614
Thanks for that Link. that is what I was looking for. But can anyone please tell me how I can set the Position/Rotation of the cutting plane with a script? I tried but failed... Code (csharp): var Obj : Transform; var vec : Vector3; @script ExecuteInEditMode() function OnDrawGizmos() { var upperLeft : Vector3 = transform.position + transform.up * 5 + transform.right * -5; var upperRight : Vector3 = transform.position + transform.up * 5 + transform.right * 5; var lowerRight : Vector3 = transform.position + transform.up * -5 + transform.right * 5; var lowerLeft : Vector3 = transform.position + transform.up * -5 + transform.right * -5; Gizmos.DrawLine(upperLeft,upperRight); Gizmos.DrawLine(upperRight,lowerRight); Gizmos.DrawLine(lowerRight,lowerLeft); Gizmos.DrawLine(lowerLeft,upperLeft); } function Update() { vec = transform.forward; Obj.renderer.materials[0].shader.SetGlobalVector("section_depth", Vector4(transform.forward.x, transform.forward.y, transform.forward.z, 0)); }
Would it be possible to modify the shader in order it to outline of the shape that has been cut? How could this be implemented ?
This is very impressive. Has any progress been made or was the development of this shader shelved? Importing the unitypackage in Unity 3.1 doesn't appear to get the same result as in the screenshot. Maybe some changes or manual setup is required?
Yes i would love to have an updated version of this shader... I have been looking for an easy way to do clipping of objects to show details underneath... Does anyone have an updated shader or ideas? Q
See my answer here : http://forum.unity3d.com/threads/34508-Simple-Cross-Section-Shader?p=670509&viewfull=1#post670509 Hope it will help Tom
Hello everybody, have anybody a workable solution for a cross section in Unity 3.x ? The way above don't works well in the current Unity version. And I don't understand the solution of solmyr. I'm not very familar with shaders, so help would be awesome Carsten
hey guys lol this is a super old thread but it still pops up relatively high on google search for clipping as well as cross section cutting so i thought i'd share with you guys an awesome unity asset that I found that works very well. In the asset store look up cross section shaders and there is one by abdullah aldandarawy that works super simple and very very well even with multiple slicing planes. Not only that but I wanted to get some very specific functions out my cross section and was able to change his very clean scripts and shader code to fit my situation. I can suggest it enough and I wouldn't pay for any other one, plus its free! I don't even know the guy I just think this is exactly what people are looking for when they find themselves here.