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 / preprocessor_fun.h
Last active May 8, 2024 06:45
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 / metal_shader_compiler_cache_location.md
Last active April 26, 2024 18:10
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 / gist:ac4339c040afabea6ee7
Created August 18, 2014 09:13
fog macros WIP
// ------------------------------------------------------------------
// Fog helpers
//
// multi_compile_fog Will compile fog variants.
// UNITY_FOG_COORDS(texcoordindex) Declares the fog data interpolator.
// UNITY_TRANSFER_FOG(outputStruct,clipspacePos) Outputs fog data from the vertex shader.
// UNITY_APPLY_FOG(fogData,col) Applies fog to color "col". Automatically applies black fog when in forward-additive pass.
// Can also use UNITY_APPLY_FOG_COLOR to supply your own fog color.
// In case someone by accident tries to compile fog code in one of the g-buffer or shadow passes:
@aras-p
aras-p / xcode.sh
Last active March 26, 2024 19:48
Blender build options
# windows:
make developer nobuild
cd ..\build_windows_x64_vc17_Release
cmake -DWITH_PYTHON_SAFETY=OFF -DWITH_ASSERT_ABORT=OFF -DWITH_ASSERT_RELEASE=OFF -DWITH_RENDERDOC=ON .
@aras-p
aras-p / ExportDDS.cs
Last active March 24, 2024 08:59
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
@aras-p
aras-p / mvp.js
Created June 6, 2011 17:30
UNITY_MATRIX_MVP et al equivalents in script
// world, view, projection matrices
var world = obj.transform.localToWorldMatrix;
var view = cam.worldToCameraMatrix;
var proj = cam.projectionMatrix;
// the actual projection matrix used in shaders
// is actually massaged a bit to work across all platforms
// (different Z value ranges etc.)
var gpuProj = GL.GetGPUProjectionMatrix (proj, false);
var gpuMV = view * world; // UNITY_MATRIX_MV
@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 / D3D9ByteCode.cpp
Last active January 27, 2024 09:53
D3D9 Shader Bytecode Patching for Half-Pixel Fixup
#include "UnityPrefix.h"
#include "D3D9ByteCode.h"
// D3D9 shader bytecode format on MSDN: https://msdn.microsoft.com/en-us/library/windows/hardware/ff552891.aspx
const UInt32 kD3D9ShaderTypeVertex = 0xFFFE0000;
const UInt32 kD3D9SwizzleShift = 16;
const UInt32 kD3D9NoSwizzle = ((0 << kD3D9SwizzleShift) | (1 << (kD3D9SwizzleShift + 2)) | (2 << (kD3D9SwizzleShift + 4)) | (3 << (kD3D9SwizzleShift + 6)));
@aras-p
aras-p / package_builds_vs2017.cmd
Created April 9, 2019 19:36
Packaging up Visual Studio & Windows 10 SDK for in-repository usage
@echo off
@rem Packages up VS2017 toolchain into builds.7z archive
@set TOOLS_VERSION=14.13.26128
@cd "%~dp0"
@set VC_PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\
@if not exist "%VC_PATH%" goto error_no_vs
@if not exist "%VC_PATH%"Tools\MSVC\%TOOLS_VERSION% goto error_no_vs