zoukankan      html  css  js  c++  java
  • Texture中指定具体颜色进行高亮显示

    实现: 高亮一张texture上相同颜色的色块。
    原理:使用step进行rgb的对比即可。



    Shader "Unlit/ChooseContinent" { //2018年4月8日 //for ui地图高亮所有相同的颜色块 Properties { _MainTex("Texture", 2D) = "white" {} _SwitchColor("SwitchColor",Int) = 0 //高光还是直接返回 _HighlightColor("HighlightColor",Color) = (0.498,1,0,0.3)//高光颜色 _ChooseR("ChooseR",Int) = 255//点击选择的颜色值 _ChooseG("ChooseG",Int) = 255 _ChooseB("ChooseB",Int) = 255 _ThresholdValue("ThresholdValue",Int) = 10//判断范围的阀值 _VertexOffset("VertexOffset",Vector) = (5,-15,0,0)//顶点偏移 } SubShader { Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" "CanUseSpriteAtlas" = "True" } Cull Back Lighting Off ZWrite Off ZTest Off Blend SrcAlpha OneMinusSrcAlpha Pass { Name "Default" CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 2.0 #include "UnityCG.cginc" #include "UnityUI.cginc" struct appdata_t { float4 vertex : POSITION; float4 color : COLOR; float2 texcoord : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float4 vertex : SV_POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; float4 worldPosition : TEXCOORD1; UNITY_VERTEX_OUTPUT_STEREO }; float4 _VertexOffset; v2f vert(appdata_t IN) { v2f OUT; UNITY_SETUP_INSTANCE_ID(IN); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); OUT.worldPosition = IN.vertex; OUT.vertex = UnityObjectToClipPos(OUT.worldPosition) - _VertexOffset; OUT.texcoord = IN.texcoord; return OUT; } sampler2D _MainTex; float _SwitchColor; float _Alpha; float4 _ChooseColor; float4 _HighlightColor; int _ChooseR; int _ChooseG; int _ChooseB; int _ThresholdValue; float4 frag(v2f IN) : SV_Target { if (_SwitchColor == 0) { return 0; } // sample the texture float4 col = tex2D(_MainTex, IN.texcoord); return step( 3 , step(abs(_ChooseR - col.r * 255), _ThresholdValue) + step(abs(_ChooseG - col.g * 255), _ThresholdValue) + step(abs(_ChooseB - col.b * 255), _ThresholdValue) )*_HighlightColor; } ENDCG } } }

      

    改变自己
  • 相关阅读:
    洛谷月赛 Hello World(升级版)
    codevs1001 舒适的路线
    vijos & codevs 能量项链
    vijos 运输计划
    noip2016普及组题解和心得
    UVa 10891 Game of Sum
    UVa 10635 Prince and Princess
    某模拟题题解 2016.11.17
    贪心入门题
    某模拟题题解 2016.11.16
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/8759828.html
Copyright © 2011-2022 走看看