Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / DepthFX.cs
Created February 22, 2023 08:17
Fake 3D effect with depth map (Unity Shader)
using UnityEngine;
// https://gist.github.com/bozzin/5895d97130e148e66b88ff4c92535b59
public class DepthFX : MonoBehaviour
{
public float power = -0.02f;
void Update()
{
@unitycoder
unitycoder / ProBuilder Notes.md
Last active May 2, 2023 11:24
ProBuilder Notes Unity

Adjust Pivot

  • Vertex mode, select 1 or more vertex, probuild window: Press Set pivot (moves pivot to that vertex pos or at their center pos if multiple)
  • Line select mode, select line (set pivot, appears in the middle of the line)
@unitycoder
unitycoder / DoomGlow.cs
Created February 17, 2023 10:37 — forked from TiliSleepStealer/DoomGlow.cs
Doom glow - fake volumetric light glow effect in Unity by Tili_us
// This file is in the public domain. Where
// a public domain declaration is not recognized, you are granted
// a license to freely use, modify, and redistribute this file in
// any way you choose.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Unity remake of a fake volumetric light glow effect
@unitycoder
unitycoder / Render Cubemap Depth Texture.cs
Created February 17, 2023 07:49
Render Cubemap Depth Texture
// https://forum.unity.com/threads/how-to-create-depth-cubemap.1400545/
GameObject cubemapCam = new GameObject( "CubemapCamera" );
            cubemapCam.AddComponent<Camera>();
            cubemapCam.transform.position = Vector3.zero;
            cubemapCam.transform.rotation = Quaternion.identity;
            cubemapCam.GetComponent<Camera>().depthTextureMode = DepthTextureMode.Depth;
            cubemapCam.GetComponent<Camera>().farClipPlane = 30;
 
            int cubemapSize = 128;
            RenderTexture _cubeMapTex = new RenderTexture( cubemapSize, cubemapSize, 16, RenderTextureFormat.Depth );
@unitycoder
unitycoder / GetData..cs
Created February 14, 2023 08:40
AudioClip GetData unsafe native access runtime
// https://forum.unity.com/threads/custom-unity-methods-bindings.1347785/
public static unsafe bool GetData(AudioClip clip, Span<float> data, uint offsetSamples)
{
#if !UNITY_2023_1_OR_NEWER || UNITY_EDITOR || DEVELOPMENT_BUILD
    if (clip.channels <= 0)
        return false;
 
    fixed (float* pData = data)
    {
        var native = NativeObjectUtility.GetNativeObject(clip);
@unitycoder
unitycoder / VTRequest.cs
Created February 12, 2023 09:25 — forked from NanyiJiang/VTRequest.cs
Unity Streaming Virtual Texture Request improvement
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#if ENABLE_VIRTUALTEXTURES
using VT = UnityEngine.Rendering.VirtualTexturing;
#endif
// [ExecuteInEditMode]
public class VTRequester : MonoBehaviour
@unitycoder
unitycoder / ScriptedImporter.cs
Created February 11, 2023 15:07
multiple scripted importers for same file type
// https://forum.unity.com/threads/multiple-glb-importers-how-do-i-fix-this.1364523/#post-8608575
// Default importer
[ScriptedImporter(1, new [] {"gltf", "glb"})]
// Optional importer
[ScriptedImporter(1, null, new [] {"gltf", "glb"})]
@unitycoder
unitycoder / VoronoiDiagram.cs
Created February 11, 2023 14:46
Voronoi Diagram from Texture2D
// https://forum.unity.com/threads/roman-mosaic-style-using-opencv-for-unity.1398250/
using UnityEngine;
using System.Collections.Generic;
 
public class VoronoiDiagram : MonoBehaviour
{
    public Texture2D image;
    public int numberOfSites = 100;
    public float scale = 1;
    private List<Vector2> sites;
@unitycoder
unitycoder / CC-Glass.shader
Created February 9, 2023 08:00 — forked from cs-altshift/CC-Glass.shader
Crying Suns Command-Center Glass Shader
Shader "Crying Suns/Command Center Glass"
{
Properties
{
[PerRendererData] _MainTex ("Main Texture (ignored)", 2D) = "white" {}
[NoScaleOffset] _ReflectionTex ("Reflection Texture", 2D) = "black" {}
_ReflectionAlpha ("Reflection Alpha", Range(0, 1)) = 0.25
_ReflectionScale ("Reflection Scale", Range(0, 1)) = 1
[HideInInspector] _SunCenteredViewportPos ("Sun Centered Viewport Position", Vector) = (0, 0, 0, 0)
[HideInInspector] _SunAngle ("Sun Angle", Float) = 0