Ejemplo n.º 1
0
        public RadialGradientFillShader(ShaderSharedResource shareRes)
            : base(shareRes)
        {
            //NOTE: during development,
            //new shader source may not recompile if you don't clear cache or disable cache feature
            //like...
            //EnableProgramBinaryCache = false;

            if (!LoadCompiledShader())
            {
                //vertex shader source
                string vs = @"        
                    attribute vec2 a_position;
                    uniform mat4 u_mvpMatrix;                     
 
                    void main()
                    {
                        gl_Position = u_mvpMatrix* vec4(a_position[0],a_position[1],0,1);  
                    }
                    ";
                //fragment source
                string fs = @"
                        precision mediump float; 
                        uniform vec3 u_center; 
                        uniform sampler2D s_texture;
                        uniform mat3 u_invertedTxMatrix;

                        void main()
                        {
                            vec4 pos=gl_FragCoord;                            
                            vec3 new_pos =  u_invertedTxMatrix* vec3(pos.x,pos.y,1.0);                            

                            //float r_distance= sqrt((pos.x-u_center.x)* (pos.x-u_center.x) + (pos.y -u_center.y)*(pos.y-u_center.y))/u_center.z;
                            float r_distance= sqrt((new_pos.x-u_center.x)* (new_pos.x-u_center.x) + (new_pos.y -u_center.y)*(new_pos.y-u_center.y))/(u_center.z);

                            if(r_distance >=0.9){
                               gl_FragColor= texture2D(s_texture,vec2(0.9,0.0));
                            }else{
                               gl_FragColor= texture2D(s_texture,vec2(r_distance,0.0));
                            }
                        }
                    ";

                //in fragment shader if we not 'clamp' r_distance
                //  if(r_distance > 1.0) r_distance =1
                //then the pattern will be repeat. ***

                if (!_shaderProgram.Build(vs, fs))
                {
                    throw new NotSupportedException();
                }

                SaveCompiledShader();
            }
            a_position         = _shaderProgram.GetAttrV2f("a_position");
            u_matrix           = _shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_center           = _shaderProgram.GetUniform3("u_center");
            s_texture          = _shaderProgram.GetUniform1("s_texture");
            u_invertedTxMatrix = _shaderProgram.GetUniformMat3("u_invertedTxMatrix");
        }
Ejemplo n.º 2
0
 //
 protected override void OnProgramBuilt()
 {
     _isBigEndian  = _shaderProgram.GetUniform1("isBigEndian");
     _convKernel   = _shaderProgram.GetUniformMat3("convKernel");
     _onepix_xy    = _shaderProgram.GetUniform2("onepix_xy");
     _kernelWeight = _shaderProgram.GetUniform1("kernelWeight");
 }
Ejemplo n.º 3
0
        //--------------------------------
        bool LoadShaders()
        {
            //--------------------------------------
            //create shader program
            shaderProgram = new MiniShaderProgram();
            //--------------------------------------

            string vs = @"        
                attribute vec3 a_position;
                attribute vec4 a_color;  

                uniform mat4 u_mvpMatrix;
                uniform vec4 u_solidColor;
                uniform int u_useSolidColor;              

                varying vec4 v_color;
                varying vec4 a_position_output;
                void main()
                {

                    a_position_output =  u_mvpMatrix* vec4(a_position[0],a_position[1],0,1);
                    gl_Position = a_position_output;
                    v_color=  vec4(1,0,0,1); 
                }
                ";
            //fragment source
            //            string fs = @"void main()
            //                {
            //                    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
            //                }
            //            ";
            string fs = @"
                    precision mediump float;
                    varying vec4 v_color;  
                    varying vec4 a_position_output;
                    void main()
                    {
                        if(a_position_output[1]>0.5){
                            gl_FragColor = vec4(0,1,1,1);
                        }else{
                            gl_FragColor= vec4(0,1,0,1); 
                        }
                    }
                ";

            if (!shaderProgram.Build(vs, fs))
            {
                throw new NotSupportedException();
            }

            a_position = shaderProgram.GetAttrV3f("a_position");
            a_color    = shaderProgram.GetAttrV4f("a_color");

            u_matrix        = shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_useSolidColor = shaderProgram.GetUniform1("u_useSolidColor");
            u_solidColor    = shaderProgram.GetUniform4("u_solidColor");


            return(true);
        }
