• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            黎明的剔透里伸出了你沁清的曖昧

            Graphics|EngineDev|GameDev|2D&3D Art

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              60 隨筆 :: 1 文章 :: 18 評論 :: 0 Trackbacks

            In OpenGL ES 2.0 glAlphaFunc isn't available, you have to implement it in a fragment shader. There isn't a lot of reference out there for this (not that I could find anyway) so I thought I'd write this up.

            It's actually quite simple to implement a quick alpha test. I needed to be able to cookie cut out sprites and fonts so I simply needed to reject fragments where the alpha value was zero. Here are the guts of a shader to do this:

            #ifdef GL_ES 
            precision highp float;
            #endif 
            uniform sampler2D u_tex0; 
            uniform bool u_alphatestenable; 
            varying vec2 v_texCoord;
            varying vec4 v_color;
            void main(){ 
                //calculate the fragment color based on the texture and the vertex colour
                vec4 basecolor = texture2D( u_tex0, v_texCoord ) * v_color;
            
                //if testing is enabled, check the alpha component and discard if zero      
                if(u_alphatestenable){ 
                    if(basecolor.a == 0.0){ 
                        //throw this fragment away
                        discard;
                    }
                }
                gl_FragColor = basecolor;
            }

             

            You need to set up a uniform variable u_alphatestenable which enables the alpha test. If you want to support different test types ( less than, greater than etc) then you will need two more uniform variables: one for the test type and one for the value to test against.

            int uni_alphatest_enable = glGetUniformLocation(mProgram, "u_alphatestenable"); 
            bool alphateston = true; 
            glUniform1i(uni_alphatest_enabl

             

            note that you shouldn't call glGetUniformLocation every frame, it should be cached somewhere.
            It's quite simple and while you may be thinking oh that is so slow it not that bad. It's faster then the fixed function pipeline which is doing tests for alpha, lights, blend modes etc. If you get paranoid then you can create multiple shaders that support different subsets of features. All you need to be careful of is the cost of calling glSetProgram (to switch shaders) which can be expensive and cause bubbles in the vertex pipeline in the hardware.

            posted on 2012-11-19 22:28 情絕格調(diào)(fresmaster) 閱讀(1571) 評論(0)  編輯 收藏 引用 所屬分類: GraphicsCodingDocuments
            99精品久久精品一区二区| 久久婷婷国产综合精品| 国产午夜久久影院| 国产精品九九久久精品女同亚洲欧美日韩综合区| 久久精品一区二区国产| 久久国产视屏| 欧美精品久久久久久久自慰| 99久久精品国产高清一区二区 | 久久久久久亚洲精品成人| 欧洲精品久久久av无码电影| 91性高湖久久久久| 亚洲精品乱码久久久久久按摩| 精品国际久久久久999波多野| 久久精品国产72国产精福利| 久久综合综合久久综合| 国产高清国内精品福利99久久 | 国产精品免费久久| 国产精品久久久久久久久软件| 亚洲AV无码久久精品蜜桃| 久久人人爽人人精品视频| 久久久久99精品成人片直播| 国产亚州精品女人久久久久久| 久久久久久久久久久| 久久青青草原综合伊人| 国产A三级久久精品| 久久久久国色AV免费观看| 99久久精品国产免看国产一区| 亚洲欧美一区二区三区久久| 久久97久久97精品免视看秋霞| 久久九九青青国产精品| 久久国产精品久久国产精品| 亚洲日本va中文字幕久久| 亚洲国产成人久久综合碰| 人人狠狠综合久久亚洲| 精品99久久aaa一级毛片| 成人午夜精品久久久久久久小说 | 无码国内精品久久人妻麻豆按摩| 久久99国产精品99久久| 精品久久久久久中文字幕人妻最新| 午夜精品久久久久久久久| 一本久久a久久精品亚洲|