Howdy, Stranger!

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

Codea 1.5 (Beta 13 & 14)

SimeonSimeon Admin Mod
edited January 2013 in Beta Posts: 5,364

Beta 13 is uploading. It's mostly fixes and corrections (thanks @mpilgrem!) and polish.

There is one main new feature: sampler2D uniforms can be interacted with in the Shader Lab. So you can choose custom textures to use while coding shaders.

I've labeled the Shader Lab as "Beta" in this release. I'm going to do this for the proper 1.5 release — rather than add all the features I would like to the Shader Lab, I'll release it in more-or-less the current state. This will help get 1.5 released faster, and allow the Shader Lab to be enhanced in future updates.

What is needed, however, are example shaders — if any of you would like to contribute shaders, please let me know. I'd love to have some great examples for people to learn from.

Also: line rendering has been significantly changed. If this causes problems, let me know.

Comments

  • edited January 2013 Posts: 196

    Mmm... I cannot create a project, or open any custom or demo projects after installing this version :P
    Codea completely freezes (if I reduce it and reopen it, it will crash).
    I have restarted my 3rd gen ipad, too. iOS 6.0.1

    Happens when I try to access the Shader Lab too

    Still happens after completely deleting Codea and reinstalling it

    edit: haha damn it, guess I won't be coding this evening :P Maybe it's a sign I should be more social and go hang with the wife and kids ^^

  • edited January 2013 Posts: 489

    (Update) Fixed in beta 1.5(14).

    Hello @Simeon. Below is an Editor bug relating to beta 1.5(12). It happens in portrait and landscape orientation:

    1. Open the Physics Lab example project (being a project with lots of tabs).

    2. Touch the Viewer to call up the on-screen keyboard, and open the in-app reference.

    3. Scroll up, so that the 'tabs' bar appears.

    4. Dismiss the on-screen keyboard.

    5. Dismiss the in-app reference, using the top left arrow button.

    6. BUG: The 'tabs' bar slides to the left as the in-app reference disappears but does not grow to fill the width of the Viewer.

  • edited January 2013 Posts: 489

    (Update) Fixed in beta 1.5(14).

    Hello @Simeon. Below is a rather subtle Editor bug in beta 1.5(12).

    1. In portrait orientation, open the Physics Lab example project.

    2. Drag the text down and release, to allow the hidden 'rubber band' to pull the text back up.

    3. BUG No. 1: The 'tabs' bar disappears, leaving a blank strip in its place.

    4. Drag the text up (hiding the 'tabs' bar zone).

    5. Drag the text all the way down (beyond row 1) and release, to allow the hidden 'rubber band' to pull the text back up.

    6. BUG No. 2: The 'momentum' of the text bouncing back up appears to cause the 'tabs' bar zone to slip a little (a few rows of pixels) off the top of the Viewer.

    7. However, it is not the momentum, but some sort of mis-match. If you repeat steps 5 and 6, more and more of the 'tabs' bar zone slips off the top of the Viewer. After about 50 repetitions, the 'tabs' bar disappears off the top of the Viewer.

  • Posts: 2,161

    Ditto on the freeze with 1.5(13).

  • SimeonSimeon Admin Mod
    Posts: 5,364

    Sorry about the freeze everyone. @Xavier you can re-install the old version (12) for now, through TestFlight.

  • SimeonSimeon Admin Mod
    Posts: 5,364

    Fix is uploaded (B14) - sorry about the bug.

  • edited January 2013 Posts: 489

    Hello @Simeon. In beta 1.5(14), I think there is a bug with color(gray, alpha):

    --
    -- Test Card
    --
    
    function setup()
        col = color(50, 150, 200, 250)
        grey = color(127)
        transparentGrey = color(127, 63)
        print(col) -- Output: (50, 150, 200, 250)
        print(grey) -- Output: (127, 127, 127, 255)
        print(transparentGrey) -- BUG Output: (127, 127, 127, 127)
    end
    
    function draw() background(0) end
    
  • SimeonSimeon Admin Mod
    Posts: 5,364

    Thanks @mpilgrem, bug fixed.

  • Posts: 2,161

    With regard to example shaders, what sort of thing are you looking for? Most of mine are quite closely linked to the code that uses them so wouldn't be suitable for a general purpose set, but on the other hand might be suitable for examples of what shaders can do.

    Looking at my list I have:

    1. Alpha mask shader: use one texture as a mask for another
    2. A group of shaders that produce the Game of Life simulation: there's the GoL itself but then also a rendering shader that takes the raw GoL texture and makes it look nicer.
    3. Various fractal shaders.
    4. A vertex shader that defines trajectories for the pieces of an image making it "explode".

    Many of these were explorations in shader capabilities and may not be optimal.

    For example, in the Game of Life you need to work with two images: a source image containing the previous iteration and a target image to record the next iteration. So I need to keep swapping between the two. At the moment, both images are registered with the shader and I use a flag to switch between the two. But the conditional thus gets evaluated for ever pixel. If the two textures are always stored in the GPU anyway then calling m.texture = image_a should just reassign a pointer and thus be much, much quicker. But if m.texture = image_a makes a fresh copy of the image then it is expensive.

    So is it better to do m.texture = image_[a/b] each draw than evaluating a conditional for each pixel?

  • SimeonSimeon Admin Mod
    edited January 2013 Posts: 5,364

    m.texture = image_a should simply tell the mesh where in GPU memory to find image_a. If image_a is not in GPU memory, it is loaded and cached (usually the first time you do the assignment). It should be faster than a conditional on every pixel.

    With the new sampler2D picker it should be easier to demonstrate slightly more advanced shaders — such as masking and blending between images.

    I am curious, do your fractal shaders render in the Shader Lab? Or are there issues that prevent this? They are really cool and would be a great asset to include, if it's something you would like to do.

    Currently the Shader Lab uses a simple Codea project to render your shader preview. I've placed the code for the Shader Lab "project" below.

    What I'd really love to do (unsure if there is time) is to add a few more of these projects — one with a 3D sphere, one with a 3D cube, and modify the existing "plane" one to subdivide the plane so that vertex shaders have more interesting data to work on. I'd also really like to allow interaction, such as drag to rotate the scene, and pinch to zoom.

    The idea was that you would be able to select from these built-in scenes by using the settings button in the upper right of the preview window (this button is hidden in build 13).

    The way it works is: the Shader Lab calls the special updateShaderSample function, which uses the special shader key #:SHADERLAB_CURRENT_SHADER (only valid while the Shader Lab is running) to return the currently edited shader. Then, whenever any uniforms are modified with the interactive popups, the Shader Lab calls updateShaderUniform with the uniform name, and new data.

    -- ShaderTemplatePlane
     
    -- Use this function to perform your initial setup
    function setup()
        m = mesh()
        key = "Cargo Bot:Codea Icon"
        tw,th = spriteSize(key)
        m.texture = key
        rectIndex = m:addRect(0,0,tw,th)
    end
     
    function updateShaderSample() 
        m.shader = shader("#:SHADERLAB_CURRENT_SHADER")
    end
     
    function updateShaderUniform(uniformName, data)
        if uniformName == "texture" then
            m.texture = data
            tw,th = spriteSize(data)
        else
            m.shader[uniformName] = data
        end
    end
     
    -- This function gets called once every frame
    function draw()
        -- This sets a dark background color 
        background(24, 24, 32, 255)
     
        -- This sets the line thickness
        strokeWidth(5)
     
        -- Do your drawing here
        m:setRect(rectIndex,WIDTH/2,HEIGHT/2,tw,th)
        m:draw()
    end
  • Posts: 2,161

    .@Simeon Thanks for the pointer on pointers - that's useful to know.

    To my immense surprise, the fractal shader does render in the lab (see latest tweet). It was a bit of a pain with the parameters because I use a switch variable to determine which fractal to choose (mandelbrot, julia set, cantor set, sierpinski triangle, newton-raphson iterations). When setting these from lua, I can set the parameter to a fixed integer. However, it's quite hard to hit a specific value in the parameter selector in the shader lab. Or at least, if there's a knack then I didn't find it. My best seemed to vary between a delta of 0.01 and 0.02, but the 0.02 would set me off course.

  • Posts: 489

    Hello @Simeon. Some comments on tween (which may repeat comments on earlier betas):

    (1) the in-app reference has the wrong names for easing functions. For example tween.easing.quadIn should be tween.easing.inQuad.

    (2) the in-app reference refers to easing functions that do not exist. For example tween.easing.quad.

    (3) the in-app reference omits the easing functions tween.easing.inCirc, .outCirc, .inOutCirc, .outInCirc.

    (4) the tween() function has the effect of creating global variables easing and loop. I am not sure if that is a bug or by design. I was surprised anything would be created outside of the tween namespace and in the global namespace.

    (5) the in-app reference says that tween() returns an 'int' but it returns a table.

  • Jmv38Jmv38 Mod
    edited January 2013 Posts: 3,295

    new drawing rules the new way to draw thin lines make them much thicker. Then my ants are now completely transformed... Then dont look like ants any more, rather like tarantula spiders... Is this new rule here to stay? If so i am going to have to redesign them completely. Please let me know. Btw, i understand there were some problems with previous drawings with thin lines, but i had managed to work with them (at the cost of a lot of work). So now if you solve them, i have back compatibility problem. Usually, it is better to do the improvement, but provide a way to enable back compatibility, so the users dont have to rework everything. But i understand it is not easy for you....
    [edit] going from stokeWidth(3) to (1.5) solves most of the problem.

  • edited January 2013 Posts: 489

    Hello @Simeon. It may be a breaking change for @Jmv38's ants - which made a feature of a bug (as well as a bug out of a feature) - but I think the new rendering of a smooth line(), at all strokeWidth's, is much improved.

    (Update) However, one (positive) side-effect is that the following 'patch' used in the Physics Lab example project is no longer required:

    (1) the project (in the PhysicsDebugDraw tab) had a strokeWidth of 2.5 for the circle's circumference and a strokeWidth of 5.0 for everything else (including in the 'Test7' tab);

    (2) the strokeWidth of 5.0 for everything else can now be reduced to be 2.5 too.

    (Further Update) However, something odd is happening for noSmooth() lines.

  • Posts: 489

    The prefix-free global variable names for use with blendMode() are also a positive development, in my view. However, the in-app reference for 'blendMode' needs to be updated, accordingly.

    Also, something odd is happening in the in-app reference rendering for 'blendMode' between the end of the 'srcFactor' section and the top of the 'destFactor' section.

  • Posts: 489

    The Spritely example project will need a little redesign: the 'Create new image.' button now falls underneath Codea's 'toggle displayMode' button, and cannot be pressed.

    It would be good to document the location of the 'toggle displayMode' button zone in the in-app reference (so that it can be avoided in code) - perhaps, currently, in the 'displayMode' entry.

  • Posts: 489

    In beta 1.5(14), the Sounds Plus example project has not yet been updated fully to use the new parameter API.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Nice shot @mpilgrem ;-) (... a feature of a bug (as well as a bug out of a feature) ...)

  • Posts: 489

    Actually, the odd behaviour of noSmooth() line() is not new to beta 1.5(14). Below is a slightly modified version of the Lines example project:

    supportedOrientations(LANDSCAPE_ANY)
    
    -- The following line is not required
    -- t = 0
    
    function setup()
        -- Additional parameter below, for smoothing option
        parameter.boolean("isSmooth", true)
        parameter.number("x1", 0, WIDTH, 100)
        parameter.number("y1", 0, HEIGHT, 100)
        parameter.number("x2", 0, WIDTH, WIDTH - 100)
        parameter.number("y2", 0, HEIGHT, HEIGHT - 100)
        parameter.number("width", 1, 100, 10)
        parameter.integer("lineCap", 0, 2, 0)
    end
    
    function draw()
        background(10, 10, 20)
        -- The following line is not required
        -- fill(255,0,0)
        stroke(255)
        strokeWidth(width)
        -- The following lines are no longer required
        -- if width < 3 then
        --     noSmooth()
        -- else
        --     smooth()
        -- end
        -- The following line could be added
        if isSmooth then smooth() else noSmooth() end
        lineCapMode(lineCap)
        line(x1, y1, x2, y2)
    end
    

    If noSmooth() then it appears that strokeWidth is capped at about 20, and it is not strictly true - as stated by the in-app reference - that the rendered line has square end caps. (Draw a diagonal line with the maximum strokeWidth.)

    If smooth() and strokeWidth(1), the line is rendered with a strange moire pattern-type effect at certain orientations.

  • Posts: 489

    Hello @Simeon. Does the following code reveal a bug in beta 1.5(14), or is it my code that is buggy?

    The mesh renders for a few seconds, then disappears for a short while, then reappears briefly, to disappear for good.

    Lua:

    --
    -- Arc
    --
    
    supportedOrientations(LANDSCAPE_ANY)
    function setup()
        parameter.number("width", 1, 100, 40)
        parameter.number("radius", 50, WIDTH / 2, 200)
        parameter.number("startAngle", -180, 180, -130)
        parameter.number("endAngle", -180, 180, 130)
        stroke(118, 223, 25)
    end
    
    function draw()
        background(64)
        strokeWidth(width)
        arc(WIDTH / 2, HEIGHT / 2, radius, startAngle, endAngle)
    end
    
    function arc(x, y, radius, a1, a2)
        local m = mesh()
        m:addRect(x, y, radius * 2, radius * 2)
        m.shader = shader("Documents:Arc")
        m.shader.size = (1 - strokeWidth()/radius) * 0.5
        m.shader.color = color(stroke())
        m.shader.a1 = math.rad(a1)
        m.shader.a2 = math.rad(a2)
        m:draw()
    end
    

    Vertex shader:

    //
    // Vertex shader: Arc
    //
    
    uniform mat4 modelViewProjection;
    
    attribute vec4 position;
    attribute vec2 texCoord;
    
    varying highp vec2 vTexCoord;
    
    void main() {
        vTexCoord = texCoord;
        gl_Position = modelViewProjection * position;
    }
    

    Fragment shader:

    //
    // Fragment shader: Arc
    //
    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) {
            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;
    }
    
  • Posts: 489

    Hello @Simeon. Could the 'expression key' pop up:

    (1) in the Shader Lab Editor, include &, |, ^ and :?

    (2) be dismissed if a (non-pop up) key is pressed instead?

  • SimeonSimeon Admin Mod
    edited January 2013 Posts: 5,364

    .@mpilgrem will do on the extra keys — Though I've included &&, ||, ^^ instead, as the bit-wise versions are not supported in GLSL. I've also put in ? and : because they go together.

    (2) might not be possible (it works for other extended keys, and for the delete key) but regular keys are ignored due to the way the popover system works.

  • SimeonSimeon Admin Mod
    Posts: 5,364

    .@mpilgrem I've tested your Arc code (great shader, by the way). It doesn't seem to disappear for me — though I've been modifying the shader system quite a lot for the next release, and fixed some bugs. I will test it more thoroughly.

  • BUG More than one call of saveProjectTab only saves the last one.

    I also have a strange effect with raw gists. If I load code form a raw gist, it contains HTML special entities, e.g < is represented as &lt;. Loading the same URL with curl is fine, or is curl doing some interpretation behind the scenes for me?

    Example (loads aciolino's take on Cider Controls):


    function setup() url = "https://gist.github.com/raw/4127177/" url = url.."1f5a7859e5a315ff692fd7af8278eb66aeda1312/CiderControls%201.5.2" http.request(url, s, f) end function s(data, status) if s == 200 then print(data) else print("Error: "..status) end end function f(err) print(err) end function draw() end
  • Some kind of demo of the aforementioned bug. Some half-baked code that loads aciolino's DropBox gist which contains 3 files. Only Main is being saved. Also: HTML special entities effect.

    Usage: Save the script below, let's name it GistLoader. Create a new project, in this case DropBox. Codea cannot create new projects, it can only modify existing ones. Run GistLoader and provide "DropBox" as project name, hit "create".


    -- GistLoader -- Cider Controls 1.5.2 from aciolino local defaulturl = "https://gist.github.com/4127177" -- DropBox from aciolino, 3files local defaulturl = "https://gist.github.com/4091848" function removeCR(text) return string.gsub(text, "\r", "") end function extractRawLinks(text) print("Extracting raw links") local links = {} for pat in string.gfind(text, [[title="View Raw" href="(.-)"]]) do print(pat) -- get tab name local start, stop, tab = string.find(pat, ".*/(.*)") -- strip .lua extension if found at end of name if string.find(tab, ".lua$") then tab = string.sub(tab, 1, -5) end table.insert(links, {link=pat, tab=tab}) end if #links == 1 then links[1].tab = "Main" end for i, l in ipairs(links) do print("link= "..l.link.." tab= "..l.tab) end return links end reqResult = 0 reqData = nil function request(url) reqResult = 0 http.request(url, reqSuccess, reqFailure) end function reqSuccess(data, status) print("status = " .. status) if status == 200 then reqData = data reqResult = 1 else print("Communication error") reqResult = -1 end end function reqFailure(err) print("Network error") print(err) reqResult = -2 end state = "idle" function createFromGist() if state == "idle" then state = "makebasereq" else print("Not idle") end end function setup() parameter.text("url", defaulturl) parameter.text("projectName") parameter.action("create", createFromGist) end glinks = nil gcount = 0 function draw() if state == "idle" then -- tunix elseif state == "makebasereq" then request(url) state = "waitforbaseresponse" elseif state == "waitforbaseresponse" then if reqResult > 0 then glinks = extractRawLinks(reqData) gcount = 1 state = "requestpart" elseif reqResult < 0 then state = "error" else -- wait end elseif state == "requestpart" then local link = glinks[gcount].link link = string.gsub(link, " ", "%%20") print("Requesting " .. link) request("https://gist.github.com" .. link) state = "waitpart" elseif state == "waitpart" then if reqResult > 0 then local data = removeCR(reqData) local tab = glinks[gcount].tab saveProjectTab(projectName .. ":" .. tab, data) print("Updating " .. projectName .. ":" .. tab) gcount = gcount + 1 if gcount > #glinks then print("All done") state = "idle" else state = "requestpart" end elseif reqResult < 0 then state = "error" else -- wait end elseif state == "error" then print("An HTTP error occurred ... resetting") state = "idle" else print("ERROR: Unknown state ... resetting") state = "idle" end end
  • The editor is doing funny things when a file contains real tab characters for indentation. It seems that the caret thinks that a tab is wider than is actually rendered. This could be a problem in the future if scripts are not originally developed inside Codea.

  • SimeonSimeon Admin Mod
    Posts: 5,364

    .@Codeslinger it sounds like we'll need to do some clean up in saveProjectTab —

    I'll modify it to replace tabs with spaces. Are there any other special characters that might be an issue? Thanks for the examples.

    Unsure of the Gist issue, it could be either Apple's networking library escaping HTML automatically, or simply how the Gist returns (and curl doing the conversion). I could look at adding some utility functions: http.escapeHTMLString( string ) and http.unescapeHTMLString( string ).

  • Wouldn't it be better if the editor knew what a tab is? As I see it it's just an issue between the rendered width and the width that is assumed for cursor movement.

    I'll try to look deeper into the networking problem. If I fetch files from my computer then http.request works fine and doesn't escape anything.

  • SimeonSimeon Admin Mod
    Posts: 5,364

    .@Codeslinger at the moment it's not possible in the editor — it seems like a simple task, but the current editor works as a mix of UIKit and Core Text, which causes all sorts of idiosyncrasies in text layout. I'm working on a rewrite of the editor that is due out after 1.5, that should be much more capable. For the moment I will have it replace tabs to ensure the files are editable.

    Thank you for looking into the networking issue, if it's a matter of escaping (or unescaping) the results, then it should be a simple fix.

  • Posts: 2,161

    Would it be possible to shift the search key? I keep hitting it by accident and then having to wait while it indexes my code.

  • SimeonSimeon Admin Mod
    Posts: 5,364

    .@Andrew_Stacey How would you re-arrange the keys? I'm open to suggestions on this.

  • Posts: 2,161

    The problem that I have is that my typing is not 100% accurate and sometimes I hit the wrong key. If that's the search button then it takes a while before I get control back again. So I'd put it somewhere which minimises the chance of accidentally pressing it. Above the Q would be a reasonable place. If completely reorganising that row then I'd group the ones that add characters separately from the meta keys (like search and documentation).

  • SimeonSimeon Admin Mod
    Posts: 5,364

    I could swap search with the parentheses () button.

    I'd like to keep Tab as the leftmost button, but I don't mind switching parentheses and search if you feel that would help.

  • SimeonSimeon Admin Mod
    edited January 2013 Posts: 5,364

    Like this:

    image

  • Posts: 2,161

    That looks much better.

  • edited January 2013 Posts: 489

    Hello @Simeon, @John. It looks like Simeon's belief about the extension/repair of the indexing of the physics.body userdata to set the value of general keys in beta 1.5(14) is correct:

    --
    -- Body
    -- in Codea beta 1.5(14)
    --
    
    function setup()
        myBody = physics.body(CIRCLE, 10)
        print(type(myBody)) -- Output: userdata
        myBody.myCustomField = "Test"
        print(myBody.myCustomField) -- Output: Test
    end
    
    function draw() background(0) end
    

    (Update) However, that is not documented in the in-app reference. You might add something like "In addition, the values of other, user-defined, fields of a body can be set and returned using the same indexing syntax as is used for tables."

  • GitHub is a diva!

    Fetching a raw gist (see some posts above) with curl on the PC delivers exactly what's expected , I also added the --raw parameter to make this sure. (I also tried tcpdump until i realized that the connection is HTTP S.)

    I tried getting it with luasocket on the PC and get a 301 (moved permanently).

    I tried a raw file from a regular repository on GitHub from within Codea and it is not mangled. Only gists. Only from within Codea.

    I still don't understand ...

    Let's have some breakfast, I'll post my problem to the regular forum then to reach a larger audience and the problem itself doesn't depend on a 1.5 specific feature.

  • edited January 2013 Posts: 489

    The following code illustrates the difference between how a noSmooth line behaves and how I would have expected it to behave:

    --
    -- Line
    --
    
    function setup()
        parameter.integer("width", 1, 100, 10)
        noSmooth()
    end
    
    function draw()
        background(0)
        strokeWidth(width)
        stroke(255, 0, 0)
        line(100, 100, WIDTH - 100, HEIGHT - 300)
        stroke(0, 255, 0)
        myLine(100, 300, WIDTH - 100, HEIGHT - 100)
        fill(0)
        text("Codea's line() (noSmooth())", WIDTH / 2, HEIGHT / 2 - 100)
        text("myLine()", WIDTH / 2, HEIGHT / 2 + 100)
        fill(255)
        text("Codea's line() (noSmooth())", WIDTH / 2 + 1, HEIGHT / 2 - 99)
        text("myLine()", WIDTH / 2 + 1, HEIGHT / 2 + 101)
    end
    
    function myLine(x1, y1, x2, y2)
        local dx = x2 - x1
        local dy = y2 - y1
        local len = math.sqrt(dx * dx + dy * dy)
        local mx = x1 + dx / 2
        local my = y1 + dy / 2
        local w = strokeWidth()
        local a = math.atan2(dy, dx)
        local m = mesh()
        m:addRect(mx, my, len, w, a)
        m:setColors(stroke())
        m:draw()
    end
    
  • SimeonSimeon Admin Mod
    Posts: 5,364

    .@mpilgrem I've changed Codea to draw noSmooth() lines without the GL_LINE primitive.

    What was happening before was that Codea was only submitting two vertices to the GPU and telling it to render with GL_LINE. This was extremely cheap, but limited the max stroke width and resulted in cut-off ends (due to the simplistic way the GPU draws lines).

    I've modified it so that Codea's lines will be identical to your example (i.e. it uses a filled rect, basically).

  • Posts: 2,161

    Just tweeted a screenshot of a bug when taking an image from the rear camera on my iPad 4. Front camera is fine. Live camera is fine. Just when doing img = image(CAMERA)

  • SimeonSimeon Admin Mod
    Posts: 5,364

    Discussion continues here: http://twolivesleft.com/Codea/Talk/discussion/2132/codea-beta-15

    This thread closed.

This discussion has been closed.