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
@brihernandez
brihernandez / VectorFuryPlayerInput.cs
Last active April 18, 2022 19:47
Example of how to use the new Input System in Unity. This is how I handled input in Vector Fury.
// This is an example of how to use the new input system in a way that I think is actually
// usable for a production game, and not just rapid prototyping. This is much more stable,
// and because it uses the C# class version of the new Input System it will fail to compile
// if something changes in the input asset, which is a VERY GOOD THING.
using UnityEngine;
public class CameraInput
{
public float Pitch = 0f;
@runevision
runevision / Text2.cs
Last active August 20, 2024 06:42
Text2 extends the Unity UI Text class and makes hyphens and soft hypens work
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// Text2 extends the Text component in Unity UI.
// It makes hyphens and soft hyphens work.
// Inserting soft hyphens in text can be tricky and confusing, given they are invisible,
// so you can instead also insert Hyphenation Point characters, which will be replaced by soft hyphens:
// https://www.compart.com/en/unicode/U+2027
public class Text2 : Text {
@khadzhynov
khadzhynov / SkyboxCubemapHorizonHSV.shader
Created April 14, 2021 17:10
Cubemap shader with adjustable vertical Scale/Offset and HSV color controls.
/*
Cubemap shader with adjustable vertical Scale/Offset and HSV color controls.
Creation goal was to enable user to create several casually-looking skyboxes in different colors from single image, drawn in 2d editing software.
Features:
- Doesn't requires 6-sides cubemap, or spherical projection: texture can be easily drawn in any 2d image editing software;
- "V Offset" option allows to move horizon line up and down with ease;
- "V Scale" allows to stretch texture;
- Rotation feature sets horizontal offset (as in original shader).
- HSV controls allows to change colors.
@brihernandez
brihernandez / PixelPerfectTrail.cs
Last active April 25, 2022 21:51
TrailRenderer that maintains a width in screen space (URP)
public class PixelPerfectTrail : MonoBehaviour
{
[SerializeField] private TrailRenderer trail = null;
[Tooltip("How small the trail width is allowed to get in pixels.")]
public float MinimumPixelSize = 1.5f;
private float startSize = 1f;
private void Awake()
@Cyanilux
Cyanilux / Tex2DArrayCreator.cs
Last active October 17, 2023 12:00
EditorWindow for creating & editing Texture 2D Arrays. Note : All textures must have same width/height, mipmap count and format/compression type! (Place in an "Editor" folder inside assets, go to Window -> "Create Texture2DArray")
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.IO;
public class Tex2DArrayCreator : EditorWindow {
private string fileName;
private List<Texture2D> textures = new List<Texture2D>();
@totallyRonja
totallyRonja / MaterialGradientDrawer.cs
Last active March 31, 2025 13:38
A Material Property Drawer for the [Gradient] attribute which lets you edit gradients and adds them to the shader as textures. More information here: https://twitter.com/totallyRonja/status/1368704187580682240
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class MaterialGradientDrawer : MaterialPropertyDrawer {
private int resolution;
@BrianMacIntosh
BrianMacIntosh / Image2.cs
Created March 4, 2021 18:03
Shader for Unity UI that uses a four-color gradient, and custom Image component for using the shader with Sliced images.
using UnityEngine;
using UnityEngine.UI;
// Based on the Unity built-in image source (Unity Reference-Only License, https://unity3d.com/legal/licenses/Unity_Reference_Only_License)
// Modified to add full-mesh UVs by Brian MacIntosh
namespace UI
{
/// <summary>
/// Image override that fills the second UV channel with uniform UVs over the entire image.
@bgolus
bgolus / WorldNormalFromDepthTexture.shader
Last active March 5, 2025 00:57
Different methods for getting World Normal from Depth Texture, without any external script dependencies.
Shader "WorldNormalFromDepthTexture"
{
Properties {
[KeywordEnum(3 Tap, 4 Tap, Improved, Accurate)] _ReconstructionMethod ("Normal Reconstruction Method", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
@dondragmer
dondragmer / PrefixSort.compute
Created January 20, 2021 23:32
An optimized GPU counting sort
#pragma use_dxc //enable SM 6.0 features, in Unity this is only supported on version 2020.2.0a8 or later with D3D12 enabled
#pragma kernel CountTotalsInBlock
#pragma kernel BlockCountPostfixSum
#pragma kernel CalculateOffsetsForEachKey
#pragma kernel FinalSort
uint _FirstBitToSort;
int _NumElements;
int _NumBlocks;
bool _ShouldSortPayload;
@hypernewbie
hypernewbie / ManualGLSLCubemapLookup.cpp
Last active December 6, 2020 21:17
Manual GLSL cubemap lookup. Hopefully correct maybe.
#include <cstdio>
#include <cmath>
struct float2
{
float x = 0.0f;
float y = 0.0f;
float2() {}
float2( float _x, float _y ) { x = _x; y = _y; }
};