User Clip Planes

I don’t see anything of that sort available in the GL library.
Why?

I cooked up something extremely simple with a surface shader. (it’s a very slight modification of one of the surface shader examples in shader lab documentation). To my surprise, it seems to work. I hope it won’t have the precision problems oblique frustum clipping has when close to the clip plane.

Shader "Test Clip" {
    Properties {
      _MainTex ("Texture", 2D) = "white" {}
      _BumpMap ("Bumpmap", 2D) = "bump" {}
	  _planePoint ("plane point", Vector) = (0,0,0,0)
	  _planeNormal ("plane normal", Vector) = (0,1,0,0)
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      Cull Off
      CGPROGRAM
      #pragma surface surf Lambert
      struct Input {
          float2 uv_MainTex;
          float2 uv_BumpMap;
          float3 worldPos;
      };
      sampler2D _MainTex;
      sampler2D _BumpMap;
	  float4 _planePoint;
	  float4 _planeNormal;
      void surf (Input IN, inout SurfaceOutput o) {
		 clip(dot(IN.worldPos - (float3)_planePoint,(float3)_planeNormal));
          o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
          o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
      }
      ENDCG
    } 
    Fallback "Diffuse"
  }

444047–15436–$TestClip.zip (96.3 KB)

2 Likes

thank you!

Now dozens of thanks to you!! This little code really saved me a lot of time

Excellent, this gives me a good base to work from. Thanks.

Thanks much. You just saved my day

Thanks a lot, works perfectly! :sunglasses: