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. sacunha

    sacunha

    Joined:
    Apr 21, 2016
    Posts:
    148
    Your asset looks really cool, but from the examples provided, it seems you can only do cross sections with planes, spheres, cubes and cilinders. Is there a way to do it with complex custom shapes?
    For example, I have 2 models (fighting each other), and I'd like to when one fist overlaps the oponent to show the 'hole' it makes. Could it do something like this?
     
  2. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Yes that is right. My asset can do much, but not everything.
    You should search for a kind of boolean shaders, intersection shaders or boolean mesh operations.
    This is not an easy matter.
    This is an example of what has been supposed to get released, but as far as I know - never got.

    I guess they might just get it working on simple solids like on the demo but didn't manage to get it working on any arbitrary mesh.
     
  3. sacunha

    sacunha

    Joined:
    Apr 21, 2016
    Posts:
    148
    Please note that when I said
    it was not my intention to diminish your work in any way. It came out wrong. My apologies. Your work is really impressive
     
  4. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Thank you very much.
    I didn't absolutely take your previous post disrespectful in any way.
    But I am concerned a bit if the number of section cases I have put into asset is not too big already. I am lacking some feedback on what from the asset is used most often and if some of that is redundant.
    Getting back to your initial question regarding cutting with 3d object I imagine possibliy a sort of Texture3D could be created for the cutting object and then could be applied as a shader variable in cross-section shader on the object to be cut.
     
  5. w_adams

    w_adams

    Joined:
    Apr 7, 2016
    Posts:
    15
    I'm trying to use the cross section / standard shader, but it doesn't render anything with transparency. Is this a known issue?

    Thanks.
     
  6. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    No, it is supposed to work with transparency, like in the demo scenes.
     
  7. w_adams

    w_adams

    Joined:
    Apr 7, 2016
    Posts:
    15
    Hmm, I'm wondering why it's not working for me. Is it possible to have a cross section shader that is basically a complete copy of the unity standard shader, and behaves the same way in the inspector, with just the cross section functionality added? Or is this how it's supposed to perform?
     
  8. arknano

    arknano

    Joined:
    Jul 17, 2013
    Posts:
    5
    Hi there, having some issues with capped box sections. I have four cubes making up parts of a map, and when viewed from above the caps do not seem to function. When I move the camera below the object, the caps appear as desired.
    Any idea what the issue might be? Unity_2018-02-17_19-42-13.png Unity_2018-02-17_19-42-23.png
     
  9. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    box-section-test10fps.gif

    I have tried to reproduce it by putting 4 boxes together.
    But it did not happen for me.
    I have used Clipping/Box/Standard shader here in this test.
    So check the render queues on your objects.
    Possibly they got somewhat mixed in wrong order.
    Or send me your scene so I could take a look.
     
  10. arknano

    arknano

    Joined:
    Jul 17, 2013
    Posts:
    5
    Thanks for your reply. I've reviewed the documentation again and it would seem that intersecting meshes aren't supported, which indeed seems to be the problem. It won't affect the design of our product (designed for an exhibition booth, which I thought was a neat coincidence after looking at your website!), so no worries at all!
     
  11. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Yes, you see on the above animated gif, that the boxes are distanced by small, but visible gap. If they touched I would have to use the "retract backfaces" feature on the shaders to move the backfaces a bit. You can also try that.
     
  12. sarahabdalfatah

    sarahabdalfatah

    Joined:
    May 23, 2017
    Posts:
    3
    I have just bought this, but honestly im finding it hard to know what to do, any sample video tutorial on how actually applying any of the clipping plane (cross section) on a regular cube? just a step by step option to something simple please
     
  13. contact2aravind

    contact2aravind

    Joined:
    Dec 24, 2017
    Posts:
    1
    Hai I would like to buy your asset, before that I have to ensure that wheather your asset works for my project. I have developed project called dicom viewer i.e voulme file loader, I have already using my shader called Unlit/BufferRender.
    Wheather your shader amphioxus with my shader or not. Herewith I have attached my shader. My friend brough your asset one year before, I have checked with your asset its not working, Could you please help me.
     

    Attached Files:

  14. arknano

    arknano

    Joined:
    Jul 17, 2013
    Posts:
    5
    Hi there, having trouble building to the Universal Windows Platform; when this package is included the build freezes. We're on 2017.3.0f3. Just wondering if this is a known issue or if you have any insight on what might fix it?
     
  15. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    It just takes time to compile all the shaders contained inside the Resources folder. I am going to move these shaders out of the Resources folder at the next update.
     
  16. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    This shader is dependent on file "../Volume/VolumeRender.cginc" and wouldn't work without it.
     
  17. molana

    molana

    Joined:
    Apr 15, 2018
    Posts:
    4
    Hi ,
    I used single-plane scene because it has many different objects with their own special cross-sections ( each object has it's individual cross section and this is very important for me) and this scene is appropriate for me. I just want to use the individual texture for each cross-section in the single-plane scene. Can anyone help me?? I do not know how to do it.
     
  18. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    This can be achieved with use of stencil shaders.
    I have sent you the project containing the below example scene:
    hatched.jpg
     
  19. pojoih

    pojoih

    Joined:
    Mar 30, 2013
    Posts:
    193
    Just to notice:

    I've got compiler errors in Unity 2017 LTS version.
    Changing every line of
    half4 tangentToWorldAndLightDir[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:lightDir]
    to
    float4 tangentToWorldAndLightDir[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:lightDir]

    in standard_CS.cginc and reimport everything helps
     
  20. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Thanks a lot.
    Yes, that fixes these errors. I have just submitted the upgrade which should work in 2017.4 and 2018.1.
    I hope it should get accepted and go live within the next few days.
     
  21. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    The asset has got updated for 2017.4 and 2018.1.

    I have got several requests for the same diffuse textures on GameObject materials and section or clipping planes materials. So I have added new example scenes for that.

    corner7.gif b7optimize.gif



    I have just submitted the new update with these scenes today and expect to get it accepted very soon.
     
    Last edited: May 20, 2018
    Amin- likes this.
  22. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    The asset got recently updated using Unity 2017.4.1
    However the current demos:
    WebGL: https://virtualplayground.d2.pl/crossSection/
    and Android apk: https://virtualplayground.d2.pl/crossSection/cs.apk
    were built from 2018.1.1

    A fix for those going to build from 2018.x:
    To avoid the shader compilation errors for gles - go to the UnityStandardCore.cginc file and replace two occurences of:
    UNITY_LIGHT_ATTENUATION(atten, i, s.posWorld);

    with:
    Code (CSharp):
    1.    #if !SHADER_API_GLES
    2.    UNITY_LIGHT_ATTENUATION(atten, i, s.posWorld);
    3.    #else
    4.    fixed atten = 1.0;
    5.    #endif
     
    Last edited: Jun 7, 2018
  23. Amin-

    Amin-

    Joined:
    Sep 27, 2017
    Posts:
    26
    hello tomekkie
    In this your picture , I marked the bugs :

    issue.jpg

    cross section " not filling "
    I have the same issue in my project !
    there are not any tips for this ?!

    thanks a lot .
     
  24. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    This screenshot dates back to the beginning to the asset.
    The reason is that the meshes intersect or butt together.
    At the beginning the only solution would be to reedit the meshes, leaving some minimal gaps between the adjacent faces, so they would not touch.
    But then I have added to the shaders the "retractBackfaces" feature, which moves the backfaces forward by a
    _BackfaceExtrusion float value which is a global shader variable.
    So you have to set the _BackfaceExtrusion global shader float in a script, and check the boolean retractBackfaces switch on the material.
    A special scene dedicated to that is included in the demo and in the asset.
     
    Amin- likes this.
  25. Amin-

    Amin-

    Joined:
    Sep 27, 2017
    Posts:
    26
    thanks for quick reply, my friend

    so how to use this feature without coding ?
    I set the " BackfaceOffsetSettings " script to my model and change that value but nothing happened!
    In addition to, change my shaders to CrossSection shaders.
     
  26. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    You can set the _retractBackfaces on the materials on your gameObject on.
    Copy the "UI_BackfacesOffset" object from the retractBackfaces scene to your scene.
    Enter the play mode and adjust the desired value with GUI slider.
    Put this value as BackfaceOffsetSettings in the BackfaceOffsetSettings script on the UI_BackfacesOffset object.
    Disable the backfaceOffsetPanel child object of the UI_BackfacesOffset, because you probably will not need this GUI slider in your game.
    Then in the play mode the role of the script will be just to set the retractBackfaces value to the shader on Start.
     
    Last edited: Jun 7, 2018
  27. MooMooMinkie

    MooMooMinkie

    Joined:
    Apr 22, 2013
    Posts:
    1
    Hi - I am having a build problem on OSX unity version 2017.4.5f1, using version 1.9:

    Shader error in 'Clipping/Box/Standard': cannot convert from 'half3' to 'float4' at Assets/crossSection/Resources/CS_Shaders/CGIncludes/standard_CS.cginc(194) (on glcore)

    the relevant code in the .cginc is:

    #define FRAGMENT_SETUP_CLIP(x) FragmentCommonData x = \
    FragmentSetup(i.tex,i.eyeVec, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS_CLIP(i));

    this doesn't happen when i build on windows. Any ideas?
     
  28. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    The version 1.9 was updated to work with the 5.6 release.
    I have updated a few times since then.
    I have just installed the OSX build support to the 2018.1.1 version, and I have tried to make a build containing this shader and it was succesful, no errors.
     
  29. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Hello :)
    Nice work!
    Is it possible to add a CrossSectionBox dynamically at runtime around a loaded gameobject?

    Thanks :)
    Jenni
     
  30. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    The current workflow assumes the cross section box gets added in Editor.
    But - of course - it could be adapted for dynamic addition at runtime.
    It is a matter or moving some functions or operations like bounding box calculation and fitting the box to the gameobject from editor to runtime.
     
  31. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    318
    Hello @tomekkie2,

    I just purchased your asset. It is very impressive!

    I am curious the best way to achieve a particular effect:


    When a character moved from one room to another, I need the room from which they were originated to be gradually hidden from top to bottom while the destination room is drawn from bottom to top.

    The rooms are of varying shapes and sizes and composed of multiple game objects. Is it possible for different groups of objects to be show/hidden independently using the planar approach?

    Or, would it be possible for one collection to be displayed only above the Y point and another below, and for which collection is display above or below to be changed at runtime?

    Thank you in advance for your time and consideration.

    Be well!

    - S.
     
  32. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    That should not be very complicated.
    I have included in some of the shaders (I don't remember at the moment if not all) the invert option. The invert option is not global, but on the material level. So you could just try to use the different sets of materials for your rooms, a set with the invert option off for one room and a set with the invert option on for the second room.
     
  33. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    318
    @tomekkie2:

    Thank you for your quick response!

    The option to invert the state of the shader is a good fallback, but would be limiting in practice. Is it possible to have different collections of items depend on a different Y-axis value?

    Be well!
    - S
     
  34. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Another option would be to use the same shaders and materials on both rooms, but to add a division plane between these rooms into clipping equation, to make everything to clip the forward way on one side of the division plane, and to clip the inverted way on the other side of the division plane.
     
  35. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Thanks for the answer :)
    I tried to add the CrossSectionBox dynamically into unity and add my loaded gameobject as the model for the SectionSetup. So far this works.
    Now when I load the model with TriLib (uses assimp) and click on "Create and Assign Section Materials" in the editor the following error occurs:
    ArgumentException: Invalid path
    System.IO.Path.GetDirectoryName (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:215)
    WorldSpaceTransitions.SectionSetup.CreateSectionMaterials () (at Assets/WorldSpaceTransitions/crossSection/scripts/SectionSetup.cs:121)
    etc.

    This error occurs because "AssetDatabase.GetAssetPath(mats)" returns empty in my case. I think this error is caused by the TriLib Loader :/

    Jenni
     
  36. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    So in the current version of the tool, there is no possibility to make it work with models loaded at runtime, right?
     
  37. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    I think it is, I will take a look in a few days.
     
  38. FGessler

    FGessler

    Joined:
    May 30, 2017
    Posts:
    4
    Currently we are also trying the same process as JenniB, therefore it would be great to know if it’s possible with this asset.
     
  39. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Thanks for your motivation, I hope to find an answer for this by tomorrow.
     
  40. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Thanks for your help :)

    I encountered another "problem".
    In my scene i am using Ambient Occlusion from the Post Processing Stack v2 of Unity.
    When i clip a part of my House model, the hidden part gets this ambient shadow attached. When i disable this ambient effect it disappeares. Any suggestion why this is the case or how i can solve this?

    upload_2018-7-30_16-8-34.png
     
  41. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    This is my solution, which works for now:

    1. Load your gameobject at runtime into the scene
    2. Create the Section Box around this model with the following code + applying the shader

    Code (CSharp):
    1. GameObject crossSectionBox = (GameObject) Instantiate(Resources.Load("CrossSectionBox"));
    2.                 SectionSetup sectionSetup = crossSectionBox.GetComponent<SectionSetup>();
    3.                 sectionSetup.model = YOURMODEL;
    4.                 sectionSetup.transform.rotation = YOURMODEL.transform.rotation;
    5.                 Renderer renderer = YOURMODEL.GetComponent<Renderer>();
    6.                 if(renderer == null) {
    7.                     renderer = YOURMODEL.GetComponentsInChildren<Renderer>()[0];
    8.                 }
    9.                 /* Set the cross section volume */
    10.                 Bounds bounds = renderer.bounds;
    11.                 CappedSectionCorner csc = sectionSetup.GetComponent<CappedSectionCorner>();
    12.                 if (csc) csc.Size(bounds);
    13.                 CappedSectionBox csb = sectionSetup.GetComponent<CappedSectionBox>();
    14.                 if (csb) csb.Size(bounds);
    15.                 Planar_xyzClippingSection pcs = sectionSetup.GetComponent<Planar_xyzClippingSection>();
    16.                 if (pcs) pcs.Size(bounds);
    17.                 crossSectionShader = Shader.Find("Clipping/Box/Standard");
    18.                 Material[] materials = renderer.materials;
    19.                 /* Apply shader to main component */
    20.                 foreach (Material material in materials) {
    21.                     material.shader = crossSectionShader;
    22.                 }
    23.                 /* Apply shader to all children of the main component */
    24.                 foreach (Transform child in YOURMODEL.transform) {
    25.                     Renderer childRenderer = child.gameObject.GetComponent<Renderer>();
    26.                     if (childRenderer != null) {
    27.                         Material[] childMaterials = childRenderer.materials;
    28.                         foreach (Material material in childMaterials) {
    29.                             material.shader = crossSectionShader;
    30.                         }
    31.                     }
    32.                 }
    This works so far for me :)
     
    tomekkie2 likes this.
  42. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Thank you very much for your input.
    Apologies for taking so much time, but I have modified the SectionSetup script to support the runtime assignments.
    The changes inlcude adding the public method "SetModel(GameObject model)" for runtime assignment.
    Then I also made the box child object to dissapear (visually) when nothing is assigned.

    So the workflow for runtime assignments would be placing the capped box prefab either in editor or at runtime and any new object can be assigned or reassigned just any time in editor or at runtime.

    The gameobject, newly assigned at runtime should have the appropriate materials already applied (Clipping/Box or Clipping/Corner ).

    When objects are heavy, assigning them at runtime could freeze the app for a while in time of the boundbox calculations. The calculation process is based on mesh vertices, so it is quite intricate.
     

    Attached Files:

    Last edited: Jul 31, 2018
  43. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Thanks :D
    In my approach I manually executed the Setup() method, but with SetModel() it is now less code :)

    Will this be an update for the next version of the plugin? So i have to replace the SectionSetup.cs for now?
     
  44. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Anyone an idea regarding the shadows?
     
  45. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    Yes, it will.
    I got complaints on freezing at start at the previous version of thescript version and now when these boxes are assigned in editor the boundbox is calculated in editor, when assigned at runtime, is calculated on assignment, and this is the best solution.
    I witt take a look in a few days into these issues with post processing and let you know.
     
  46. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Thank you :)

    One thing i saw during playing with the section box tool is, when i have two section boxes in my scene, both with different models attached, depending on which section box i am currently changing, the other model in the section box fully disappeares :eek:

    upload_2018-8-2_18-35-26.png
     

    Attached Files:

  47. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    I tested it and yes it freezes for some seconds.
    Your getBounds() method takes too long. With my approach using
    Code (CSharp):
    1. Bounds bounds = Renderer.bounds;
    it executes faster. Maybe you can adjust it in your code?
     
  48. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    That works certainly very well if you have a single renderer and the crossection box is orientated in world coordinates.
    But the cross section box is supposed to work on hierarchies with objects randomly oriented within the parent, and can also be optionally oriented either to world or to the parent.
    So if you just simply collected and encapsulated the renders bounds from the child objects, the resulting bounds would not respond the real bounds, but would get much bloated.
    But I have noticed something missing in the script and I have added one line and take this opportunity to upload it again.
     

    Attached Files:

  49. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    669
    That is because the only one single crosssection box is supported at the moment by the asset.

    The cross section boundbox is driven by global shader variables.
    There is a possibility to make on she shaders an option to expose these global variables locally and then if you have multiple boxes you could apply separate sets of materials to each of the boxes' models and iterate through materials on the boxes individually when the boxes change.
     
  50. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    You found anything so far? :)

    Jenni
     
unityunity