本文是 https://www.bilibili.com/video/BV1ZChGz8EkH 视频的笔记。

Godot 中在使用 Forword+ 时候,引入了 Render Pipeline

与其有关的还有 Compositor

https://docs.godotengine.org/en/stable/classes/class_renderingdevice.html

https://docs.godotengine.org/en/stable/tutorials/rendering/compositor.html

手动创建一个 Render Pipeline

顶点缓冲区对象 VBO

var vertex : PackedFloat32Array = [0.0, -1.0,  # 0-1.0, 1.0,  # 11.0, 1.0    # 2
]var vertex_bytes : PackedByteArray = vertex.to_byte_array();
vertex_buffer = rd.vertex_buffer_create

顶点数组对象 VAO

VAO 是用于描述 VBO 的结构布局

帧缓存对象 FBO

帧缓存对象表示渲染管线的渲染目标纹理

var frametexture_format : RDTextureFormat = RDTextureFormat.new();
frametexture_format.format = RenderingDevice.DATA_  R32G32B32A32_SFLOAT;
frametexture.width = 512;
frametexture.height = 512;
frametexture.usage_bits = \RenderingDevice.TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | \ # 需要指定此纹理可用作帧缓冲对象中的颜色附件RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT;framebuff_texture = rd.texture_create(frametexture_format, RDTextureView.new()); # 1. 创建一个图形 API 纹理# 创建完纹理对象,就可以创建帧缓冲对象了
# 帧缓冲对象类似于一个纹理集合,图像作为“附件”附加到帧缓冲对象上
# 渲染管线会将渲染出来的不同的结果,存储到帧缓冲对象中的不同的附件上
# 这里将 **颜色附件纹理** 传入,Godot 会根据传入的附件类型自动推断帧缓冲格式var framebuffers : Array[RID] = [ framebuffer_texture ];
framebuffer = rd.framebuff_create(framebuffers);

编写 glsl


提交到 GPU

调度 GPU 执行图形渲染,并等待同步

rd.submit();
rd.sync();

获取帧缓冲的颜色附件纹理数据并显示

var data : PackedByteArray = rd.texture_get_data(framebuffer_texture, 0);
var img : Image = Image.create_from_data(512, 512, false, Image.FORMAT_RGBAF, data);
$TextureRect.texture = ImageTexture.create_from_image(img);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/952802.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!