Codea (Beta 15 & 16)

You have to set them yourself, when you use the shader. The Shader Lab sets the bindings every frame for all uniforms, but that would be slow and potentially unnecessary for most use cases. Like @mpilgrem mentioned, I will offer a way for you to copy the ‘sample’ binding code out of the Shader Lab.

In the Bindings editor, I have quickly found myself missing the ability to place the location of the cursor precisely.

.@mpilgrem I will be bringing the extended keyboard and autocomplete to the bindings editor, but not until 1.5.x. I miss it too.

Hi. In the recent releases you dont move to the search result when pressing on a result. Shouldnt it move to the result?

I recently used the old Codea, what a difference! The help is so much better now. :slight_smile:

.@tnlogy yes, it should. That’s a bug I’ve had on my list for a while.

Glad to hear the help is much better.

Hi,

jumping in late to test the Beta, had some other things going on… current version really looks cool :slight_smile:

I have tried an early beta and wanted to do a lighting shader, as thats most important for my project, but as I remember, there were no normals in the mesh. Now I can see them in the documentation, so I think they have been added meanwhile (or I have overlooked them before).

Now my question is: Did anybody else already create a lighting shader? I searched the forum, but only found a post that somebody wanted to try. Otherwise I will try…

I think there should be everything thats needed for it: The projection and modelview matrices and the vertex normals. The light position can be passed into the shader then. I’d like to replace my lua calculated lighting demo posted some time ago with a shader.

Kilam.

.@KilamMalik It might be a bit basic for you, but my toroidal Game of Life shader had a lighting component.

.@KilamMalik i think the mesh.normal is just a predefined name for mesh attributes, but it is not computed by codea: you have to compute and assign the normals yourself. So there is not much new there.

Yes, you have to compute normals yourself. We could probably compute flat-facing normals per-triangle, though you’d probably want to overwrite them with smooth normals.

Here is an example reading an Obj file and using a light shader. You have to point out a texture, could not figure out any way in Codea to get data from an image to create a string. Are there any functionality for that, so that I can use image.data?

https://gist.github.com/4690383

edit:@tnlogy bet me to it heh :stuck_out_tongue: I’ll leave my example, since i don’t play with the buffer functionality.

@KilamMalik - It don’t think anyone has posted a simple one

In my example, you will notice the normals are handled properly by the mesh class, and properly used as vec3 attribute by the shader.

I believe there was a plan in Codea to implement them, that’s why they’re handled properly ?

local data = mesh()
data.vertices = verts
data.colors = colors
 -- you need to compute the normals, I use my blender to image exporter
data.normals = normals
    
data.shader = shader("Documents:celShading")
data.shader.light = vec3(1,-1,1):normalize()
// Vertex shader
uniform mat4 modelViewProjection;
uniform lowp vec3 light;

attribute vec4 position;
attribute vec4 color;
attribute vec3 normal;

varying lowp vec4 vColor;
varying lowp float shade;
void main()
{
    vColor = normalize(modelViewProjection * vec4(normal,0));
    shade = dot(vColor.xyz, light);
    vColor = color;

    gl_Position = (modelViewProjection * position);
}
//fragment
varying lowp vec4 vColor;
varying lowp float shade;

void main()
{
    if (shade<.2)
        gl_FragColor = vec4(vColor.xyz * .3, 1.0);
    else
    if (shade<.4)
        gl_FragColor = vec4(vColor.xyz * .7, 1.0);
    else
        gl_FragColor = vColor;
}

Cheers

An irritating bug that I see from time to time is when press play one of the tabs turn red, but there is no indication where the error is. In earlier releases you could see the error in the panel, since it switched view. I suppose you are supposed to see the error message in the tab, but it only works sometimes.

A future feature I would like is if say, the first 4 items in projects are the most recently used projects. :slight_smile:

.@tnlogy if the tab highlights red then that indicates a syntax error usually — so the code shouldn’t be able to run. Are you able to reproduce coding errors that can trigger a tab to highlight red with no error message?

Sometimes I get error messages but have to manually scroll to the line. Not nice when there are several hundred lines in the editor.

Here’s a reproduction of a truly missing message that seems to work always for me:

  • Go to Physics Lab example
  • In Main, add a single curly brace } in the first empty line
  • Switch to PhysicsDebugDraw tab
  • Hit run, the Main tab turns red but no message can be found
  • In Main, hit run again, message appears

Premature analysis:

  • When in different tab, message gets lost
  • When in same tab, message appears but no auto-scroll to that line

Thank you @Codeslinger. I’ve changed this behaviour so that error messages no longer disappear when switching into a tab with errors, and the editor will automatically scroll to the first error in a tab that contains errors when opening it.

.@tnlogy I sometimes get the red tab with no erro message. I 've figured out that 95% of times it is after modying an if.. then...else ... end statement and forgetting the end keyword. Then the compiler goes all the way to the end of the tab, which makes sense, and there it does not find the expected end keyword. So it knows the problem, but the error can be anywhere in the code. It does not make sense to show the last line in error, because the error is not there. So next time you get the red tab, check the last if.then.else.end you’ve modified.

.@Simeon Hi would it be possible to include to version 1.5 the ability to load images of any size? Like 5000x4000 for instance, even on ipad1? If you cannot display them because too big for shader and texture limits, it is ok because i just want to display a subpart of this image. The problem is not breaking the image into pieces once it is in codea, it is to open the jpeg file. Because i cannot access to the jpeg raw data with codea, i cannot write my own decoder. So can you do something for that? I am open to any compromize solution too, as long as i can read the big original jpeg or png image directly into codea…

@Simeon - regarding bindings, it seems that shaders from previous versions show the wrong Codea Expression for the mat4 modelViewProjection (new shaders work fine).

New shaders show “modelMatrix() * viewMatrix() * projectionMatrix()” while old shaders only show “matrix()”.

I suppose it’s not really a problem if you think about it, but just letting you know in case there is an underlying issue.

.@Jmv38 a 5000x4000 would take up 76 MB of memory when loaded, an iPad 1 has 256 MB RAM. Once you account for the OS and apps, it usually has less than 100 MB free. I think loading such a large image on iPad 1 into system memory would cause the application to quit due to low memory.

There are ways to load such images that use a tile-based renderer or loader, but that would take us a long time to implement, and certainly wouldn’t be possible to include in 1.5 without significantly delaying it.

.@Xavier thank you for the report. Shaders from previous versions never had bindings, so Codea simply generates a default value for a mat4 type, which is matrix(). This issue only effects beta users with old shaders — it won’t be an issue in the release version.

@Simeon that’s what I figured :stuck_out_tongue: