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 / 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 "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 / 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 / PostDepthToWorldPos.shader
Last active October 30, 2023 18:14
Get the world position from the camera depth texture with no external dependencies. Works as a post process or on an transparent object in the scene.
Shader "PostDepthToWorldPos"
{
Properties
{
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
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 / 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)
@bgolus
bgolus / PristineRadialGrid.shader
Last active January 31, 2024 11:01
An application of the Pristine Grid technique onto radial grid with atan derivative discontinuity fixes applied. https://bgolus.medium.com/the-best-darn-grid-shader-yet-727f9278b9d8 https://bgolus.medium.com/distinctive-derivative-differences-cce38d36797b
Shader "Pristine Radial Grid"
{
Properties
{
[Toggle] _WorldUV ("Use World Space UV", Float) = 1.0
_GridScale ("Grid Scale", Float) = 1.0
[Toggle] _UseAdaptiveAngularSegments ("Use Adaptive Angular Segment Count", Float) = 0.0
[IntRange] _AngularSegments ("Angular Segments", Range(1,360)) = 4.0
Shader "Pristine Triplanar Grid"
{
Properties
{
[KeywordEnum(World,Object,ObjectAlignedWorld)] _GridSpace ("Grid Space", Float) = 0.0
_GridScale ("Grid Scale", Float) = 1.0
[Toggle(USE_VERTEX_NORMALS)] _UseVertexNormals ("Use Vertex Normals", Float) = 0.0
[Toggle] _ShowOnlyTwo ("Show Only Two Grid Axis", Float) = 0.0
@bgolus
bgolus / PristineMajorMinorGrid.shader
Last active March 8, 2024 13:35
Pristine Grid applied to a grid that has support for major and minor lines and colored axis lines
Shader "Pristine Major Minor Grid"
{
Properties
{
[KeywordEnum(X, Y, Z)] _Axis ("Plane Axis", Float) = 1.0
[IntRange] _MajorGridDiv ("Major Grid Divisions", Range(2,25)) = 10.0
_AxisLineWidth ("Axis Line Width", Range(0,1.0)) = 0.04
_MajorLineWidth ("Major Line Width", Range(0,1.0)) = 0.02
_MinorLineWidth ("Minor Line Width", Range(0,1.0)) = 0.01