Skip to content

Instantly share code, notes, and snippets.

@SableRaf
Created November 23, 2020 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SableRaf/a201508a07befa19205732581342ebbe to your computer and use it in GitHub Desktop.
Save SableRaf/a201508a07befa19205732581342ebbe to your computer and use it in GitHub Desktop.
Sohail Mehra – Spark AR Scripting - Ep 1 - Basics (updated for Spark AR Studio v102)
const Materials = require('Materials');
const Textures = require('Textures');
const Shaders = require('Shaders');
const Time = require('Time');
const Reactive = require('Reactive');
// const Diagnostics = require("Diagnostics");
// const {log} = require('Diagnostics');
async function main()
{
const myMaterial = await Materials.findFirst('material0');
const myCameraTexture = await (await Textures.findFirst('cameraTexture0')).signal;
let uvs = await Shaders.vertexAttribute({variableName: Shaders.VertexAttribute.TEX_COORDS}); // {variableName: ‘TEX_COORDS’} would work too
let ct = Reactive.mul(Time.ms,0.001);
let curve = Reactive.abs(Reactive.sin(ct));
let color = await Shaders.textureSampler(myCameraTexture, uvs);
let modulationColor = Reactive.pack4(curve,0,0,1);
let finalColor = Reactive.mul(color, modulationColor);
myMaterial.setTextureSlot('DIFFUSE', finalColor);
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment