Howdy, Stranger!

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

Are there any 'gotchas' when using meshes?

in Questions Posts: 21

I'm struggling to debug a subtle rendering issue in my game and could use some advice. The symptom of the problem is rect, sprite, text, and mesh:draw are visible only when another mesh:draw call is called. In my program I can narrow down the draw call to a particular mesh which looks like this (psuedo-code):

function draw()
    background()
    ...
    pushMatrix()
    translate(z = 0.8)
    mesh:draw() -- removing this causes all subsequent `rect`, `text`, and `sprite` calls to be invisible
    rect()
    popMatrix()
    ...
    pushMatrix()
    translate(z = 1.0)
    rect() -- also invisible
    popMatrix()
    ...
end

Investigation so far:

  • Immediate suspicions are something to do with depth testing; however, after significant investigation, this does not seem to be the case. There seems to be a subtle interaction between the mesh draw call and the others.
  • All mesh shaders use the standard modelViewProjection * position computation in the vertex shader, which should include the z transform.
  • The projection matrix is altered occasionally during draw but not for the problematic mesh draw call.
  • One can assume the vertices of the meshes and other calls are correctly specified.
  • All [push|pop]Matrix calls have been checked for matching pairs.
  • Not all draw calls are affected however affected draw calls are consistency affected.
  • I have hit similar issues with other meshes.

Are there any peculiarities regarding drawing meshes with depth testing that I should know about?

Comments

  • Posts: 1,200

    @alteous - can you give us a few details on what device you are using plus iOS and Codea version number.

  • Posts: 21

    iPad 2 (A1395)
    iOS 9.3.5 (13G36)
    Codea version 2.5.2 (99)

  • edited January 5 Posts: 1,200

    @alteous - thanks for that, just noticed something similar in development version with text() but I am pretty sure it’s just my coding. Taking a lot of digging to home into problem cause.

  • SimeonSimeon Admin Mod
    Posts: 4,924

    @alteous I wouldn't look past it being our bug, it's unfortunate that we don't still support iOS 9 so we can see if it's limited to that version of Codea.

    I can offer to run your full project and comment / uncomment the offending line to see how it goes (and if the bug still exists, put it through the debugger on my end to see if it's a problem in the engine).

  • edited January 5 Posts: 21

    I have prepared an example that reproduces the issue:

    parameter.boolean("bug_here", true)
    
    local vertex_shader = [[
    #version 100
    precision highp float;
    uniform mat4 modelViewProjection;
    attribute vec4 position;
    attribute vec2 texCoord;
    varying vec2 vTexCoord;
    void main() {
        vTexCoord = texCoord;
        gl_Position = modelViewProjection * position;
    }
    ]]
    
    local fragment_shader = [[
    #version 100
    precision mediump float;
    uniform sampler2D texture;
    varying vec2 vTexCoord;
    void main() {
        gl_FragColor = texture2D(texture, vTexCoord);
    }
    ]]
    
    function setup()
        displayMode(OVERLAY)
        rectMode(CORNER)
        noSmooth()
        strokeWidth(1)
        stroke(255, 255, 0)
        fill(50, 50, 40, 60)
    
        empty_mesh = mesh()
        empty_mesh.shader = shader(vertex_shader, fragment_shader)
        empty_mesh.shader.texture = "Blocks:Blank White"
    
        white_rect = mesh()
        white_rect.shader = shader(vertex_shader, fragment_shader)
        white_rect.texture = "Blocks:Blank White"
        white_rect:addRect(45.5, 11.5, 1.0, 1.0)
    end
    
    function draw()
        background(40, 40, 50)
    
        pushMatrix()
        local min = vec2(28.0, 8.0)
        local max = vec2(75.8125, 24.0)
        ortho(min.x, max.x, min.y, max.y)
        translate(0, 0, 0.75)
        white_rect:draw()
        ortho() -- reset projection matrix
        popMatrix()
    
        assert(empty_mesh.size == 0)
        if bug_here then empty_mesh:draw() end
    
        pushMatrix()
        translate(0, 0, 1.0)
        rect(0.5 * WIDTH, 0.5 * HEIGHT, 16, 48)
        popMatrix()
    end
    

    Edit: Reduced size of example.

    image.jpeg 12.1K
    image.jpeg 11.5K
  • edited January 5 Posts: 21

    The left/right image shows the output with bug_here = true/false. Both images are expected to have a white rectangle and a yellow rectangle outline. The yellow outline may have only three sides visible; that is expected and not noteworthy.

    Note that the yellow rectangle appears if empty_mesh uses the default shader or if it is not drawn.

  • Posts: 21

    @Bri_G Would you mind running on your hardware (supposing it is different) to see whether the same problem occurs?

  • dave1707dave1707 Mod
    edited January 5 Posts: 7,550

    @alteous Here’s an image of what I see with your code. It’s the same with the slider set to true or false. I’m on the latest everything. Codea 2.6.3 (136) ios 12.1.1 using an iPad Air.

  • Posts: 385

    @alteous i see no difference between bug_here true or false.
    ipadpro latest version, ios12.1

  • edited January 5 Posts: 21

    @dave1707 @piinthesky Thanks for trying.

    This is disappointing. It seems this problem is specific to my outdated version of Codea running on iOS 9 which will not be upgraded.

    @Simeon Were you able to reproduce the problem?

    Edit: This may be worked around by ensuring 'empty' meshes with mesh.size == 0 are never drawn.

  • Posts: 1,200

    @alteous - I’m on the same as @dave1707 but on an iPad Pro and I see the same images he does.

    Also on my iPad 2 Codea version 2.5.2 (99) and iOS 9.3.5 I see the bug, the yellow rectangle disappears totally.

  • SimeonSimeon Admin Mod
    Posts: 4,924
    @alteous sorry about this bug. I also can’t reproduce on iPhone X

    I’m really curious as to which lines in your sample are causing the issue.
  • pacpac
    Posts: 208

    Wait wait wait. Bri_g you are the same as @dave1707. Then why didn’t you just login in both of the places with the same username and password.

    This is a website it is universal for all computers and phones and tablets.

  • pacpac
    Posts: 208

    And if you are really @dave1707 then have him comment back. To me.

  • pacpac
    Posts: 208

    Hey @alteous have you checked to see if you are calling Background() because if you are there reason it may be showing up is because it is getting erased by the background function.

    I had this same trouble for a while.

  • pacpac
    Posts: 208

    And the only reason it works when the mesh is there is because the mesh stays on the screen even when the screen get redrawn.

  • dave1707dave1707 Mod
    Posts: 7,550

    @pac What @Bri_G meant was he’s running the same Codea and iOS versions as I am. We are not the same person if that’s what you think. @Bri_G and I are seperated by about 3600 miles. @pac, we are seperated by about 800 miles.

  • pacpac
    Posts: 208

    Oh cool.

    How do you know where I live?

  • dave1707dave1707 Mod
    Posts: 7,550

    @pac As a Mod I have access to more info than a normal user. I don’t know where you live, just a general location within a few hundred miles or so.

Sign In or Register to comment.