Skip to content

Instantly share code, notes, and snippets.

@yearofthewhopper
Last active March 3, 2020 10:01
Show Gist options
  • Save yearofthewhopper/3b788660ee0b9348b1ba81559212050a to your computer and use it in GitHub Desktop.
Save yearofthewhopper/3b788660ee0b9348b1ba81559212050a to your computer and use it in GitHub Desktop.
const Textures = require('Textures')
const Shaders = require('Shaders')
const R = require('Reactive')
const console = require('Diagnostics')
// get face material
const faceCameraMaterial = Materials.get('face0')
// get camera shader signal
const cameraColor = Textures.subTexture.get('Camera')
// get texture coords
const texc = Shaders.vertexAttribute({ variableName: Shaders.VertexAttribute.TEX_COORDS })
// const
// get per-fragment uv
const uv = Shaders.fragmentStage(texc)
// fx parameters
const cell = 0.05
const strength = 2
// new uv
const newUV = uv
.mod(cell)
.mul(strength)
.add(
R.val(cell)
.mul(
R.sign(strength).mul(R.val(-1))
)
)
// sampling texture color
const finalColor = Shaders.textureSampler(cameraColor, texc.add(newUV))
// Assign the shader signal to the texture slot
faceCameraMaterial.setTexture(finalColor, { textureSlotName: Shaders.DefaultMaterialTextures.DIFFUSE })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment