This beta is starting to get closer to the release version.
####Bindings
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:
Saving camera image bug when in landscape mode (as reported by @Bortels and @Andrew_Stacey)
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).
-- Camera
-- Use this function to perform your initial setup
function 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
cameraSource(CAMERA_FRONT)
-- Get the width and height
camWidth, camHeight = spriteSize( CAMERA )
end
function checkCameraSource()
-- Here we'll check our parameter and change sources accordingly
if CameraSource == 0 then
cameraSource( CAMERA_FRONT )
else
cameraSource( CAMERA_BACK )
end
camWidth, camHeight = spriteSize( CAMERA )
end
-- This function gets called once every frame
function draw()
-- Configure our camera source
checkCameraSource()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Draw the special CAMERA sprite
sprite( CAMERA, WIDTH/2, HEIGHT/2, math.min( camWidth, WIDTH ) )
if img then
sprite(img,100,100,200)
end
end
function touched(touch)
if touch.state == ENDED then
img = image(CAMERA)
end
end
.@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)?
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.
@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?
.@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.
.@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:
--
-- 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.modelViewProjection = modelMatrix() * viewMatrix() * projectionMatrix()
m.shader.a1 = math.rad(a1)
m.shader.a2 = math.rad(a2)
m:draw()
end
```
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’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:
(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 matrix() but 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?