Search Unity

A shader that cuts a texture from a texture

Discussion in 'Shaders' started by MrKsi, Jun 25, 2022.

  1. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
    Hi!
    I need to make a shader that cuts a texture from a texture
    Below is a picture of how I need it to be as a result:
    upload_2022-6-25_18-57-7.png
    I have a shader blank, but I do not know in which direction I should move next:
    Code (Boo):
    1.  
    2. Shader "KJPiGames/GlassImortalShader"
    3. {
    4.      Properties
    5.     {
    6.         _Color ("Color", Color) = (1,1,1,1)
    7.         _MainTex ("Broken Glass", 2D) = "white" {}
    8.         _HoleTex ("Hole Texture", 2D) = "white" {}
    9.     }
    10.  
    11.  
    12.     SubShader
    13.     {
    14.         Tags { "RenderType"="Opaque" }
    15.         LOD 250
    16.         CGPROGRAM
    17.  
    18.         #pragma surface surf Lambert
    19.         fixed4 _Color;
    20.         sampler2D _MainTex;
    21.         sampler2D _HoleTex;
    22.         struct Input
    23.         {
    24.             float2 uv_MainTex;
    25.             float2 uv_HoleTex;
    26.         };
    27.  
    28.         void surf (Input IN, inout SurfaceOutput o)
    29.         {
    30.             fixed4 base = tex2D(_MainTex, IN.uv_MainTex);
    31.             fixed4 two = tex2D(_HoleTex, IN.uv_HoleTex);
    32.  
    33.             two *= _Color;
    34.             base.rgb = base.rgb * base.a + two.rgb * (1 - base.a);
    35.             o.Albedo = base.rgb;
    36.             o.Alpha = _Color.a;
    37.         }
    38.  
    39.         ENDCG
    40.  
    41.     }
    42.     FallBack "Diffuse"
    43. }
    44.  
     
  2. tmcthee

    tmcthee

    Joined:
    Mar 8, 2013
    Posts:
    119
    change line 36 to
    Code (CSharp):
    1.  
    2. o.Alpha = two.r;
    3.  
    That should use the red channel from your hole texture as the alpha.
     
  3. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
    upload_2022-6-25_19-14-9.png
    It didn't help
     
  4. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
  5. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
    Okay, I did, who needs to take it

    Code (Boo):
    1. Shader "KJPiGames/GlassImortalShader"
    2. {
    3.     Properties{
    4.         _MainTex("Albedo (RGB)", 2D) = "white" {}
    5.         _MaskTex("Mask", 2D) = "white" {}
    6.     }
    7.         SubShader{
    8.             Tags { "RenderType" = "Opaque" "Queue" = "Transparent"}
    9.             Blend SrcAlpha OneMinusSrcAlpha
    10.             CGPROGRAM
    11.             #pragma surface surf Standard keepalpha
    12.             #pragma target 3.0
    13.             sampler2D _MainTex;
    14.             sampler2D _MaskTex;
    15.             struct Input {
    16.                 float2 uv_MainTex;
    17.             };
    18.             void surf(Input IN, inout SurfaceOutputStandard o) {
    19.                 fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
    20.                 fixed4 m = tex2D(_MaskTex, IN.uv_MainTex);
    21.                 c = c * m.r;
    22.                 o.Albedo = c.rgb;
    23.                 o.Alpha = c.a;
    24.             }
    25.             ENDCG
    26.     }
    27.  
    28.     FallBack "Diffuse"
    29. }
     
  6. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139