Hey everyone, sorry I haven’t posted in a while, I’ve been having a lot of troubles getting my iPad to charge, and it might be a while until I can use Codea again (unless it comes out for Mac OS X ). Anyway, in the spirit of holiday things, I made a new demo of 3D snow, this time using OpenGL’s instancing to increase quality and performance. It generates a single mesh of randomly positioned and rotated triangles covering a wide and short area, and draws it a bunch of times using instancing to create a ton of snow without much of a hit to performance. It runs at 60 FPS on an iPad Air, rendering 90,000 vertices (I think I could get it to 120K or 150K but it went a little below 60 FPS), which is pretty good.
Also, if you turn up the “stretch” parameter, toggle the “night” parameter, and increase the “timeSpeed” parameter, it looks like you’re traveling at warp speed.
@Jmv38 Sorry, I forgot to include a function in another library - add this to the end of the Utility tab:
-- Function tweak to make shaders easier, so I can call shader("X") instead of shader(Shaders.X.vS, Shaders.X.fS)
local _shader = shader
function shader(...)
if select("#", ...) == 1 then
local data = Shaders[select(1, ...)]
if data ~= nil then
return _shader(data.vS, data.fS)
else
return _shader(...)
end
else
return _shader(...)
end
end
@Jmv38 I didn’t think it was bad for FPS. I can’t really remember why, but I just got into the habit of putting three collectgarbage() calls in a row at the end of the draw function, to prevent memory leaks slowing things down. Try removing them and see if you can increase the number of triangles per mesh without affecting the FPS.
@Ignatz I think it has something to do with the maximum number of instances at a time, it seemed to be around 400. Try increasing the number of triangles per mesh and see if you can push it further, like here:
...local vspread = 5
for i = 1, **200** do
local rel...
Really nice and very beautiful. The matrix transforms in the draw loop seem a little heavy though. I wonder whether it might be possible to pre-calculate some paths for the instances and store them in a look-up table?