本文介绍了OpenGL ES 2.0中的多遍着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先-子例程是否需要GLSL 4.0+?那么它在OpenGL ES 2.0的GLSL版本中不可用吗?

First - Does subroutines require GLSL 4.0+? So it unavailable in GLSL version of OpenGL ES 2.0?

相当了解什么是多遍着色器.
好吧,我的照片是什么?

I quite understand what multi-pass shaders are.
Well what is my picture:

  1. 使用一些着色器将一组东西(例如精灵)绘制到FBO.
  2. 将FBO视为大屏幕尺寸四边形的大纹理,并使用另一个着色器,例如,将纹理颜色转换为灰度.
  3. 将FBO纹理四边形绘制到具有灰度颜色的屏幕上.

或者这叫别的吗?

那么multi-pass =使用另一个着色器输出到另一个着色器输入吗?那么我们渲染一个对象两次或更多次?着色器输出如何到达另一个着色器输入?

So multi-pass = use another shader output to another shader input? So we render one object twice or more? How shader output get to another shader input?

例如

glUseProgram(shader_prog_1);//Just plain sprite draw
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, /*some texture_id*/);
 //Setting input for shader_prog_1
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
//Disabling arrays, buffers
glUseProgram(shader_prog_1);//Uses same vertex, but different fragment shader program
//Setting input for shader_prog_2
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

任何人都可以用基本方式提供一个简单的例子吗?

Can anyone provide simple example of this in basic way?

推荐答案

通常,术语多遍渲染"是指使用不同的着色器多次渲染同一对象,并将结果累积在帧缓冲区中.累积通常是通过混合完成的,而不是通过着色器完成的.也就是说,第二个着色器获取第一个着色器的输出.它们每个都执行部分计算,并且混合阶段将它们组合为最终值.

In general, the term "multi-pass rendering" refers to rendering the same object multiple times with different shaders, and accumulating the results in the framebuffer. The accumulation is generally done via blending, not with shaders. That is, the second shader doesn't take the output of the first. They each perform part of the computation, and the blend stage combines them into the final value.

如今,这主要用于正向渲染场景中的照明.您为每个光源渲染一次每个对象,传递不同的照明参数,并且每次渲染光源时都可能使用不同的着色器.用于累积结果的混合模式是累加的,因为光反射率是累加的性质.

Nowadays, this is primarily done for lighting in forward-rendering scenarios. You render each object once for each light, passing different lighting parameters and possibly using different shaders each time you render a light. The blend mode used to accumulate the results is additive, since light reflectance is an additive property.

这是与您的帖子其余部分完全不同的问题,但答案是肯定的.

This is a completely different question from the entire rest of your post, but the answer is yes and no.

否,就ARB_shader_subroutine是OpenGL扩展而言,因此可以通过任何OpenGL实现来实现.是的,从实际意义上讲,实际上可以实现shader_subroutine的任何硬件也可以实现GL 4.x的其余部分,因此已经在宣传4.x功能.

No, in the sense that ARB_shader_subroutine is an OpenGL extension, and it therefore could be implemented by any OpenGL implementation. Yes, in the practical sense that any hardware that actually could implement shader_subroutine could also implement the rest of GL 4.x and therefore would already be advertising 4.x functionality.

实际上,您不会找到非4.x OpenGL实现支持的shader_subroutine.

In practice, you won't find shader_subroutine supported by non-4.x OpenGL implementations.

它是GLSL ES ,因此在GLSL ES 2.0中不可用.不要将桌面OpenGL 与OpenGL ES 混淆.它们是两种不同的事物,具有不同的GLSL版本和不同的功能集.他们甚至不共享扩展名(最近的扩展名除外).

It is unavailable in GLSL ES 2.0 because it's GLSL ES. Do not confuse desktop OpenGL with OpenGL ES. They are two different things, with different GLSL versions and different featuresets. They don't even share extensions (except for a very few recent ones).

这篇关于OpenGL ES 2.0中的多遍着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 16:04