Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
vertex color in shader? — Gideros Forum

vertex color in shader?

PanPanPanPan Member
edited September 2013 in General questions
hi^^
i am trying to write a shader in 2.0.0-alpha.1
my problem is:
how can i get the color in shader which set in mesh:setColorArray?
and how can i use glVertexAttribPointer in Effect

thanks^^

Comments

  • atilimatilim Maintainer
    edited September 2013 Accepted Answer
    Hi,

    You can access the color vertices as
    attribute vec4 COLOR0;
    For example, here is the default vertex and pixel shaders of Mesh class:
    attribute vec4 POSITION0;
    attribute vec4 COLOR0;
    attribute vec2 TEXCOORD0;
     
    uniform mat4 g_MVPMatrix;
     
    varying vec4 color;
    varying vec2 texCoord;
     
    void main()
    {
        gl_Position = g_MVPMatrix * POSITION0;
        color = COLOR0;
        texCoord = TEXCOORD0;
    }
    and
    #ifndef GL_ES
    #define lowp
    #define mediump
    #define highp
    #endif
     
    varying lowp vec4 color;
    varying mediump vec2 texCoord;
     
    uniform lowp vec4 g_Color;
    uniform lowp sampler2D g_Texture;
     
    void main()
    {
        gl_FragColor = g_Color * color * texture2D(g_Texture, texCoord);
    }
    Currently you cannot specify custom vertex attributes or attach multiple textures to Mesh class but we'll improve it with the next release.
  • it work!!!
    thanks^^
Sign In or Register to comment.