Skip to content

Instantly share code, notes, and snippets.

@Fewes
Fewes / PolarCoordinates.hlsl
Created February 6, 2024 07:17
Polar/spherical coordinates conversion functions
#ifndef POLAR_INCLUDED
#define POLAR_INCLUDED
#define PI 3.14159265359
float2 UVToPolar(float2 uv)
{
return float2(uv.x * (2 * PI), (uv.y - 0.5) * PI);
}
using UnityEngine;
public static class HaltonSequenceGenerator
{
public static void GenerateHaltonSequence(float[] result)
{
for (int i = 0; i < result.Length; i++)
{
result[i] = Halton(2, i);
}
@Fewes
Fewes / gist:016d74e0bee453cc74130865865ddc6c
Created February 17, 2023 09:46
Clear console (not just errors)
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(SceneView));
System.Type logEntries = assembly.GetType("UnityEditor.LogEntries");
logEntries.GetMethod("Clear").Invoke(new object (), null);
Shader "Wireframe"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_WireColor ("Wire Color", Color) = (0, 0, 0)
_Smoothing ("Smoothing", Range(0, 10)) = 1
_Thickness ("Thickness", Range(0, 10)) = 1
}
// Uniform random distribution.
// Great for effects with a limited number of samples, like SSAO.
public static Vector4[] UniformKernel(int n, bool hemisphere)
{
Random.State state = Random.state;
// Set the random seed so repeat calls with n samples always returns the same result
Random.InitState(0);
Vector4[] result = new Vector4[n];
for (int i = 0; i < n; i++)
@Fewes
Fewes / PixelDot.shader
Last active May 12, 2021 04:38
Renders a screen-aligned, distance-independent, resolution-independent, pixel-perfect quad in Unity. Use it with the built-in quad mesh. You don't have to rotate or scale the mesh renderer, the shader will take care of it.
Shader "FX/PixelDot"
{
Properties
{
[NoScaleOffset] _MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
_Size ("Pixel Size", Range(1, 64)) = 1
}
SubShader
{
@Fewes
Fewes / Tricubic.cginc
Last active March 22, 2024 18:23
Tricubic texture sampling using 8 trilinear samples
#ifndef TRICUBIC_INCLUDED
#define TRICUBIC_INCLUDED
float4 Cubic(float v)
{
float4 n = float4(1.0, 2.0, 3.0, 4.0) - v;
float4 s = n * n * n;
float x = s.x;
float y = s.y - 4.0 * s.x;
float z = s.z - 4.0 * s.y + 6.0 * s.x;
@Fewes
Fewes / Distortion.shader
Last active November 15, 2022 13:48
Distortion shader for Unity. Supports a normal map.
Shader "Distortion"
{
Properties
{
_Refraction ("Refraction", Range (0.00, 10.0)) = 1.0
_Power ("Power", Range (1.00, 10.0)) = 1.0
_AlphaPower ("Vertex Alpha Power", Range (1.00, 10.0)) = 1.0
_BumpMap( "Normal Map", 2D ) = "bump" {}
_Cull ( "Face Culling", Int ) = 2
@Fewes
Fewes / ScrollableEditorCameraSpeed.cs
Last active April 11, 2017 17:00
Allows you to control the scene camera speed using the scroll wheel in the Unity editor (much like UE4).
using UnityEngine;
using UnityEditor;
using System.Reflection;
[InitializeOnLoad]
public static class ScrollableEditorCameraSpeed
{
static ScrollableEditorCameraSpeed()
{
float cameraSpeed = 10.0f;
@Fewes
Fewes / ValveExtendedShaderGUI.cs
Last active January 9, 2019 23:35
The custom GUI needed to use my vr_extended shader for The Lab Renderer: https://gist.github.com/Fewes/503951a86bc6825ea622c4b6c94e2643.js
// Copyright (c) Valve Corporation, All rights reserved. ======================================================================================================
#if ( UNITY_EDITOR )
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor
{