Skip to content

Instantly share code, notes, and snippets.

@kamend
Created October 18, 2019 11:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamend/8db1ead7840d82c8f85265f9c60c3664 to your computer and use it in GitHub Desktop.
Save kamend/8db1ead7840d82c8f85265f9c60c3664 to your computer and use it in GitHub Desktop.
const Diagnostics = require('Diagnostics');
const Scene = require('Scene');
const Shaders = require('Shaders');
const Materials = require("Materials");
const R = require("Reactive");
const CameraInfo = require('CameraInfo');
const Textures = require('Textures');
const mat = Materials.get("material0");
const cameraTexture = Textures.get("cameraTexture0");
const cameraColor = cameraTexture.signal;
// get the texture coordinates in fragment stage
const texcoords = Shaders.fragmentStage(Shaders.vertexAttribute({'variableName': Shaders.VertexAttribute.TEX_COORDS}));
var color = R.pack4(1,0,0,1);
const pixelSizeX = R.div(1,CameraInfo.previewSize.width);
const pixelSizeY = R.div(1,CameraInfo.previewSize.height);
const isHalfStep = R.step(texcoords.y, 0.5);
const isHalf = R.mix(0,1,isHalfStep);
const newUV = R.pack2(
R.mul(R.mul(isHalf,texcoords.x),2),
R.mul(texcoords.y,2)
);
var sampled = greaterThenSignal(texcoords.y,0.5, R.pack4(1,0,0,1), R.pack4(0,1,0,1));
//var sampled = Shaders.textureSampler(cameraColor, newUV);
// set texture to sampled
const textureSlot = Shaders.DefaultMaterialTextures.DIFFUSE
mat.setTexture(sampled, {textureSlotName: textureSlot});
function greaterThenSignal(shadersignal, value, leftSignal, rightSignal) {
var step = R.step(shadersignal, value);
return R.mix(leftSignal, rightSignal, step);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment