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();
        }
    }

}
相关推荐
林枫依依20 小时前
Unity Webgl在编辑器中报错:Cannot connect to destination host
unity·编辑器·webgl
KhalilRuan20 小时前
Unity-Shader详解-其一
unity·游戏引擎
Clank的游戏栈1 天前
Unity多线程渲染指令队列设计与集成技术详解
windows·unity·游戏引擎
Thomas_YXQ1 天前
Unity3D IK解算器技术分析
开发语言·搜索引擎·unity·全文检索·unity3d·lucene
星火撩猿2 天前
常见游戏引擎介绍与对比
unity·ue5·游戏引擎·godot
sky_smile_Allen2 天前
[Unity]-[UI]-[Prefab] 关于Unity UGUI 的布局及组件讲解
ui·unity·游戏引擎
太妃糖耶2 天前
URP-利用矩阵在Shader中实现物体的平移和缩放
unity·矩阵
是阿根2 天前
unity使用iTextSharp生成PDF文件
unity·c#·游戏引擎
常城3 天前
Unity中通过TMP使用图片字体
unity·游戏引擎
惊鸿醉3 天前
⭐Unity 开发 | 如何通过 NTP 网络时间实现精准的跨平台时间同步【附完整源码 + UI 模块 + 偏差分析】
网络·unity·游戏引擎