Skip to content

Instantly share code, notes, and snippets.

View jdolan's full-sized avatar

Jay Dolan jdolan

View GitHub Profile
@jdolan
jdolan / render_loop.c
Last active January 10, 2023 14:45
This won't work, either..
drawDepthPass();
drawOcclusionQueries();
populateScene();
updateOcclusionQueries();
drawScene();
@jdolan
jdolan / shadowmapping.glsl
Created January 10, 2023 14:35
Shadow sampler of a cubemap array texture in GLSL
uniform samplerCubeArrayShadow texture_shadowmap_cube;
/**
* @return The fraction of the sample that is _not_ shadowed (0.0 - 1.0).
*/
float sample_shadowmap(in light_t light, in int index) {
// the position of the fragment in light space
vec4 position = vec4(light.model.xyz - vertex.model, 1.0);
@jdolan
jdolan / shadow_gs.glsl
Created January 10, 2023 14:34
Point shadows geometry shader using cubemap array texture
void main() {
light_t light = lights[light_index];
vec4 translate = vec4(-light.model.xyz, 0.0);
for (int i = 0; i < 6; i++) {
gl_Layer = light_index * 6 + i;
for (int j = 0; j < 3; j++) {
@jdolan
jdolan / r_occlude_wrong.c
Created January 10, 2023 14:32
Naive OpenGL Occlusion Query implementation (don't do this).
glBeginQuery(GL_ANY_SAMPLES_PASSED, query->name);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, query->elements); // draw the AABB
glEndQuery(GL_ANY_SAMPLES_PASSED);
glGetQueryObjectiv(query->name, GL_QUERY_RESULT, &query->result);
if (query->result) {
// draw the object(s) the query was guarding
}
@jdolan
jdolan / r_occlude.c
Created January 10, 2023 14:29
Decoupling renderer framerate from occlusion query framerate.
/**
* @brief Updates and re-draws active occlusion queries for the current frame.
*/
void R_UpdateOcclusionQueries(r_view_t *view) {
if (!r_occlude->integer) {
return;
}
if (view->flags & VIEW_FLAG_NO_DELTA) {
@jdolan
jdolan / index.html
Created July 23, 2015 18:42
Bassdrive HTML5 player
<audio controls autoplay="autoplay"><source src="http:///shouthost.com.17.streams.bassdrive.com:8200/;stream.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
@jdolan
jdolan / JSON.c
Created December 13, 2014 19:51
Parse a JSON file into a Dictionary and query it with JSONPath.
Data *data = $(alloc(Data), initWithContentsOfFile, path);
Dictionary *dict = $$(JSONSerialization, objectFromData, data, 0);
Number *dataStoreInitConns = $$(JSONPath, objectWithPath, dict0, "$.web-app.servlet[0].init-param.dataStoreInitConns");
assert(10 == (int) dataStoreInitConns->value);
release(data);
release(dict);
@jdolan
jdolan / config.h
Created June 16, 2014 22:59
Quake2World config.h
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 to build a client. */
#define BUILD_CLIENT 1
/* Set to the canonical name of the target machine */
#define BUILD_HOST "x86_64-darwin13.1.0"
/* Define to 1 to build a master server. */
@jdolan
jdolan / r_bsp_model.c
Last active March 7, 2021 23:53
BSP surface unwinding for surface area calculation
/*
* @brief Unwinds the surface, iterating all non-collinear vertices.
*
* @return The next winding point, or NULL if the face is completely unwound.
*/
static const vec_t *R_UnwindBspSurface(const r_bsp_model_t *bsp, const r_bsp_surface_t *surf,
const vec_t *last) {
const int32_t *se = &bsp->surface_edges[surf->first_edge];
const vec_t *v0 = R_BSP_VERTEX(bsp, *se)->position;
@jdolan
jdolan / r_entity.c
Last active December 29, 2015 18:39
Projection shadows
/*
* @brief Applies any configuration and tag alignment, populating the model-view
* matrix for the entity in the process.
*/
static void R_SetMatrixForEntity(r_entity_t *e) {
vec_t *o = e->origin, *a = e->angles;
if (e->parent) {
vec3_t forward, tmp;