• ugui 灰度shader mask冲突解决 转。。。


    项目上遇到了一个问题,灰度shader无法在mask下使用,两个之间会一定的冲突。经查验是mask组件对shader的相关属性有要求,添加相关的属性则可符合要求使其他shader使用UGui里的mask。

    1. Shader "Custom/Opaque"
    2. {
    3. Properties
    4. {
    5. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6. _Color ("Tint", Color) = (1,1,1,1)
    7. // required for UI.Mask
    8. _StencilComp ("Stencil Comparison", Float) = 8
    9. _Stencil ("Stencil ID", Float) = 0
    10. _StencilOp ("Stencil Operation", Float) = 0
    11. _StencilWriteMask ("Stencil Write Mask", Float) = 255
    12. _StencilReadMask ("Stencil Read Mask", Float) = 255
    13. _ColorMask ("Color Mask", Float) = 15
    14. }
    15. SubShader
    16. {
    17. Tags
    18. {
    19. // ...
    20. }
    21. // required for UI.Mask
    22. Stencil
    23. {
    24. Ref [_Stencil]
    25. Comp [_StencilComp]
    26. Pass [_StencilOp]
    27. ReadMask [_StencilReadMask]
    28. WriteMask [_StencilWriteMask]
    29. }
    30. ColorMask [_ColorMask]
    31. Pass
    32. {
    33. // ...
    34. }
    35. }
    36. }

    完整代码如下:

    Shader "Unlit/graytest"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {}
    _StencilComp("Stencil Comparison", Float) = 8
    _Stencil("Stencil ID", Float) = 0
    _StencilOp("Stencil Operation", Float) = 0
    _StencilWriteMask("Stencil Write Mask", Float) = 255
    _StencilReadMask("Stencil Read Mask", Float) = 255
    _ColorMask("Color Mask", Float) = 15
    _LayerDepth("LayerDepth", Float) = 15
    }

    SubShader
    {
    Tags { "RenderType"="Opaque""Queue"="Geometry" }
    LOD 100
    Stencil
    {
    Ref[_Stencil]
    Comp[_StencilComp]
    Pass[_StencilOp]
    ReadMask[_StencilReadMask]
    WriteMask[_StencilWriteMask]
    }
    ColorMask[_ColorMask]
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // make fog work
    #pragma multi_compile_fog

    #include "UnityCG.cginc"

    struct appdata
    {
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
    };

    struct v2f
    {
    float2 uv : TEXCOORD0;
    UNITY_FOG_COORDS(1)
    float4 vertex : SV_POSITION;
    };

    sampler2D _MainTex;
    float4 _MainTex_ST;

    v2f vert (appdata v)
    {
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    UNITY_TRANSFER_FOG(o,o.vertex);
    return o;
    }

    fixed4 frag (v2f i) : SV_Target
    {
    // sample the texture
    fixed4 c = tex2D(_MainTex, i.uv);
    fixed4 col = c.r*0.3 + c.g*0.59 + c.b*0.11;
    // apply fog
    UNITY_APPLY_FOG(i.fogCoord, col);
    return col;
    }
    ENDCG
    }
    }
    }

  • 相关阅读:
    webpack(二)
    webpack(一)
    初探Vue SSR(1)
    Node版本管理控制器n
    Gitlab用户在组中有五种权限:Guest、Reporter、Developer、Master、Owner
    微信小程序分享参数传递
    关于vue-cli3.*搭建项目遇到问题整理
    请求头出现provisional headers are shown 和 vue-cli 3.x配置跨域代理
    HDU6409 没有兄弟的舞会
    HDU6446 Tree and Permutation
  • 原文地址:https://www.cnblogs.com/rexzhao/p/8477450.html
Copyright © 2020-2023  润新知