Skip to content

Instantly share code, notes, and snippets.

@Cyanilux
Cyanilux / CopyDepthFeature.cs
Last active February 10, 2024 19:56
URP Renderer Feature to force a CopyDepth pass (Unity 2022.2, URP)
/*
Afaik in Unity 2022.2,
If URP uses a Depth Prepass :
- The depth texture will only contain opaque objects, based on the Default Opaque Layer Mask
at the top of the Universal Renderer asset.
- So if you remove a layer from that and instead render it with RenderObjects features,
those objects no longer appear in the depth texture, even if their shader is writing depth :(
- Same goes for any Transparent objects with ZWrite On. The depth texture won't include those
@Cyanilux
Cyanilux / ExampleUsage.cs
Last active December 27, 2023 17:25
PropertyAttribute/Drawer used to auto-filter ObjectPicker window (showing assets / scene references) by name - Unity, IMGUI
// Example usage in some other script
[FilterObjectPicker("Projectile")]
public GameObject projectilePrefab;
// When clicking object field in inspector, would only see gameobjects with "Projectile" in name.
// Can remove filter text at top of object picker to see all gameobjects again.
// To allow scene references, add second param as true. e.g. :
[FilterObjectPicker("Test", true)]
@Cyanilux
Cyanilux / SceneColorSetup.cs
Created July 4, 2023 17:00
Setup _CameraOpaqueTexture (for Scene Color node) in Unity's Built-in Render Pipeline (BiRP)
/*
Copies the camera buffer after rendering opaques, to _CameraOpaqueTexture property so the Scene Color node can work in the Built-in RP.
Attach this script to the Main Camera (and any other cameras you want an Opaque Texture for)
Will also work for Scene Views (Though if a new window is opened will need to enter & exit play mode)
Tested in 2022.2
@Cyanilux
*/
using UnityEngine;
using UnityEngine.Rendering;
@Cyanilux
Cyanilux / CustomRendererFeature.cs
Last active September 26, 2023 11:36
Custom ScriptableRendererFeature/ScriptableRenderPass example for URP 2022+. From https://www.cyanilux.com/tutorials/custom-renderer-features/#full-example
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class CustomRendererFeature : ScriptableRendererFeature {
public class CustomRenderPass : ScriptableRenderPass {
private Settings settings;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class GlitchRenderFeature : ScriptableRendererFeature {
class CustomRenderPass : ScriptableRenderPass {
private Settings settings;
private FilteringSettings filteringSettings;
@Cyanilux
Cyanilux / customCommands.md
Last active November 24, 2022 11:52
Some custom commands for the YAGPDB discord bot.

Wrote these YAGPDB discord bot custom commands for Harry Alisavakis' discord (Technically Speaking), but maybe others will find it useful so sharing them here ~ Enjoy!

In the server we have a channel where users can suggest themes for upcoming tech art challenges, and others can react (first emoji only) to vote for it. These commands assist with keeping track of these themes and votes.

Users use a -suggestTheme <theme> command. Then when reactions are made (or if -updateThemes is used) a message, posted by the bot previously during setup, is updated with an embed listing the themes, sorted by no. of votes. That message is pinned for easy access.

@Cyanilux
Cyanilux / RenderToDepthTexture.cs
Last active August 7, 2024 06:08
URP Render Feature that manually renders DepthOnly pass to _CameraDepthTexture, filtered by LayerMask. Tested in URP v10, Unity 2020.3
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
/*
- Renders DepthOnly pass to _CameraDepthTexture, filtered by LayerMask
- If the depth texture is generated via a Depth Prepass, URP uses the Opaque Layer Mask at the top of the Forward/Universal Renderer asset
to determine which objects should be rendered to the depth texture. This feature can be used to render objects on *other layers* into the depth texture as well.
@Cyanilux
Cyanilux / Renderer2DBlitTest.cs
Created November 28, 2021 13:03
Possible workaround for the 2D Renderers not allowing you to assign Renderer Features
// Possible workaround for the 2D Renderers not allowing you to assign Renderer Features yet.
// Enqueues a ScriptableRenderPass without relying on a Renderer Feature
// Used with https://github.com/Cyanilux/URP_BlitRenderFeature/blob/master/Blit.cs
public class Renderer2DBlitTest : MonoBehaviour {
public Blit.BlitSettings settings;
private Blit.BlitPass blitPass;
private void OnEnable(){
blitPass = new Blit.BlitPass(settings.Event, settings, "BlitTest");
@Cyanilux
Cyanilux / FogOfWarHandler.cs
Created November 17, 2021 16:46
Fog of war example using Graphics.Blit. But probably not very optimised.
using UnityEngine;
public class FogOfWarHandler : MonoBehaviour {
public RenderTexture rt_units; // Render Texture asset, stores circles around units
public RenderTexture rt; // Render Texture asset, combines rt_units with rt from previous frame
public Material material_cloudBrush; // shader : max(_MainTex, brush), where brush is a circle drawn at _Pos with _Radius and _Edge (softness)
public Material material_combine; // shader : max(_MainTex, _OtherTex)
public FogOfWarUnit[] units; // MonoBehaviour with public float properties : radius and softness
@Cyanilux
Cyanilux / GrassInstanced.hlsl
Last active January 27, 2024 12:15
Experiments with using DrawMeshInstancedIndirect with Shader Graph
// https://twitter.com/Cyanilux/status/1396848736022802435?s=20
#ifndef GRASS_INSTANCED_INCLUDED
#define GRASS_INSTANCED_INCLUDED
// ----------------------------------------------------------------------------------
// Graph should contain Boolean Keyword, "PROCEDURAL_INSTANCING_ON", Global, Multi-Compile.
// Must have two Custom Functions in vertex stage. One is used to attach this file (see Instancing_float below),
// and another to set #pragma instancing_options :