Skip to content

Instantly share code, notes, and snippets.

/*
© 2010 Jens Ayton
This code may be used freely.
*/
uniform float uValue; // Value/brighness component.
const float kPi = 3.141592653589793;
/*
© 2010 Jens Ayton
This code may be used freely.
*/
uniform float uValue; // Value/brighness component.
const float kPi = 3.141592653589793;
@rygorous
rygorous / gl_leak_check.c
Last active August 29, 2015 13:57
DYI GL object leak checker.
static void check_for_leaks()
{
GLuint max_id = 10000; // better idea would be to keep track of assigned names.
GLuint id;
// if brute force doesn't work, you're not applying it hard enough
for ( id = 1 ; id <= max_id ; id++ )
{
#define CHECK( type ) if ( glIs##type( id ) ) fprintf( stderr, "GLX: leaked " #type " handle 0x%x\n", (unsigned int) id )
CHECK( Texture );
@castano
castano / hemicube.cpp
Created June 20, 2014 09:46
Hemicube Integrator
#include "hemicube.h"
#define PACK_HEMICUBES 1
static void get_hemicube_face_normal(int index, Vector3 *forward, Vector3 *left, Vector3 *up) {
// Unwrapped hemicube with positive-Z in the middle.
switch (index) {
case 0: *forward = Vector3(+1, 0, 0); *left = Vector3( 0, 1, 0); break;
template<class T>
class range
{
public:
class range_iterator
{
public:
range_iterator(const T Position_) : Position(Position_)
{
}
@dwilliamson
dwilliamson / SH.h
Last active July 12, 2021 13:32
Shared SH Library for C++/HLSL/OpenCL/CUDA using pycgen to generate/document optimal transforms
//
// References
//
// [1] Sloan, P.-P., Luna, B., and Snyder, J. 2005.
// Local, deformable precomputedradiance transfer.
// ACM Trans. Graph. 24, 3, 1216–1223
//
// [2] Stupid Spherical Harmonics (SH) Tricks
// Peter-Pike Sloan, Microsoft Corporation
@memononen
memononen / gist:cef31ababbfa6cde5eea
Created November 23, 2014 19:05
Drawing clipped anti-aliased graph using triangle strip
// Draws a graph using a triangle strip and simple gradient texture.
// Anti-aliasing may be off by a half a pixel.
// Works reasonable well with smooth as well as noisy data.
// The basic idea is that we draw the graph using a full height quad (or two triangles)
// per segment between two samples, and then we calculate texture coordinates
// so that 1px anti-aliasing gradient passes through the data points. The texture coordinate
// is calculated using the segment normal and one segment end point.
struct Point {
float x, y;
@ocornut
ocornut / printf_tips.cpp
Last active March 24, 2023 11:23
C/C++ tips for using printf-style functions
// C/C++ tips for using printf-style functions
// Lots of manipulation can be expressed simply and fast with printf-style formatting
// Also helps reducing the number of temporaries, memory allocations or copies
// ( If you are looking for a simple C++ string class that is printf-friendly and not heap-abusive,
// I've been using this one: https://github.com/ocornut/Str )
// If you are interested in a FASTER implementation of sprintf functions, see stb_sprintf.h
// https://github.com/nothings/stb/blob/master/stb_sprintf.h
// How to concatenate non-zero terminated strings
@BeRo1985
BeRo1985 / order_independent_transparency.glsl
Last active May 10, 2019 21:32
Hybrid atomic loop weighted blended order independent transparency implementation
// Hybrid atomic loop weighted blended order independent transparency implementation (work in progress)
// Copyright (C) 2014 by Benjamin 'BeRo' Rosseaux
// Licensed under the CC0 license, since in the German legislation exists no public
// domain.
// This implementation needs at least OpenGL 4.3 as minimum OpenGL version, due to my usage of shader storage buffer objects here
// Supports also additive blending for emission color portions
uniform sampler2D uTexTailWeightedBlendedOrderIndependentTransparencyColor;
@dwilliamson
dwilliamson / SphereIndexing.hlsl
Created July 30, 2015 23:50
Faster Sphere Indexing
float3 PositionToOctahedron(float3 position)
{
// Normalize input position to unit sphere to simplify required ops
float3 P = normalize(position);
// Get octant index
float3 side = P >= 0 ? 1 : 0;
float octant_index = side.x + side.y * 2 + side.z * 4;
// Project onto octahedron face, then onto each x/y plane