How to use shaders from Shade

What’s the correct way to use a shader created in Shade in Codea. I copied the explosion shader from Shade into the Codea Dropbox folder. When I tap the screen, I start the explosion shader and stop it after a little over a second. Each time I start it, it seems to start at a different point in the explosion sequence. Also, it doesn’t seem to look like it does in the Shader example explosion. I don’t normally use Shade, so I’m not sure exactly how it’s supposed to be setup and used.


function setup()
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")        
    scene = craft.scene(), 202, 223, 255)
    skyMaterial.horizon=color(98, 166, 114, 255), vec3(0,0,0), 450, 0, 1000)

function draw()
    if explode then
    if cnt>0 then
        if cnt<1 then
    text("tap screen for explosion",WIDTH/2,HEIGHT-100)

function update(dt)

function createSphere(p)
    if pt then

function touched(t)
    if t.state==BEGAN then

@dave1707 +1

@dave1707 , i have a vague memory that you have to feed in the elapsedTime to the shader via a .time=elapsedTime.

@piinthesky This is a shader from Shade. I haven’t used Shade that much so I don’t know if there’s a way or how to pass anything to it. I’ve noticed even running the explosion in Shade multiple times, it doesn’t start at what you would consider the beginning. The first node in the shader is Time. The description for Time says it starts when the shader is loaded. So you would think that each time you start the shader it would start at 0.

PS. I just figured out how to pass a value to a shader.

@dave1707 when you build a shader in Shade you can expose properties

For example, if you open the “Checkers” sample shader and tap on the “Properties” button in the main side panel area, you should see “Color A”, “Color B” and “Size”

These will be available as parameters on your exported shader inside Codea

To make something a property, when you select the appropriate node (some sort of value output node, like a texture, number, color, and so on) you can select whether it is a “property” or a “constant”. If you select “property” you can give it a custom name and it will be exposed as a parameter in the exported shader

For the “Explosion” shader I believe the time nodes are automatically exported as “time” on the shader. But you could replace the time node with a number node and give it an explicit name (this will stop the shader from animating in Shade, but assigning an animated value to that parameter in Codea will cause the shader to animate)

@Simeon Thanks for the info. I’m starting to play more with Shade to see how it can be used with Codea.

@dave1707 I’d love to see any progress you make.

@dave1707 have you progressed on this? If you wanted to share an updated version of the code you started this discussion with, that would be very helpful. It’s always nice when a thread contains a working demonstration of the issue brought up in the title.

In case anyone wants a version of @dave1707 ’s origin code with a nice little icon, I’ve attached one.

I make these for myself because I have jillions of projects, both mine and other people’s, and it helps immensely to have icons on them so I don’t forget what they are.

I scaled the explosion up a bit too because I wanted to see it better.

@UberGoober, pt.material=craft.material(asset.documents.Explosion) Does not exist

@krdavis ooops. Should be fixed now.


One problem with the explosion shader is that it doesn’t always start at the beginning. It’s based on time so depending on when you start it, you’ll be at different points in time so it could be near the end of its cycle.

@dave1707 I know, that’s why I asked if you’d made any progress on this one :wink:

@Simeon I was playing with Shade and trying to pass a color to the Properties of a simple shader I made. In the Properties panel, the name was Color (upper case C). In my Codea project I tried using the name Color but it wouldn’t work. Just for kicks I changed the name in Codea to color (lower case c) and it worked. So is the Properties name between Codea and the shader not case sensitive or something.

I tried the Checkers shader with a Properties name Size. Codea didn’t work with Size but it did work with size.

@dave1707 - color is a reserved word in Codea does that mean you were effectively passing a vec4() to the shader?

@Bri_G I don’t think that was the problem because the same thing happened with Checkers. The name in the shader was Size, but the name that worked in Codea was size. So apparently even though the name is uppercase in Shade, the name should be lower case in Codea.

@UberGoober Heres an updated version of an explosion. It always starts when you tap the screen. It’s not perfect, but I’m still playing with Shade.

PS. zip file removed. See farther down.

@dave1707 that is super cool!

Any idea why the previous version had a bumpy exterior but this one seems to be totally spherical?

@UberGoober I saw that and I’m not sure why. Like I said, I just started to play around with shaders from Shade used in Codea. I’ll have to figure out what’s up since I started with the same shader in both versions.