Created
August 4, 2019 15:13
-
-
Save lassemt/b4728584ec95c721cdc314c23fe024b2 to your computer and use it in GitHub Desktop.
SparkAR greyscale black and white shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const D = require('Diagnostics'); | |
const Scene = require('Scene'); | |
const Time = require('Time'); | |
const R = require('Reactive'); | |
const S = require('Shaders'); | |
const Mat = require('Materials'); | |
const Tex = require('Textures'); | |
const Patches = require('Patches'); | |
// | |
// Get materials | |
// | |
const matBackground = Mat.get('background'); | |
// | |
// Get textures | |
// | |
const texSigCamera = Tex.get('camera').signal; | |
// | |
// Get scene objects | |
// | |
const objBackground = Scene.root.find('background'); | |
// | |
// Define constants | |
// | |
// const screenScale = Patches.getScalarValue('screenScale'); | |
// const screenSize = R.pack2(Patches.getPoint2DValue('screenSize').x, Patches.getPoint2DValue('screenSize').y); | |
// const screenSizeScaled = R.div(screenSize, screenScale); | |
const uv = S.vertexAttribute({'variableName': S.VertexAttribute.TEX_COORDS}); | |
// | |
// Varies | |
// | |
// let FRAME = Time.ms.div(1000); | |
// | |
// B&W shader | |
// | |
function make_bw(tex, texcoord) { | |
const color = S.textureSampler(tex, texcoord); | |
const gray = R.dot(R.pack3(color.x, color.y, color.z), R.pack3(0.299, 0.587, 0.114)); | |
return R.pack4(gray, gray, gray, color.w); | |
} | |
let texBW = make_bw(texSigCamera, uv); | |
matBackground.setTexture(texBW, {textureSlotName: 'diffuseTexture'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment