opengles 渲染摄像头为圆形? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
notedit
V2EX    问与答

opengles 渲染摄像头为圆形?

  •  
  •   notedit 2016-03-30 15:47:18 +08:00 1931 次点击
    这是一个创建于 3482 天前的主题,其中的信息可能已经有所发展或是发生改变。
    想要把 camera preview 渲染为圆形(不是用一个 mask 做圆形),不过对 shader 语言不熟悉,不知道有没有对 opengles 和 shader 了解的朋友指点一下。
    10 条回复    2016-03-30 18:05:09 +08:00
    acros
        1
    acros  
       2016-03-30 16:07:53 +08:00 via iPhone   1
    没看懂你的要求...是指把摄像机看到的画面渲染到球面上? (就像一个镜面球反射出环境?)
    acros
        2
    acros  
       2016-03-30 16:13:35 +08:00
    搜一下 cubemap 看看是不是你说的那种~
    notedit
        3
    notedit  
    OP
       2016-03-30 17:14:37 +08:00
    @acros 类似 不用球型 圆形就好
    notedit
        4
    notedit  
    OP
       2016-03-30 17:15:32 +08:00
    @acros 简单来说就是圆形摄像头
    acros
        5
    acros  
       2016-03-30 17:28:23 +08:00
    @notedit 就是这个“圆形”不明白啊
    shadertoy 上有些效果,你可以参考下。

    https://www.shadertoy.com/results?query=fisheye
    notedit
        6
    notedit  
    OP
       2016-03-30 17:35:31 +08:00
    @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
       2016-03-30 17:39:13 +08:00
    再通俗一点是我想把 camera preview 裁剪成圆形 显示
    acros
        8
    acros  
       2016-03-30 17:44:02 +08:00   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
       2016-03-30 17:59:08 +08:00
    @acros 好 我试一下

    方便加个联系方式么 我的微信是我的 用户名
    acros
        10
    acros  
       2016-03-30 18:05:09 +08:00
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2561 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 05:07 PVG 13:07 LAX 22:07 JFK 01:07
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86