栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

图片颜色局部处理

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

图片颜色局部处理

鼠标点击位置,图片局部颜色处理:

Shader "Unlit/Highlight"
{
	Properties
	{
		_MainTex("Texture", 2D) = "white" {}
	}
		SubShader
	{
		Tags { "RenderType" = "Transparent" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#include "UnityCG.cginc"

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

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			float2 m_uv;
			float m_r;

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

			fixed4 frag(v2f i) : SV_Target
			{
				fixed4 col = tex2D(_MainTex, i.uv);
				float minx = m_uv.x - 0.2;
				float maxx = m_uv.x + 0.2;

				float miny = m_uv.y - 0.2;
				float maxy = m_uv.y + 0.2;

				if (i.uv.x > minx && i.uv.x < maxx && i.uv.y>miny && i.uv.y < maxy)
				{
					col.r = 1;
				}
				return col;
			}
			ENDCG
		}
	}
}

C#代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Highlight : MonoBehaviour
{
    public RectTransform m_rt;
    public Material mat;
    public Camera rayCamera;
    private void Start()
    {
        if (rayCamera == null)
            rayCamera = Camera.main;
    }


    private void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Vector2 uipos = Vector3.one;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(m_rt, Input.mousePosition, Camera.main, out uipos);
            uipos += new Vector2(250, 250);
            uipos /= 500;
            mat.SetVector("m_uv", uipos);
            Debug.LogError(uipos);
        }
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/901938.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号