Unity 获取RenderTexture像素颜色值

拿来吧你~

🦪功能介绍

💡不通过Texture2D 而是通过ComputerShader 提取到RenderTexture的像素值,效率有提升哦!

💡通过扩展方法调用,方便快捷:xxxRT.GetPixel

💡传送门👈

🌭Demo

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
namespace ZYF
{
    public class GetRTPixelDemo : MonoBehaviour
    {
        public RenderTexture rt;
        public UnityEvent<Color> onGetColor;
        private void Update()
        {
#if !ENABLE_INPUT_SYSTEM
            var mPos = Input.mousePosition;
#else
            var mPos = Mouse.current.position.value;
#endif
            var pos = new Vector2Int((int)mPos.x, (int)mPos.y);
            var color= rt.GetPixel(new GetRTPixelExtension.RequestInfo(pos));
            onGetColor?.Invoke(color);
        }
        private void OnDestroy()
        {
            rt?.EndGetPixel();
        }
    }

}
相关推荐
浅陌sss13 小时前
Unity中可靠的UDP实现
unity
奔跑的犀牛先生19 小时前
unity学习46:反向动力学IK
unity
幻世界21 小时前
【工具插件类教学】实现运行时2D物体交互的利器Runtime2DTransformInteractor
unity·交互·运行时2d物体交互
音视频牛哥2 天前
Unity实现高性能多实例RTSP|RTMP播放器技术实践
unity·游戏引擎·音视频·实时音视频·大牛直播sdk·rtsp播放器·rtsp player
Artistation Game2 天前
三、Unity基础(主要框架)
游戏·unity·c#·游戏引擎
Edision_li2 天前
DeepSeek教unity------MessagePack-03
unity·messagepack
lalapanda2 天前
Unity学习part2
学习·unity·游戏引擎
CODE_RabbitV2 天前
【快速入门】Unity 常用组件(功能块)
unity·游戏引擎
BuHuaX2 天前
Unity-New Input System
unity·c#·游戏引擎·游戏程序·lucene
Edision_li3 天前
DeepSeek教unity------UI框架
学习·ui·unity·c#