notedit
V2EX  ›  问与答

opengles 渲染摄像头为圆形?

  •  
  •   notedit · Mar 30, 2016 · 2254 views
    This topic created in 3718 days ago, the information mentioned may be changed or developed.
    想要把 camera preview 渲染为圆形(不是用一个 mask 做圆形),不过对 shader 语言不熟悉,不知道有没有对 opengles 和 shader 了解的朋友指点一下。
    10 replies    2016-03-30 18:05:09 +08:00
    acros
        1
    acros  
       Mar 30, 2016 via iPhone   ❤️ 1
    没看懂你的要求...是指把摄像机看到的画面渲染到球面上? (就像一个镜面球反射出环境?)
    acros
        2
    acros  
       Mar 30, 2016
    搜一下 cubemap 看看是不是你说的那种~
    notedit
        3
    notedit  
    OP
       Mar 30, 2016
    @acros 类似 不用球型 圆形就好
    notedit
        4
    notedit  
    OP
       Mar 30, 2016
    @acros 简单来说就是圆形摄像头
    acros
        5
    acros  
       Mar 30, 2016
    @notedit 就是这个“圆形”不明白啊
    shadertoy 上有些效果,你可以参考下。

    https://www.shadertoy.com/results?query=fisheye
    notedit
        6
    notedit  
    OP
       Mar 30, 2016
    @acros 在 android 上面 摄像头 camera preview 是有固定的几种比例,没法改

    如果我要一个方形的 camera preview 我需要自己拿到每一帧的数据 用 opengl 处理。

    比如 我把 camera preview 显示成正方形需要的 shader 如下:

    ```

    private final String vertexShaderCode =
    "attribute vec4 vPosition;" +
    "attribute vec2 inputTextureCoordinate;" +
    "varying vec2 textureCoordinate;" +
    "void main()" +
    "{" +
    "gl_Position = vPosition;" +
    "textureCoordinate = inputTextureCoordinate;" +
    "}";

    private final String fragmentShaderCode =
    "#extension GL_OES_EGL_image_external : require\n" +
    "precision mediump float;" +
    "varying vec2 textureCoordinate;\n" +
    "uniform samplerExternalOES s_texture;\n" +
    "void main() {" +
    " gl_FragColor = texture2D( s_texture, textureCoordinate );\n" +
    "}";



    ```


    我现在想把摄像头的 preview 渲染成圆形 不知道这里的 shader 怎么写
    notedit
        7
    notedit  
    OP
       Mar 30, 2016
    再通俗一点是我想把 camera preview 裁剪成圆形 显示
    acros
        8
    acros  
       Mar 30, 2016   ❤️ 1
    呃··· 如果只是要裁剪成圆,直接在 Shader 里面指定一个 p = vec2(rx,ry)作为圆形, Ra 半径,当前 textureCoordinate 和 vec2(rx,ry)的距离平方和半径平方比较下不就得到结果了?

    if(lengthSqure(p,inputTextureCoordinate) <= Ra * Ra){
    gl_FragColor = texture2D( s_texture, textureCoordinate )
    }else{
    gl_FragColor = vec4(0,0,0,1);
    }
    notedit
        9
    notedit  
    OP
       Mar 30, 2016
    @acros 好 我试一下

    方便加个联系方式么 我的微信是我的 用户名
    acros
        10
    acros  
       Mar 30, 2016
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1439 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 17:00 · PVG 01:00 · LAX 10:00 · JFK 13:00
    ♥ Do have faith in what you're doing.