Search Unity

Transparent Vertex Boolean Shader

Discussion in 'Shaders' started by unitycis, Feb 20, 2018.

  1. unitycis

    unitycis

    Joined:
    May 18, 2017
    Posts:
    5
    I am working on boolean shader for WebGL, Where one object's particular part should be hide/transparent when it comes in range of another transparent object, In my code first object's particular part is getting visible when its coming with the range of second object, i want reverse of this function where second object's part should be invisible on contacted part.
    Please see attached ScreenShot.
    AlphaEffect is applied on first object (Textured in image)
    StandardShader is applied on second object (Red colour object in image)
    ===========================Code=====================

    Shader "AlphaEffect" {
    Properties {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _RimColor ("Rim Color", Color) = (1,1,1,1)
    }

    SubShader {
    Pass {
    ZTest Always Cull Off ZWrite off
    Fog { Mode off }

    CGPROGRAM
    #pragma vertex vert_img
    #pragma fragment frag
    #pragma fragmentoption ARB_precision_hint_fastest
    float4 _RimColor;
    #include "UnityCG.cginc"

    uniform sampler2D _MainTex;
    uniform float _TexWidth;
    uniform float _TexHeight;

    fixed4 frag (v2f_img i) : COLOR
    {

    fixed4 original = tex2D(_MainTex, i.uv);

    return original;
    }
    ENDCG

    }
    }

    Fallback Off

    }
     

    Attached Files:

    jagrawat likes this.
  2. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
  3. unitycis

    unitycis

    Joined:
    May 18, 2017
    Posts:
    5
    Hello Thank you for reply,
    As you can see common area of both cube are visible so that common area should be invisible/hide. Texture of second cube is showing on red cube, i want that area should be invisible
     
  4. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    So the intersected area of both cube should not be drawn? In that case you going to need additional pre-rendering stuff to let shaders figure our what areas will be special. What you can try:
    - Create new camera that renders into renderTexture with replacement shader (https://docs.unity3d.com/ScriptReference/Camera.SetReplacementShader.html), the custom shader will be simple unlit that fills 1/255 of color.
    - When other objects will sample renderTexture and if the color is greater than 1/255, it knows there was two or more objects drawn.