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

}
相关推荐
4Forsee1 天前
【增强现实】快速上手 Vuforia Unity Android AR 应用开发
android·unity·ar
两水先木示1 天前
【Unity】对指定物体进行描边——模板测试法
unity·游戏引擎·shader·外描边
Miss_SQ1 天前
实现Unity录音、百度云语音转文字
unity·语音识别
CreasyChan1 天前
unity 对象池实测可用
unity·c#
weixin_424294671 天前
Unity项目的Artifacts文件夹过大怎么解决?
unity·游戏引擎
没事写写笔记1 天前
Unity HDRP14.0.12 Volume 配置参数
unity
红黑色的圣西罗1 天前
手游手动异形屏适配方案,类“明日方舟”
unity
Longyugxq2 天前
Untiy的Webgl端网页端视频播放,又不想直接mp4格式等格式的。
unity·音视频·webgl
avi91113 天前
Unity毛玻璃渲染模糊渲染Shader数学入门
unity·aigc·图形学·shader·hlsl
微光守望者3 天前
Unity小知识【1】:刚体(Rigidbody)与碰撞器(Collider)的区别,你真的清楚吗?
unity·游戏引擎