Skip to content

Instantly share code, notes, and snippets.

View michael-sacco's full-sized avatar

Michael Sacco michael-sacco

View GitHub Profile
@michael-sacco
michael-sacco / FPSCounter.cs
Created December 10, 2021 07:23
Simple Frame Time Calculator for Unity. Works with TextMeshPro. Sends to DebugLog if TMPro is unavailable.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace OccaSoftware
{
public class FPSCounter : MonoBehaviour
{
float deltaTime;
@michael-sacco
michael-sacco / VideoPlayerManager
Last active December 10, 2021 08:07
Video playlists from URL. Automatically loops.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
namespace OccaSoftware
{
[RequireComponent(typeof(VideoPlayer))]
public class VideoPlayerManager : MonoBehaviour
{
@michael-sacco
michael-sacco / GetCameraMotionVectors.hlsl
Last active June 17, 2025 21:57
Unity Get Camera Motion Vectors in Custom Pass for Universal Render Pipeline (URP)
#ifndef GETCAMERAMOTIONVECTORS_INCLUDE
#define GETCAMERAMOTIONVECTORS_INCLUDE
#if defined(USING_STEREO_MATRICES)
float4x4 _PrevViewProjMStereo[2];
#define _PrevViewProjM _PrevViewProjMStereo[unity_StereoEyeIndex]
#define _ViewProjM unity_MatrixVP
#else
float4x4 _ViewProjM;
float4x4 _PrevViewProjM;
@michael-sacco
michael-sacco / SubpixelAA.hlsl
Last active October 12, 2022 23:57
A copy of the Subpixel AA method from the Visual Effect Graph shader.
// This method is called from the Vertex stage of Unity's Visual Effect Graph shader.
// This function scales the size of the VFX Particle such that it occupies at least one pixel on screen.
// It also modifies the alpha such that the alpha is inversely faded according to the change in size.
void SubpixelAA(float3 position, inout float alpha, float size, inout float scaleX, inout float scaleY)
{
float2 localSize = size * float2(scaleX, scaleY);
float clipPosW = TransformPositionVFXToClip(position).w;
float minSize = clipPosW / (0.5f * min(abs(UNITY_MATRIX_P[0][0]) * _ScreenParams.x, abs(UNITY_MATRIX_P[1][1]) * _ScreenParams.y)); // max size in one pixel
float2 clampedSize = max(localSize,minSize);
float fade = (localSize.x * localSize.y) / (clampedSize.x * clampedSize.y);
@michael-sacco
michael-sacco / HaltonSequencer.cs
Created October 27, 2022 16:37
A demonstration of Halton Sequencing Quasirandom Noise
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Note that the Halton bases must consist of coprime integers.
// Learn more about the Halton sequence: https://en.wikipedia.org/wiki/Halton_sequence
// Learn more about low discrepancy sequences: https://en.wikipedia.org/wiki/Low-discrepancy_sequence
// Learn more about coprime numbers: https://en.wikipedia.org/wiki/Coprime_integers
@michael-sacco
michael-sacco / DemoAltosAPI.cs
Created June 12, 2023 14:19
Demo of Altos API
// See manual: https://www.occasoftware.com/manual/altos
using UnityEngine;
using OccaSoftware.Altos.Runtime;
[ExecuteAlways]
public class DemoAltosAPI : MonoBehaviour
{
[SerializeField]
private SkyDefinition skyDefinition;