Skip to content

Instantly share code, notes, and snippets.

@ShiftedClock
ShiftedClock / TrackTransform.cs
Last active March 10, 2023 07:11
Unity component to make one transform track another transform's position, rotation, and scale with optional offset fields for each. Intended for Edit mode.
using UnityEngine;
[ExecuteAlways]
public class TrackTransform : MonoBehaviour
{
[SerializeField]
private Transform target;
[SerializeField]
private Vector3 positionOffset = Vector3.zero;
[numthreads(8,8,1)]
void RayMarchKernel (uint3 id : SV_DispatchThreadID)
{
const float2 uv = float2(id.xy) / screenSize.xy;
const float deviceDepth = LoadCameraDepth(id.xy); // This can be omitted if you're just finding rd
const float z = (1.0 - deviceDepth) * 2.0 - 1.0; // [-1, 1]
const float4 clip = float4(uv * 2.0 - 1.0, z, 1.0); // ([-1, 1], [-1, 1], z, 1)
float4 view = mul(cameraInvProj, clip);
view /= view.w; // perspective correction
const float3 depthPosition = mul(cameraToWorld, view).xyz;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
+CapsLock::CapsLock
CapsLock::Escape
Shader "FullScreen/CopyColorAndDepth"
{
HLSLINCLUDE
#pragma vertex Vert
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl"
using UnityEngine;
public class PolarCharacterController {
[SerializeField] private float moveSpeed;
private PolarCoordinate pc;
public void Awake () {
pc = new PolarCoordinate(transform);
}
@ShiftedClock
ShiftedClock / LoopyIndex.cs
Created September 22, 2019 08:45
Integer that can only be incremented and decremented, and loops around
class LoopyIndex {
private int basement;
private int ceiling;
private int value;
private int initialValue;
public LoopyIndex (int basement, int ceiling, int initialValue) {
this.basement = basement;
this.ceiling = ceiling;
//TODO: Error checking to make sure initialValue is between basement and ceiling.
// Author : Sébastien Bérubé
// Created : Dec 2014
// Modified : Feb 2016
//
// Ice raymarching experiment, built on top of primitives shader from Inigo Quilez :
// https://www.shadertoy.com/view/Xds3zN
//
// You can play with the sliders : 1-Normal map scale
// 2-Isosurface thickness
// 3-Color / refraction normal / other debug stuff
@ShiftedClock
ShiftedClock / AmbientOcclusion.cginc
Created April 27, 2019 09:18
An ambient occlusion routine for a raymarched shader
uniform float _AoStepsize, _AoIntensity;
uniform int _AoIterations;
float AmbientOcclusion(float3 ro, float3 p, float3 re, float3 n) {
float step = _AoStepsize;
float ao = 0.0;
float dist;
for (int i = 1; i <= _AoIterations; i++) {
dist = step * i;
ao += max(0.0,(dist - distanceField(ro, p + n * dist, re).w) / dist);
#define M_PI 3.1415926535897932384626433832795
#define M_2PI 6.2831853071795864769252867665590
#define SKY_R 60.0 // inner radius of sky sphere
#define TRANS_MAT 2.0 // largest material ID for transparent materials
// Many, many thanks to IQ for providing the incredibly helpful sample
// code for getting started with ray marching: https://www.shadertoy.com/view/Xds3zN
precision mediump float;
uniform float time;
uniform vec2 uResolution;
@ShiftedClock
ShiftedClock / Scene0.cginc
Last active April 5, 2019 20:14
Raymarching setup
uniform float4x4 _cubeMatrix;
uniform float3 _cubeScale;
uniform float4x4 _hexagonMatrix;
uniform float _hexagonWidth;
uniform float _hexagonHeight;
float Scene0 (float3 p) {
float res;
float3 cubMat = mul(_cubeMatrix, float4(p,1)).xyz;