Ejemplo n.º 4
0
        protected bool BuildProgram(string vs, string fs)
        {
            //NOTE: during development,
            //new shader source may not recompile if you don't clear cache or disable cache feature
            //like...
            //EnableProgramBinaryCache = false;

            //---------------------
            if (!LoadCompiledShader())
            {
                if (!_shaderProgram.Build(vs, fs))
                {
                    return(false);
                }
                SaveCompiledShader();
            }

            //-----------------------
            a_position      = _shaderProgram.GetAttrV3f("a_position");
            a_texCoord      = _shaderProgram.GetAttrV2f("a_texCoord");
            u_matrix        = _shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_orthov_offset = _shaderProgram.GetUniform2("u_ortho_offset");
            s_texture       = _shaderProgram.GetUniform1("s_texture");
            OnProgramBuilt();
            return(true);
        }
Ejemplo n.º 5
0
 protected override void OnProgramBuilt()
 {
     _horizontal = _shaderProgram.GetUniform1("blur_horizontal");
     //TODO: review here
     //temp fixed for big vs little-endian
     _isBigEndian = _shaderProgram.GetUniform1("isBigEndian");
 }
 protected override void OnProgramBuilt()
 {
     _isBigEndian = shaderProgram.GetUniform1("isBigEndian");
     _d_color     = shaderProgram.GetUniform4("d_color");
     _c_compo     = shaderProgram.GetUniform1("c_compo");
     _c_intensity = shaderProgram.GetUniform1("c_intensity");
 }
Ejemplo n.º 7
0
        protected override void OnProgramBuilt()
        {
            //TODO: review here
            //temp fixed for big vs little-endian

            _blur_x = _shaderProgram.GetUniform1("blur_x");
            _blur_y = _shaderProgram.GetUniform1("blur_y");
        }
 protected bool BuildProgram(string vs, string fs)
 {
     //---------------------
     if (!shaderProgram.Build(vs, fs))
     {
         return(false);
     }
     //-----------------------
     a_position = shaderProgram.GetAttrV3f("a_position");
     a_texCoord = shaderProgram.GetAttrV2f("a_texCoord");
     u_matrix   = shaderProgram.GetUniformMat4("u_mvpMatrix");
     s_texture  = shaderProgram.GetUniform1("s_texture");
     OnProgramBuilt();
     return(true);
 }
Ejemplo n.º 9
0
        public SmoothLineShader(ShaderSharedResource shareRes)
            : base(shareRes)
        {
            //NOTE: during development,
            //new shader source may not recompile if you don't clear cache or disable cache feature
            //like...
            //EnableProgramBinaryCache = false;

            if (!LoadCompiledShader())
            {
                //we may store this outside the exe ?

                //vertex shader source
                string vs = @"                   
                    attribute vec4 a_position;  
                    uniform mat4 u_mvpMatrix;
                    uniform vec4 u_solidColor;
                
                    uniform float u_linewidth;
                    varying vec4 v_color; 
                    varying float v_distance;
                    varying float p0;
            
                    void main()
                    {   
                
                        float rad = a_position[3];
                        v_distance= a_position[2];
                        float n_x = sin(rad); 
                        float n_y = cos(rad);  
                        vec4 delta;
                        if(v_distance <1.0){                                         
                            delta = vec4(-n_x * u_linewidth,n_y * u_linewidth,0,0);                       
                        }else{                      
                            delta = vec4(n_x * u_linewidth,-n_y * u_linewidth,0,0);
                        }
    
                         if(u_linewidth <= 0.5){
                            p0 = 0.5;      
                        }else if(u_linewidth <=1.0){
                            p0 = 0.475;  
                        }else if(u_linewidth>1.0 && u_linewidth<3.0){                    
                            p0 = 0.25;  
                        }else{
                            p0= 0.1;
                        }
                
                        vec4 pos = vec4(a_position[0],a_position[1],0,1) + delta;                 
                        gl_Position = u_mvpMatrix* pos;                
                        v_color= u_solidColor;
                    }
                ";

                //fragment source
                //float factor= 1.0 /p0;
                string fs = @"
                    precision mediump float;
                    varying vec4 v_color;  
                    varying float v_distance;
                    varying float p0;                
                    void main()
                    {    
                        if(v_distance < p0){                        
                            gl_FragColor =vec4(v_color[0],v_color[1],v_color[2], v_color[3] *(v_distance * (1.0/p0)) * 0.55);
                        }else if(v_distance > (1.0-p0)){                         
                            gl_FragColor =vec4(v_color[0],v_color[1],v_color[2], v_color[3] *((1.0-v_distance) * (1.0/p0) * 0.55));
                        }
                        else{ 
                            gl_FragColor =v_color; 
                        } 
                    }
                ";
                //---------------------
                if (!_shaderProgram.Build(vs, fs))
                {
                    return;
                }
                //
                SaveCompiledShader();
            }


            //-----------------------
            a_position   = _shaderProgram.GetAttrV4f("a_position");
            u_matrix     = _shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_solidColor = _shaderProgram.GetUniform4("u_solidColor");
            u_linewidth  = _shaderProgram.GetUniform1("u_linewidth");
        }
