标签: render-to-texture

glFramebufferTexture2D性能

我正在使用GPU进行繁重的计算,这需要大量的渲染到纹理操作.这是一个迭代计算,因此对纹理进行大量渲染,然后将纹理渲染到另一个纹理,然后将第二个纹理渲染回第一个纹理,依此类推,每次都将纹理传递到着色器.

我的问题是:对于我想要渲染的每个纹理都有一个单独的FBO更好glFramebufferTexture2D吗,或者我应该在每次想要更改渲染目标时使用一个FBO并绑定目标纹理?

我的平台是iPhone上的OpenGL ES 2.0.

iphone opengl-es framebuffer render-to-texture

5
推荐指数
1
解决办法
3322
查看次数

多个渲染目标不保存数据

我正在使用SlimDX,使用着色器模型4定位DirectX 11.我有一个像素着色器"preProc",它处理我的顶点并保存三种数据纹理.一个用于每像素法线,一个用于每像素位置数据,一个用于颜色和深度(颜色占用rgb和深度采用alpha通道).

然后,我在后处理着色器中使用这些纹理以实现屏幕空间环境遮挡,但似乎没有数据在第一个着色器中保存.

这是我的像素着色器:

PS_OUT PS( PS_IN input )
{
    PS_OUT output;
    output.col = float4(0,0,0,0);
    output.norm = float4(input.norm,1);
    output.pos = input.pos;
    return output;
}
Run Code Online (Sandbox Code Playgroud)

它输出以下结构:

struct PS_OUT
{
    float4 col : SV_TARGET0;
    float4 norm : SV_TARGET1;
    float4 pos : SV_TARGET2;
};
Run Code Online (Sandbox Code Playgroud)

并采用以下结构进行输入:

struct PS_IN
{
    float4 pos : SV_POSITION;
    float2 tex : TEXCOORD0;
    float3 norm : TEXCOORD1;
};
Run Code Online (Sandbox Code Playgroud)

但是在我的后期处理着色器中:

Texture2D renderTex : register(t1);
Texture2D normalTex : register(t2);
Texture2D positionTex : register(t3);
Texture2D randomTex : register(t4);
SamplerState samLinear : register(s0);

float4 …
Run Code Online (Sandbox Code Playgroud)

directx rendering hlsl slimdx render-to-texture

5
推荐指数
1
解决办法
2527
查看次数

THREE.js:从THREE.WebGLRenderTarget获取数据

ATHREE.Texture可以用作材质中的贴图,并且具有称为“图像”的属性。ATHREE.WebGLRenderTarget可以用作材质中的贴图,但不具有称为“图像”的属性。

我如何从 a 检索纹理数据WebGLRenderTarget?我想将其保存到文件中(或者,如果不可能,则保存为字节数组)。

render-to-texture three.js

5
推荐指数
1
解决办法
4344
查看次数

如何在共享上下文中呈现给FBO?

我有一个应用程序,我需要执行以下操作:

  1. 将纹理从磁盘加载到GL纹理中
  2. 在其上运行图像过滤器(通过FBO将其渲染到另一个纹理上)
  3. 在屏幕上显示生成的纹理

我有那么多工作.

接下来,我希望能够将步骤#2移动到单独的共享GL上下文中.

在初始化时,我创建了一个共享上下文:

rootContext = CGLGetCurrentContext();
CGLPixelFormatObj pf = CGLGetPixelFormat(rootContext);
CGLCreateContext(pf, rootContext, &childContext);
Run Code Online (Sandbox Code Playgroud)

...然后使其成为当前并在其上设置帧缓冲...

CGLSetCurrentContext(childContext);
glGenTextures(1, &childTexture);
glBindTexture(GL_TEXTURE_2D, childTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGenFramebuffers(1, &childFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, childFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, childTexture, 0);
Run Code Online (Sandbox Code Playgroud)

然后,当渲染每一帧时,我将childContext当前渲染并渲染到它:

CGLSetCurrentContext(childContext);
glBindFramebuffer(GL_FRAMEBUFFER, childFramebuffer);
glUseProgram(childProgram);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, inputTexture);
glUniform1i(childTextureUniform, 0);

