Skip to content

Instantly share code, notes, and snippets.

@Fewes
Fewes / vr_extended.shader
Last active January 9, 2019 23:34
A modified version of Valve's standard shader for The Lab renderer. It supports vertex colors, vertex AO (alpha channel) as well as up to four detail textures. It also repacks metalness, roughness, AO and the detail mask into a single mask texture. Please note you need the custom GUI for it: https://gist.github.com/Fewes/43f2b97fe8785e9a69e22836…
// Copyright (c) Valve Corporation, All rights reserved. ======================================================================================================
// Modified to support vertex colors, vertex color linearization, vertex ao (through vertex alpha), up to 4 detail textures as well as tighter mask packing
//
// The mask texture is laid out like this:
// R - Metalness
// G - Roughness
// B - Ambient occlusion
// A - Detail mask, where:
// 0-25% intensity = Detail map 1
// 25-50% intensity = Detail map 2
@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
{
@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 / 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 / Tricubic.cginc
Last active May 7, 2024 07:16
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 / 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
{
// 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++)
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
}
@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);
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);
}