• <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) 閱讀(1561) 評論(0)  編輯 收藏 引用 所屬分類: Graphics 、Coding 、Documents
            久久久精品免费国产四虎| 97久久精品午夜一区二区| 久久久久无码专区亚洲av| 99久久精品九九亚洲精品| 亚洲综合久久夜AV | 亚洲精品NV久久久久久久久久| 欧美伊香蕉久久综合类网站| 久久综合九色综合网站| 无遮挡粉嫩小泬久久久久久久| 中文字幕无码精品亚洲资源网久久| 无码AV中文字幕久久专区| 精品国产VA久久久久久久冰| 伊人久久精品影院| 欧美亚洲另类久久综合婷婷| 一本色道久久HEZYO无码| 久久99国产精品99久久| 69国产成人综合久久精品| 国产精品亚洲美女久久久| 久久久免费观成人影院| 丰满少妇人妻久久久久久| 久久男人中文字幕资源站| 久久国产免费观看精品3| 中文字幕无码精品亚洲资源网久久| 中文字幕久久精品 | 精品欧美一区二区三区久久久| 久久综合色之久久综合| 久久精品女人天堂AV麻| 国产成人精品综合久久久| 青青草原综合久久大伊人| 久久精品人人槡人妻人人玩AV| 亚洲国产精品久久久久久| 国产成人精品白浆久久69| 狠狠色丁香婷婷综合久久来来去 | 国产精品亚洲综合专区片高清久久久 | 久久精品国产99久久香蕉| 久久99精品久久久久久久不卡| 色综合久久中文综合网| 九九精品99久久久香蕉| 久久精品国产清自在天天线| 亚洲va国产va天堂va久久| 久久久久亚洲AV成人网|