Skip to content

Instantly share code, notes, and snippets.

@bgolus
bgolus / StableConstantTextureSize.shader
Created April 6, 2019 18:50
Visually stable constant screen space sized texture shader for Unity
Shader "Unlit/Stable Constant Texture Size"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
@bgolus
bgolus / HatchBlend6_DistanceAndFOVCorrected.shader
Created December 11, 2019 08:18
A modification of Kyle Halladay's Pencil Sketch Effect shader from his blog post here: http://kylehalladay.com/blog/tutorial/2017/02/21/Pencil-Sketch-Effect.html
// A modification of Kyle Halladay's Pencil Sketch Effect shader
// http://kylehalladay.com/blog/tutorial/2017/02/21/Pencil-Sketch-Effect.html
// Blends between two scales of hatching based on distance and camera fov to
// keep a perceptually constant hatching scale (assuming consistent mesh UVs).
Shader "Unlit/SingleObjectHatch_DistanceAndFOVCorrected"
{
Properties
{
@bgolus
bgolus / StereographicProjectionBubble.shader
Created February 28, 2020 06:33
Modifying UVs using stereographic projection to create the illusion of a sphere.
Shader "Unlit/StereographicProjectionBubble"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_PanSpeed ("Pan Speed", Float) = 0.1
_Spherify ("Spherify", Range(0,1)) = 1
}
SubShader
{
Shader "Custom/ACNH_SewingCloth"
{
Properties
{
[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
[NoScaleOffset] _BumpMap ("Normal Map", 2D) = "bump" {}
[NoScaleOffset] _EdgeAlpha ("Alpha", 2D) = "white" {}
_Cutoff ("Alpha Test Cutoff", Range(0,1)) = 0.5
_Offset ("Offset (XY)", Vector) = (0,0,0,0)
@bgolus
bgolus / CameraFacingBoxRaycast.shader
Created July 6, 2020 00:07
A "single triangle" cube shader. Really a shader that orients a flat mesh towards the camera and uses a box ray intersection to draw a cube in the interior.
Shader "Unlit/CameraFacingBoxRaycast"
{
Properties
{
_Cube ("Texture", Cube) = "" {}
_MeshScale ("Mesh Scale", Float) = 1.0
[Toggle] _DisableCameraFacing ("Disable Camera Facing", Float) = 0.0
}
SubShader
{
Shader "Hidden/JumpFloodOutline"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "PreviewType" = "Plane" }
Cull Off ZWrite Off ZTest Always
@bgolus
bgolus / WorldNormalFromDepthTexture.shader
Last active April 25, 2024 03:51
Different methods for getting World Normal from Depth Texture, without any external script dependencies.
Shader "WorldNormalFromDepthTexture"
{
Properties {
[KeywordEnum(3 Tap, 4 Tap, Improved, Accurate)] _ReconstructionMethod ("Normal Reconstruction Method", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
@bgolus
bgolus / MobileVRHighlight.shader
Last active October 25, 2023 01:44
A mobile VR and MSAA friendly single object highlight shader using the stencil buffer
Shader "Mobile VR Highlight" {
Properties {
_ColorOutline ("Outline", Color) = (1,1,1,1)
_ColorInterior ("Interior", Color) = (0.25,0.25,0.25,0.25)
_ColorInteriorFaded ("Interior Faded", Color) = (0.1,0.1,0.1,0.1)
_ColorInteriorOcc ("Interior Occluded", Color) = (0.15,0.15,0.15,0.15)
_ColorInteriorOccFaded ("Interior Occluded Faded", Color) = (0.05,0.05,0.05,0.05)
_PulseRateMod ("Pulse Rate Modifier", Float) = 4.0
_OutlneWidth ("Outline Pixel Width", Float) = 1.0
}
@bgolus
bgolus / MatCapTechniques.shader
Created January 29, 2022 00:37
Showing multiple matcap techniques, including a proposed improved method that's no more expensive than the usual fix if you're starting with the world position and world normal.
Shader "Unlit/MatCap Techniques"
{
Properties
{
[NoScaleOffset] _MatCap ("MatCap", 2D) = "white" {}
[KeywordEnum(ViewSpaceNormal, ViewDirectionCross, ViewDirectionAligned)] _MatCapType ("Matcap UV Type", Float) = 2
}
SubShader
{
Tags { "RenderType"="Opaque" }
@bgolus
bgolus / InfiniteGrid.shader
Last active January 20, 2024 05:11
Infinite Grid shader with procedural grid with configurable divisions and major and minor lines markings.
Shader "Unlit/InfiniteGrid"
{
Properties
{
[Toggle] _WorldUV ("Use World Space UV", Float) = 1.0
_GridScale ("Grid Scale", Float) = 1.0
_GridBias ("Grid Bias", Float) = 0.5
_GridDiv ("Grid Divisions", Float) = 10.0
_BaseColor ("Base Color", Color) = (0,0,0,1)
_LineColor ("Line Color", Color) = (1,1,1,1)