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"); s_texture = _shaderProgram.GetUniform1("s_texture"); OnProgramBuilt(); return(true); }
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"); }
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); }
public RectFillShader(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; attribute vec4 a_color; uniform mat4 u_mvpMatrix; uniform vec2 u_ortho_offset; varying vec4 v_color; void main() { gl_Position = u_mvpMatrix* vec4(a_position+ u_ortho_offset,0,1); v_color= a_color; } "; //fragment source string fs = @" precision mediump float; varying vec4 v_color; void main() { gl_FragColor = v_color; } "; if (!_shaderProgram.Build(vs, fs)) { throw new NotSupportedException(); } SaveCompiledShader(); } a_position = _shaderProgram.GetAttrV2f("a_position"); u_ortho_offset = _shaderProgram.GetUniform2("u_ortho_offset"); a_color = _shaderProgram.GetAttrV4f("a_color"); u_matrix = _shaderProgram.GetUniformMat4("u_mvpMatrix"); }
public GlyphFillShader(CanvasToShaderSharedResource canvasShareResource) : base(canvasShareResource) { //---------------- //vertex shader source string vs = @" attribute vec2 a_position; uniform mat4 u_mvpMatrix; uniform vec4 u_solidColor; uniform vec2 u_2d_offset; varying vec4 v_color; void main() { gl_Position = u_mvpMatrix* vec4(a_position[0] +u_2d_offset[0],a_position[1]+ u_2d_offset[1],0,1); v_color= u_solidColor; } "; //fragment source string fs = @" precision mediump float; varying vec4 v_color; void main() { gl_FragColor = v_color; } "; if (!shaderProgram.Build(vs, fs)) { throw new NotSupportedException(); } a_position = shaderProgram.GetAttrV2f("a_position"); u_matrix = shaderProgram.GetUniformMat4("u_mvpMatrix"); u_solidColor = shaderProgram.GetUniform4("u_solidColor"); u_2d_offset = shaderProgram.GetUniform2("u_2d_offset"); }
public RectFillShader(ShaderSharedResource shareRes) : base(shareRes) { //---------------- //vertex shader source string vs = @" attribute vec2 a_position; attribute vec4 a_color; uniform mat4 u_mvpMatrix; varying vec4 v_color; void main() { gl_Position = u_mvpMatrix* vec4(a_position[0],a_position[1],0,1); v_color= a_color; } "; //fragment source string fs = @" precision mediump float; varying vec4 v_color; void main() { gl_FragColor = v_color; } "; if (!shaderProgram.Build(vs, fs)) { throw new NotSupportedException(); } a_position = shaderProgram.GetAttrV2f("a_position"); a_color = shaderProgram.GetAttrV4f("a_color"); u_matrix = shaderProgram.GetUniformMat4("u_mvpMatrix"); }
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 }