Skip to content

Instantly share code, notes, and snippets.

@reinsteam
reinsteam / import_sdkmesh.h
Last active December 25, 2015 21:19
Sample of parsing Microsoft .sdkmesh format frequently used in samples
#pragma once
typedef unsigned long long u64;
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef signed char i8;
typedef float f32;
#define MAX_PATH 260
@reinsteam
reinsteam / tbn_from_quat.c
Last active October 15, 2020 03:05
Snippet to calculate TBN basis from quaternion in 8 instructions (seems like this one is used at Crytek: http://www.crytek.com/download/izfrey_siggraph2011.pdf)
/*----------------------------------------------------------------------------------------------------------------------
Custom cross-product: mad + mul
----------------------------------------------------------------------------------------------------------------------*/
half3 crs(half3 v0, half3 v1)
{
//return cross(v0, v1);
half3 v0_0 = v0.yzx;
half3 v0_1 = v1.zxy;
half3 v1_0 = v0.zxy;
half3 v1_1 = v1.yzx;
@reinsteam
reinsteam / AoS2SoA.c
Last active August 29, 2015 14:13
AoS => SoA transformation for 3-component vectors
/*----------------------------------------------------------------------------------------------------------------------
input : srcStream => four 3-component vectors : x0y0z0 x1y1z1 x2y2z2 x3y3z3
output : dstStream => three 4-component vectors : x0x1x2x3 y0y1y2y3 z0z1z2z3
----------------------------------------------------------------------------------------------------------------------*/
void AoS2SoA(float * __restrict dstStream, float const * __restrict srcStream)
{
__m128 x1_y1_z1_x2 = _mm_load_ps(srcStream + 0);
__m128 y2_z2_x3_y3 = _mm_load_ps(srcStream + 4);
__m128 z3_x4_y4_z4 = _mm_load_ps(srcStream + 8);
@reinsteam
reinsteam / log2_avx2_packet.asm
Last active August 29, 2015 14:21
log2 computation (12-16 at a time) using SSE2/AVX2 instruction set based on minimax polynomial approximation (coefficients finding is based on Remez Exchange algorithm)
.data
cval_one DD 03f800000r ; 1
DD 03f800000r ; 1
DD 03f800000r ; 1
DD 03f800000r ; 1
DD 03f800000r ; 1
DD 03f800000r ; 1
DD 03f800000r ; 1
DD 03f800000r ; 1
@reinsteam
reinsteam / UnityMipColorsTexture.cs
Last active October 17, 2015 12:56
Snippet for generation helper texture for mip level colorization (http://aras-p.info/blog/2011/05/03/a-way-to-visualize-mip-levels/)
static public Texture2D CreateMipColorsTexture()
{
var MipColorsTexture = new Texture2D(32, 32, TextureFormat.ARGB32, true);
MipColorsTexture.hideFlags = HideFlags.HideAndDontSave;
Color[] colorArray = new Color[6]
{
new Color(0.0f, 0.0f, 1.0f, 0.8f),
new Color(0.0f, 0.5f, 1.0f, 0.4f),
new Color(1.0f, 1.0f, 1.0f, 0.0f),
@reinsteam
reinsteam / transpose_4x4_sse.c
Last active October 17, 2015 12:48
Alternative transpose methods comparing to _MM_TRANSPOSE4_PS defined in xmmintrin.h without shufps
static void transpose_4x4_ver0(__m128 & v0, __m128 & v1, __m128 v2, __m128 v3)
{
__m128 a0 = _mm_unpacklo_ps(v0, v1); /* a0 = { x0, x1, y0, y1 } */
__m128 a1 = _mm_unpackhi_ps(v0, v1); /* a1 = { z0, z1, z0, z1 } */
__m128 a2 = _mm_unpacklo_ps(v2, v3); /* a2 = { x2, x3, y2, y3 } */
__m128 a3 = _mm_unpackhi_ps(v2, v3); /* a3 = { z2, z3, z2, z3 } */
v0 = _mm_unpacklo_ps(a0, a2); /* v0 = { x0, x1, x2, x3 } */
v1 = _mm_unpackhi_ps(a0, a2); /* v1 = { y0, y1, y2, y3 } */
Build
{
Units = function ()
local prog = Program
{
Name = "project_name",
Sources = { "main.c" },
-- Place in MSVC solution folder.
using UnityEngine;
using UnityEditor;
using System.IO;
public class BakeCubemap : ScriptableWizard
{
public Transform CapturePosition;
public int Antialiasing = 4;
public int CubemapResolution = 128;
@reinsteam
reinsteam / enum_heaps.c
Created August 28, 2015 11:51
Sample code of heap enumeration without using Tool Help functions <tlhelp32.h>
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
#endif
#pragma warning (push)
/* 4820: '<struct-name>' : 'n' bytes padding added after data member '<member-name>'*/
# pragma warning (disable : 4820)
# include <windows.h>
# include <stdio.h>
@reinsteam
reinsteam / enum_volume.c
Created August 28, 2015 23:17
Sample code of volumes enumeration to get physical and logical sector alignment
#pragma warning (push)
/* 4820: '<struct-name>' : 'n' bytes padding added after data member '<member-name>'*/
# pragma warning (disable : 4820)
# pragma warning (disable : 4255 4668)
# include <windows.h>
# include <stdio.h>
#pragma warning (pop)
typedef unsigned u32;