Skip to content

Instantly share code, notes, and snippets.

View maluoi's full-sized avatar
:shipit:
Squirreling away code.

Nick Klingensmith maluoi

:shipit:
Squirreling away code.
View GitHub Profile
@maluoi
maluoi / GrabBar.cs
Last active March 22, 2023 22:21
StereoKit: using a grab bar below the window for movement.
Pose grabBarPose = new Pose(0, 0, -0.5f, Quat.LookDir(0, 0, 1));
Vec2 windowSize = Vec2.Zero; // First frame will not be in the right spot unless we know window size in advance.
public void Update()
{
// Use the size of the Window to position it directly above the grab
// bar. Note that we're using the Pose relative Up direction instead of
// just the Y axis.
Pose windowPose = grabBarPose;
windowPose.position -= grabBarPose.Up * windowSize.y;
// Begin the window, only show the body, and don't allow the user to
@maluoi
maluoi / SKRecenter.cs
Last active September 14, 2023 07:22
StereoKit "Reset to center"
using StereoKit;
SK.Initialize("SKRecenter");
SK.Run(() => {
Mesh.Sphere.Draw(Material.Default, Matrix.TS(0, 0, -0.5f, 0.1f));
if (Input.Key(Key.Space).IsJustActive()) {
// Get the head pose, and flatten the rotation to just the Y axis.
Pose head = Input.Head;
head.orientation.x = 0;
@maluoi
maluoi / Assets\fresnel.hlsl
Last active February 25, 2023 05:07
StereoKit fresnel shader
#include <stereokit.hlsli>
//--color: color = 1,1,1,1
//--color2:color = 0,0,0,1
//--slope = 1000
//--threshold = 0.2
float4 color;
float4 color2;
float threshold;
namespace StereoKit
{
/// <summary>Some utility functions for converting coordinate data to and
/// from some commonly used tools!
///
/// StereoKit uses a right-handed coordinate system, where +x is to the
/// right, +y is upwards, and -z is forward. This is the exact same
/// coordinate system as OpenXR, so no conversions are necessary there :)
///
/// Unity uses a left-handed coordinate system, where +x is to the right,
using System.Collections.Generic;
namespace StereoKit.Framework
{
public class StaticScene
{
internal List<StaticSceneItem> _items = new List<StaticSceneItem>();
public void AddModel(Model model, Matrix at)
{
@maluoi
maluoi / Camera.cs
Created July 28, 2022 19:29
A partial StereoKit camera controller
using System;
namespace StereoKit.Framework
{
class Camera : IStepper
{
public delegate bool IntersectionDelegate(Ray worldRay, out Ray worldIntersection);
float _headHeight = 1.5f;
float _floor = 0;
@maluoi
maluoi / blit_template.hlsl
Created August 27, 2021 03:37
StereoKit Blit Shader
//--name = sk/blit/identity
//--source = white
Texture2D source : register(t0);
SamplerState source_s : register(s0);
struct vsIn {
float4 pos : SV_Position;
float2 uv : TEXCOORD0;
};
@maluoi
maluoi / LerpAnimations.cs
Last active April 29, 2022 23:11
A quick example of lerp-based animations with StereoKit
// This demo can be seen in motion here:
// https://twitter.com/koujaku/status/1407538105070997504
using StereoKit;
using System;
class Program {
static void Main(string[] args) {
// Initialize StereoKit
if (!SK.Initialize(new SKSettings { appName = "LerpAnim" }))
@maluoi
maluoi / DitherTransparent.shader
Created February 2, 2021 20:30
Dither based transparent Unity shader that preserves overlapping features.
Shader "Unlit/Dither Transparent" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_Offset ("Dither Depth Offset", Range(1,100)) = 40
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
@maluoi
maluoi / OcclusionMesh.cs
Last active January 20, 2021 00:10
StereoKit Occlusion Mesh
#if WINDOWS_UWP
using StereoKit;
using System;
using System.Collections.Generic;
using System.Numerics;
using Windows.Foundation;
using Windows.Perception.Spatial;
using Windows.Perception.Spatial.Surfaces;
using Windows.Storage.Streams;