• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              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 情絕格調(fresmaster) 閱讀(1571) 評論(0)  編輯 收藏 引用 所屬分類: GraphicsCodingDocuments
            久久精品中文无码资源站| 亚洲精品乱码久久久久久自慰| 97久久香蕉国产线看观看| 精品久久久久久国产免费了| 伊人久久大香线蕉综合热线| 国内精品伊人久久久久AV影院| 国产午夜精品久久久久九九电影 | 久久久久波多野结衣高潮| 久久久精品人妻一区二区三区四 | 久久经典免费视频| 久久99国产精品久久99| 久久精品青青草原伊人| 久久天天躁狠狠躁夜夜2020| 久久亚洲私人国产精品vA| 91麻豆国产精品91久久久| 精品久久久久久无码人妻蜜桃| 亚洲精品乱码久久久久久中文字幕| 一本久久a久久精品综合夜夜| 99久久无色码中文字幕人妻| 中文字幕精品久久| 久久亚洲高清综合| 久久露脸国产精品| 久久精品亚洲福利| 国产精品99久久不卡| 国产精品久久久久久一区二区三区| 2021最新久久久视精品爱| 亚洲精品乱码久久久久久蜜桃| 久久伊人精品青青草原日本| 久久中文字幕一区二区| 久久婷婷国产麻豆91天堂| 热99re久久国超精品首页| 久久青草国产手机看片福利盒子| 国产精品久久久久久福利69堂| 久久er99热精品一区二区| 国内精品九九久久久精品| 97久久久久人妻精品专区 | 东京热TOKYO综合久久精品| 久久精品国产精品亚洲毛片| 无码精品久久久久久人妻中字| 亚洲AV无码久久精品色欲| 久久精品无码一区二区无码|