This beta is starting to get closer to the release version.
The main new feature is the “Bindings” tab in the Shader Lab. This should make writing shaders much more interesting.
The bindings tab is like a spreadsheet of your uniform variables. You can assign arbitrary Codea expressions to each uniform (such as CAMERA, or ElapsedTime, or CurrentTouch, and so on). They don’t have to be simple, any Lua code will work as an expression.
The Shader Lab now includes a whole bunch of example shaders. I’m a bit unsure if I will be able to include certain shaders, because some were taken from places like Heroku, where the license is unclear. If you have any cool shaders to contribute, please send them to me and I will include them.
Issues carried over from the previous thread:
Here’s code that demonstrates the problem I’m having with taking photos. The problem only shows with the rear-camera and only when the picture is taken. It also only happens in portrait mode (I don’t know if it used to fail in landscape as well - I hadn’t tested it before β15).
-- Use this function to perform your initial setup
print("This example shows you how to use camera input")
-- Create a switch for our camera source
parameter.integer("CameraSource", 0, 1)
-- We'll start by setting the source to the front camera
-- Get the width and height
camWidth, camHeight = spriteSize( CAMERA )
-- Here we'll check our parameter and change sources accordingly
if CameraSource == 0 then
cameraSource( CAMERA_FRONT )
cameraSource( CAMERA_BACK )
camWidth, camHeight = spriteSize( CAMERA )
-- This function gets called once every frame
-- Configure our camera source
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
-- Draw the special CAMERA sprite
sprite( CAMERA, WIDTH/2, HEIGHT/2, math.min( camWidth, WIDTH ) )
if img then
if touch.state == ENDED then
img = image(CAMERA)
.@Andrew_Stacey thanks for the example, I’ve finally managed to fix this one (it was due to the rear camera returning padded data for portrait orientation).
.@John has also fixed the setContext() viewport clipping issue, as well as bool and float array support for shaders.
There are only a few remaining issues and we’ll be able to submit 1.5 for everyone.
.@Simeon What’s the status with the various
SetContext issues? Will we get a z-level? What about the fact that drawing on to images seems to clip against the current screen (so drawing on to a portrait image when in landscape mode and vice versa)?
.@Simeon Whoops - cross-posting! That’s great about the viewport clipping.
I’m unsure if we can respect the depth buffer in render-to-texture (i.e. setContext). It requires an OpenGL ES extension that appears to be available on most iPads, but I’m not sure how much work it will be to implement.
Beta 16 is going up.
Addresses setContext viewport bug and saving camera images from the rear camera in portrait orientations.
Hello @Simeon. Do you plan to repair the output select/copy in final version? This is useful to report error messages or anything else…
@Simeon Earlier you had proposed a “copy” button that would pick up the output contents and move them to the clipboard, since the new output doesn’t support copy/paste. Any chance of that sneaking in?
Hello @Simeon. The odd behaviour I was having with my ‘arc’ code still persists with beta 1.5(16). I am using iOS 6.1 on an iPad 2.
Pressing the ‘Replay’ button four or five times with the following code causes Codea to crash:
-- Print Bug ?
for k, v in pairs(_G) do
.@mpilgrem that’s an odd one, and hard to figure out. It only happens when my device is disconnected from the debugger, making it extremely hard to figure out what the crash is.
Has anyone tried the bindings feature? It would be great to get some feedback on it before release.
.@mpilgrem edit: I’ve looked into this and it appears that rapidly creating and assigning shaders to mesh objects can cause the modelViewProjection matrix not to be set correctly. You can fix this for now by modifying your arc code to set it manually:
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)
arc(WIDTH / 2, HEIGHT / 2, radius, startAngle, endAngle)
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.modelViewProjection = modelMatrix() * viewMatrix() * projectionMatrix()
m.shader.a1 = math.rad(a1)
m.shader.a2 = math.rad(a2)
Anyone else having trouble getting 16? Despite several hours of trying, cold restarts, and trying different networks, I’m still getting “this application can’t be downloaded right now.”
I installed yesterday, it was ok.
Hello @Simeon. Thank you for the patch on ‘Arc’.
I’ve tried the bindings feature, and it seems to work as you have explained.
I have one thought: it would be good to be able to copy of all the bindings into a ‘snippet’ of text that could then be pasted elsewhere (for example, on to the Forum). How about touching and holding on any of the Uniforms would bring up a pop up: ‘Copy all’? To use my ‘Arc’ shader as an example, this could then create a snippet:
float a1 = 0.0;
float size = 0.3;
mat4 modelViewProjection = modelMatrix() * viewMatrix() * projectionMatrix();
that could be pasted elsewhere?
(1) I appreciate that the Shader Lab will be beta in Codea 1.5, but is there any possibility of being able to ‘duplicate’ or ‘rename’ Shaders in Documents/Your Shaders?
(2) Given the icon for the ‘Basic’ pack of Shaders in the Lab, should the example shader ‘Ellipse’ be in the ‘Basic’ pack and not in the ‘Patterns’ pack?
(3) If the
mat4 modelViewProjection binding is not previously set, it would be good if the default binding first created was not
modelMatrix() * viewMatrix() * projectionMatrix()
.@mpilgrem thanks for your feedback. being able to copy all the bindings was exactly a feature I was thinking of — I had pushed it back until after 1.5, but given that you have brought it up independently I might be able to put it back in.
There used to be a button called “Shader Info” that was going to present sample code of how to use the shader with your saved bindings assigned to uniforms, and the option to copy the Lua code to pasteboard.
I think I might be able to fit that feature in, at least a duplicate function if not rename.
Yes I had the same thought, the problem is the ellipse code is complex and I wanted dead simple shaders under “Basic”. I just couldn’t think of an appropriate icon.
Good point, I will set its default value to that Codea expression.
.@Simeon a very important feature is the ability to set a shader from the lua program. Can the binding be set from the program like you’ve done for the vertext and fragment shaders?