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

}
相关推荐
LF男男1 天前
GameManager.cs
unity
郝学胜-神的一滴2 天前
[简化版 GAMES 101] 计算机图形学 07:图形学投影完全推导
c++·unity·图形渲染·three.js·unreal engine
Avalon7123 天前
Unity3D响应式渲染UI框架UniVue
游戏·ui·unity·c#·游戏引擎
ellis19703 天前
Unity UI性能优化一之插件【Unity UI Optimization Tool】
unity·性能优化
Zik----3 天前
Unity基础学习笔记(B站视频课整理)
unity·vr
郝学胜-神的一滴4 天前
罗德里格斯旋转公式(Rodrigues‘ Rotation Formula)完整推导
c++·unity·godot·图形渲染·three.js·unreal
田鸡_4 天前
Unity新输入系统(Input System)教学篇
unity·游戏引擎·游戏程序
EQ-雪梨蛋花汤4 天前
【Unity笔记】Unity 音游模板与免费资源:高效构建节奏游戏开发全指南
笔记·unity·游戏引擎
星辰徐哥4 天前
Unity基础:游戏对象的激活与隐藏:SetActive方法详解
游戏·unity·lucene
微莱羽墨4 天前
零、0基础入门Unity 安装详细教程(2026最新版教程,安装Unity看这一篇就够了!)
unity·游戏引擎·unity安装