webgl - pass texture map to another fragment shader
问题描述
I want to generate a texture map in WebGl in one fragment shader and then pass that texture map to another fragment shader for processing but the syntax escapes me. I believe if I understood it correctly, an example I found online said I could do something like this:
(1)
// setup frame buffer and depth buffer for the two fragment shaders.
(2)
// texture map generating frag shader:
uniform sampler2D texturemap;
void main(){
// generate texture map
vec4 coorindate_value = ...;
output_texture = texture( texturemap , coorindate_value );
// my understanding is that that sampler2d will generate some kind of a mapping. how can I map coorindate_value to some other vec4, like another vec4 coordinate???
}
(3)
// second fragment shader:
uniform sampler2D same_texturemap;
void main(){
vec4 coorindate_value = ...;
vec4 value = texture2D( same_texturemap , coorindate_value );
// the returned value should be one of the color values from the first fragment shader, correct??
}
I'm not looking for anyone to provide code to help me here necessarily, but just to get some confirmation that I have an understanding of how this could work. I suppose my main confusion is over what sampler2D actually does. Is it like a dictionary or hashtable in that it maps between two values, and if so, how do I choose what those two values are? Any tips or corrections would be great.
thanks much in advance
解决方案
Asampler2D
是对纹理单元的引用。纹理单元保存对纹理的引用。texture2D
纹理是一个二维数据数组,您可以使用该函数提取数据。您将 sampler2D 制服和归一化纹理坐标传递给它。它从纹理返回一个采样值。我说采样值是因为该值的生成方式取决于纹理的过滤器设置。
WebGL 中的输出是通过一个特殊的变量gl_FragColor
。如果没有绑定帧缓冲区,则输出将转到画布的当前帧缓冲区。
您可能需要阅读一些关于 webgl 的教程。这是一篇专门关于纹理和渲染到纹理的文章,但如果您不熟悉 WebGL 的其余部分,您可能需要阅读前面的文章。
推荐阅读
- excel - 我可以使用 Python 自动更改 Excel 插件中的提示吗?
- java - Java, Inheritance, Generics - using parameters of subtypes in template method implementations
- python - 如何在另一个脚本中运行一个脚本?
- swift - 即使值不是 nil,也会发生 nil 崩溃
- android - 为什么我的 APK 下载会覆盖已安装的无关 apk 文件?
- c++ - .cpp 文件中未定义的引用错误
- android - Ionic 4-后台用户位置跟踪
- delphi - 当 TFormatSetting 设置为 en-US 时,如何解决“10,000.00”不是有效的浮点值
- javascript - Disqus Iframe 未在 AMP 安装时调整大小
- typescript - 强制执行可选类型打字稿