Skip to content

Instantly share code, notes, and snippets.

View SoylentGraham's full-sized avatar
🌴
I like trees.

Graham Reeves SoylentGraham

🌴
I like trees.
View GitHub Profile
@SoylentGraham
SoylentGraham / gist:2b280a16f675371eab6e
Created January 10, 2016 19:20
Ultra simple (and innacurate) nearest colour picking pixel shader (outputs the index)
varying highp vec2 oTexCoord;
uniform sampler2D Texture0; // rgba
uniform sampler2D Texture1; // palette
uniform vec2 Texture1_PixelSize;
const highp mat3 Transform = mat3( 1,0,0, 0,1,0, 0,0,1 );
const int TransparentPixelIndex = 0;
float GetColourScore(vec4 a,vec4 b)
{
@SoylentGraham
SoylentGraham / gist:c6326adb2047bfc13a28
Created February 24, 2016 16:26
pixel shader fade towards edges
float2 texelsize; // 1/width
bool isalpha(uv,offset)
{
// if bilinear sampling, then you might want to increase this rather than checking for pure 0
return sample( uv + offset*texelsize ).w < 0.1;
}
float getdistancetoedge(uv,float radius)
@SoylentGraham
SoylentGraham / PaintCloudData.shader
Created May 3, 2016 22:31
Shader based texture painting. Add the script to a plane with a collider and attach a render texture
Shader "NewChromantics/PaintCloudData"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
PaintUv("PaintUv", VECTOR) = (0,0,0,0)
PaintBrushSize("PaintBrushSize", Range(0,0.1) ) = 0.1
}
SubShader
{
@SoylentGraham
SoylentGraham / HwndExtractor.cpp
Created June 20, 2016 14:15
Windows Window capture in PopMovie.xyz
#include "HwndExtractor.h"
#include <future>
#include <SoyJson.h>
void EnumWindows(ArrayBridge<TWindowHandle>&& Handles,std::function<bool(const std::string&)> Filter)
{
// WNDENUMPROC
auto EnumWindowsCallback = [](HWND window_handle, LPARAM param) -> BOOL
{
@SoylentGraham
SoylentGraham / gist:bef991c9cd38f9b9c39e549bfcfb05a9
Created September 13, 2017 15:46
Unity Find all objects of type in a scene including inactive
static T[] FindObjectsOfTypeIncludingDisabled<T>()
{
var ActiveScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene ();
var RootObjects = ActiveScene.GetRootGameObjects ();
var MatchObjects = new List<T> ();
foreach (var ro in RootObjects) {
var Matches = ro.GetComponentsInChildren<T> (true);
MatchObjects.AddRange (Matches);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
/// <summary>
/// General utilities
/// </summary>
public static class PopCloud
{
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel ParsePositionColour
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
//RWTexture2D<float4> Result;
struct XyzRgba
{
float x;
@SoylentGraham
SoylentGraham / FfmpegPipe.cs
Created May 10, 2018 18:21
Use pipes in c# to pull a specific frame (time) from ffmpeg into a texture in unity. SLOW.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using System.IO;
using System;
// stolen from https://github.com/keijiro/FFmpegOut/blob/master/Assets/FFmpegOut/FFmpegPipe.cs
// then gave up and wrote from scratch
@SoylentGraham
SoylentGraham / OculusVRCTester.cs
Created May 31, 2018 17:18
Oculus auto VRC tester
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using System.Diagnostics;
using System.IO;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
@SoylentGraham
SoylentGraham / CameraRecorder.cs
Created September 18, 2018 10:17
Hacky record-360/equirect in unity
// use this shader https://github.com/SoylentGraham/PopUnityCommon/blob/master/BlitCubemapToEquirect.shader
// and utils in here https://github.com/SoylentGraham/PopUnityCommon/blob/master/PopTexture.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRecorder : MonoBehaviour {
public Cubemap RenderTargetCubemap;
public RenderTexture RenderTargetEquirect;