Search Unity

CrossSection

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

?

What render pipeline are you using or going to use with the CrossSection Asset?

  1. Built-in

    29.7%
  2. URP

    54.9%
  3. HDRP

    15.4%
  4. other

    0 vote(s)
    0.0%
  1. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    crossSection tool has got released on the AssetStore.

    Here are the demos:

    WEBGL asset scenes demo (standard render pipeline)
    WEBGL asset scenes demo (universal render pipeline URP)
    WEBGL demo examples (standard pipeline)
    WEBGL demo examples (URP)
    Standalone Windows HDRP demo
    apk demo (builtin)
    apk demo (URP)


    Very simple to setup.
    Works on shaders.
    Works well on closed and not intersecting meshes as can be seen on the screenshots below and demos.
    Intersectig meshes are also supported with retract backfaces shader feature or by set of dedicated stencil materials shaders.

    The complex demos show the crossSection tool applied to some free models from the AssetStore.

    4 step process to setup single plane section:
    sections_2.gif
    demo_0000132.jpg
    timber_section.gif

    Contains a selective edge effect and supports post-processing effects.
    Untitled-20.gif
    Image Sequence_012_0000.jpg

    AssetStore link.
     
    Last edited: Jan 6, 2024
  2. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    What are the advantages of your shader against this one?
     
    Last edited: Jan 21, 2014
  3. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    There is a number of crossection shaders examples in this thread. The basic idea is exactly the same. But I've challenged myself with the idea of a crossection tool and I wanted a bit better and more versatile ones.
    Means you won't get this effect on these models with shaders from the thread. I actually use a set of substitute shaders for some selected Unity built-in shaders.

    BTW. The links keep on working for me. Does anyone else find them broken?
     
    Last edited: Jan 22, 2014
  4. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Very nice idea!
    I will be a future customer :)

    Keep up the good work!
    Kenshin

    PS: Demo links works fine for me
     
  5. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Thanks @kenshin.
    I hope you would find that useful.
    Possibly not as much in games as in architectural presentations or custom 3d object viewers.
     
  6. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    A simple script for the horizontal floor crossections together with the demo scene was added today.
     
    Last edited: Jul 11, 2014
  7. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    House model is nice, but I am not able to apply the crosssection effect .... any hint? :)
     
  8. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Not any more.
    Try now.
    Terribly sorry and great thanks for letting me know.
    The scene is loaded dynamically and I just changed the script name, rebuilt the loading scene and forgot to rebuild the target scene, so it lost a reference to the script.
     
  9. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    No problem man! :)

    Your script is very cool I have bought and I hope to use it soon in a real project.
    Keep up the good work!


    Bye
    Kenshin
     
  10. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
  11. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Would buy it if it was a Shaderforge-Shader that I could edit to fit my needs.....
     
  12. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    This is intended for making (faked) cross sections on complex GameObjects, using various materials with build-in Unity shaders - rather than a shaders collection.
    I have never used the Shader Forge, but tried to find out on the web if it is possible to define clippling planes and backface passes with Shader Forge and haven't found anything.
     
  13. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    It took me awhile to get the hang of working with this, but it works really well.

    I put together a quick demo that shows how to use it with prefabs (basically analyze the prefab materials up front, but apply the changes to an instance without wrecking the materials on other instances of the same prefab), and perhaps more importantly, how to quickly and easily use a GameObject to get the right position and angle of the desired clipping plane.

    The demo isn't interactive, but the code is fairly heavily commented and of course, if you can modify the location of the Marker object in the Prefab. Hope it helps. (And Tomasz, if you find it useful, please feel free to add it to your AssetStore package.)
     

    Attached Files:

    sarahabdalfatah likes this.
  14. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    You may be interested in this.
     
  15. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Thanks for your valuable contribution.
    Together with other posts It makes me understand that i have overcomplicated the issue a bit by setting the SectionOffset parameter.
    I guess it is messing the whole thing and I should just drop it, leaving just SectionPoint.
    Then allow for moving the SectionPoint within the rendeners.bounds of the GameObject and rotating the plane normal aroud the SectionPiont with the move/rotate gizmo.
    I would be going to change that at the nearest chance.
     
    Last edited: Apr 24, 2016
    kenshin likes this.
  16. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Last edited: Apr 27, 2016
  17. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
  18. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    (moved from the other thread)

    I just purchased your clipping asset to use the spherical clipping feature.

    However, I can't seem to get it working in a simple situation. I've tested the example scene and it works fine. But I can't seem to rework the SphereSectionExample script to work for a standard clipping situation, with a game object being used to determine the clipping sphere's position.

    In other words, I'm trying to have the clipping sphere follow a gameobject, as you can do with the other clipping methods. But I can't seem to get it working - at most I get the standard clipping even though I'm using the sphere script.

    So how should I set up the sphere clipping to achieve this?

    Thanks.

    EDIT
    Nevermind, turns out I just didn't have the proper CrossSection shader applied (one with the sphere feature on it.) Thanks for the great asset! :)

    I do have one request: do you think you will add support for rectangle or square clipping bounds? Or would it be easy to add myself?

    And I do have one more issue:
    it seems that, at least with the sphere shader, the clipped objects' shadows are still visible. Is there a fix for this? I could screenshot the issue if needed.
     
  19. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    I just had considered some features as experimental and didn't include them in all of the shaders to limit the number of variants possible.
    You could check the directives inside the shader; it could be something like:
    Code (CSharp):
    1. #pragma multi_compile __ CLIP_PLANE CLIP_TWO_PLANES CLIP_SPHERE CLIP_CUBE
    - to include all of them actually.
    Clipped object shadows: - it is not possible to dynamically update the baked shadows in the baked shadows lighting mode; try the realtime shadows instead.
    The below is the sample of what I have got, when trying to add the cube clipping. Is that what you are after? It is a bit more complicated than sphere clipping because the orientation matters here (in sphere does not).
    cube.jpg
    BTW I have just thought that cylinder clipping might also be interesting as you could make a "bulleting" effect using that; Unity has introduced new coding feature:
    Code (CSharp):
    1. Shader.SetGlobalVectorArray
    It could be used to set an array of clipping cylinders or spheres.
     
    tapawafo likes this.
  20. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    Thanks for the in-depth reply!

    I'll try your suggestion out. I actually was using realtime shadows, however now that I think about it, it may actually be Unity's new Ambient Occlusion camera effect that is shading the clipped object. I'll test it out and get back to you.

    As for the rectangular clipping, yes, that looks excellent, thank you! Cylinders would make a nice addition too, now that you mention it.

    And on the arrays - yes, it would be fantastic to have multiple clipping 'objects!' That would definitely be a killer feature - being able to have multiple clipping objects would allow tons of interesting applications, like clipping a character's mesh as a way of severing limbs, and etc...

    I'll be sure to leave a review on the asset page - thanks again for the amazing support. :)
     
  21. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    The realtime shadows get clipped on the standard and standard(specular setup) only, and only front faces do cast shadows, section surface (faked) does not.

    Thanks for the suggestions, I have tried to make a "bulleting" multiple clipping cylinders shader.

    bullets.jpg


    The shaders do not support dynamically sized arrays, the array size has to be declared and then it sets the limit for the maximum number of bullets.

    I have added these two scenes to the WebGL demo here:
    http://virtualplayground.d2.pl/crossSection/

    I will include them in the next release of the asset.
     
    tapawafo likes this.
  22. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    Looks great! Amazing work. :)
     
  23. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    At a cost of some extra complication and some extra rendering passes and draw calls I have managed to add (fake) caps as well as extra colouring and hatching.
    Possibly I will include that in the next releases of the asset.

    hatch.jpg
     
    tapawafo likes this.
  24. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    Wow, you work fast!

    Can't wait to try out the next release. :)
     
  25. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Thanks.
    As this could be named "box outside clipping setup" I think I should definately add an "inside box corner setup" that would have not six as in this case, but three clipping planes.
    I could add that to the asset.
    But I fear of making the asset cluttered to much, so users could get lost when they see too many scenes, too many stuff in it.
     
  26. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    I haven't needed to use this shader in quite awhile, so maybe it's already there, but I would think adding material support would be more useful than solid colors and hard-coding patterns like hatching.

    I was also trying to imagine how to add clip geometry (rather than a bunch of pre-determined shapes) but all I can think of is the newish Shader.SetGlobalMatrixArray for passing vertex info, and the array size limits probably make that impractical.
     
  27. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Thanks.
    Solid colors do matter when you have more then one cutting planes and obtuse angle between them.
    Hatching is not hardcoded, absolutely, it is just the material property which can be set to none and you can just use colors then.
    Using capping allows to use shading on section surfaces, the option I have used so far was _emission color.

    I guess most users would just get satisfied with the simplest possible one-plane setup and this should be exposed so they should be able to find it quickly and the basic built-in shaders are supported. Do you have any specific idea what is missing or what was missing at the time you were using this or what should I add?

    The geometry data passed to the shader ranges from 2 (single plane) to 5 (the box section mentioned recenty in this thread) Vectors and I can't see a specific use for Shader.SetGlobalMatrixArray at the moment.
    Do you find the manipulation objects like gizmos, GUI's useful
     
  28. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    I only needed a clipping plane. I suppose if you got into anything more complex you'd basically be talking about CSG. Not exactly simple stuff. But I was only referring to SetGlobals as a way to "cheat" to get arbitrary geometry into the shader (e.g. not to actually use it as matrix data). Just speculating.

    It didn't have the manipulation stuff when I used it. :)
     
    tomekkie2 likes this.
  29. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Basically I am also using Global variables and Shader.Enable/Disable Keyword to switch between the clipping patterns.
     
  30. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    CrossSection tool has just been updated and new features got included.
     
    tapawafo likes this.
  31. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    A new dissolve option:
    dissolve.jpg
    Drop me a line if anyone interested whether to include anything like that into a future release of the asset.

    I was wondering if use fade transparency, but finally decided not to use any transparency in order to not loose receiving shadows.
    Transparent shaders using fading or pre-multiply modes do not receive shadows, only cutout shaders using alphatest do.
    So I made this dissolve - basing on random texture3D.
    dissolve2.jpg
    Tweaking the texture scale value brings more cool effects:
    dissolve3.jpg dissolve4.jpg
     
    Last edited: Jul 31, 2017
    tapawafo likes this.
  32. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    outline_post_effect.jpg
    I am going to add this feature to the next update.
    But it depends on the Legacy Image Effects asset, so the user will have to import the selected files from Legacy Image Effects asset first, and the unitypackage with this will be included inside the asset folder.
     
    tapawafo likes this.
  33. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    989
    Hi tomekkie2,
    You shaders look really great and I'm considering purchasing this asset. However, I am curious if they support deferred rendering? More specifically, does the end-cap fill work in deferred?
     
  34. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Yes, but the dissolve option from my second last post here will be included in the other asset (free) - to be released soon.
    And the edge effect - from my last post here - (not included now - to be included in the nearest update) - will not work in deferred rendering.
     
  35. ben0ki

    ben0ki

    Joined:
    Oct 30, 2017
    Posts:
    13
    Hi tomekkie2,
    Awesome asset but I can't seem to make it work! I'm still new to unity so i'm struggling to figure out what scripts/systems tie to what - is there a more basic instruction text/video somewhere?
    Thanks
     
  36. chrisb1976

    chrisb1976

    Joined:
    Nov 14, 2016
    Posts:
    6
    Do the supplied shaders (e.g. Clipping - Box - Standard) work in Unity 2017? We are having trouble getting assets with them to receive shadows (baked or realtime). I am going to test again using Unity 5.6, see if the same thing happens.
     
  37. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    It used to work in Unity 5.6
    Now the latest Unity release is 2017.2, so maybe it is time for the update.
     
  38. frigi

    frigi

    Joined:
    Jul 15, 2014
    Posts:
    9
    Hi @tomekkie2,

    I really like the shaders!

    I have a few cases where they produce some hiccups though and would love to hear your thoughts:

    The first one is quite obvious:
    Intersecting meshes (or surfaces that are very close to each other) produce a whole lot of flickering and black cross sections. I'm fully aware that this sort of geometry is not ideal and I'm trying to avoid it as much as possible but that just won't always be possible. I think in my case there are ways to potentially cover up those spots with a different piece of solid geometry to hide the artefacts but I'd welcome any best practices you might have encountered while testing!

    The second issue might be a bit more delicate I'm afraid:
    As soon as I add a postprocessing stack to the camera (doesn't matter if it's still empty or has an actual effect enabled) all objects with your shaders on them turn black when running on an iPhone. More specifically this only happens when the camera is a certain distance from the object. As long as it's fairly close everything is fine but once the distance increases to roughly 1m it starts to clip to black. One can actually see the clipping move with the camera so it's possible to have the same object render fine and completely black depending on how close each point on the surface is to the camera. I couldn't reproduce this yet in the editor.

    I'm using Unity 2017.2 and the iPhone is running on iOS 11

    Also, when are you planning to release the dissolve option (and possibly also the transparent fade option I've seen somewhere around the forums lately)? I'd really like to give them a try as they would be great for a current project! Would it even be possible to get a package before it's released/approved on the asset store? (I can verify my purchase of course)

    Thanks!

    Fabian
     
  39. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    looks like the asset is not available anymore?
    are you calculating actual clipping planes or working with depth and front-backfade colors (or stencil masks?)
    would it work with intersecting geometry?

    I made a shader working with backfaces and setting the depth values of my cut-plane to the backface pixels but unfortunately the geometry is intersecting so that's not working there (because I maskout the frontfaces in the depth texture to not overwrite them..., see attached screenshots below)

    image_720.png

    image_360.png

    another attempt is to use a geometry shader for the cap plane but that's not finished yet
     
    Last edited: Dec 28, 2017
  40. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Try the Retrack backfaces feature, which I have added to fix that.

    I will take a look at this issue when updating for 2017.3

    I have already released that as free asset, see my asset store page.
     
  41. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    The asset is still available, I have just updated the links on the first entry, which so far pointed to the starting version which got deprecated - sorry for that.
    The asset uses face normals to detect front/back and stencil masks where the hatches are seen and in general is not recommended to use with intersecting geometry.
     
  42. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    Thanks for the info! Got my own geometry shader working now too which I needed because of the intersections... it's also super easy add slice textures with this

    upload_2017-12-30_15-24-48.png

    upload_2017-12-30_15-29-48.png
     
    softscience, tomekkie2 and one_one like this.
  43. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    intersection.png
    It is good idea to add a support for intersecting meshes. I did that by using additional stencil shader.
    Geometry shaders are beyond scope of my asset at the moment, because they are not supported in WebGL and I wouldn't like to put anything that wouldn't work in WebGL.
     
    Last edited: Jan 8, 2018
  44. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    ah so that works as well? Ok need to learn stencil shaders :)
     
  45. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Quite well.
    But it costs some extra draw passses compared to 'normal', non intersection setup.
    It uses stencils, not geometry shaders so can be available in webgl.
    I have already included that into demo scenes, so you can see.
    I have resumbitted the package, so it should be available soon.
     
    Last edited: Jan 10, 2018
  46. jbedo

    jbedo

    Joined:
    Mar 9, 2015
    Posts:
    5
    It is possible to render just the cross section result and hide everything else? I just started with unity.
     
  47. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    sectionOnly.png
    If that is what you are after, this can be easily achieved by putting two stencil materials on the object.
    The first one, name it SaveFrontToStencils, will use shader whose stencil section could look like this:
    Code (CSharp):
    1.         Stencil{
    2.             Ref [_StencilMask]
    3.             Comp never
    4.             Fail Replace
    5.         }
    The stencil section of the second shader could look like:
    Code (CSharp):
    1.         Stencil{
    2.             Ref [_StencilMask]
    3.             Comp NotEqual
    4.             Pass Zero
    5.         }
    (The stencil mask values of both material have to be the same)
     
  48. jbedo

    jbedo

    Joined:
    Mar 9, 2015
    Posts:
    5
    Thanks a lot, excellent shaders!!
     
    tomekkie2 likes this.
  49. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    outlines_only.png

    And it is also possible to see the section outline only. When you put:
    Code (CSharp):
    1. Comp never
    in the 3rd line of the stencil section of the second shader code.
    The above image comes from the game view, because this is the camera view.
    It just requires the camera image effects included in the package.
    The Comp property could also be parameterized as shader/material property, so you could switch the property on the material to see either the cross section result or its outline only.
     
    Last edited: Jan 30, 2018
  50. jbedo

    jbedo

    Joined:
    Mar 9, 2015
    Posts:
    5
    Thank you, sorry I missed the last post.
     
    Last edited: Jan 30, 2018