m.texture = image_a should simply tell the mesh where in GPU memory to find image_a. If image_a is not in GPU memory, it is loaded and cached (usually the first time you do the assignment). It should be faster than a conditional on every pixel.
With the new sampler2D picker it should be easier to demonstrate slightly more advanced shaders — such as masking and blending between images.
I am curious, do your fractal shaders render in the Shader Lab? Or are there issues that prevent this? They are really cool and would be a great asset to include, if it’s something you would like to do.
Currently the Shader Lab uses a simple Codea project to render your shader preview. I’ve placed the code for the Shader Lab “project” below.
What I’d really love to do (unsure if there is time) is to add a few more of these projects — one with a 3D sphere, one with a 3D cube, and modify the existing “plane” one to subdivide the plane so that vertex shaders have more interesting data to work on. I’d also really like to allow interaction, such as drag to rotate the scene, and pinch to zoom.
The idea was that you would be able to select from these built-in scenes by using the settings button in the upper right of the preview window (this button is hidden in build 13).
The way it works is: the Shader Lab calls the special
updateShaderSample function, which uses the special shader key
#:SHADERLAB_CURRENT_SHADER (only valid while the Shader Lab is running) to return the currently edited shader. Then, whenever any uniforms are modified with the interactive popups, the Shader Lab calls
updateShaderUniform with the uniform name, and new data.
-- Use this function to perform your initial setup
m = mesh()
key = "Cargo Bot:Codea Icon"
tw,th = spriteSize(key)
m.texture = key
rectIndex = m:addRect(0,0,tw,th)
m.shader = shader("#:SHADERLAB_CURRENT_SHADER")
function updateShaderUniform(uniformName, data)
if uniformName == "texture" then
m.texture = data
tw,th = spriteSize(data)
m.shader[uniformName] = data
-- This function gets called once every frame
-- This sets a dark background color
background(24, 24, 32, 255)
-- This sets the line thickness
-- Do your drawing here