Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Using a shader - solved

edited April 2014 in Shaders Posts: 425

I have made a timer shader based on the arc shader which should show a countdown like timer and it works fine in the shader lab, but when I try to use it in a project it doesn't work. there are no error messages, just a blank screen. Am I doing something wrong?

Comments

  • edited April 2014 Posts: 425
    -- Main
    displayMode(STANDARD)
     
    function setup()
     
        timeshader={
        vertexShader=[[
        //
    // Vertex shader: Timer
    //
     
    uniform mat4 modelViewProjection;
     
    attribute vec4 position;
    attribute vec2 texCoord;
     
    varying highp vec2 vTexCoord;
     
    void main() {
        vTexCoord = texCoord;
        gl_Position = modelViewProjection * position;
    }
     
        ]],
        fragmentShader=[[
        //
    // Fragment shader: Timer
    //
     
    precision highp float;
     
    uniform float size;
    uniform float a1;
    uniform float a2;
    uniform vec4 color;
     
    varying vec2 vTexCoord;
     
    void main() {
        vec4 col = vec4(0.0);
        vec2 r = vTexCoord - vec2(0.5);
        float d = length(r);
        if (d > size && d < 0.5) {
    // this pixel is within the outer and outside the inner ring(s)
            float a = atan(r.y, r.x);
            if (a2 > a1) {
                if (a > a1 && a < a2) {
                    col = color;
                }
            } else {
                if (a > a1 || a < a2) {
                    col = color;
                }
            }
        }
        gl_FragColor = col;
    }
        ]]
        }
     
        m = mesh()
     
        m.shader = shader(timeshader.vertexShader,timeshader.fragmentShader)
     
        r=m:addRect(0, 0, 0, 0)
        -- m:setRectColor(i, 255,0,0)
    end
     
    -- This function gets called once every frame
    function draw()
        -- This sets a dark background color
        background(0, 0, 0, 255)
     
        -- This sets the line thickness
        strokeWidth(5)
        m:setRect(r,WIDTH/2,HEIGHT/2,100,100)
        m.shader.a1=math.fmod(ElapsedTime,math.pi*2)-math.pi
        m.shader.a2=-math.pi
        m.shader.color=vec4(0,1,0,1)
        m.shader.size=0.2
     
        -- Draw the mesh
        m:draw()
    end
  • Posts: 1,595

    rIdx needs to have a size! The last two parameters of addRect need to be much greater then 0 (width and height)

  • Posts: 425

    @Luatee i fixed that but it stil won't work

  • Posts: 1,976

    The shader doesn't work in the shader lab for me.

    Another problem might be the color uniform's value, though. You want to set it to color(255,255,0,255), not vec4(1,1,0,1).

  • edited April 2014 Posts: 425

    Sorry this was my fault. I didn't supply the correct uniforms.
    The code should work now

Sign In or Register to comment.