Ejemplo n.º 10
0
 protected override void OnProgramBuilt()
 {
     u_alpha = _shaderProgram.GetUniform1("u_alpha");
 }
Ejemplo n.º 11
0
        protected override void OnInitGLProgram(object sender, EventArgs args)
        {
            string vs = @"                   
            attribute vec4 a_position; 
            attribute vec4 a_color;            

            uniform mat4 u_mvpMatrix;
            uniform vec4 u_solidColor;
            uniform int u_useSolidColor;              
            uniform float u_linewidth;

            varying vec4 v_color; 
            varying float v_distance;
            varying float p0;
            
            void main()
            {   
                
                float rad = a_position[3];
                v_distance= a_position[2];

                float n_x = sin(rad); 
                float n_y = cos(rad);  

                vec4 delta;
                if(v_distance <1.0){                                         
                    delta = vec4(-n_x * u_linewidth,n_y * u_linewidth,0,0);                       
                }else{                      
                    delta = vec4(n_x * u_linewidth,-n_y * u_linewidth,0,0);
                }
    
                if(u_linewidth <= 0.5){
                    p0 = 0.5;      
                }else if(u_linewidth <=1.0){
                    p0 = 0.45;  
                }else if(u_linewidth>1.0 && u_linewidth<3.0){
                    
                    p0 = 0.25;  
                }else{
                    p0= 0.1;
                }
                
                vec4 pos = vec4(a_position[0],a_position[1],0,1) + delta;                 
                gl_Position = u_mvpMatrix* pos;                

                if(u_useSolidColor !=0)
                {
                    v_color= u_solidColor;
                }
                else
                {
                    v_color = a_color;
                }
            }
            ";
            //fragment source
            string fs = @"
                precision mediump float;
                varying vec4 v_color;  
                varying float v_distance;
                varying float p0;                
                void main()
                {
                    float d0= v_distance; 
                    float p1= 1.0-p0;
                    float factor= 1.0 /p0;
            
                    if(d0 < p0){                        
                        gl_FragColor =vec4(v_color[0],v_color[1],v_color[2], v_color[3] *(d0 * factor));
                    }else if(d0> p1){                         
                        gl_FragColor =vec4(v_color[0],v_color[1],v_color[2], v_color[3] *((1.0-d0)* factor));
                    }
                    else{
                        gl_FragColor =v_color;
                    } 
                }
            ";

            if (!shaderProgram.Build(vs, fs))
            {
                throw new NotSupportedException();
            }


            a_position      = shaderProgram.GetVtxAttrib("a_position");
            a_color         = shaderProgram.GetVtxAttrib("a_color");
            u_matrix        = shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_useSolidColor = shaderProgram.GetUniform1("u_useSolidColor");
            u_solidColor    = shaderProgram.GetUniform4("u_solidColor");
            u_linewidth     = shaderProgram.GetUniform1("u_linewidth");
            //--------------------------------------------------------------------------------
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //setup viewport size
            int max = Math.Max(this.Width, this.Height);

            //square viewport
            GL.Viewport(0, 0, max, max);
            orthoView = MyMat4.ortho(0, max, 0, max, 0, 1);
            //--------------------------------------------------------------------------------

            //load image
        }
        public InvertAlphaLineSmoothShader(ShaderSharedResource shareRes)
            : base(shareRes)
        {
            //-------------------------------------------------------------------------------
            string vs = @"                   
            attribute vec4 a_position;    

            uniform mat4 u_mvpMatrix;
            uniform vec4 u_solidColor; 
            uniform float u_linewidth;

            varying vec4 v_color; 
            varying float v_distance;
            varying float p0;
            
            void main()
            {   
                
                float rad = a_position[3];
                v_distance= a_position[2];

                float n_x = sin(rad); 
                float n_y = cos(rad);  

                vec4 delta;
                if(v_distance <1.0){                                         
                    delta = vec4(-n_x * u_linewidth,n_y * u_linewidth,0,0);                       
                }else{                      
                    delta = vec4(n_x * u_linewidth,-n_y * u_linewidth,0,0);
                }
    
                if(u_linewidth <= 0.5){
                    p0 = 0.5;      
                }else if(u_linewidth <=1.0){
                    p0 = 0.45;  
                }else if(u_linewidth>1.0 && u_linewidth<3.0){
                    
                    p0 = 0.25;  
                }else{
                    p0= 0.1;
                }
                
                vec4 pos = vec4(a_position[0],a_position[1],0,1) + delta;                 
                gl_Position = u_mvpMatrix* pos;                

                v_color= u_solidColor;
            }
            ";
            //fragment source
            //this is invert fragment shader ***
            //so we
            string fs = @"
                precision mediump float;
                varying vec4 v_color;  
                varying float v_distance;
                varying float p0;                
                void main()
                {
                    float d0= v_distance; 
                    float p1= 1.0-p0;
                    float factor= 1.0 /p0;
            
                    if(d0 < p0){                        
                        gl_FragColor = vec4(v_color[0],v_color[1],v_color[2], 1.0 -(v_color[3] *(d0 * factor)));
                    }else if(d0> p1){                         
                        gl_FragColor= vec4(v_color[0],v_color[1],v_color[2],1.0-(v_color[3] *((1.0-d0)* factor)));
                    }
                    else{ 
                       gl_FragColor = vec4(0,0,0,0);                        
                    } 
                }
            ";

            //---------------------
            if (!shaderProgram.Build(vs, fs))
            {
                return;
            }
            //-----------------------

            a_position   = shaderProgram.GetAttrV4f("a_position");
            u_matrix     = shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_solidColor = shaderProgram.GetUniform4("u_solidColor");
            u_linewidth  = shaderProgram.GetUniform1("u_linewidth");
            _strokeColor = Drawing.Color.Black;
        }
