setting cache metadata on files in s3

i use Amazon’s AWS Console for uploading files to S3 and i always have to remember to manually add in the Cache-Control metadata so that i don’t get boned on bandwidth fees. i wish they would put in a nice default for that but oh well. i searched around for a better tool to use that would let me also recursively update the metadata on all my S3 files but the only one that seemed to have that feature and run on OSX cost $70!
read more →

visualizing data structures with svg

so i found dropping SVG to disk is an easy and fun way to visualize or debug data structures. here’s all it takes in C: FILE * fp = fopen("kdtree.svg", "w"); fprintf(fp, "<svg version=&quot;1.1&quot; width=&quot;1024&quot; height=&quot;1024&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;>\n"); fprintf(fp, "<line stroke=&quot;#%06x&quot; stroke-width=&quot;.1&quot; x1=&quot;%f&quot; y1=&quot;%f&quot; x2=&quot;%f&quot; y2=&quot;%f&quot;/>\n", …); fprintf(fp, "</svg>"); what’s nice is then you can load the file up in firefox or inkscape and zoom in. also you can easily draw in other data like triangles and circles or put nodes you’re interested in in different colors and what not.
read more →

quick maya curves export script

i needed a quick script tonight to export a slew of curves outta maya and google failed me so now that i’ve hacked a quick script for it i figure i’ll post it for future lazy coders :) here you go - a simple python script to export curves from maya ;) from maya.cmds import * import maya.OpenMaya as OpenMaya def findNode (name): selectionList = OpenMaya.MSelectionList() selectionList.add(name) node = OpenMaya.MObject() selectionList.
read more →

splines

a couple months ago i needed to look up some spline equations and was disappointed to find there wasn’t any page on the internet with just a nice list of the most common spline equations for graphics. so i wound up making one of my own complete with interactive flash graphics to play with. i forgot to ever post about it here though so i’m doing that now. enjoy: common spline equations for graphics!
read more →

writing binary files with maxscript

recently i’ve written a bunch of maxscripts to export test data from 3dsmax for various things. doing a c++ exporter would be waaay overkill when i just need a quick spline or mesh. thankfully writing binary data from max is trivial. maxscript: f = fopen filename “wb” count = numKnots $ 1 writeLong f count for i = 1 to count do ( p = getKnotPoint $ 1 i writeFloat f p.
read more →

circular harmonics

i was playing with circular harmonics and having quite some fun and since i don’t see a lot about them on the web i wrote up a quick text: circular harmonics.  they’re nice and very simple basis functions.
read more →

photoshop blend modes

i mentioned to merlucin that i had found a nice website awhile back with the formulas for the photoshop blend modes. this is probably useful to others as well so i’ll post it here. www.pegtop.net/delphi/articles/blendmodes/. here’s a summary so you don’t have to navigate through all the links to collect em all. multiply a * b screen 1 - (1 - a) * (1 - b)
read more →

transparency

sorting alpha blended objects back to front gets transparency something like 95% correct in games. that last 5% is a real pain though and happens when you have objects with bounds that overlap so that no matter what order you draw them in you’re going to get errors. sorting the triangles for a transparent object isn’t difficult, but sorting the triangles between objects when those objects have different materials and the two sets of triangles interpenetrate each other
read more →

quick macros

quick macros is a killer feature in devstudio i use all the time that not many other people seem to know about or use.  it’s perfect for quickly automating repetitive changes.  for example if you want to take a large enum and turn it into a table of strings that’s a lot of typing!  instead, using a quick macro just go to the first line, hit ctrl+shift+r then add your quotes, delete any enum prefix, ctrl+u after the first character to get some nice lower case, then finish it off with the cursor on the next line.
read more →

maxscript

i’m in love with maxscript. if you don’t know, it’s the scripting system for 3dsmax. i had some good times with it like five years ago, but we parted ways when when i started using maya. maya has its own scripting system called mel, but i never really hit it off with mel and instead just stuck with c++ plugins. one nice thing with maxscript is that you can write quick exporters
read more →

shed some bytes

hex edit a shader compiled with the HLSL compiler and you’ll see it has added a bunch of extra data. it has an embedded constant table and a big fat string saying the compiler version. if you are making an intro this is wasting bytes! here’s the easiest way to strip that out. compile in two steps instead of one: fxc /nologo /EPixelShader /Tps_1_1 shaders.fx shaderPs.psh psa /FhshaderPs.
read more →

hlsl compiler

microsoft’s HLSL compiler is nice.  it’s amazing that you can do the math behind the ps1.1 texm3x3vspec instruction and the compiler recognizes it and emits a single instruction.  when it does that you get the feeling that the compiler is a sentient genius carefully studying and optimizing your code.  but of course cruel reality eventually steps in and spits in your face! here are some some examples of the HLSL compiler making baby jesus cry:
read more →

add in parallel

add to 64 3-bit numbers in parallel using mmx intrinsics:


__m64 plane0, plane1, plane2; // source bit planes
__m64 out0, out1, out2;       // result bit planes
__m64 x;                      // bits to add
__m64 carry;                  // temp
out0  = _mm_xor_si64(x, plane0);
carry = _mm_and_si64(x, plane0);
out1  = _mm_xor_si64(carry, plane1);
carry = _mm_and_si64(carry, plane1);
out2  = _mm_xor_si64(carry, plane2);

mmx makes me happy :)

