Unity3DCrossSectionShader icon indicating copy to clipboard operation
Unity3DCrossSectionShader copied to clipboard

OnePlaneBSPTransparent

Open freeseus opened this issue 6 years ago • 0 comments

I'm trying to get the "OnePlaneBSPTransparent" shader to look like the unlit texture (no shadows). The following code below works, but it has shading, which I would like to remove:

Shader "CrossSection/OnePlaneBSPTransparent" { Properties{ _Color("Color", Color) = (1,1,1,1) _CrossColor("Cross Section Color", Color) = (1,1,1,1) _MainTex("Albedo (RGB)", 2D) = "white" {} _Glossiness("Smoothness", Range(0,1)) = 0 _Metallic("Metallic", Range(0,1)) = 0 _Transparency("Transparency", Range(0.0,1)) = 1 _PlaneNormal("PlaneNormal",Vector) = (0,1,0,0) _PlanePosition("PlanePosition",Vector) = (0,0,0,1) _StencilMask("Stencil Mask", Range(0, 255)) = 255 }

SubShader{
    Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
    //LOD 200
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha

    Stencil{
        Ref [_StencilMask]
        CompBack Always
        PassBack Replace
   
        CompFront Always
        PassFront Zero
    }

    Cull Back
    CGPROGRAM
    // Physically based Standard lighting model, and enable shadows on all light types
	#pragma surface surf Standard fullforwardshadows alpha
   
    // Use shader model 3.0 target, to get nicer looking lighting
	#pragma target 3.0
   
    sampler2D _MainTex;
   
    struct Input {
        float2 uv_MainTex;
        float3 worldPos;
    };
   
    half _Glossiness;
    half _Metallic;
    fixed4 _Color;
    fixed4 _CrossColor;
    fixed3 _PlaneNormal;
    fixed3 _PlanePosition;
    float _Transparency;
    bool checkVisability(fixed3 worldPos){
        float dotProd1 = dot(worldPos - _PlanePosition, _PlaneNormal);
        return dotProd1 > 0  ;
    }

    void surf(Input IN, inout SurfaceOutputStandard o){
        if (checkVisability(IN.worldPos))discard;
        fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
        o.Albedo = c.rgb;
        // Metallic and smoothness come from slider variables
        o.Metallic = _Metallic;
        o.Smoothness = _Glossiness;
        o.Alpha = _Transparency;
    }

    ENDCG
    Cull Front
    CGPROGRAM
    // Physically based Standard lighting model, and enable shadows on all light types
	#pragma surface surf Standard fullforwardshadows alpha
	// Use shader model 3.0 target, to get nicer looking lighting
	#pragma target 3.0
    sampler2D _MainTex;
   
    struct Input{
        float2 uv_MainTex;
        float3 worldPos;
    };
   
    half _Glossiness;
    half _Metallic;
    fixed4 _Color;
    fixed4 _CrossColor;
    fixed3 _PlaneNormal;
    fixed3 _PlanePosition;
    float _Transparency;
    bool checkVisability(fixed3 worldPos){
        float dotProd1 = dot(worldPos - _PlanePosition, _PlaneNormal);
        return dotProd1 > 0  ;
    }

    void surf(Input IN, inout SurfaceOutputStandard o){
        if (checkVisability(IN.worldPos))discard;
        fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
        o.Albedo = c.rgb;
        // Metallic and smoothness come from slider variables
        o.Metallic = _Metallic;
        o.Smoothness = _Glossiness;
        o.Alpha = _Transparency;
    }

    ENDCG
}

//FallBack "Diffuse"

}

I have also provided the code for the unlit/texture below:

Shader "CrossSection/UnlitTextureTest"{ Properties{ _MainTex("Base (RGB) Trans (A)", 2D) = "white" {} }

SubShader{
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 100
 
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha

    Pass{
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #pragma multi_compile_fog

        # include "UnityCG.cginc"

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

        struct v2f{
            float4 vertex : SV_POSITION;
            half2 texcoord : TEXCOORD0;
            UNITY_FOG_COORDS(1)
        };

        sampler2D _MainTex;
        float4 _MainTex_ST;

        v2f vert(appdata_t v){
            v2f o;
            o.vertex = UnityObjectToClipPos(v.vertex);
            o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
            UNITY_TRANSFER_FOG(o, o.vertex);

            return o;
        }

        fixed4 frag(v2f i) : SV_Target{
            fixed4 col = tex2D(_MainTex, i.texcoord);
            UNITY_APPLY_FOG(i.fogCoord, col);
            
            return col;
        }		

        ENDCG
    }
}

}

freeseus avatar Aug 31 '19 18:08 freeseus