Skip to content

Instantly share code, notes, and snippets.

@DanMillerDev
DanMillerDev / BlendShapeObjectSwitcher.cs
Last active April 15, 2020 20:10
Unity ARKit Blend shape object activator
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.iOS;
public class BlendShapeObjectSwitcher : MonoBehaviour {
private static float THRESHOLD = 0.4f;
bool enabled = false;
@DanMillerDev
DanMillerDev / ExampleClass
Created March 9, 2018 03:51
load texture from web on android
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public string url = "https://docs.unity3d.com/uploads/Main/ShadowIntro.png";
IEnumerator Start()
{
Texture2D tex;
@DanMillerDev
DanMillerDev / LightEstimation.cs
Created July 31, 2018 18:03
Light Estimation for ARFoundation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.XR;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
[RequireComponent(typeof(Light))]
public class LightEstimation : MonoBehaviour
{
// Shader targeted for low end devices. Single Pass Forward Rendering.
Shader "Custom/Shadows Only"
{
// Keep properties of StandardSpecular shader for upgrade reasons.
Properties
{
_Alpha("Shadow Alpha", float) = 0.5
// Blending state
#ifndef LIGHTWEIGHT_SIMPLE_LIT_PASS_INCLUDED
#define LIGHTWEIGHT_SIMPLE_LIT_PASS_INCLUDED
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Shadows.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
@DanMillerDev
DanMillerDev / MobileARShadow.shader
Created July 30, 2019 05:48
Shadows on transparent geometry shader for Unity
//This is based on a shader from https://alastaira.wordpress.com/2014/12/30/adding-shadows-to-a-unity-vertexfragment-shader-in-7-easy-steps/
Shader "Custom/MobileARShadow"
{
SubShader {
Pass {
// 1.) This will be the base forward rendering pass in which ambient, vertex, and
// main directional light will be applied. Additional lights will need additional passes
// using the "ForwardAdd" lightmode.
@DanMillerDev
DanMillerDev / MobileOcclusion.shader
Created July 30, 2019 05:52
Occlusion shader for Unity. Can be used for mobile AR Occlusion
Shader "Custom/MobileOcclusion"
{
SubShader {
Pass {
// Render the Occlusion shader before all
// opaque geometry to prime the depth buffer.
Tags { "Queue"="Geometry" }
ZWrite On
ZTest LEqual
@DanMillerDev
DanMillerDev / FeatheredPlaneShader.shader
Created March 19, 2020 14:50
shader for feathering the edges of planes in AR Foundation
Shader "Unlit/FeatheredPlaneShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_TexTintColor("Texture Tint Color", Color) = (1,1,1,1)
_PlaneColor("Plane Color", Color) = (1,1,1,1)
}
SubShader
{
@DanMillerDev
DanMillerDev / build_multiplatform_xr.sh
Created March 12, 2025 18:30
Shell script for building a Meta Quest, AndroidXR and visionOS build in Unity via CLI batchmode
#!/bin/bash
# Set common variables for your Unity project, Replace these with your editor and project path
UNITY_PATH="/Applications/Unity/Hub/Editor/6000.1.0b8/Unity.app/Contents/MacOS/Unity"
PROJECT_PATH="/Users/dan/Documents/UnityRepos/Crossplatform_MR_GDC2025"
BUILD_OUTPUT_DIR="/Users/dan/Documents/UnityRepos/Crossplatform_MR_GDC2025/Builds"
BUILD_PROFILE_QUEST="Assets/Settings/Build Profiles/MetaQuest.asset"
BUILD_PROFILE_ANDROIDXR="Assets/Settings/Build Profiles/AndroidXR.asset"
BUILD_PROFILE_VISIONOS="Assets/Settings/Build Profiles/visionOS.asset"
@DanMillerDev
DanMillerDev / XRPermissions.cs
Created March 14, 2025 21:20
A script for managing permissions across Apple Vision Pro, Meta Quest and Android XR. It references world space UI element to let the user know about missing or denied permissions.
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using System.Collections.Generic;
using TMPro;
using UnityEngine.Android;
#if UNITY_VISIONOS
using UnityEngine.XR.VisionOS;
#endif
public class XRPermissions : MonoBehaviour