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.
viewer.mode=FULLSCREEN
function setup()
cnt=0
fill(255)
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(158, 202, 223, 255)
skyMaterial.horizon=color(98, 166, 114, 255)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 450, 0, 1000)
end
function draw()
update(DeltaTime)
scene:draw()
if explode then
cnt=80
explode=false
createSphere(vec3(0,0,0))
end
if cnt>0 then
cnt=cnt-1
if cnt<1 then
pt:destroy()
end
end
text("tap screen for explosion",WIDTH/2,HEIGHT-100)
end
function update(dt)
scene:update(dt)
end
function createSphere(p)
if pt then
pt:destroy()
end
pt=scene:entity()
pt.position=vec3(p.x,p.y,p.z)
pt.model=craft.model.icosphere(1,2)
pt.material=craft.material(asset.documents.Dropbox.Explosion)
end
function touched(t)
if t.state==BEGAN then
explode=true
end
end
@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)
@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.
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.
@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.
@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 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.