Skip to content

Instantly share code, notes, and snippets.

View gerard-geer's full-sized avatar

Gerard Geer gerard-geer

  • Fort Worth, TX
View GitHub Profile
@gerard-geer
gerard-geer / type-agnostic-glsl-array.glsl
Created July 24, 2015 10:22
A rudimentary approach to emulating non-uniform, type-agnostic arrays in GLSL.
// By Gerard Geer, under MIT license
// A 2,4,8 or 16 element array implemented as a binary tree, #defined for type agnosticity.
#define ARR2(x, a,b) (x<1) ? a : b
#define ARR4(x, a,b,c,d) (x<2) ? ARR2(x,a,b) : ARR2(x-2,c,d)
#define ARR8(x, a,b,c,d, e,f,g,h) (x<4) ? ARR4(x, a,b,c,d) : ARR4(x-4, e,f,g,h)
#define ARR16(x, a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p) (x<8) ? ARR8(x, a,b,c,d, e,f,g,h) : ARR8(x-8, i,j,k,l, m,n,o,p)
// Shadertoy entry point.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
@gerard-geer
gerard-geer / random-dots.glsl
Created September 4, 2015 05:56
Random dots in pure GLSL.
/*
The same old random function with a different signature.
*/
vec2 rand(vec2 co){
return vec2(
fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453),
fract(cos(dot(co.yx ,vec2(8.64947,45.097))) * 43758.5453)
)*2.0-1.0;
}
@gerard-geer
gerard-geer / warped_dirs.frag
Last active October 8, 2015 05:33
Never, ever, warp ray directions.
/**
* Written by Gerard Geer.
* License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
*
* Version 1.0
* Version 1.1 Optomized/cleaned up a bit, and did some more documentin'.
* Version 1.2 Gave pipes a clear protective coating. (I made them shiny.)
* I also changed some colors.
* Version 1.3 Functioned out determining reflectivity and deflection. This allowed me
* to add some variation in the reflections in the form of puddles
@gerard-geer
gerard-geer / loadingtextures.cpp
Created March 17, 2017 22:03
Need some help on texture loading
void AFreshMeshActor::UpdateTextureRegions(UTexture2D* Texture, int32 MipIndex,
uint32 NumRegions, FUpdateTextureRegion2D* Regions,
uint32 SrcPitch, uint32 SrcBpp,
uint8* SrcData, bool bFreeData)
{
if (Texture && Texture->Resource)
{
struct FUpdateTextureRegionsData
{
@gerard-geer
gerard-geer / loadingtextures.cpp
Created March 17, 2017 22:03
Need some help on texture loading
void AFreshMeshActor::UpdateTextureRegions(UTexture2D* Texture, int32 MipIndex,
uint32 NumRegions, FUpdateTextureRegion2D* Regions,
uint32 SrcPitch, uint32 SrcBpp,
uint8* SrcData, bool bFreeData)
{
if (Texture && Texture->Resource)
{
struct FUpdateTextureRegionsData
{