Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrés Leone Gámez forestrf

View GitHub Profile
@forestrf
forestrf / Selectable.cs
Last active March 31, 2023 08:12
Improved UI navigation on Selectable.cs
View Selectable.cs
// Improved navigation code
using System;
using System.Collections.Generic;
using UnityEngine.Serialization;
using UnityEngine.EventSystems;
namespace UnityEngine.UI
{
[AddComponentMenu("UI/Selectable", 35)]
[ExecuteAlways]
@forestrf
forestrf / PhotoshopMathFP.hlsl
Created March 4, 2023 23:38 — forked from unitycoder/PhotoshopMathFP.hlsl
PhotoshopMath hlsl shader
View PhotoshopMathFP.hlsl
// https://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/
/*
** Photoshop & misc math
** Blending modes, RGB/HSL/Contrast/Desaturate
**
** Romain Dura | Romz
** Blog: http://blog.mouaif.org
** Post: http://blog.mouaif.org/?p=94
*/
@forestrf
forestrf / aaStepFastBoth.hlsl
Created February 1, 2023 00:14
aaStep HLSL
View aaStepFastBoth.hlsl
// Smooth equivalent to step(a, b) and both a and b can have their value change.
float aaStepFastBoth(float a, float b) {
return saturate((b - a) / max(fwidth(b), fwidth(a)));
}
@forestrf
forestrf / BlurEffect.compute
Created April 8, 2022 19:46 — forked from Refsa/BlurEffect.compute
Unity URP custom render feature for UI Blur
View BlurEffect.compute
#pragma kernel Downscale
#pragma kernel GaussianBlurVertical
#pragma kernel GaussianBlurHorizontal
#pragma kernel BoxBlur
Texture2D<float4> _Source;
RWTexture2D<float4> _Dest;
float _Amount;
float2 _Size;
@forestrf
forestrf / ExtendedScriptableObjectDrawer.cs
Created November 13, 2021 02:06 — forked from tomkail/ExtendedScriptableObjectDrawer.cs
Displays the fields of a ScriptableObject in the inspector
View ExtendedScriptableObjectDrawer.cs
// Developed by Tom Kail at Inkle
// Released under the MIT Licence as held at https://opensource.org/licenses/MIT
// Must be placed within a folder named "Editor"
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
@forestrf
forestrf / fbfetch.shader
Created September 22, 2021 12:27 — forked from aras-p/fbfetch.shader
Framebuffer fetch shader in Unity
View fbfetch.shader
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
// in practice: only compile for gles2,gles3,metal
#pragma only_renderers framebufferfetch
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
@forestrf
forestrf / ButtonWithOneModifierOrdered.cs
Created July 29, 2021 22:12
Unity Input modifier that accepts a modifier + a button but the modifier must be pressed before button
View ButtonWithOneModifierOrdered.cs
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Scripting;
using UnityEngine;
using UnityEngine.InputSystem;
namespace AshInput {
[Preserve]
[DisplayStringFormat("1º{modifier}+2º{button}")]
public class ButtonWithOneModifierOrdered : InputBindingComposite<float> {
@forestrf
forestrf / DebugUtil.cs
Created March 26, 2021 11:52 — forked from AlexanderDzhoganov/DebugUtil.cs
Dump RenderTexture to PNG in Unity
View DebugUtil.cs
public static class DebugUtil
{
public static void DumpRenderTexture(RenderTexture rt, string pngOutPath)
{
var oldRT = RenderTexture.active;
var tex = new Texture2D(rt.width, rt.height);
RenderTexture.active = rt;
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
@forestrf
forestrf / ComputeGunLead.cs
Created March 24, 2021 20:41 — forked from brihernandez/ComputeGunLead.cs
Computes a point for a gun to aim at in order to hit a target using linear prediction.
View ComputeGunLead.cs
/// <summary>
/// Computes a point for a gun to aim at in order to hit a target using linear prediction.
/// Assumes a bullet with no gravity or drag. I.e. A bullet that maintains a constant.
/// velocity after it's been fired.
/// </summary>
public static Vector3 ComputeGunLead(Vector3 targetPos, Vector3 targetVel, Vector3 ownPos, Vector3 ownVel, float muzzleVelocity)
{
// Extremely low muzzle velocities are unlikely to ever hit. This also prevents a
// possible division by zero if the muzzle velocity is zero for whatever reason.
if (muzzleVelocity < 1f)
@forestrf
forestrf / Distortion.shader
Created February 21, 2021 02:06 — forked from Fewes/Distortion.shader
Distortion shader for Unity. Supports a normal map.
View Distortion.shader
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