Skip to content

Instantly share code, notes, and snippets.

View StagPoint's full-sized avatar

StagPoint Software StagPoint

  • StagPoint Software
  • Seattle, WA
View GitHub Profile
@renaudbedard
renaudbedard / gist:7a90ec4a5a7359712202
Created September 11, 2014 18:39
Billboarding for Unity surface shaders
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
// get the camera basis vectors
float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
float3 up = float3(0, 1, 0); //normalize(UNITY_MATRIX_V._m10_m11_m12);
float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);
// rotate to face camera
@JohnnyBeluga
JohnnyBeluga / Unity Basic Tessellation Shader
Last active April 4, 2018 05:01
Basic triangle Unity ShaderLab Shader; Tessellates a triangle mesh and colors it red.
Shader "Tesselation/Triangle_Tesselation" {
Properties {
_TessEdge ("Edge Tess", Range(1,64)) = 2
}
SubShader {
Pass {
CGPROGRAM
#pragma target 5.0
// cpp port by @saephoed
// ogre based (working; some minor bugs; no ui) port of
// see http://experilous.com/1/planet-generator/2014-09-28/planet-generator.js
// see http://experilous.com/1/blog/post/procedural-planet-generation
// see twitter @AndyGainey
/// hpp ///
#ifndef INCLUDED_World
@mzaks
mzaks / RectTransformTools.cs
Last active April 14, 2025 18:11
Adjust RectTransform Anchors for Unity UI
using UnityEngine;
using UnityEditor;
public class RectTransformTools {
[MenuItem("GameObject/Adjust RectTransform Anchors %l")]
static void Adjust()
{
foreach(GameObject gameObject in Selection.gameObjects){
adjustRectTransform(gameObject);
@HilariousCow
HilariousCow / gist:7f301b04c28fdf61e71f
Last active March 31, 2024 18:33
Load All Prefabs In Directory
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public static class PrefabLoader
{
//So, there's no "load all assets in directory" function in unity.
//I guess this is to avoid people using Prefabs as "data blobs".
//They'd rather you use ScriptableObjects... which is fine in some cases,
@wwwtyro
wwwtyro / gist:beecc31d65d1004f5a9d
Created March 16, 2015 05:54
GLSL ray-sphere intersection
float raySphereIntersect(vec3 r0, vec3 rd, vec3 s0, float sr) {
// - r0: ray origin
// - rd: normalized ray direction
// - s0: sphere center
// - sr: sphere radius
// - Returns distance from r0 to first intersecion with sphere,
// or -1.0 if no intersection.
float a = dot(rd, rd);
vec3 s0_r0 = r0 - s0;
float b = 2.0 * dot(rd, s0_r0);
@keijiro
keijiro / Skybox-Cubed LOD.shader
Created March 31, 2015 13:11
Cubemapped Skybox Shader with LOD Level
Shader "Skybox/Cubemap LOD" {
Properties {
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
[Gamma] _Exposure ("Exposure", Range(0, 8)) = 1.0
_Rotation ("Rotation", Range(0, 360)) = 0
_LodLevel ("LOD Level", Range(0, 10)) = 0
[NoScaleOffset] _Tex ("Cubemap (HDR)", Cube) = "grey" {}
}
SubShader {
@AngryAnt
AngryAnt / MoveComponentContext.cs
Last active July 5, 2017 05:44
Adds "Move to Top" and "Move to Bottom" items to the inspector context menu of components.
using UnityEngine;
using UnityEditor;
public class MoveComponentContext
{
enum Destination
{
Top,
Bottom
@cjacobwade
cjacobwade / CheapToggle.shader
Created August 18, 2015 21:22
#unity3d example showing how to add a checkbox to a shader property and use it to flip between colors.
Shader "Custom/CheapToggle"
{
Properties
{
_ColorA ( "Color A", Color ) = ( 1, 1, 1, 1 )
_ColorB ( "Color B", Color ) = ( 1, 1, 1, 1 )
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
@zsoi
zsoi / TerrainDataCloner.cs
Last active January 14, 2025 02:33
Helper to deep-copy a TerrainData object in Unity3D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ZS.Tools
{
/// <summary>
/// Provides means to deep-copy a TerrainData object because Unitys' built-in "Instantiate" method