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

}
相关推荐
mxwin7 小时前
Unity URP 法线贴图色彩空间、编码与解码
unity·游戏引擎·贴图·shader
mxwin10 小时前
Unity Shader URP:将法线可视化,便于调试
unity·游戏引擎·shader
蓝黑墨水11 小时前
unity相关链接
unity·游戏引擎
mxwin11 小时前
Unity Shader 法线贴图的七种错误用法
unity·游戏引擎·贴图·shader
mxwin14 小时前
Unity URP 切线空间详解
unity·游戏引擎·shader
RReality1 天前
【Unity UGUI】血条 / 进度条(HP Bar)
ui·unity·游戏引擎·图形渲染
mxwin2 天前
Unity Shader URP:法线如何进行光照计算
unity·游戏引擎·shader
郝学胜-神的一滴2 天前
中级OpenGL教程 009:用环境光告别模型死黑
前端·c++·unity·godot·图形渲染·opengl·unreal
mxwin2 天前
Unity URP 中的法线生成完全指南
unity·游戏引擎
游乐码2 天前
Unity基础(十五)LineRender画线功能
unity·游戏引擎