Skip to content

Instantly share code, notes, and snippets.

void TexelSnap_float(float3 WorldPos, float4 UV0, float4 TexelSize, out float3 SnappedWorldPos)
{
// 1.) Calculate how much the texture UV coords need to
// shift to be at the center of the nearest texel.
float2 originalUV = UV0.xy;
float2 centerUV = floor(originalUV * (TexelSize.zw))/TexelSize.zw + (TexelSize.xy/2.0);
float2 dUV = (centerUV - originalUV);
// 2b.) Calculate how much the texture coords vary over fragment space.
// This essentially defines a 2x2 matrix that gets
@antonkudin
antonkudin / RenameAttribute.cs
Created November 21, 2023 02:49
Rename variable names inside your properties
using UnityEngine;
#if UNITY_EDITOR
[System.AttributeUsage(System.AttributeTargets.Field)]
public class RenameAttribute : PropertyAttribute
{
public string[] renamePairs;
public RenameAttribute(params string[] renamePairs)
{
@antonkudin
antonkudin / nudgeVertex.py
Last active January 2, 2024 03:18
Nudge selection in a direction
bl_info = {
"name": "Move Vertices by Direction",
"blender": (2, 80, 0),
"category": "Mesh",
}
import bpy
from bpy.types import Operator
from bpy.props import FloatProperty, BoolProperty
from mathutils import Vector, Matrix
@antonkudin
antonkudin / spherefog.shader
Last active January 9, 2024 05:55
Spherical fog unity shader
// original from https://forum.unity3d.com/threads/share-volume-fog-shader.147323/
Shader "Effect/SphereFog" {
Properties {
_FogColor ("Fog Color", Color) = (1,1,1,1)
[space]
_Density ("Density", Float) = 1
_Power ("Power/gamma", Float) = 4
_Offset ("Offset", Range(-.1,.1)) = -0.003
[space]
_NearbyOffset ("Nearby Offset", Float) = -1
@antonkudin
antonkudin / pipeGenerator.cs
Created September 26, 2023 13:48
Generates pipe mesh from mesh segments
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pipeGenerator : MonoBehaviour
{
[SerializeField] Mesh straightMesh;
[SerializeField] Mesh elbowMesh;
[Space]
[SerializeField] Vector3[] pathPoints;
@antonkudin
antonkudin / Mathfx.cs
Created December 14, 2022 16:22
Adjust path so segments of path are more or less the same length
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mathfx
{
public static void normalizePoints(ref List<Vector2> path) {
float length = 0;
List<float> lengths = UnityEngine.Pool.GenericPool<List<float>>.Get();
class treeThing {
// tree design: all the changable variables in one place!
struct treeStyle {
// skipping stuff like how many branches per tree, sticks per branch..
// sticks
Vector2 stickAngleJagMM; // how jaggy the branches are (min-max)
Vector2 stickLengthMM; // how long the sticks are (min-max)
@antonkudin
antonkudin / logoAssembler.cs
Last active May 2, 2019 10:34
MegaSphere logo assembler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class logoAssembler : MonoBehaviour {
[SerializeField] bool debugMe;
[SerializeField] bool remakePixels;
[SerializeField] bool autoPlay;
[SerializeField][Range(0,10)] float autoDur = 10;
// threshold for mask can be controlled using vertex color alpha (useful for spriteRenderers or particle systems)
// _MainTex: alpha of this texture is used as a mask
// _EmissionTex: usually rgb noise texture, adjust it's scaling if needed
// color remap and oscilation for each channel of emission can be modified in _EmStrobeBFALR, _EmStrobeBFALG, _EmStrobeBFALB
// Base: base amplitude of brightness oscilation
// Freq: frequency of oscilation
// Ampl: amplitude of oscilation
// L: how much _EmissionTex affects this color
Shader "StandardWMask" {
// c# companion script
// SpriteUVToShader.cs -------------------------------------------------------------------------------------------------------------------------------- //
// Save you your project, add to your SpriteRenderer gameObject
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]