Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] crossSection tool

Discussion in 'Assets and Asset Store' started by tomekkie2, Jan 21, 2014.

  1. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    I am using gizmos for translating and rotating objects in game mode: https://assetstore.unity.com/packages/tools/modeling/runtime-level-design-52325

    When rotating the cross section box, not just the rotation of the box gets changed, also it scales.
    This happends because your code is updating the box all the time or should I search in the gizmo code?

    When i rotate it via unity in the scene mode, it just rotates, no scaling.
     
    Last edited: Aug 17, 2018
  2. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Any solution for that? :/
     
  3. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Is there any possibillity to use your SectionBox in a reversed version?
    So that all objects inside your box are hidden and outside visible.
     
  4. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Yes, this is absolutely possible, but requires some modifications to the scripts and section box shader as well.
     
  5. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Can you give me some hints what i need to modify?
     
  6. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    How would it be supposed to work?
    So now the section box initial size comes from the gameobject bounding box. And then you can move the box sides with mouse or touches. The camera is outside the box.
    How are you going to set the box size and then manipulate it?

    Possibly a a good starting point for that could be a corner section, just imagine adding two more planes to it.
     
  7. pmargain

    pmargain

    Joined:
    Aug 10, 2017
    Posts:
    10
    Hi,

    Just purchased the cross section shader asset and get many errors. I'm a newbie and don't really know what's going on. I've installed it in 2017 and 2018 and can't use it due to the compiler errors. Please advice. Thanks. Here is a list of errors in Unity 2017

    Shader error in 'Clipping/Corner/Standard (Specular setup)': 'FragmentSetup': cannot convert from 'float4[3]' to 'half4[3]' at Assets/WorldSpaceTransitions/crossSection/CS_Shaders/CGIncludes/UnityStandardCore_CS.cginc(203) (on d3d1

    Shader error in 'CrossSection/Standard (Specular setup)': 'FragmentSetup': cannot convert from 'float4[3]' to 'half4[3]' at Assets/WorldSpaceTransitions/crossSection/CS_Shaders/CGIncludes/UnityStandardCore_CS.cginc(203) (on d3d11)

    Assets/WorldSpaceTransitions/crossSection/Editor/CrossSectionStdShaderGUI.cs(289,84): error CS0117: `UnityEditorInternal.InternalEditorUtility' does not contain a definition for `IsMobilePlatform'

    Shader error in 'CrossSection/Standard': 'FragmentSetup': cannot convert from 'float4[3]' to 'half4[3]' at Assets/WorldSpaceTransitions/crossSection/CS_Shaders/CGIncludes/UnityStandardCore_CS.cginc(203) (on d3d11)

    Shader error in 'Clipping/Box/Standard (Specular setup)': 'FragmentSetup': cannot convert from 'float4[3]' to 'half4[3]' at Assets/WorldSpaceTransitions/crossSection/CS_Shaders/CGIncludes/UnityStandardCore_CS.cginc(203) (on d3d11)

    Shader error in 'CrossSection/Standard (Roughness setup)': 'FragmentSetup': cannot convert from 'float4[3]' to 'half4[3]' at Assets/WorldSpaceTransitions/crossSection/CS_Shaders/CGIncludes/UnityStandardCore_CS.cginc(203) (on d3d11)

    Shader error in 'Clipping/Corner/Standard': 'FragmentSetup': cannot convert from 'float4[3]' to 'half4[3]' at Assets/WorldSpaceTransitions/crossSection/CS_Shaders/CGIncludes/UnityStandardCore_CS.cginc(203) (on d3d11)
     
  8. WHKS

    WHKS

    Joined:
    Dec 13, 2011
    Posts:
    61
    can you have more than one clipping plane at a time?
     
  9. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Any idea how is it possible that even when the section box is greater than the model, these parts get colored?
    upload_2018-11-8_15-5-55.png
     
  10. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    + a second question:
    When i move the section box via a gizmo when a model is applied to it, then also the scale and rotation is changed. Is there an update function which can cause this?
     
  11. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,216
    Any chance to get it running in Lightweight SRP?

    What about your idea to build in in Unitys ShaderGraph?
    I tried so but not successfully because of missing "Opacity Mask" masternode input.
     
  12. jun476

    jun476

    Joined:
    May 28, 2017
    Posts:
    1
    Hello, compiling the .apk file with unity217.3.1, has been a failure, please tell me a correct method, thank you
     
  13. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    With this section setup i'm not able build it for windows, since in this file the setModel method uses code from UnityEditor part. Is there any possibility i can build it?
     
  14. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    I think I should be able to get the basic setups working with SRP shader graph. But the stencil buffers are not available for SRP yet, so it is not be possible to recreate the box section, corner section and many other features that are based on stencils in SRP yet.
    The SRP is still in the preview mode. Maybe I could gradually update the whole asset once it will get developed. But I'm not sure if I should just add the lwrp support into the asset or if to release a separate asset for lwrp.
    The LWRP would require a separate set of shaders and materials and using global ints instead of keywords in scripts.

    This is the single_plane scene I have recreated in LWRP:
    cs_lwrp.png
     
    Last edited: Dec 16, 2018
    Cascho01 likes this.
  15. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Obviously this can not work. Apologies and thanks for pointing this out. I will correct that in the nearest update.
     
  16. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    If you mean a number of clipping planes on a single material - this is managed by shader keywords included in a given shader file.
    In the "single_plane" demo scene you can see one single clipping plane.
    In the "pie" demo scene you can see two planes intersected along a line.
    In the "box_capped" or "cube_section" demo scene you can see six planes.

    The clipping planes in the demo are managed by global shader properties.
    But with use of script you can override them on the material levels, so you can also have separate plane settings for different materials.
     
  17. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,216
    Any chance you share the single plane LWRP shader so that we can play with it in Unity?
     
  18. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669

    Attached Files:

    Last edited: Dec 20, 2018
  19. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,216
    Cool!
    But without having tested it yet, I see the shader uses alpha.
    So the Rendering mode has to be set to Fade or Transparent, right?
    This is what I definitevely want to avoid because of the widely known depth sorting issues with many transparent objects.
     
  20. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    The default render queue in this shader is 2000, i.e. opaque. You can find the settings on the PBR Master Node.
     
  21. DcDeath

    DcDeath

    Joined:
    Apr 15, 2013
    Posts:
    12
    Hi, I was wondering if there is a cross section shader that works independently, meaning you could cut one in half on the x and the other on the y for example?
     
  22. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    All can work independenty.
    Including these from this asset as well as one for LWRP shader graph attached few entries earlier in this thread.
    Usually global properties are used, because usually models have not a single one but a number of materials.
    And usually we want the same cross section plane or surface on all the materials.
    For that reason the cross section properties are usually hidden and are managed from script as global properties.
    But they can always be overriden on the local material level. localSection.png
     
  23. Knipscher

    Knipscher

    Joined:
    Jun 20, 2018
    Posts:
    79
    Have you tried this in the HDRP? I tried to recreate the graph, but I wasn't able to get the section color to show up correctly -- it still receives light and shadow information. Maybe I missed something in the graph.
    ClippingPlaneExample.PNG

    ClippingPlane.PNG
     
    Last edited: Jan 8, 2019
  24. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    That is true - it depends on lighting - the shader graph based on the above attached file doesn't always bring correct results.
     
  25. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    165
    Hello @tomekkie2,

    I just purchased this asset based on the good reviews, and because it looks like it does what I need it to do. However, I'm having trouble figuring it out (perhaps in part because I'm doing so under a deadline). I need to animate a clipping plane in such a way that it reveals a road, making the road appear to be growing from a starting point. Much like you would if making a building grow from the ground in arch viz, but horizontal. Can you explain, step by step, how I would do this? Or provide a simple scene, say a plane and a cube it clips? (I think part of the problem I'm having trying to learn by looking at the provided scenes is sorting through the scripts and other elements that are more to do with the presentation via a runtime GUI, so a simple scene would be great.) Then I could see if I might be able to animate the pieces, and in this case I'll be using Timeline.

    Any help would be greatly appreciated!
     
  26. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Take a look a the simple section scene.
    The SinglePlaneSection object will be needed, with SectionSetup script.
    Assign your road gameobject as this script "model" variable.
    Animate an object along your road and attach the GizmoFollow script to it.

    This will work well if the road path is straight or little bendy i.e. the road direction range fits within 0-90 degree range.
    Or if a plane perpendicular to the road path crosses the path in one single point - for all the road length.
    If the road is more bendy - a solution could be to segment it and apply the cross-section for current segment only covering up to 90 degree, and switch on all the segments behind and switch off all the segments ahead.
    - if I got right what you mean.
     
    SpencerPDX likes this.
  27. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    165
    OK, I'll give that a shot, thanks very much!
     
  28. CaseyNSM

    CaseyNSM

    Joined:
    Aug 17, 2018
    Posts:
    8
    I've been trying to chase you down to ask you a specific question about your asset store time "World Space Transitions" we've been using it for our projects and have love the results, but we have run into an issue where if we need to export a package with the shaders and dependencies we run into an issue where the imported asset's Fading shaders can't find certain source files:



    Is there a fix for this? Thanks for your time if you can help us!
     
  29. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    165
    Hi again @tomekkie2,

    Finally getting a chance to try this, I've immediately hit a snag: The asset I have does not have a scene called "simple section." I have cube_section and sphere_section scenes, but nothing in the project has "simple" in the name.

    Tried importing the asset again (in case I accidently deleted this simple section scene), and Unity tells me I've already imported everything from the project.

    Here are all the scenes I'm seeing in the asset's scene directory:



    Thanks for the suggestions so far, and any help with this issue would be appreciated.

    In the meantime, I'll see if I can get your suggestion to work in one of these scenes.
     
  30. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    165
    Hi @tomekkie2,

    Following up, I did find a SinglePlaneSection in a scene called "single_plane" - is that the one you meant?

    Added a reference to my road object in the "model" field of SinglePlaneSection.

    Noticed SinglePlaneSection had "check shaders" and "create and assign section materials" buttons. When I did that, the existing Gizmo object sliced my road. Animated the Gizmo object and it animated the slicing. So that was promising.

    Added the GizmoFollow script to a Unity Plane object and it didn't seem to work at first, but then realized it was cutting at 90 degrees to the plane of the Plane. So that's workable too.

    However my road has multiple materials (for sidewalks and such), and in the process a single material was assigned to all parts of the object. So apparently I would have to rebuild the road to use a single material in order to use this approach? (Edit: I extracted my original sidewalk materials from my model, assigned them the cross-section shader, and assigned them back to the sidewalk objects - and it seemed to work! Funny how asking for help on a forum often leads me to figure out how to do things on my own.)

    Also, where the interior of the model is revealed, it has a bright red material, which isn't appropriate to what I'm doing. I really only need the backfaced polys culled and I'm good. (Edit: Never mind, instantly found the _SectionColor part of the shader)

    Thanks again for the help.



     
    Last edited: Mar 13, 2019
  31. NocSchecter

    NocSchecter

    Joined:
    Aug 19, 2015
    Posts:
    32
    Hi tomekkie2,
    I like your asset, it's what I was looking for. I am interested in buying it but before I would like you to answer some questions I have about its use:

    1.- The shaders that you use to make the curtes in the objects can be used in real time? For example, if I want the shader that cuts with plans, I go to Edit> Project settings> Graphics and add it to the list of Always Included Shaders.

    I commented because I was working with similar asset for cuts and when I did the procedure mentioned above and compiled my computer used 100% CPU, 95% ram and took days without generating a compiled (try to leave it several days because it was generating the shaders variants).

    2.- Are you using an extended standard shader with your cutting functions? from what I see it supports textures

    In summary what matters to me is that I can use the shaders in real time without generating large load lapses when creating my executable.

    thanks! :)
     
  32. softscience

    softscience

    Joined:
    Jan 30, 2014
    Posts:
    5
    Ah amazing! how are you using the geometry shader to resolve the issue of intersecting geometry still being visible through the cross-section?
     
  33. svg_mBerger

    svg_mBerger

    Joined:
    Nov 5, 2018
    Posts:
    7
    Will there be a Release with LWRP soon? Would be super useful for one of my projects that depends on LWRP with ShaderGraph. I already recreated the shader graph you provided, but I need a way to use a Plane mesh to determine the Cut of the mesh. Is there a way to achieve this, already?
     
    Robko75 likes this.
  34. w_adams

    w_adams

    Joined:
    Apr 7, 2016
    Posts:
    15
    Hi, I'm trying to use the tubes section shader and wondering if it is possible to make the cross-sectional shape of the tube which is doing the sectioning elliptical instead of circular? I've spent a little bit of time going through your code to figure out how you create the tubes in the shader, and obviously _AxisDir and _Rad are used, but I can't figure out where they are actually used to create your tubes. Would you please point me in the right direction?

    Thanks!
     
  35. w_adams

    w_adams

    Joined:
    Apr 7, 2016
    Posts:
    15
    For anyone wondering about this, I've just figured this out by evaluating an ellipse inequality against the posWorld vertex instead of the circle evaluation on line 182 of the section_clipping_CS.cginc:

    Code (CSharp):
    1.  
    2.     uniform float3 test = float3(-0.1, 1, 0);
    3.        if(_hitCount>0) _clip = _clip || (posWorld, (posWorld.x - test.x)*(posWorld.x - test.x)/.04 + (posWorld.z - test.z)*(posWorld.z - test.z)/.25 < 1);
    4.         //if(_hitCount>0) _clip = _clip || ((dot(posWorld - _hitPoint0 - _AxisDir0 * dot(_AxisDir0, posWorld - _hitPoint0),posWorld - _hitPoint0 - _AxisDir0 * dot(_AxisDir0, posWorld - _hitPoint0)) - _Rad0*_Rad0)<0) ;
    Which would work really for any 2D shape evaluation.
     
  36. cspid

    cspid

    Joined:
    Apr 25, 2014
    Posts:
    22
    Hello, could you please give a bit more information on how to override the shaders with script? I would like to have multiple clipping planes which affect certain materials but not others.
    Thanks!
     
  37. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    I can show you an example:
    Zrzut ekranu (110).png

    I wanted here to change the _SectionPoint 's on the individual cylinders to their centres.
    Code (CSharp):
    1. public class AlignSectionPointToCenter : MonoBehaviour
    2. {
    3.     //Material mat;//(if you wanted dynamic)
    4.     void Start()
    5.     {
    6.         //create and apply new material instance
    7.         Material mat = GetComponent<Renderer>().material;
    8.         mat.SetVector("_SectionPoint", transform.position);
    9.     }
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         //mat.SetVector("_SectionPoint", transform.position);//(if you wanted dynamic)
    15.     }
    16. }
    In this example some materials were shared between the cylinders, that's why I have created new material instances.
    If that was not the case I would use existing materials with:
    Material mat = GetComponent<Renderer>().sharedMaterial;
     
  38. Josen_Premium

    Josen_Premium

    Joined:
    Oct 24, 2018
    Posts:
    1
    @tomekkie2 Hi I recently bought your asset, it works perfectly for capped box, but is there a way to do it the other way around, making whats inside the box invisible and whats outside visible ? I know you have a version with the planes inverted the box corner one, but i would like it to be like a cube with 6 planes instead of just 3, would that be possible?
     
  39. cspid

    cspid

    Joined:
    Apr 25, 2014
    Posts:
    22
    Thanks for this! One last question if you don't mind - in an example like your picture above, how could I have one clipping plane that cuts the blue cylinders but not the green ones, and a second clipping plane that cuts the green cylinders but not the blue ones?

    Thanks !
     
  40. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Assign one cross-section material to green ones, and a second material to blue(silver) ones.
    Then use:
    Vector3 greenPoint;
    Material greenMat = greenCyl.GetComponent<Renderer>().sharedMaterial;
    greenMat.SetVector("_SectionPoint", greenPoint);
    Vector3 bluePoint;
    Material blueMat = blueCyl.GetComponent<Renderer>().sharedMaterial;
    blueMat.SetVector("_SectionPoint", bluePoint);
     
    Last edited: Jun 28, 2019
  41. Lenaely

    Lenaely

    Joined:
    Jun 28, 2019
    Posts:
    9
    Hello,

    I have purchased the plugin, it is cool.
    My problem is that I don't succeed in setting different section colors for intersected gemometry.

    I would like to mix the "Intersected geometry" and the "various material" but I don't know how.

    The render looks weird, because we can see "through" the surface of the mesh.

    Could you help me please ?

     
    Last edited: Jul 8, 2019
  42. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Yes, that can be done, of course.
    These are two groups of primitive cylinders intersected.
    ezgif.com-optimize(1).gif

    Or - using other set of shaders - we can reveal the number of intersected objects in the area:
    - hazel hatched - no intersection
    - green hatched - two cylinders intersect
    - blue hatched - three cylinders intersect
    int4.gif
     
    Last edited: Jul 12, 2019
  43. huzhen1211

    huzhen1211

    Joined:
    Oct 14, 2014
    Posts:
    2
    I bought this asset, very good, but I found a small problem.
    When I combine intersected_geometry with box_capped, the following situation arises.
    As you can see, there is a problem in the section behind the box.
    Can you solve this problem? Thank you very much.

    box1.png
     
  44. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    box_capped setup does not support intersecting geometry.
    intersected_geometry setup is supposed to work with single plane, not box.
    If there was a way to make the box_capped setup to work on intersected geometry, I guess that would make it more complicated and more resources intensive, but I have no idea at the moment.
     
  45. huzhen1211

    huzhen1211

    Joined:
    Oct 14, 2014
    Posts:
    2
    Thank you very much for your quick reply.
    I also have a question to ask, in intersected geometry, each object must add a material to take effect.
    This requires additional work.
    Can you realize the function of intersected geometry without adding this material? Thank you.
    mat.jpg
     
  46. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    The intersected_geometry setup uses stencil buffers to implement cross section on intersected meshes.
    The role of the IntersectPrepare material is to write to stencil buffers.
    Each encountered backface decreases the buffer value and Each encountered frontface increases it.
    Then the second material renders only when the numbers of encountered front faces and backfaces are the same i.e. after leaving the intersected object.
    These materials have different stencil operations and different render queues so I do not think it would be possible to combine them into a single one using single shader.
    You can read more on stencil shaders and see examples in the manual here https://docs.unity3d.com/2019.1/Documentation/Manual/SL-Stencil.html
     
    Last edited: Jul 12, 2019
  47. Lenaely

    Lenaely

    Joined:
    Jun 28, 2019
    Posts:
    9
    Hi,

    Thank you for your help so far.
    I'm trying to use "intersected geometry" shaders with the Planar xyzSectionGUI, it works great.

    But the intersectedPrepare shader doesn't support textures. I can only set a color to fill my surfaces instead.
    What should I add to the shader code to perform this?
    I'd like not to use planes.

    Thank you in advance.
     
  48. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    The intersectedPrepare shader doesn't support textures, because it is applied to mixed bits of meshes, some of them are frontfaces and some are backfaces, but are neither coplanar nor sharing common surface.
    So if we put the texture on them they would look strange.
    What effect do you need to get?
     
  49. Lenaely

    Lenaely

    Joined:
    Jun 28, 2019
    Posts:
    9
    Ho ok.
    Well, I forget about texturing for now ;)

    Thank you for your quick reply and help.
     
  50. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73
    @tomekkie2 @Cascho01 Is it possible to use this asset for VR dev? for example by using a Laserpointer to move the crossection plane?
     
    Last edited: Aug 7, 2019
unityunity