glBindBuffer(GL_ARRAY_BUFFER, childQuadPositionBuffer);
glVertexAttribPointer(childPositionAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, (void*)0);
glEnableVertexAttribArray(childPositionAttribute);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, childQuadElementBuffer);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void*)0);
glDisableVertexAttribArray(childPositionAttribute);

glUseProgram(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Run Code Online (Sandbox Code Playgroud)

...然后我创建rootContext …

opengl macos fbo core-graphics render-to-texture

5
推荐指数
2
解决办法
2279
查看次数

android OpenGLES 1.x CameraPreview到Surfacetexture

我正在尝试将相机预览发送到surfacetexture对象并将其渲染到正方形上.我有运行GLES20的代码,但没有为1.x找到任何东西.基本上它应该像这样工作,对吧?

// setup texture
gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
gl.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, ...);
...

// setup surfacetexture object
surface = new SurfaceTexture(textures[0]);
surface.setOnFrameAvailableListener(this);


// setup camera
mCamera = Camera.open(0);
Camera.Parameters param = mCamera.getParameters();
List<Size> psize = param.getSupportedPreviewSizes();
//find previewsize to match glsurface from renderer
param.setPreviewSize(psize.get(i).width, psize.get(i).height);
mCamera.setParameters(param);

// set the texture and start preview
mCamera.setPreviewTexture(surface);
mCamera.startPreview();


// in the "onFrameAvailable" handler, i switch a flag to mark a new frame
updateSurface = true;


// and in the renderloop i update and …
Run Code Online (Sandbox Code Playgroud)

opengl-es render-to-texture android-camera opengl-es-1.1

5
推荐指数
1
解决办法
1287
查看次数

iOS AVPlayer渲染到纹理

我正在尝试理解AVPlayer,但Apple文档中的示例并不是很简单,我遇到了一些问题.

我需要做的是从电影创建渲染到纹理,以便在我的场景中我可以使用它来将它映射到OpenGL纹理中(这已经完成了每个帧!)

根据我的理解,我认为我应该使用AVURLAsset,但我不太确定.

任何人都能指出我正确的方向吗?此外,如果您对iOS的简单Video-> RTT示例有任何了解,那将是很棒的(通过Google搜索无法找到任何内容)

render-to-texture ios avplayer

5
推荐指数
1
解决办法
2380
查看次数

WebGL上的快速纹理乒乓实现

我正在尝试在WebGL上实现GPGPU计算,我需要在其中存储中间结果。整个计算不适合一个片段着色器,因此我必须将其拆分为几轮。

我实现了纹理乒乓技术,其中有两个纹理,可以交换每个渲染。

我有数千次渲染回合来获取结果数据,其中新数据依赖于以前的数据(不可能并行执行)。我有一个很大的纹理来存储所有数据,但是每轮需要在几个像素上进行计算(每轮8-20像素,纹理为1024x1024)。

我典型的片段着色器代码如下:

void main () {
    vec4 c = gl_FragCoord - 0.5;
    float position = (c.y * TEXTURE_SIZE) + c.x;
    float offset = mod(position, BLOCK_SIZE);
    float block = floor(position / BLOCK_SIZE);

    if ( offset >= (TMP_WORK_OFFSET) && offset < (TMP_WORK_OFFSET + WORKS_PER_ROUND)) {
         //Do the computation here
    } else {
         //Just return the pixel from the texture
         gl_FragColor = texture2D(uSampler, vTextCoord.st);
    }
}
Run Code Online (Sandbox Code Playgroud)

目前,我每轮渲染整个帧,并且我想配置顶点以仅渲染优化所需的像素。第一个想法如下:

1. Set full frame squad vertecies.
2. Switch to simpleCopy shader program.
3. Copy …
Run Code Online (Sandbox Code Playgroud)

gpgpu opengl-es render-to-texture webgl

5
推荐指数
0
解决办法
740
查看次数

WebGL渲染到浮点纹理

我正在编写一些WebGL代码,需要渲染到浮点纹理.
通过扩展gl.getExtension('OES_texture_float');, gl.getExtension('OES_texture_float_linear');我现在能够创建和绘制此纹理并使用线性过滤器.
但它似乎没有正确计算.

