The Open-Cross-Section-Project (PBR+Shaderforge)

Hi,

I am producing ArchViz projects and tinkered a little CrossSection shader in Shaderforge:


See it in WebGL.

Being optimized for ArchViz it has two section planes, a horizontal and a vertical one.
The shader recieves position and y-rotation using global values from a runtime-helper-transform-gizmo which is included in the attached Unitypackage.

It is far away from being perfect but may be a good starting point for your improvements:
You are invited to use the package for free and share your improvements here.

Maybe someone knows how to access the backfaces and make them red?

Looking forward,
Carsten

PS: Please make your improvements in Shaderforge, so that users can simply customize it to their needs without writing any shadercode.

2606160–182932–TheOpenCrossSectionProject.unitypackage (1.5 MB)

3 Likes

I have accessed the backfaces.
To get that I turned your shader backfaces off.
Then made a simple backfaces shader and applied it to GameObject’s duplicates.
See the result here:

I think it would be more logical to set/enable a shader keyword instead of a float like “_OpacityOverride” to manage the clipping on/off.

I made this backfaces shader outside SF, but I guess it should be possible to make a similar one in SF or even add the backface in the crossSection shader.

I am just wondering if there are any practical reasons for setting another clipping plane just perpendicular to the first one instead of paralell or inclined at arbitrary angle.
Is there a need for more planes, like a third one perpendicular to the first two?

I also like the gizmo, athough there are errors with moving it along axis. It actually moves on clicking the axis, especially when clicking from directions close to paralell. I guess the raycast hit.point should be cast on the axis in order to eliminate that.

2607532–182853–TheOpenCrossSectionProject.unitypackage (1.73 MB)

You can use the Face Sign node to differentiate between front and back faces, then lerp the color based on that value.

1 Like

Thanks, that´s a way to do it, but doublicating geometry is not my favorite way.

In architecture presentations we usually have only two sections, horizontal and vertical.
But defining a sectionplane by a direction (a faces normal, Vector3) would also be a great.
But unfortunately I wasn´t able to make it in SF.

Feel free to improve and upload the Gizmo.cs script :wink:

Ahhhh, I didn´t know about that node! :hushed:
Implemented it in the Shaderforge-Shader and updated the Unitypackage:

Great - now we have customized colored backfaces!

Do you mean two sections active at a time or only one at a time; horizontal or vertical ?

I guess you can define a second angle so the normal could be converted and passed as angles.

So now you will be able to use the cross section to show variety of materials using separate colors for structure, insulation, etc.

Common 2d cad-drawings are based on a single section, vertical OR horizotal…
Well, having a cross section tool for realtime architecture presentations offers new possibilities and there are no rules.
So I thought having the two sectionplanes active at the same time is cool and reasonable.

This would be the way to go, but my nodetree in SF is a bit hacky and until now I don´t know how it could be done.
Maybe the whole node structure should be reconsidered.

Agree, the project now looks cool with 2 perpendicular planes and y rotation, don’t you fear it would get a bit weird if we added the second rotation axis? Not too much and too complicated for an average user?

I guess that could be a key issue for the further development of this open source SF-cross-section project. Possibly someone will know and will help us.

1 Like

Yes, it would get too complicated for the average user, but I would allow to enable the second axis in a little menue under advanced settings…

Definately!

2612641--183221--pie.jpg

It might be cool to apply a pie section like this:
http://virtualplayground.d2.pl/SFcrossSection/pie/

  • if someone finds a way to put the plane normals in the SF nodetree. I have modified the shaders manually.

is it possible, or has anyone made a shader where the polygons are clipped against a bounding volume, like a cube or sphere?

I would like to make two parallel cross-sections, just to get a slice of 3d object. Is it possible with hat shader?

Yes, definately, but I´m afraid you´ll have to try it on your own (with Shaderforge).

I understand. However, unfortunately I know nothing about shaders, nor shadowforge, so I won’t be able to do this on my own. I just had an idea, how I could use it and hoped that maybe it will be ok as it is. Thanks for reply.

Not difficult; you can start from the sliced shader example here:
Unity - Manual: Surface Shader examples.

Hello. I’ve make a system like yours for an app of Embryo Visualization in 3D, but i want to make that hidden part of the gameObject not clickable. Do you think this possible?

Well, the vertices still exist and the collider also remains unaffected, - so I don´t know how, sorry.

Or maybe, when the object is totally hidden, disabling it. But i don’t know what condition i can use to make it happen.

2681668--189524--ClippingProblem1.PNG



That’s relatively easy to achieve, but with the section area not clickable, either. I could post a simple script for that, if still interested.
To make clipped volume not clickable - just cast a ray and check the hit.point the same way like is is being done in shader and that’s all.

I would use a more generic plane notation that can handle any plane position and rotation. Pretty much the same as unity uses internally in the Plane class. (Normal and distance from the origin.) It might look a bit more complicated at first, but it can be implemented very elegantly (and fast) in a shader. And it still needs just 4 floating point values.

There are various ways to initialize the Plane object base on a transform, but this is one:

new Plane (transform.rotation * Vector3.up, transform.position); // No rotation has the plane facing up

Then you transfer the information to the shader like this:

new Vector4 (plane.normal, plane.distance); // This probably only works with my own Vector4 version...
new Vector4 (plane.normal.x, plane.normal.y, plane.normal.z, plane.distance); // This should work by default

Then to detect whether you are clipped by the plane in the shader:

if (dot (pos_world, plane.xyz) > plane.w) // Elegant
{
}

An extra feature is that you can easily apply shading to the clipped part by just reusing the plane normal:

// Inside the clip detection if
normal_world = plane.xyz;
// Apply shading or just output the new normal