简体   繁体   English

色散效果GLSL着色器Opengl ES 2.0

[英]Color Spread Effect GLSL Shaders Opengl ES 2.0

I am looking to create a effect using GLSL on Android and OpenGL ES 2.0 where at the beginning I convert a colored image into greyscale using shaders and later show the original colors spreading one pixel at a time starting from any one corner vertex of the image. 我正在寻找在Android和OpenGL ES 2.0上使用GLSL创建效果的方法,其中一开始,我使用着色器将彩色图像转换为灰度,然后显示从图像的任何一个角顶点开始一次扩散一个像素的原始颜色。

I have been to able to successfully apply the first effect (convert to greyscale) 我已经能够成功应用第一个效果(转换为灰度)

But I cant figure out how to choose one pixel at a time and show a spreading effect on the image ? 但是我不知道如何一次选择一个像素并在图像上显示扩散效果?

(Can anyone just push me in the right direction ?) (有人可以按正确的方向推动我吗?)

最终要求

First, I think you'll need to create a bitmap in client memory. 首先,我认为您需要在客户端内存中创建一个位图。 This bitmap will serve to tell your shader which pixels should be converted to grayscale. 此位图将告诉您的着色器哪些像素应转换为灰度。 Imagine a giant 2-D array of Boolean values. 想象一个巨大的二维数组的布尔值。 Zeros for false, ones for true. 零代表假,1代表真。 You only need one channel. 您只需要一个频道。

For each rendered frame, you will convert your bitmap into GL texture with glTexImage2D and pass it into your shader along with the color image. 对于每个渲染的帧,您将使用glTexImage2D将位图转换为GL纹理,并将其与彩色图像一起传递到着色器中。

Your frag shader will look something like this: 您的碎片着色器将如下所示:

uniform Sampler2D s_input;
uniform Sampler2D s_pixelsToGrayscale;
varying vec2 v_texCoord;

main() {
    vec4 color = texture2D(s_input, v_texCoord);
    vec4 isGrayscalePixel = texture2D(s_pixelsToGrayscale, v_texCoord);
    if( isGrayscalePixel.x > 0.0 ) {
        color = vec4(0.2126*color.r + 0.7152*color.g + 0.722*color.b);
    }
    gl_FragColor = color;
}

The most annoying part of this is going to be creating your bitmap, unless you are new to post process effects (in which case you might want to start investigating a full-screen quad) This should be enough to at least send you in the right direction, but if you're uncomfortable reading this kind of shader, I imagine you have your work cut out for you. 其中最烦人的部分是创建位图,除非您不熟悉后期处理效果(在这种情况下,您可能要开始研究全屏四边形),这至少足以使您正确地发送给您方向,但是如果您不喜欢这种着色器,我想您已经为您完成了工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM