Skip to content

Instantly share code, notes, and snippets.

View aras-p's full-sized avatar

Aras Pranckevičius aras-p

View GitHub Profile
@aras-p
aras-p / SceneViewShowMips.shader
Last active January 8, 2025 03:03
Unity editor scene view "show mips" shader (as it is in 5.6 alpha)
/* C# code that sets up the mip colors texture:
s_MipColorsTexture = new Texture2D (32, 32, TextureFormat.RGBA32, true);
s_MipColorsTexture.hideFlags = HideFlags.HideAndDontSave;
Color[] colors = new Color[6];
colors[0] = new Color (0.0f, 0.0f, 1.0f, 0.8f);
colors[1] = new Color (0.0f, 0.5f, 1.0f, 0.4f);
colors[2] = new Color (1.0f, 1.0f, 1.0f, 0.0f); // optimal level
colors[3] = new Color (1.0f, 0.7f, 0.0f, 0.2f);
colors[4] = new Color (1.0f, 0.3f, 0.0f, 0.6f);
colors[5] = new Color (1.0f, 0.0f, 0.0f, 0.8f);
@aras-p
aras-p / preprocessor_fun.h
Last active January 6, 2025 17:59
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@aras-p
aras-p / unity_6_empty_web_build.md
Last active January 1, 2025 09:41
Unity 6 "empty" web build file sizes

This short post by Defold people about "empty project build size" comparison between Defold, Unity and Godot (twitter, mastodon) sparked my interest.

It is curious that Godot builds seem to be larger than Unity? Would not have expected that! Anyway.

A way more extensive Unity "web" build comparison and analysics is over at https://github.com/JohannesDeml/UnityWebGL-LoadingTest but here are just my short notes in trying out Unity 6 (6.0.23 - Oct 2024).

Default (3D, URP) template

@aras-p
aras-p / prefix.shader
Created September 4, 2016 15:56
Prefix to compile Shadertoy shaders to Vulkan/SPIR-V
// pasting this in front of most shadertoys allows them to be compiled with:
// glslangValidator -V inputFile.frag -o outputFile.spv
#version 430
layout(binding = 1, std140) uniform glob {
uniform vec3 iResolution;
uniform float iGlobalTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform float iFrameRate;
uniform float iChannelTime[4];
@aras-p
aras-p / metal_shader_compiler_cache_location.md
Last active October 29, 2024 00:46
Apple Metal Shader Compiler Cache location

As per gfx-rs/gfx#3716 (comment) :

macOS has a system shader cache at $(getconf DARWIN_USER_CACHE_DIR)/com.apple.metal

On my MacBookPro that is under /var/folders/52/l9z1nqld5yg99tb_s3q6nyhh0000gn/C

  • System shaders: /var/folders/52/l9z1nqld5yg99tb_s3q6nyhh0000gn/C/com.apple.metal
  • Blender shaders: /var/folders/52/l9z1nqld5yg99tb_s3q6nyhh0000gn/C/org.blenderfoundation

Delete all the folders in there to clear the cache.

@aras-p
aras-p / Projector Light.shader
Last active September 9, 2024 14:33
Projector shaders without fixed function
Shader "Projector/Light" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_ShadowTex ("Cookie", 2D) = "" {}
_FalloffTex ("FallOff", 2D) = "" {}
}
Subshader {
Pass {
ZWrite Off
@aras-p
aras-p / building_oiio.md
Last active August 11, 2024 21:29
Building OpenImageIO from source locally

Windows

OIIO build instructions currently just say this for Windows:

Method 1 - from source I really need someone to write correct, modern docs about how to build from source on Windows.

So I decided to figure that out.

Easiest: get Blender first :)

@aras-p
aras-p / DebugNode.hlsl
Created January 3, 2020 10:37
"Print a value" custom function node code for Unity ShaderGraph
// Quick try at doing a "print value" node for Unity ShaderGraph.
// Tested on Unity 2019.2.17 with ShaderGraph 6.9.2.
//
// Use with CustomFunction node, with two inputs:
// - Vector1 Value, the value to display,
// - Vector2 UV, the UVs of area to display at.
// And one output:
// - Vector4 Color, the color.
// Function name is DoDebug.
@aras-p
aras-p / fbx_visibility_export.diff
Created February 8, 2023 10:10
Blender FBX Visibility export
diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index c5cd93a7..f15b3a8a 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -1688,7 +1688,8 @@ def fbx_data_object_elements(root, ob_obj, scene_data):
animatable=True, animated=((ob_obj.key, "Lcl Rotation") in scene_data.animated))
elem_props_template_set(tmpl, props, "p_lcl_scaling", b"Lcl Scaling", scale,
animatable=True, animated=((ob_obj.key, "Lcl Scaling") in scene_data.animated))
- elem_props_template_set(tmpl, props, "p_visibility", b"Visibility", float(not ob_obj.hide))
+ elem_props_template_set(tmpl, props, "p_visibility", b"Visibility", float(not ob_obj.hide),
@aras-p
aras-p / ExportDDS.cs
Last active June 6, 2024 02:21
Unity DDS file exporter for compressed textures
// Adds context menu to TextureImporter objects, saves .dds next to input texture, including mipmaps.
// Tested with Unity 2021.3.4
using System;
using UnityEngine;
using UnityEditor;
using System.IO;
using Unity.Collections.LowLevel.Unsafe;
struct DDSHeader