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
using UnityEngine; | |
using System.Collections; | |
// This script is meant to be attached to your main camera. | |
// If you want to use it on more than one camera at a time, it will require | |
// modifcations due to the Camera.on* delegates in OnEnable()/OnDisable(). | |
[ExecuteInEditMode] | |
public class CustomProjection : MonoBehaviour { | |
private void OnEnable(){ |
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
using UnityEngine; | |
using System.Collections; | |
[ExecuteInEditMode] | |
public class TreesCamera : MonoBehaviour { | |
private void OnEnable(){ | |
// Optional, only enable the callbacks when in the editor. | |
if(Application.isEditor){ | |
// These callbacks are invoked for all cameras including the scene view and camera previews. | |
Camera.onPreCull += ScenePreCull; |
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 <stdint.h> | |
#include <stdio.h> | |
#include "disassembler.h" | |
// 6502 instruction tables. | |
enum OPCODE { | |
OP_LDA, OP_LDX, OP_LDY, OP_STA, OP_STX, OP_STY, OP_ADC, OP_SBC, | |
OP_INC, OP_INX, OP_INY, OP_DEC, OP_DEX, OP_DEY, OP_ASL, OP_LSR, | |
OP_ROL, OP_ROR, OP_AND, OP_ORA, OP_EOR, OP_CMP, OP_CPX, OP_CPY, |
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
#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
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
uniform sampler2D texture; | |
varying vec2 uv; | |
void main(){ | |
vec2 size = textureSize(texture); | |
vec2 puv = uv*size; | |
vec2 hfw = 0.5*fwidth(puv); | |
vec2 fl = floor(puv - 0.5) + 0.5; |
NewerOlder