Skip to content

Instantly share code, notes, and snippets.

View pema99's full-sized avatar

Pema Malling pema99

View GitHub Profile
@pema99
pema99 / SlangMarcher.shader
Created May 5, 2024 22:31
Slang Raymarcher
Shader "pema99/SlangMarcher"
{
Properties
{
_Iterations ("Max iterations", Float) = 128
_MaxDist ("Max distance", Float) = 50
_MinDist ("Min distance", Float) = 0.001
}
SubShader
{
@pema99
pema99 / QuadLightEmitter.cs
Created March 21, 2024 23:04
Analytical polygonal irradiance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteAlways]
public class QuadLightEmitter : MonoBehaviour
{
[ColorUsage(false, true)]
public Color color = Color.white;
public Transform[] verts;
@pema99
pema99 / BufferMap.cs
Last active October 20, 2023 20:31
BufferMap - A dense, associative map from handle to value, with O(1) amortized complexity for all operations.
// SPDX-License-Identifier: MIT
// Author: pema99
// This file contains an implementation of a data structure I've named a BufferMap.
// It works as a map from 'handles' to values, where handles are just integers.
// You insert values into the map, and are returned an automatically generated handle.
// You can then use this handle to retrieve the value, or remove it from the map.
// Handles are never invalidated until they are explicitly removed.
// Amortized time complexities for adding, removing and getting a value from
// the map are all O(1). Additionally, the data structure has the property that
@pema99
pema99 / QuadIntrinsics.cginc
Last active May 20, 2024 04:42
Emulated Quad and Wave intrinsics for basic fragment shaders
// SPDX-License-Identifier: MIT
// Author: pema99
// This file contains functions that simulate Quad and Wave Intrinsics without access to either.
// For more information on those, see: https://github.com/Microsoft/DirectXShaderCompiler/wiki/Wave-Intrinsics
// To use the functions, you must call SETUP_QUAD_INTRINSICS(pos) at the start of your fragment shader,
// where 'pos' is the pixel position, ie. the fragment input variable with the SV_Position semantic.
// Note that some functions will require SM 5.0, ie. #pragma target 5.0.
@pema99
pema99 / WorldPositionFromDepth.shader
Created September 15, 2023 19:24
WorldPositionFromDepth thx d4rkpl4y3r and lox
Shader "Unlit/GridAllocation"
{
SubShader
{
Tags { "Queue" = "Overlay" }
ZTest Always
Pass
{
CGPROGRAM
@pema99
pema99 / AudioLinkUI.shader
Last active February 26, 2024 09:12
AudioLinkUI V3
Shader "AudioLink/AudioLinkUI"
{
Properties
{
_Gain("Gain", Range(0, 2)) = 1.0
[ToggleUI] _Autogain("Autogain", Float) = 0.0
_Threshold0("Low Threshold", Range(0, 1)) = 0.5
_Threshold1("Low Mid Threshold", Range(0, 1)) = 0.5
_Threshold2("High Mid Threshold", Range(0, 1)) = 0.5
Shader "Unlit/Shadowed"
{
SubShader
{
Pass
{
Tags { "LightMode"="Always" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
Shader "Unlit/AudioLinkUI"
{
Properties
{
}
SubShader
{
Pass
{
CGPROGRAM
float3 drawTopArea(float2 uv)
{
float3 color = FOREGROUND_COLOR;
float areaWidth = 1.0 - FRAME_MARGIN * 2;
float areaHeight = 0.35;
float boxWidth = areaWidth / 4.0;
for (uint i = 0; i < 4; i++)
{
float3 drawTopArea(float2 uv)
{
float3 color = FOREGROUND_COLOR;
float areaWidth = 1.0 - FRAME_MARGIN * 2;
float areaHeight = 0.35;
float boxWidth = areaWidth / 4.0;
for (uint i = 0; i < 4; i++)
{