hey, i’m still trying out different things with mesh and performance testing
basically trying to test the performance difference between setting shader uniform values directly and using custom buffer attributes instead, if anyone knows of using buffers is faster or not that would save some time
i ran into a problem when trying to use buffers, and i’m surprised it’s even working because i’m not sure this of the intent of buffers to be used this way
but as you can see in the screen shots the full effect is the normal Ripple shader and the broken half image is my attributes ripple shader
function setup()
m = mesh()
m:addRect(WIDTH/2,HEIGHT/2,600,600)
m.texture = asset.documents.Assets.Demo.Frames.maxSize — your image here
m.shader = shader(asset.documents.ripple) --shader (vert, frag)
end
function draw()
background(40, 40, 50)
a = m:buffer("time")
b = m:buffer("freq")
a:resize(1)
b:resize(1)
a[1] = ElapsedTime
b[1] = 1
m:draw()
end
//
// Ripple vertex shader
//
//This is the current model * view * projection matrix
// Codea sets it automatically
uniform mat4 modelViewProjection;
//This is the current mesh vertex position, color and tex coord
// Set automatically
attribute vec4 position;
attribute vec4 color;
attribute vec2 texCoord;
attribute float time;
attribute float freq;
//This is an output variable that will be passed to the fragment shader
varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
varying lowp float vTime;
varying lowp float vFreq;
void main()
{
gl_Position = modelViewProjection * position;
//Pass values to our fragment shader
vColor.rgb = color.rgb * color.a;
vColor.a = color.a;
vTexCoord = texCoord;
vTime = time;
vFreq = freq;
}
//
// Ripple fragment shader
//
//This represents the current texture on the mesh
uniform lowp sampler2D texture;
//The interpolated vertex color for this fragment
varying lowp vec4 vColor;
//The interpolated texture coordinate for this fragment
varying highp vec2 vTexCoord;
varying lowp float vTime;
varying lowp float vFreq;
void main()
{
highp vec2 tc = vTexCoord.xy;
highp vec2 p = -1.0 + 2.0 * tc;
highp float len = length(p);
highp vec2 uv = tc + (p/len)*vFreq*cos(len*24.0-vTime*4.0)*0.03;
highp vec4 col = texture2D(texture,uv);
gl_FragColor = vec4(col.rgb * vColor.rgb, col.a);
}
also, when i coded this in the Shader Lab, it shows as a Red Error for the Frag tab but there is no highlight error in the tab itself.
the bindings are empty which I think is expected, BUT, IF this is a bug and I’m using buffers correctly AND buffers are faster than setting shader.uniform directly, then it would be great to have custom attributes appear in bindings