是否有可能提出类似的顶点着色器和片段着色效果Android相机preVIEW,并保存OpenGLES所拍摄的图像? [英] Is it Possible to give effect like Vertex Shader and Fragment Shader to the Android Camera Preview , and Save the Captured image with OpenGLES?

查看:191
本文介绍了是否有可能提出类似的顶点着色器和片段着色效果Android相机preVIEW,并保存OpenGLES所拍摄的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个是我的VertexShader和片段着色器文件:

This two are My VertexShader and Fragment 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();
}

现在,我想用这个code给出的Andr​​oid摄像头preVIEW相机preVIEW影响。而且还希望保存图片的捕获这种效果。

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.

那么,是否可以这样做??? 如果是的话,请帮我带一些code,因为我是新来OpenGles与Android相机。

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.

推荐答案

是的,这是绝对有可能。有很多不同的方法来建立这个,和一个小code样品不会真正帮助不大。其基本思路是,以养活你从相机到OpenGL作为纹理帧。

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.

查看摄像机图像作为一个OpenGL纹理本地相机的取景器之上。该人士$ ​​C $ C应该给你一个想法如何继续。

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.

这篇关于是否有可能提出类似的顶点着色器和片段着色效果Android相机preVIEW,并保存OpenGLES所拍摄的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