Is it Possible to give effect like Vertex Shader a

2019-02-15 03:09发布

This two are My VertexShader and Fragment Shader file:

Vertex Shader File:

    attribute vec4 position;
attribute vec4 inputTextureCoordinate;

varying vec2 textureCoordinate;
varying vec4 co;

void main()
{
    gl_Position = position;
    textureCoordinate = inputTextureCoordinate.xy;
    co = inputTextureCoordinate;
}

Fragment Shader File:

    uniform sampler2D videoFrame; // the texture with the scene you want to blur
varying mediump vec2 textureCoordinate;
varying mediump vec4 co;
precision mediump float;

vec4 nightVision()
{
    float luminanceThreshold = 0.2; // 0.2
    float colorAmplification = 2.0; // 4.0
    float effectCoverage = 1.0; // 1.0
    vec4 finalColor;
    // Set effectCoverage to 1.0 for normal use.
    if (co.x < effectCoverage)
    {
        vec3 c = texture2D(videoFrame, co.st).rgb;

        float lum = dot(vec3(0.30, 0.59, 0.11), c);
        if (lum < luminanceThreshold) {
            c *= colorAmplification; 
        }
        vec3 visionColor = vec3(0.1, 0.95, 0.2);
        finalColor.rgb = (c) * visionColor;
    } else {
        finalColor = texture2D(videoFrame, co.st);
    }
    vec4 sum = vec4(0.0, 0.0, 0.0, 1.0);
    sum.rgb = finalColor.rgb;
    return sum;
}


void main(void)
{
    gl_FragColor = nightVision();
}

Now, I want to Use this code to give the Camera Preview Effect in Android Camera preview. And also want to save the Picture that captured by that effect.

So is it possible to do so ??? If yes then Please help me with Some code as i am new to OpenGles with Android Camera.

1条回答
爷的心禁止访问
2楼-- · 2019-02-15 03:50

Yes, it's definitely possible. There are a lot of different approaches to building this, and a small code sample won't really help much. The basic idea is to feed the frames you get from the camera to OpenGL as textures.

Check out Camera image as an OpenGL texture on top of the native camera viewfinder. The source code should give you an idea for how to proceed.

查看更多
登录 后发表回答