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 / gist:783703
Created January 17, 2011 23:34
GLSL Bumped Specular
// Final for now...
// iPhone 3Gs: 5.9ms
#ifdef VERTEX
attribute vec4 a_position;
attribute vec2 a_uv;
attribute vec3 a_normal;
attribute vec4 a_tangent;
uniform mat4 u_mvp;
@aras-p
aras-p / gist:783759
Created January 18, 2011 00:12
Lighting texture creation
// lr,lg,lb - light color
// spec = specular power
int idx = 0;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x, idx+=4)
{
float vx = float(x) / width;
float vy = float(y) / height;
float nl = vx;
@aras-p
aras-p / gist:783784
Created January 18, 2011 00:31
GLSL Bumped Specular Initial
#ifdef VERTEX
attribute vec4 a_position;
attribute vec2 a_uv;
attribute vec3 a_normal;
attribute vec4 a_tangent;
uniform mat4 u_mvp;
uniform mat4 u_world2object;
uniform vec4 u_worldlightdir;
uniform vec4 u_worldcampos;
@aras-p
aras-p / delete-tags-from-remote.sh
Created April 11, 2011 18:19
Delete tags from remote git repository
# deletes all local tags
git tag | xargs git tag -d
# deletes all remote tags: list remote tags, skip ones that end with "{}", push remote deletion
git ls-remote --tags | awk '!/\{\}$/ {print ":"$2}' | xargs git push origin
@aras-p
aras-p / hacktified.css
Created April 17, 2011 13:42
Messing with syntax highlighting for altdevblogaday
.wp_syntax, .wp_syntax .line_numbers, .wp_syntax .code, .wp_syntax pre {
background-color: #f8f8f8;
color: #111;
font-family: Consolas, Lucida Console, Monaco, monospace;
}
.wp_syntax {
border-radius: 5px;
margin: 0 0 1.5em 0;
border: 1px solid #ddd;
@aras-p
aras-p / iPad2Crash.shader
Created May 18, 2011 16:16
Shader crashes on iPad 2
/* Both vertex & fragment shaders (define VERTEX or FRAGMENT before loading each).
Looks like crash caused by indexing into uniform array. Crash goes away if:
1) replacing array indices [i] with actual constants (0 & 1) and removing index math, OR
2) removing unrelated ALU ops (' - viewpos'), OR
3) rewriting shader to not be unrolled; using for (int i = 0; i < 2; ++i) loop.
Shader by itself does not make any practical sense, I just simplified a more complex shader to smallest that still crashes.
Crashes inside PVR driver on iPad 2, iOS 4.3:
@aras-p
aras-p / iPad2Crash2.c
Created June 1, 2011 07:25
iPad2 another driver crash
/*
Crashes iPad 2, iOS 4.3. Thread 0 Crashed:
0 IMGSGX543GLDriver 0x30c28b92 UpdateShaderParams + 14
1 IMGSGX543GLDriver 0x30c29266 glrUpdateCtxSysFragmentProgram + 1406
2 IMGSGX543GLDriver 0x30c21970 glrUpdateFragmentProgramInline + 292
3 IMGSGX543GLDriver 0x30c21e58 glrLoadCurrentPipelinePrograms + 576
4 IMGSGX543GLDriver 0x30c2a54c gldUpdateDispatch + 856
5 GLEngine 0x35ca1bac gleDoDrawDispatchCore + 252
6 GLEngine 0x35c285cc glDrawArrays_IMM_Exec + 208
7 OpenGLES 0x30bd2edc glDrawArrays + 28
@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 / glsl.c
Created September 5, 2011 19:43
GLSL uniforms foo
// i = uniform location of vec4 array
// this is fine
glUniform4fv (i, 4, GL_FALSE, ptr); // load 4 elements of an array
// this is NOT fine!
glUniform4fv (i+0, 1, GL_FALSE, ptr); // this will set one element of an array
glUniform4fv (i+1, 1, GL_FALSE, ptr+4); // this and following may or might not work!
glUniform4fv (i+2, 1, GL_FALSE, ptr+8);
glUniform4fv (i+3, 1, GL_FALSE, ptr+12);
@aras-p
aras-p / rgbm.c
Created September 7, 2011 04:50
Encoding to RGBM
// in our case,
const float kRGBMMaxRange = 8.0f;
const float kOneOverRGBMMaxRange = 1.0f / kRGBMMaxRange;
// encode to RGBM, c = ARGB colors in 0..1 floats
float r = c[1] * kOneOverRGBMMaxRange;
float g = c[2] * kOneOverRGBMMaxRange;
float b = c[3] * kOneOverRGBMMaxRange;