Search Unity

User Clip Planes

Discussion in 'Shaders' started by ivkoni, Dec 3, 2010.

  1. ivkoni

    ivkoni

    Joined:
    Jan 26, 2009
    Posts:
    978
    I don't see anything of that sort available in the GL library.
    Why?
     
  2. ivkoni

    ivkoni

    Joined:
    Jan 26, 2009
    Posts:
    978
    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.

    Code (csharp):
    1.  
    2. Shader "Test Clip" {
    3.     Properties {
    4.       _MainTex ("Texture", 2D) = "white" {}
    5.       _BumpMap ("Bumpmap", 2D) = "bump" {}
    6.       _planePoint ("plane point", Vector) = (0,0,0,0)
    7.       _planeNormal ("plane normal", Vector) = (0,1,0,0)
    8.     }
    9.     SubShader {
    10.       Tags { "RenderType" = "Opaque" }
    11.       Cull Off
    12.       CGPROGRAM
    13.       #pragma surface surf Lambert
    14.       struct Input {
    15.           float2 uv_MainTex;
    16.           float2 uv_BumpMap;
    17.           float3 worldPos;
    18.       };
    19.       sampler2D _MainTex;
    20.       sampler2D _BumpMap;
    21.       float4 _planePoint;
    22.       float4 _planeNormal;
    23.       void surf (Input IN, inout SurfaceOutput o) {
    24.          clip(dot(IN.worldPos - (float3)_planePoint,(float3)_planeNormal));
    25.           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    26.           o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
    27.       }
    28.       ENDCG
    29.     }
    30.     Fallback "Diffuse"
    31.   }
    32.  
     

    Attached Files:

    Last edited: Dec 4, 2010
    taxvi and Wolfram like this.
  3. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    339
    thank you!
     
  4. RyuMaster

    RyuMaster

    Joined:
    Sep 13, 2010
    Posts:
    468
    Now dozens of thanks to you!! This little code really saved me a lot of time
     
  5. Dover8

    Dover8

    Joined:
    Aug 20, 2010
    Posts:
    94
    Excellent, this gives me a good base to work from. Thanks.
     
  6. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Thanks much. You just saved my day
     
  7. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    Thanks a lot, works perfectly! :cool: