Skip to content

Instantly share code, notes, and snippets.

View forestrf's full-sized avatar

Andrés Leone Gámez forestrf

View GitHub Profile
@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
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
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.
/// <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.
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
@forestrf
forestrf / PixelDot.shader
Created October 10, 2020 20:41 — forked from Fewes/PixelDot.shader
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
{
@forestrf
forestrf / Tricubic.cginc
Created August 31, 2020 15:33 — forked from Fewes/Tricubic.cginc
Tricubic texture sampling for Unity
/*--------------------------------------------------------------------------*\
Copyright (c) 2008-2009, Danny Ruijters. All rights reserved.
http://www.dannyruijters.nl/cubicinterpolation/
This file is part of CUDA Cubic B-Spline Interpolation (CI).
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
@forestrf
forestrf / UniversalPipelineTemplateShader.shader
Created May 31, 2020 19:39 — forked from phi-lira/UniversalPipelineTemplateShader.shader
Template shader to use as guide to create Universal Pipeline ready shaders. This shader works with Universal Render Pipeline 7.1.x and above.
// When creating shaders for Universal Render Pipeline you can you the ShaderGraph which is super AWESOME!
// However, if you want to author shaders in shading language you can use this teamplate as a base.
// Please note, this shader does not necessarily match perfomance of the built-in URP Lit shader.
// This shader works with URP 7.1.x and above
Shader "Universal Render Pipeline/Custom/Physically Based Example"
{
Properties
{
// Specular vs Metallic workflow
[HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
@forestrf
forestrf / LICENSE
Created May 20, 2020 00:52 — forked from JohannesMP/LICENSE
[Unity3D] A Reliable, user-friendly way to reference SceneAssets by script.
/*******************************************************************************
* Don't Be a Jerk: The Open Source Software License.
* Adapted from: https://github.com/evantahler/Dont-be-a-Jerk
*******************************************************************************
* _I_ am the software author - JohannesMP on Github.
* _You_ are the user of this software. You might be a _we_, and that's OK!
*
* This is free, open source software. I will never charge you to use,
* license, or obtain this software. Doing so would make me a jerk.
*
@forestrf
forestrf / AshUpdater.cs
Last active May 19, 2020 19:53
Hook into before and after common Unity update functions
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.LowLevel;
using UnityEngine.Profiling;
// http://web.archive.org/web/20180315122537/http://beardphantom.com/ghost-stories/unity-2018-and-playerloop/
namespace Ashkatchap.ExtraUpdaters {
@forestrf
forestrf / BehaviourTree.cs
Created March 12, 2020 01:30 — forked from NovemberDev/BehaviourTree.cs
Behaviour Tree in C#
using System;
using System.Linq;
using System.Collections.Generic;
public enum BTS
{
Success,
Failure,
Running
}