Ejemplo n.º 13
0
        public void InitShader()
        {
            if (isInited)
            {
                return;
            }
            //----------------

            //vertex shader source
            string vs = @"        
            attribute vec3 a_position;
            attribute vec4 a_color; 
            attribute vec2 a_texcoord;
            
            uniform mat4 u_mvpMatrix;
            uniform vec4 u_solidColor;
            uniform int u_useSolidColor;            
            uniform int u_useAggColor;             

            varying vec4 v_color;
            varying vec2 v_texcoord;
             
            void main()
            {
                float a= a_position[2]; //before matrix op
                gl_Position = u_mvpMatrix* vec4(a_position[0],a_position[1],0,1);
                if(u_useAggColor !=0)
                { 
                     
                    v_color= vec4(u_solidColor.r /255.0,u_solidColor.g /255.0,u_solidColor.b/255.0, a/255.0);
                }
                else if(u_useSolidColor !=0)
                {   
                    v_color= u_solidColor;                         
                }
                else
                {
                    v_color = a_color;
                } 
                v_texcoord= a_texcoord;
            }
            ";
            //fragment source
            string fs = @"
                precision mediump float;
                varying vec4 v_color; 
                varying vec2 v_texcoord;                 
                void main()
                {       
                    gl_FragColor= v_color;
                }
            ";

            if (!shaderProgram.Build(vs, fs))
            {
                throw new NotSupportedException();
            }

            a_position      = shaderProgram.GetVtxAttrib("a_position");
            a_color         = shaderProgram.GetVtxAttrib("a_color");
            a_textureCoord  = shaderProgram.GetVtxAttrib("a_texcoord");
            u_matrix        = shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_useSolidColor = shaderProgram.GetUniform1("u_useSolidColor");
            u_useAggColor   = shaderProgram.GetUniform1("u_useAggColor");
            u_solidColor    = shaderProgram.GetUniform4("u_solidColor");
            shaderProgram.UseProgram();
            isInited = true;
        }
