Howdy, Stranger!

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

Screen messing up

When I add a standard shader to the dark green mesh it messes up my screen. Without shader: https://db.tt/rBpYifpy With shader: https://db.tt/qFZSTQHf
Am I missing something obvious?

Comments

  • Posts: 2,020

    Looks to me like your shader is expecting a texture and not finding one.

  • Posts: 11

    Maybe...
    self.mk is my mesh and
    I tried:

        self.mk.shader = shader("Dropbox:BasicShader")
        self.mk.texture = readImage("Dropbox:Grass")
        self.mk.shader.texture = readImage("Dropbox:Grass")
    

    I am just using a startup shader where I haven't changed any code.

  • Posts: 2,020

    Can we see the rest of the code, including the shader?

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Holger_gott - your shader probably has an error. It's possible that recent changes to Codea or OpenGL have broken it, but we can't tell you unless we know which shader it is and how you've used it.

    By the way, the correct way to set the texture is "self.mk.texture =", not "self.mk.shader.texture=".

  • Posts: 11

    Simplified code:


    -- Problem -- Use this function to perform your initial setup function setup() v = {} t = {} table.insert(v,vec3(-200,0,-200)) table.insert(v,vec3(200,0,-200)) table.insert(v,vec3(-200,0,200)) table.insert(v,vec3(200,0,200)) table.insert(v,vec3(200,0,-200)) table.insert(v,vec3(-200,0,200)) table.insert(t,vec2(0,0)) table.insert(t,vec2(1,0)) table.insert(t,vec2(0,1)) table.insert(t,vec2(1,1)) table.insert(t,vec2(1,0)) table.insert(t,vec2(0,1)) mk = mesh() mk.vertices = v mk.texCoords= t mk.texture = readImage("Planet Cute:Gem Blue") --mk.shader=shader("Dropbox:BasicShader") pos=vec3(0,200,700) end function draw() background(40, 40, 50) perspective() camera(pos.x,pos.y,pos.z,0,0,-2000) mk:draw() resetMatrix() ortho() viewMatrix(matrix()) sprite("Cargo Bot:Clear Button",100,100) strokeWidth(32) stroke(255, 0, 0, 255) lineCapMode(ROUND) line(WIDTH-30,30,WIDTH-30,80) text("problem",60,HEIGHT-40) end
  • Posts: 11

    The shader:

    //
    // A basic vertex shader
    //
    
    //This is the current model * view * projection matrix
    // Codea sets it automatically
    uniform mat4 modelViewProjection;
    
    //This is the current mesh vertex position, color and tex coord
    // Set automatically
    attribute vec4 position;
    attribute vec4 color;
    attribute vec2 texCoord;
    
    //This is an output variable that will be passed to the fragment shader
    varying lowp vec4 vColor;
    varying highp vec2 vTexCoord;
    
    void main()
    {
        //Pass the mesh color to the fragment shader
        vColor = color;
        vTexCoord = texCoord;
    
        //Multiply the vertex position by our combined transform
        gl_Position = modelViewProjection * position;
    }
    
    //
    // A basic fragment shader
    //
    
    //Default precision qualifier
    precision highp float;
    
    //This represents the current texture on the mesh
    uniform lowp sampler2D texture;
    
    //The interpolated vertex color for this fragment
    varying lowp vec4 vColor;
    
    //The interpolated texture coordinate for this fragment
    varying highp vec2 vTexCoord;
    
    void main()
    {
        //Sample the texture at the interpolated coordinate
        lowp vec4 col = texture2D( texture, vTexCoord ) * vColor;
    
        //Set the output color to the texture color
        gl_FragColor = col;
    }
    
    
  • IgnatzIgnatz Mod
    edited May 2015 Posts: 5,396

    @Holger_gott - You need to add this line after mk.texCoords=t

    mk:setColors(color(255))

    The reason it matters is that the standard fragment shader multiplies the texture colour by the vertex colour, and if you haven't set it, it gives an error or uses black (the result is the same). Setting it to white (which the shader treats as 1 rather than 255) will draw the mesh properly.

    You can alternatively fix it by removing * vColor from the fragment shader

    PS if you are interested in exploring shaders, I have an ebook here

  • Posts: 11

    It fixes the mesh but the text, the line and the sprite are still not drawn correct

  • IgnatzIgnatz Mod
    edited May 2015 Posts: 5,396

    oh yes they are, for me, anyway

Sign In or Register to comment.