Approach for displaying intersection between plane and sphere

Hello everybody,

right now I’m working on a virtual Math Laboratory to examine intersections in the field of linear algebra with the Oculus Rift.

So far I couldn’t imagine a feasible solution to display a plane which intersects a sphere. For the first tries I used the standard transparent shader for both objects. Depending on the camera angle, sometimes the plane looks like that it is completely behind or in front of the sphere.

Do you have any ideas for displaying this case focusing on the intersection circle?

I was thinking about boolean operations between the plane and the sphere to cut out the intersection circle of the sphere and highlight it with a brigther stroke. But I have no clue how to solve this on runtime.

The next thing I’ll try will be something like a glas shader. I’ll follow a tutorial for shader forge.

I’m looking forward to any tips and recommendations!

Bump

Nobody?

It’s still an issue

I wrote a bit about transparency sorting here:
Render Mode - Transparent doesn’t work see video

TLDR: It’s working as expected. The efficient sorting of transparency in real time rendering is an unsolved problem, especially in the case of two transparent surfaces intersecting.

The solution for you would likely be to have to cut the model up on the CPU side and send it over as multiple parts that will be sorted properly … use those boolean operations you’re trying to show off for real!

As for the outline, that’s a tough one as well. There are plenty of ways to do this in a shader when mixing opaque and transparent geometry, but for all transparent you’re going to again have to rely on doing this on the CPU. Likely you’ll need to generate a mesh for the lines lines around the intersection and the mesh you want to highlight (which will also need to be split up if you want it to sort). You could also modify the model’s vertex colors or write to a texture that’s displayed, or pass information to the shader about the intersection plane and sphere and do distance field tests, but these get ugly fast for anything more than a single intersection and the texture copy back to the GPU can be slow which is bad for VR.

Thanks for your replay bgolus.

My approach now is to get this CGS library running with Unity primitives. After completing the step of boolean operations of two meshes, I’ll try to create proper material to display the intersection properly.

I guess your wants may be just an invert soft particle, like this

I modified a particle shader for this

Before Ctrl+C and Ctrl+V . You need to let soft particles work : turn on soft particles in quality setting

Shader "Particles/Intersection Additive" {
    Properties{
        _TintColor("Tint Color", Color) = (0.5,0.5,0.5,0.5)
        _MainTex("Particle Texture", 2D) = "white" {}
    _InvFade("Soft Particles Factor", Range(0.1,100.0)) = 1.0
    }

        Category{
        Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask RGB
        Cull Off Lighting Off ZWrite Off ZTest LESS

        SubShader{
        Pass{

        CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_particles
#pragma multi_compile_fog

#include "UnityCG.cginc"

        sampler2D _MainTex;
    fixed4 _TintColor;

    struct appdata_t {
        float4 vertex : POSITION;
        fixed4 color : COLOR;
        float2 texcoord : TEXCOORD0;
    };

    struct v2f {
        float4 vertex : SV_POSITION;
        fixed4 color : COLOR;
        float2 texcoord : TEXCOORD0;
        UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
            float4 projPos : TEXCOORD2;
#endif
    };

    float4 _MainTex_ST;

    v2f vert(appdata_t v)
    {
        v2f o;
        o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
#ifdef SOFTPARTICLES_ON
        o.projPos = ComputeScreenPos(o.vertex);
        COMPUTE_EYEDEPTH(o.projPos.z);
#endif
        o.color = v.color;
        o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
        UNITY_TRANSFER_FOG(o,o.vertex);
        return o;
    }

    sampler2D_float _CameraDepthTexture;
    float _InvFade;

    fixed4 frag(v2f i) : SV_Target
    {
#ifdef SOFTPARTICLES_ON
        float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
    float partZ = i.projPos.z;
    float fade = saturate(_InvFade * (sceneZ - partZ));
    i.color.a += saturate(1 - fade) * (1 - i.color.a);
    _TintColor.a += saturate(1 - fade) * (1 - _TintColor.a);
#endif

    fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
    UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
    return col;
    }
        ENDCG
    }
    }
    }
}

2379331--161858--QQ截图20151113004536.jpg

1 Like


I love the result. Thanks a lot!

1 Like

Good morning all together,

kinda got back to this thread, because there is a desire to extend this visualization to something like this (the drawn outline and especially the dotted part):

Source: Geogebra

Does anybody have an idea for this approach, maybe using the package Vectrosity?

So far I can think of calculating many points of the circle’s circumference, draw the visible ones as straight line and the hidden ones as dotted,

I just don’t know yet how to determine if a point is hidden or not. And I still have to figure out, how to make the hidden part of the circle visible.