Ejemplo n.º 14
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            //----------------
            //vertex shader source
            string vs = @"        
            precision mediump float;
            attribute vec2 a_position;
            attribute vec3 a_color; 
            attribute vec2 a_texcoord;
            
            uniform mat4 u_mvpMatrix;
            uniform vec4 u_solidColor;
            uniform int u_useSolidColor;            

            varying vec4 v_color;
            varying vec2 v_texcoord;
             
            void main()
            {
                
                gl_Position = u_mvpMatrix* vec4(a_position[0],a_position[1],0.0,1.0);
                if(u_useSolidColor !=0)
                {
                    v_color= u_solidColor;                                       
                }
                else
                {
                    v_color = vec4(a_color,1.0);
                } 
                v_texcoord= a_texcoord;
            }
            ";
            //fragment source
            string fs = @"
                precision mediump float;
                varying vec4 v_color; 
                varying vec2 v_texcoord;                 
                void main()
                {       
                    
                    //gl_FragColor = vec4(1,v_texcoord.y,0,1);
                    gl_FragColor= v_color;
                }
            ";

            if (!shaderProgram.Build(vs, fs))
            {
                throw new NotSupportedException();
            }


            a_position      = shaderProgram.GetAttrV2f("a_position");
            a_color         = shaderProgram.GetAttrV3f("a_color");
            a_textureCoord  = shaderProgram.GetAttrV2f("a_texcoord");
            u_matrix        = shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_useSolidColor = shaderProgram.GetUniform1("u_useSolidColor");
            u_solidColor    = shaderProgram.GetUniform4("u_solidColor");
            //--------------------------------------------------------------------------------
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //setup viewport size
            int max = Math.Max(this.Width, this.Height);

            //square viewport
            GL.Viewport(0, 0, max, max);
            orthoView = MyMat4.ortho(0, max, 0, max, 0, 1);
            //--------------------------------------------------------------------------------

            //load image
        }
Ejemplo n.º 15
0
        public InvertAlphaLineSmoothShader(ShaderSharedResource shareRes)
            : base(shareRes)
        {
            //NOTE: during development,
            //new shader source may not recompile if you don't clear cache or disable cache feature
            //like...
            //EnableProgramBinaryCache = false;

            if (!LoadCompiledShader())
            {
                //vertex shader source
                string vs = @"                   
                attribute vec4 a_position;     
                uniform mat4 u_mvpMatrix; 
                uniform float u_linewidth;
                uniform vec2 u_ortho_offset;  
                varying float v_distance; 
                void main()
                {                   
                    float rad = a_position[3];
                    v_distance= a_position[2]; 

                    vec2 delta;
                    if(v_distance <1.0){                                         
                        delta = vec2(-sin(rad) * u_linewidth,cos(rad) * u_linewidth) + u_ortho_offset;   
                    }else{                      
                        delta = vec2(sin(rad) * u_linewidth,-cos(rad) * u_linewidth)+ u_ortho_offset;  
                    } 
                    gl_Position = u_mvpMatrix*  vec4(a_position[0] +delta[0],a_position[1]+delta[1],0,1); 
                }
                ";
                //fragment source
                //this is invert fragment shader ***


                //p0= cutpoint of inside,outside
                //1/p0 = factor
                string fs = @"
                    precision mediump float;      
                    uniform float p0; 
                    varying float v_distance; 
                    void main()
                    {  
                        if(v_distance < p0){                        
                            gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0-((v_distance * (1.0 /p0))));
                        }else if(v_distance> (1.0-p0)){                         
                            gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0-(((1.0-v_distance)* (1.0 /p0))));
                        }
                        else{ 
                            discard;                      
                        } 
                    }
                ";


                //string fs = @"
                //    precision mediump float;
                //    uniform vec4 u_solidColor;
                //    uniform float p0;
                //    varying vec2 v_dir;
                //    varying float v_distance;

                //    void main()
                //    {
                //        float factor= 1.0 /p0;
                //        if(v_distance < p0){
                //            gl_FragColor = vec4(u_solidColor[0],u_solidColor[1],u_solidColor[2], 1.0-(u_solidColor[3] *(v_distance * factor)));
                //        }else if(v_distance> (1.0-p0)){
                //            gl_FragColor = vec4(u_solidColor[0],u_solidColor[1],u_solidColor[2], 1.0-(u_solidColor[3] *((1.0-v_distance)* factor)));
                //        }
                //        else{
                //            discard;
                //        }
                //    }
                //";

                //---------------------
                if (!_shaderProgram.Build(vs, fs))
                {
                    return;
                }

                //-----------------------
                SaveCompiledShader();
            }


            a_position     = _shaderProgram.GetAttrV4f("a_position");
            u_matrix       = _shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_ortho_offset = _shaderProgram.GetUniform2("u_ortho_offset");
            u_linewidth    = _shaderProgram.GetUniform1("u_linewidth");
            u_p0           = _shaderProgram.GetUniform1("p0");
            _cutPoint      = SetCutPoint(0.5f); //this are fixed for inverted alpha smooth line shader
        }
