用着色器打孔

时间:2018-03-12 07:02:22

标签: shader hlsl

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"
}

这里首次编码着色器。 我已经找到了一个非常好的教程来实现上述大部分内容。 现在它做的是使球形区域发光并着色,但其他一切都是灰色的:简单。 但是,我想从那里做一些改变,并且真的卡住了。

我想要做的是用球形区域替换颜色,只在这个表面上形成一个透明孔。我是在正确的轨道上吗?或者我甚至没有使用正确的着色器类型?

Current of the shader

0 个答案:

没有答案