基本上价值需要加在​​一起所以我正在使用

    gl.blendEquation(gl.FUNC_ADD);
    gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
    gl.enable(gl.BLEND);
    gl.disable(gl.DEPTH_TEST);
Run Code Online (Sandbox Code Playgroud)

渲染到纹理时.也可能出现负值要添加.

现在经过几个小时的谷歌搜索后,我遇到了这个:WEBGL_color_buffer_float扩展

到目前为止,我正在使用该命令

    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, rttFramebuffer.width, rttFramebuffer.height, 0, gl.RGBA, gl.FLOAT, null);
Run Code Online (Sandbox Code Playgroud)

但我想我需要RGBA32F改用.这有可能吗?如果可以,我该如何使用扩展格式?


已解决:正如答案所示,使用的格式没有错误.我为着色器制服分配了一些错误的值,并且确实使用了非常不利的背景颜色,导致错误的可视化.

floating-point render-to-texture webgl

5
推荐指数
1
解决办法
4355
查看次数

使用目标GL_TEXTURE_2D在纹理上渲染相机预览

我正在尝试使用目标在OpenGL纹理上渲染相机预览GL_TEXTURE_2D.我非常了解SurfaceTexture,但我无法使用它,因为它只适用于GL_TEXTURE_EXTERNAL_OES.在SurfaceTexture的文档中,它写成:

 Each time the texture is bound it must be bound to the GL_TEXTURE_EXTERNAL_OES target rather than the GL_TEXTURE_2D target
Run Code Online (Sandbox Code Playgroud)

我无法使用,GL_TEXTURE_EXTERNAL_OES因为我必须在现有代码中进行大量更改.

有没有办法实现这一目标也很快?

shader android opengl-es render-to-texture android-camera

4
推荐指数
1
解决办法
3064
查看次数

将 OpenGL 渲染保存到图像文件

尽管 OpenGL 的功能很简单,但仍然让我感到困惑,但我开始学习它是如何工作的。

我正在寻找一个离屏渲染的最小示例来帮助我入门。

我的应用程序将获取一堆三角形以及有关如何相对于相机定位它们的信息,并将渲染结果保存到图像文件中。目前没有照明、材质或后期处理。

我观看了有关创建离屏上下文、创建 FBO、渲染到纹理等的教程。我不介意使用 QT,因为它方便地提供 OpenGL 工具、窗口和 QImage。据我了解,为了能够对渲染图像进行图像处理,您需要将渲染目标设置为纹理,然后使用着色器,最后将纹理读取到数组中。

试图把事情放在一起从来没有让我有一个好的起点。我要么陷入设置依赖项的困境,要么黑屏,要么盯着那些除了我需要的东西之外做了太多事情的项目。

更新1:可以正常工作了。

#include <QtGui/QGuiApplication>
#include <QtGui/QSurfaceFormat>
#include <QtGui/QOffscreenSurface>
#include <QtGui/QOpenGLFunctions_4_3_Core>
#include <QtGui/QOpenGLFramebufferObject>
#include <QtGui/QOpenGLShaderProgram>
#include <QDebug>
#include <QImage>
#include <QOpenGLBuffer>

int main(int argc, char* argv[])
{
   QGuiApplication a(argc, argv);

   QSurfaceFormat surfaceFormat;
   surfaceFormat.setMajorVersion(4);
   surfaceFormat.setMinorVersion(3);

   QOpenGLContext openGLContext;
   openGLContext.setFormat(surfaceFormat);
   openGLContext.create();
   if(!openGLContext.isValid()) return -1;

   QOffscreenSurface surface;
   surface.setFormat(surfaceFormat);
   surface.create();
   if(!surface.isValid()) return -2;

   openGLContext.makeCurrent(&surface);

   QOpenGLFunctions_4_3_Core f;
   if(!f.initializeOpenGLFunctions()) return -3;

   qDebug() << QString::fromLatin1((const char*)f.glGetString(GL_VERSION));

   QSize vpSize = QSize(100, 200);

   qDebug("Hi");

   QOpenGLFramebufferObjectFormat fboFormat;
   fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
   QOpenGLFramebufferObject fbo(vpSize, fboFormat); …
Run Code Online (Sandbox Code Playgroud)

c++ opengl qt fbo render-to-texture

4
推荐指数
1
解决办法
6797
查看次数