# Scripting, shader integration idea (need input)

## Recommended Posts

n00body    345
-- Situation -- Cg for shaders, Squirrel for scripting, SqPlus for binding. -- Idea -- ____To use Squirrel's table data structure to store uniform names as keys, and their values in the slot corresponding to that key. Then the uniform names can be treated like members of a struct, so that setting the uniforms is conceptually simpler for the scripter. This would also allow adding new uniforms without messing with the C++ code at all. I could also overload the _set metamethod so that assigning them calls the uniform upload method, though I figure uploading them all at once would be more efficient. -- Example script --
// Squirrel code, using my bound math classes

params = {};

params.worldViewProj = Matrix4x4.RotateZXY(30, 40, 50);
params.upDirection = Vector3(0.0, 0.0, 1.0);
params.eyePosWorld = eyePosition;

setMaterialParams("SoldierClothing", params);


-- Concerns -- ____I'm not sure how well this technique will scale, and what kind of performance hit it will cause. I expect a fair hit from having to iterate over the table in my C++ code, checking the types of each slot in the table, to determine correct uniform upload method. Then having to get the actual data from the Squirrel VM. -- Questions -- ____Can you guys offer your thoughts on this system? What kinds of pitfalls might I encounter? Any suggestions from your personal experience working with Squirrel, or scripting in general? Thanks. [Edited by - n00body on August 16, 2008 12:49:04 AM]