Ejemplo n.º 16
0
        public SmoothLineShader(ShaderSharedResource shareRes)
            : base(shareRes)
        {
            //NOTE: during development,
            //new shader source may not recompile if you don't clear cache or disable cache feature
            //like...
            //EnableProgramBinaryCache = false;

            if (!LoadCompiledShader())
            {
                //we may store this outside the exe ?

                //vertex shader source

                string vs = @"        
                    precision mediump float;
                    attribute vec4 a_position;  
                    uniform vec2 u_ortho_offset; 
                     
                    uniform mat4 u_mvpMatrix; 
                    uniform float u_linewidth;                  
                    varying float v_distance; 
                    varying vec2 v_dir; 
                    void main()
                    {                   
                        float rad = a_position[3];
                        v_distance= a_position[2]; 
                        vec2 delta;
                        if(v_distance <1.0){                                         
                            delta = vec2(-sin(rad) * u_linewidth,cos(rad) * u_linewidth) + u_ortho_offset;                       
                            v_dir = vec2(0.80,0.0);
                        }else{                      
                            delta = vec2(sin(rad) * u_linewidth,-cos(rad) * u_linewidth) + u_ortho_offset;
                            v_dir = vec2(0.0,0.80);  
                        } 
                        gl_Position = u_mvpMatrix*  vec4(a_position[0] +delta[0],a_position[1]+delta[1],0,1);
                    }
                ";



                //version3
                string fs = @"
                    precision mediump float;
                    uniform vec4 u_solidColor;
                    uniform float p0;
                    varying float v_distance;
                    varying vec2 v_dir;                      
                    void main()
                    {   
                         gl_FragColor =vec4(u_solidColor[0],u_solidColor[1],u_solidColor[2], 
                                            u_solidColor[3] *((v_distance* (v_dir[0])+ (1.0-v_distance)* (v_dir[1]))  * (1.0/p0)) * 0.55);  
                    }
                ";

                ////old version 2
                //string fs = @"
                //    precision mediump float;
                //    uniform vec4 u_solidColor;
                //    uniform float p0;
                //    varying float v_distance;
                //    void main()
                //    {
                //        if(v_distance < p0){
                //            gl_FragColor =vec4(u_solidColor[0],u_solidColor[1],u_solidColor[2], u_solidColor[3] *(v_distance * (1.0/p0)) * 0.55);
                //        }else{
                //            gl_FragColor =vec4(u_solidColor[0],u_solidColor[1],u_solidColor[2], u_solidColor[3] *((1.0-v_distance) * (1.0/p0)) * 0.55);
                //        }
                //    }
                //";
                ////old version 1
                //string fs = @"
                //    precision mediump float;
                //    uniform vec4 u_solidColor;
                //    uniform float p0;
                //    varying float v_distance;
                //    void main()
                //    {

                //        if(v_distance < p0){
                //            gl_FragColor =vec4(u_solidColor[0],u_solidColor[1],u_solidColor[2], u_solidColor[3] *(v_distance * (1.0/p0)) * 0.55);
                //        }else if(v_distance >= (1.0-p0)){
                //            gl_FragColor =vec4(u_solidColor[0],u_solidColor[1],u_solidColor[2], u_solidColor[3] *((1.0-v_distance) * (1.0/p0)) * 0.55);
                //        }else{
                //            gl_FragColor = u_solidColor;
                //        }
                //    }
                //";


                //---------------------
                if (!_shaderProgram.Build(vs, fs))
                {
                    return;
                }
                //
                SaveCompiledShader();
            }


            //-----------------------
            a_position     = _shaderProgram.GetAttrV4f("a_position");
            u_ortho_offset = _shaderProgram.GetUniform2("u_ortho_offset");
            u_matrix       = _shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_solidColor   = _shaderProgram.GetUniform4("u_solidColor");
            u_linewidth    = _shaderProgram.GetUniform1("u_linewidth");
            u_p0           = _shaderProgram.GetUniform1("p0");
        }
