• <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
            狠狠狠色丁香婷婷综合久久五月 | 久久天天躁夜夜躁狠狠| 久久伊人五月丁香狠狠色| 国内精品久久久久影院亚洲| 色婷婷综合久久久久中文| 日本免费久久久久久久网站| 久久久国产视频| 色综合久久精品中文字幕首页| 久久乐国产精品亚洲综合| 东京热TOKYO综合久久精品| 久久久精品波多野结衣| 久久中文骚妇内射| 久久久免费观成人影院| 国产美女久久精品香蕉69| 婷婷久久综合| 国产AV影片久久久久久| 国产精品免费福利久久| 亚洲精品无码专区久久久| 久久影院久久香蕉国产线看观看| 久久婷婷五月综合97色| 久久无码高潮喷水| 日韩欧美亚洲国产精品字幕久久久| 免费观看久久精彩视频| 久久久无码人妻精品无码| 少妇无套内谢久久久久| 亚洲伊人久久综合影院| 久久久久无码精品国产app| 久久精品国产99国产精偷| www.久久热.com| 久久婷婷五月综合国产尤物app| 狠狠色综合网站久久久久久久高清| 国产成人精品久久一区二区三区av| 99久久综合狠狠综合久久止| 国产成人久久精品激情| 99久久久国产精品免费无卡顿 | 爱做久久久久久| www亚洲欲色成人久久精品| 久久久综合九色合综国产| 97久久天天综合色天天综合色hd| 韩国免费A级毛片久久| 亚洲国产精品婷婷久久|