Skip to content

Instantly share code, notes, and snippets.

View ColinLeung-NiloCat's full-sized avatar

ColinLeung-NiloCat ColinLeung-NiloCat

View GitHub Profile
@aras-p
aras-p / foo.md
Last active January 27, 2021 06:32
Controlling fixed function states from materials/scripts in Unity

(typing off the top of my head, might not compile)

Since Unity 4.3:

In the shader, instead of writing Cull Off, write Cull [_MyCullVariable], the value will be fetched from the material or global float/int variable _MyCullVariable then.

You could have it be part of material, e.g. inside Properties block:

[Enum(Off,0,Front,1,Back,2)] _MyCullVariable ("Cull", Int) = 1
@LotteMakesStuff
LotteMakesStuff / 1.md
Last active January 5, 2023 20:54
UPM: How to make a custom package

UPM: How to make a custom package So, Unity has this shiny new package manager, and you have code you want to share between projects - wouldn't it be great if we could bundle up our shared code and plug it into all the projects that need it? Let's figure out how to make our own Package!


Todo

  • Modify the project manifest
  • Make a package manifest
  • Package the manifest up with some test code
  • Try it out in Unity!

@phi-lira
phi-lira / FullScreenQuad.cs
Created March 19, 2019 14:02
LWRP FullScreenQuad feature example. This can be used to extend LWRP render to render a full screen quad.
namespace UnityEngine.Rendering.LWRP
{
// A renderer feature contains data and logic to enqueue one or more render passes in the LWRP renderer.
// In order to add a render feature to a LWRP renderer, click on the renderer asset and then on the + icon in
// the renderer features list. LWRP uses reflection to list all renderer features in the project as available to be
// added as renderer features.
public class FullScreenQuad : ScriptableRendererFeature
{
[System.Serializable]
public struct FullScreenQuadSettings
@CarlLee
CarlLee / Bloom.shader
Last active May 16, 2023 10:28
UE4 bloom for unity
Shader "Hidden/Bloom"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
struct appdata
@alexanderameye
alexanderameye / DepthNormalsFeature.cs
Created December 23, 2019 11:04
DepthNormalsFeature
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class DepthNormalsFeature : ScriptableRendererFeature
{
class DepthNormalsPass : ScriptableRenderPass
{
int kDepthBufferBits = 32;
private RenderTargetHandle depthAttachmentHandle { get; set; }
@jimfleming
jimfleming / UnityDiffuseLightmap.shader
Last active June 21, 2023 00:44
Example depicting applying Unity lightmapping data to a simple diffuse shader.
Shader "Diffuse Lightmap" {
Properties {
_MainTex ("Texture 1", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
Pass {
@elringus
elringus / BlendModes.c
Last active March 11, 2024 11:32
Popular blend mode algorithms implemented in Nvidia's Cg. https://elringus.me/blend-modes-in-unity/
fixed3 Darken (fixed3 a, fixed3 b)
{
return min(a, b);
}
fixed3 Multiply (fixed3 a, fixed3 b)
{
return a * b;
}
@phi-lira
phi-lira / UnlitTexture.shader
Last active March 23, 2024 18:12
URP Unlit Texture example
Shader "Custom/UnlitTexture"
{
Properties
{
[MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
[MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
}
// Universal Render Pipeline subshader. If URP is installed this will be used.
SubShader
@phi-lira
phi-lira / UniversalPipelineTemplateShader.shader
Last active April 4, 2024 13:42
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
@Refsa
Refsa / GrabScreenFeature.cs
Last active April 9, 2024 13:04
Unity URP custom grab pass
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class GrabScreenFeature : ScriptableRendererFeature
{
[System.Serializable]
public class Settings