Skip to content

Instantly share code, notes, and snippets.

View runevision's full-sized avatar

Rune Skovbo Johansen runevision

View GitHub Profile
@runevision
runevision / BurstMethodTester.cs
Last active May 3, 2024 13:31
Using Unity Burst directly on methods without jobs - unofficial example code
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using UnityEngine;
// This example code demonstrates using Unity Burst directly on a static method without jobs.
// Unity NativeArrays can't be used directly in Unity Burst methods (only in Burst jobs),
// so we have to pass pointers to arrays instead.
@runevision
runevision / Shadows.cginc
Last active May 3, 2024 13:32
Water Foam Particle Shader
UNITY_DECLARE_SHADOWMAP(_SunCascadedShadowMap);
float4 _SunCascadedShadowMap_TexelSize;
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights_splitSpheres(wpos)
#define GET_SHADOW_FADE(wpos, z) getShadowFade_SplitSpheres(wpos)
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord(wpos,cascadeWeights)
/**
* Gets the cascade weights based on the world position of the fragment and the poisitions of the split spheres for each cascade.
@runevision
runevision / Unity versions not affected by Unity Runtime Fee.md
Created September 14, 2023 09:45
Unity versions not affected by Unity Runtime Fee

Unity versions not affected by Unity Runtime Fee

This is information that has been dug up by me and others in the Unity community. It's not official information from Unity (but most of the linked resources are). It is also not legal advise. I am not a lawyer.

TLDR:

Contrary to what Unity themselves are saying, for games made with these Unity versions, developers can elect not to be affected by a newer version of the Terms of Service that introduces the Unity Runtime Fee:

  • Unity 2022.x or earlier
  • Unity 2021.x LTS or earlier
@runevision
runevision / Text2.cs
Last active December 15, 2022 10:01
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 {
@runevision
runevision / ObjectExtensions.cs
Created September 16, 2019 13:11
obj.IsDestroyed() method for Unity objects
public static class ObjectExtensions {
public static bool IsDestroyed (this UnityEngine.Object obj) {
// Returns true if the object has been destroyed;
// false if it's actually null.
// (You could throw a NullReferenceException instead
// in the latter case if you wanted.)
return obj == null && !ReferenceEquals (obj, null);
}
}
@runevision
runevision / RedistributeUVsPostProcessor.cs
Created September 15, 2019 13:31
Redistribute UVs PostProcessor for Unity
// This can be used to redistribute the UV coordinates
// (either, U, V, or both) on an imported mesh which represents an
// extruded surface, such as ropes, or other shapes extruded along a
// spline. It's important for this method to work, that all vertices
// of each edge loop have the same U or V coordinate (depending on
// which is chosen for redistribution).
//
// Usage:
//
// Meshes that should be redistributed should contain "Redistribute"
@runevision
runevision / CameraTrackingRefraction.cs
Created October 22, 2017 11:09
Unity CommandBuffer replacement for GrabPass - works with multiple separate cameras.
using UnityEngine;
using UnityEngine.Rendering;
// This script is added to cameras automatically at runtime by the ObjectNeedingRefraction scripts.
public class CameraTrackingRefraction : MonoBehaviour {
[System.NonSerialized]
public int lastRenderedFrame = -1;
Camera cam;
using UnityEngine;
using System.Collections.Generic;
[System.Serializable]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver {
[SerializeField]
private List<TKey> keys = new List<TKey> ();
[SerializeField]
private List<TValue> values = new List<TValue> ();
/**
* The following code is derived from the original code from: http://schemingdeveloper.com.
* The derived version was developed by Rune Skovbo Johansen - http://runevision.com
*
* Modifications in the derived version:
*
* - Averaged normals are calculated as a weighted average based on face area,
* known as "face weighted normals" or "area weighted normals".
*
* - An ignoreFactor parameter has been added which can cull normals from the average
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
namespace Cluster {
public class CollisionCall : MonoBehaviour {
public LayerMask layerMask = -1;