0
Shader "Custom/Mask" 
{
    Properties 
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _ColorStrength("Color Strength", Range(1,4)) = 1
        [Space(10)]
        _EmissionColor("Emission Color", Color) = (1,1,1,1)
        _EmissionTex("Emission (RGB)", 2D) = "white"{}
        _EmissionStrength("Emission Strength", Range(1,4)) = 1
        [Space(10)]
        _Transparency("Transparency", Range(0, 1)) = 0
    }
    SubShader 
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows

        #pragma target 3.0

        sampler2D _MainTex, _EmissionTex;

        struct Input 
        {
            float2 uv_MainTex;
            float2 uv_EmissionTex;
            float3 worldPos;
        };

        fixed4 _Color, _EmissionColor;
        half _ColorStrength, _EmissionStrength, _Transparency;

        uniform float4 FILTERmask_Position;
        uniform half FILTERmask_Radius;
        uniform half FILTERmask_Softness;

        void surf (Input IN, inout SurfaceOutputStandard o) 
        {
            // Albedo
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            // Grayscale
            half grayscale = (c.r + c.g + c.b) * .3;
            fixed3 c_g = fixed3(grayscale,grayscale,grayscale);
            // Emission
            fixed4 e = tex2D(_EmissionTex, IN.uv_EmissionTex) * _EmissionColor * _EmissionStrength;
            // Transparency
            // Put Transparency here

            half dist = distance(FILTERmask_Position, IN.worldPos);
            half sum = saturate((dist - FILTERmask_Radius) / -FILTERmask_Softness);
            fixed4 lerpColor = lerp(fixed4(c_g,1),c * _ColorStrength,sum);
            fixed4 lerpEmission = lerp(fixed4(0, 0, 0, 0), e, sum);

            o.Albedo = c.rgb/*lerpColor.rgb*/;
            o.Emission = lerpEmission.rgb;
            o.Alpha = c.a * _Transparency;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

First time coding shader here. I've found a pretty good tutorial to follow to achieve most of above. What it does now is making a spherical area glow and colorize, but everything else gray: Simple. However, I wanted to make some change of my own from there and really got stuck.

What I wanted to do was replace the colorization with the spherical area to just make a transparent hole on this surface. Am I on the right track? Or am I not even using the right shader type?

Current of the shader

Arcana Affinity
  • 307
  • 7
  • 18
  • your shader doesn't work for me.when I change properties nothing happens, Take a photo if possible.The question is not clear but I think you need [Boolean operations on polygons](https://en.wikipedia.org/wiki/Boolean_operations_on_polygons) In modeling software.so you can use stencil buffers to making it like this [tutorial](https://gamedev.stackexchange.com/questions/152824/how-can-i-create-a-see-behind-walls-effect/152825#152825) – Seyed Morteza Kamali Mar 12 '18 at 08:07
  • @SeyedMortezaKamali Thanks for trying to help! I've added a picture to demonstrate the current of my shader. If, in your attempt, the _Transparency and everything about it didn't work, then yes that's exactly where I am. – Arcana Affinity Mar 12 '18 at 08:12
  • your transparent didn't work because you should use alpha in your pragma like this : `#pragma surface surf Standard fullforwardshadows alpha:fade` – Seyed Morteza Kamali Mar 12 '18 at 08:13
  • @SeyedMortezaKamali That was magical. It did the _Transparency some good, but the entire surface is now faded by _Transparency, not the spherical area. I assume this is what I've done wrong in my o,Alpha? – Arcana Affinity Mar 12 '18 at 08:16
  • 1
    because Instead of using texture alpha you should use circle alpha so change the alpha line to `o.Alpha = 1-sum * _Transparency;` – Seyed Morteza Kamali Mar 12 '18 at 08:25
  • @SeyedMortezaKamali Problem is solved! Thank you soooo much! q.Q What should I be touching if I wanted to make multiple of those circle areas? In my last attempt the shader only accepted one circle at a time. – Arcana Affinity Mar 12 '18 at 08:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/166662/discussion-between-seyed-morteza-kamali-and-ho-jeong-lee). – Seyed Morteza Kamali Mar 12 '18 at 08:29

0 Answers0