Skip to content

Instantly share code, notes, and snippets.

@thelucre
thelucre / SimpleToon.shader
Created February 24, 2020 20:11
[UNITY] Flat Color/Texture Shader with Shadows
// Based heavily on https://roystan.net/articles/toon-shader.html
Shader "Custom/Simple Toon"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Main Texture", 2D) = "white" {}
// Ambient light is applied uniformly to all surfaces on the object.
[HDR]
@thelucre
thelucre / HighBrowCounter.js
Created March 14, 2019 17:11
Count the number of eyebrow raises in Snapchat Lens Studio
// -----JS CODE-----
var highBrowCount = 0;
/**
* BrowsRaisedEvent, triggered when the user's brows change to raised.
* LensStudio does all of this detection for us, we just listen for the event.
* @param {BrowsRaisedEvent} ev
*/
// Callback for the BrowsRaisedEvent
@thelucre
thelucre / EventBindingExample.js
Created March 14, 2019 17:03
Binding to Scene events in Snapchat Lens Studio
// -----JS CODE-----
/**
* UpdateEvent, fires every frame
* @param {UpdateEvent} ev
*/
// Callback for the UpdateEvent
function onUpdate(ev) {
print(getDeltaTime());
}
@thelucre
thelucre / AutoRotate.js
Created March 9, 2019 00:19
AutoRotate script for Snapchat Lens Studio
// -----JS CODE-----
//@input vec3 Rotation
//@input float Speed
// Equivalent to GameObject
var object = script.getSceneObject();
// Just like Unity Transform!
var transform = script.getTransform();
@thelucre
thelucre / VisibleToggle.js
Created March 8, 2019 17:53
Touch Interaction test for Snapchat Lens Studio
// -----JS CODE-----
// Code runs runs during the `Initialized` event
// Properties set out of function scope are per-instance values
var isVisible = true;
var so = script.getSceneObject();
var mesh = so.getComponentByIndex("MeshVisual", 0);
var mat = mesh.getMaterial(0).clone();
@thelucre
thelucre / TextureTransition.shader
Created February 7, 2019 17:58
Unity Transparent Noise Transition Shader
Shader "Custom/TextureTransition" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_EdgeColor ("Edge Color", Color) = (1,1,1,1)
_Blend ("Blend Value", Range(0,1)) = 0
_EdgeSize ("Edge Size", Range(0,1)) = 0.05
_Noise ("Noise Texture", 2D) = "white"
}
@thelucre
thelucre / accelerometer-normalization.js
Last active December 28, 2018 20:45
deviceorientation normalization notes
// check for window.orientation || window.screen.orientation.angle
let h;
switch (window.screen.orientation.angle) {
case 0:
h = "portrait";
break;
case 180:
h = "portrait-upside-down";
break;
case -90:
// Virtual occlusion, hide objects behind, without being visible to the user
// Useful with AR Utils: https://github.com/jonas-johansson/ARCoreUtils
// Shader src: https://forum.unity.com/threads/clipping-objects-behind-a-higher-plane.492147/#post-3205094
Shader "Custom/ARStencilOcclusion" {
SubShader {
Tags { "Queue" = "Background-1" }
Pass {
using System;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
public class AutoMoveAndRotate : MonoBehaviour
{
public Vector3andSpace moveUnitsPerSecond;
public Vector3andSpace rotateDegreesPerSecond;
public bool ignoreTimescale;
@thelucre
thelucre / OutlineShader.shader
Created September 25, 2018 22:08 — forked from michidk/OutlineShader.shader
An outline shader made for Unity with the help of @OverlandGame. It adjusts the size of the outline to automatically accomodate screen width and camera distance.
// An outline shader made for Unity with the help of @OverlandGame by @miichidk
// It adjusts the size of the outline to automatically accomodate screen width and camera distance.
// See how it looks here: https://twitter.com/OverlandGame/status/791035637583388672
// How to use: Create a material which uses this shader, and apply this material to any meshrenderer as second material.
Shader "OutlineShader"
{
Properties
{
_Width ("Width", Float ) = 1
_Color ("Color", Color) = (1,1,1,1)