Ejemplo n.º 17
0
 //
 protected override void OnProgramBuilt()
 {
     u_convKernel   = _shaderProgram.GetUniformMat3("convKernel");
     u_onepix_xy    = _shaderProgram.GetUniform2("onepix_xy");
     u_kernelWeight = _shaderProgram.GetUniform1("kernelWeight");
 }
Ejemplo n.º 18
0
 protected override void OnProgramBuilt()
 {
     _u_color  = _shaderProgram.GetUniform4("u_color");
     _u_buffer = _shaderProgram.GetUniform1("u_buffer");
     _u_gamma  = _shaderProgram.GetUniform1("u_gamma");
 }
        public InvertAlphaLineSmoothShader(ShaderSharedResource shareRes)
            : base(shareRes)
        {
            //NOTE: during development,
            //new shader source may not recompile if you don't clear cache or disable cache feature
            //like...
            //EnableProgramBinaryCache = false;


            //TODO: review here ...
            if (!LoadCompiledShader())
            {
                //vertex shader source
                string vs = @"                   
                attribute vec4 a_position;    

                uniform vec2 u_ortho_offset; 
                uniform mat4 u_mvpMatrix;
                uniform vec4 u_solidColor; 
                uniform float u_linewidth;

                varying vec4 v_color; 
                varying float v_distance;
                varying float p0;
            
                void main()
                {   
                
                    float rad = a_position[3];
                    v_distance= a_position[2];

                    float n_x = sin(rad); 
                    float n_y = cos(rad);  

                    vec2 delta;
                    if(v_distance <1.0){                                         
                        delta = vec2(-n_x * u_linewidth,n_y * u_linewidth) +u_ortho_offset;                       
                    }else{                      
                        delta = vec2(n_x * u_linewidth,-n_y * u_linewidth)+ u_ortho_offset;
                    }
    
                    if(u_linewidth <= 0.5){
                        p0 = 0.5;      
                    }else if(u_linewidth <=1.0){
                        p0 = 0.45;  
                    }else if(u_linewidth>1.0 && u_linewidth<3.0){
                    
                        p0 = 0.25;  
                    }else{
                        p0= 0.1;
                    } 
                     
                    gl_Position = u_mvpMatrix*  vec4(a_position[0] +delta[0],a_position[1]+delta[1],0,1);
                    v_color= u_solidColor;
                }
                ";
                //fragment source
                //this is invert fragment shader ***
                //so we
                string fs = @"
                    precision mediump float;
                    varying vec4 v_color;  
                    varying float v_distance;
                    varying float p0;                
                    void main()
                    {
                        float d0= v_distance; 
                        float p1= 1.0-p0;
                        float factor= 1.0 /p0;
            
                        if(d0 < p0){                        
                            gl_FragColor = vec4(v_color[0],v_color[1],v_color[2], 1.0 -(v_color[3] *(d0 * factor)));
                        }else if(d0> p1){                         
                            gl_FragColor= vec4(v_color[0],v_color[1],v_color[2],1.0-(v_color[3] *((1.0-d0)* factor)));
                        }
                        else{ 
                           gl_FragColor = vec4(0,0,0,0);                        
                        } 
                    }
                ";
                //---------------------
                if (!_shaderProgram.Build(vs, fs))
                {
                    return;
                }

                //-----------------------
                SaveCompiledShader();
            }


            a_position      = _shaderProgram.GetAttrV4f("a_position");
            u_orthov_offset = _shaderProgram.GetUniform2("u_ortho_offset");
            u_matrix        = _shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_solidColor    = _shaderProgram.GetUniform4("u_solidColor");
            u_linewidth     = _shaderProgram.GetUniform1("u_linewidth");
            _strokeColor    = Drawing.Color.Black;
        }