This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check if a tile is visible onscreen using it's MVP transform. | |
static inline bool MapTileFrustumCull(const mat4 mvp){ | |
// Clip space center and extents. | |
vec4 c = {mvp.m[12], mvp.m[13], mvp.m[14], mvp.m[15]}; | |
vfloat ex = vabs(mvp.m[ 0]) + vabs(mvp.m[ 4]) + vabs(mvp.m[ 8]); | |
vfloat ey = vabs(mvp.m[ 1]) + vabs(mvp.m[ 5]) + vabs(mvp.m[ 9]); | |
vfloat ez = vabs(mvp.m[ 2]) + vabs(mvp.m[ 6]) + vabs(mvp.m[10]); | |
// Check the bounds against the clip space viewport using a conservative w-value. | |
vfloat w = vmax(0, c.w + vabs(mvp.m[ 3]) + vabs(mvp.m[ 7]) + vabs(mvp.m[11])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <math.h> | |
#include <stdio.h> | |
#include <GL/gl.h> | |
// A vaguely SDL-like API | |
void iSDL_init(void); | |
bool iSDL_should_exit; | |
void iSDL_swap_buffers(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double delta_time_filtered(double dt_nanos){ | |
// Warm start the filter by assuming 60 Hz. | |
static double x[] = {1.6e7, 1.6e7, 1.6e7}, y[] = {1.6e7, 1.6e7, 1.6e7}; | |
// IIR filter coefficients. 2rd order lowpass butterworth at 1/128 the sample rate. | |
static const double b[] = {6.321391700454014e-5, 0.00012642783400908025, 6.321391700454014e-5}; | |
static const double a[] = {1.0, -1.9681971279272976, 0.9684499835953156}; | |
// Apply IIR filter coefficients. | |
double value = b[0]*dt_nanos; | |
for(uint i = 2; i > 0; i--){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void do_zoom(AppState* app, tina* coro, int button, double direction){ | |
if(glfwGetMouseButton(app->window, button) != GLFW_PRESS) return; | |
Camera* cam = &app->camera; | |
double speed = 0; | |
double t0 = glfwGetTime(); | |
while(glfwGetMouseButton(app->window, button) == GLFW_PRESS){ | |
double t1 = glfwGetTime(); | |
double dt = t1 - t0; | |
t0 = t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include "tracy/TracyC.h" | |
#include "drift_game.h" | |
typedef struct PhysicsContext PhysicsContext; | |
typedef struct { | |
uint idx0, idx1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Appologies for the messy code. | |
// It was run through SPIRV-Cross | |
// I cleaned it up and renamed the variables by hand. | |
#version 330 | |
layout(std140) uniform Locals | |
{ | |
mat2x4 LightMatrix; | |
float LightRadius; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Used for culling tiles in a map renderer I wrote. | |
* All tiles used geometry in the [-1, 1] range, and their mvp matrix would get precalculated. | |
* So it was simply a matter of seeing if their projected OBB overlapped with the screen's clip space. | |
* Returns true if the cube is visible. (false positives for near misses due to conservative w-value) | |
*/ | |
static inline bool MapTileFrustumCull(const mat4 mvp){ | |
// Clip space center of the cube is the last column of the matrix. | |
vec4 c = {mvp.m[12], mvp.m[13], mvp.m[14], mvp.m[15]}; | |
// Clip space extents are the component wise absolute values of the first three columns. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FragOutput { | |
half4 a0 : SV_TARGET0; | |
half4 a1 : SV_TARGET1; | |
half4 b1 : SV_TARGET2; | |
half4 a2 : SV_TARGET3; | |
half4 b2 : SV_TARGET4; | |
}; | |
// Double angle formula derived from the trig identity. | |
float2 DoubleAngle(float2 n){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline fixed mulx_fast(fixed x, fixed y){return (fixed){(x.asint >> 8) * (y.asint >> 8)};} | |
static inline fixed mulx(fixed x, fixed y){ | |
bool neg = (x.asint ^ y.asint) < 0; | |
union { | |
u32 asint; | |
struct {u16 hi, lo;}; | |
} _x, _y; | |
if(x.asint >= 0) _x.asint = x.asint; else _x.asint = -x.asint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
00000204 <start>: | |
204: 1039 00a1 0001 moveb a10001 <VDP_REG_DMA_SRC2+0xa06901>,%d0 | |
20a: 0200 000f andib #15,%d0 | |
20e: 6700 000c beqw 21c <start+0x18> | |
212: 23fc 04fd 1e0d movel #83697165,a14000 <VDP_REG_DMA_SRC2+0xa0a900> | |
218: 00a1 4000 | |
21c: 4a79 00c0 0004 tstw c00004 <VDP_CTRL> | |
222: 41f9 00c0 0004 lea c00004 <VDP_CTRL>,%a0 | |
228: 30bc 8004 movew #-32764,%a0@ | |
22c: 30bc 8144 movew #-32444,%a0@ |
NewerOlder