filtering trick

here’s how you cut down the number of texture samples needed for a filter. instead of sampling two adjacent pixels, scaling by a weight, and adding, sample at a point in between the pixel and use a different weight. to calculate the offset between the pixels and the new weight just set the two equations equal. p0 * w0 + p1 * w1 = (p0 * (1 - offset) + p1 * offset) * newWeight
read more →

orthonormalization

gram-schmidt orthonormalization is really elegant, but i haven’t had occasion to use it in practice. a common situation i run into requires creating an orthonormal basis from three 3d vectors which start pretty close to orthogonal. for example, say you have a forward vector and also approximate right and up vectors and you want them all orthonormal. sounds like a perfect job for gram-schmidt orthonormalization right? sure, but it’s more efficient to just do two cross products.
read more →

plain text code

writing computer programs in plain text files is ridiculously old fashioned. are documents created in plain text? no. there are WYSIWYG editors and rich document formats. are images created in plain text? no. there are great painting tools where you can visualize and manipulate them in 2D. are three dimensional models created in plain text? again, no. there are tools that visualize and manipulate them in the 3D domain. so are computer
read more →

wish list

here are some random things i want for c++ and devstudio: regular expressions built into the c++ syntax. not some library implementation of regular expressions like boost or the regex in c#, but easy syntax like in perl or ruby. source code styles sheets. instead of putting a line of //===… above every function, just add that as a rule to your style sheet and all code you view gets
read more →

blargh

devstudio kills me when i edit html. i’ll format my html source just perfectly the way i want it then at some point i’ll switch to the design tab to preview it and when i switch back devstudio has mangled the file! it will strip extra lines and move my tags around relative to the text they contain. there’s no reason for this and it’s just cruel and unusual. i’d like to meet the guy responsible for this buggy behavior so i can punch him in the stomach.
read more →

crappy book

my new bathroom book is andrei alexandrescu's modern c++ design. it's fitting because like me when i'm on the can, alexandrescu is full of crap.

test scenes

here's a great way to make simple test scenes:

  1. write a maya translater to export to xml
  2. use ruby and rexml to process the xml into a c header
  3. #include

sse is a pain

mmx is great. sse is not. mmx fits all the uses i try it with just great (64 bit stuff, rgba pixels, etc). everytime i use sse i end up wasting so many cycles shuffling data in and out of memory and between the registers. a horizontal add instruction would help a lot (which sse3 has i think).

texts

i've written some texts. they cover creating cellular textures, making lens flare textures, finding good normals for metaballs, the pq-torus knot, an easy point in triangle test, and a method of packing lightmaps into larger textures. you can read them here