Skip to content

Instantly share code, notes, and snippets.

@Cyanilux
Cyanilux / customCommands.md
Last active Mar 7, 2022
Some custom commands for the YAGPDB discord bot.
View customCommands.md

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 Dec 3, 2021
URP Render Feature that manually renders DepthOnly pass to _CameraDepthTexture, filtered by LayerMask. Tested in URP v10, Unity 2020.3
View RenderToDepthTexture.cs
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 Nov 28, 2021
Possible workaround for the 2D Renderers not allowing you to assign Renderer Features
View Renderer2DBlitTest.cs
// 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 Nov 17, 2021
Fog of war example using Graphics.Blit. But probably not very optimised.
View FogOfWarHandler.cs
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 May 3, 2022
Experiments with using DrawMeshInstancedIndirect with Shader Graph
View GrassInstanced.hlsl
// 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 :
@Cyanilux
Cyanilux / DrawGrass.cs
Last active Apr 24, 2022
Experiments with DrawMeshInstanced and DrawMeshInstancedIndirect for drawing grass (over terrain)
View DrawGrass.cs
// https://twitter.com/Cyanilux/status/1396848736022802435
// Requires a specific shader to read the _PerInstanceData buffer at SV_InstanceID
// I use a shader made in Shader Graph, See : https://gist.github.com/Cyanilux/4046e7bf3725b8f64761bf6cf54a16eb
// Also note, there's no frustum culling involved in this example. Typically a compute shader is used for this.
using UnityEngine;
public class DrawGrass : MonoBehaviour {
@Cyanilux
Cyanilux / SGTessellation.hlsl
Last active Apr 30, 2021
Allows you to inject tessellation into SG & URP, but hacky / can be difficult to work with. Unsure if the same method can work for HDRP. Also see : https://twitter.com/Cyanilux/status/1388158860574314498. Tested in v10. Could definitely break at some point, use at your own risk :)
View SGTessellation.hlsl
// @Cyanilux
// Note : Also requires setting up "_TessellationUniform" Float in Blackboard
/*
Allows you to inject tessellation into SG & URP, but hacky / can be difficult to work with.
While this works, it's maybe not as useful as you might think. I believe any vertex displacement would need to be
taken out of the graph and moved into the domain function below (since tessellation still runs after vertex shader).
I thought about using the VertexDescriptionFunction from the generated code, but sadly that's generated after the injection point
so can't be called as it's undeclared at that point.
@Cyanilux
Cyanilux / UnlitDepthNormalsFeature.cs
Last active May 25, 2021
Renders Unlit Opaque objects into CameraNormalsTexture for SSAO Depth Normals mode
View UnlitDepthNormalsFeature.cs
/*
Render Unlit Opaque objects into CameraNormalsTexture for SSAO Depth Normals mode.
If you need Alpha clipping or vertex displacement, you'll need to use Depth mode,
or edit the generated shader code to add in the DepthNormals pass instead.
This is meant as an alternative if you don't need those.
For depthNormalsMat, I'm using a blank PBR/Lit SG with passIndex set to 4 (corresponds to it's DepthNormals pass).
*/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
@Cyanilux
Cyanilux / Tex2DArrayCreator.cs
Last active Aug 21, 2021
EditorWindow for creating & editing Texture 2D Arrays. Note : All textures must have same width/height, mipmap count and format/compression type! (Place in an "Editor" folder inside assets, go to Window -> "Create Texture2DArray")
View Tex2DArrayCreator.cs
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.IO;
public class Tex2DArrayCreator : EditorWindow {
private string fileName;
private List<Texture2D> textures = new List<Texture2D>();