Skip to content

Instantly share code, notes, and snippets.

What's changed is that semitransparent and additive cards used to be cross-processed independently of what was behind them, and now the final image gets cross-processed only once. In general this results in several scenes which were previously very blue being less so, clouds no longer have a blue halo around them, and grain uniformly covers the screen. Here are some before-and-afters of the most affected areas:

20220413093211_1 20220413093400_1 20220413103517_1 20220413104135_1 ![20220413104331_1](https://user-images.githubusercontent.com/37276056/163223895-8411980e-c6af-4da6-8f01-0fd60b9f430

@notnullnotvoid
notnullnotvoid / b2deepclone.cpp
Created February 17, 2022 07:03
the box2d cloning code from sir happenlance, just for reference for those who might find it useful - it relies heavily on the block allocator strategy used by box2d so the strategy here wouldn't work if you replace the allocator with someting radically different
#include "b2deepclone.hpp"
#include "level.hpp"
#include "box2d.h"
#include "trace.hpp"
//definitions copied from b2_block_allocator.cpp
static const int32 b2_chunkSize = 16 * 1024;
struct b2Chunk {
int32 blockSize;
b2Block* blocks;
@notnullnotvoid
notnullnotvoid / wc.cpp
Last active February 8, 2020 16:31
Optimizing simultaneous word and line counting for HMN
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
//NOTE: the correct behavior of this function is unfortunately not guaranteed by the standard
static char * read_entire_file(const char * filepath) {
FILE * f = fopen(filepath, "rb");
assert(f);
@notnullnotvoid
notnullnotvoid / List.hpp
Created June 27, 2019 06:54
Rounding polygon corners
#ifndef ARRAYLIST_HPP
#define ARRAYLIST_HPP
#include <stdlib.h>
#include <assert.h>
#include <string.h>
//NOTE: this struct zero-initializes to a valid state!
// List<T> list = {}; //this is valid
template <typename TYPE>
@notnullnotvoid
notnullnotvoid / LineRenderer.cpp
Last active January 31, 2023 19:36
Line rendering code
/*
IMPORTANT INFO:
This code is made to be renderer-agnostic.
You would complete the implementation by implementing the triangle() function for your particular renderer.
The code is not written to make use of an index buffer, so it is not perfectly efficient in terms of memory usage.
You can replace the vector / matrix math with types from your own math library if you want, or leave it as-is.
This implementation assumes coordinates are in screen pixel space (circleDetail() relies on that fact).
If you want to draw partially transparent lines, you will need render all triangles of a line at the same depth
and use the less-than or greater-than or not-equal depth test (e.g. glDepthFunc(GL_LESS) or GL_GREATER or GL_NOTEQUAL)
because some triangles overlap.
@notnullnotvoid
notnullnotvoid / PGraphics2DX.java
Last active June 14, 2019 22:32
Newly optimized versions of P2DX methods
//NOTE: here I've included only the methods that I changed.
@Override
public void ellipseImpl(float a, float b, float c, float d) {
if (useParentImpl) {
super.ellipseImpl(a, b, c, d);
return;
}
beginShape(POLYGON);
@notnullnotvoid
notnullnotvoid / collision.cpp
Last active May 30, 2019 15:05
minkowski-vs-ray collision
//NOTE: rayStart should be identical to *pos at the beginning of the function
static void collide_with_volumes(Vec2 rayStart, Vec2 rayDir, Vec2 * pos, Vec2 * vel,
List<LineSegment> lines, List<Circle> circles,
List<Vec2> * normals, float tick, float bounce)
{
//NOTE: We do a discrete collision response step before the continuous collision step
// to fix a bug where the player could push themselves out of bounds when walking into
// corners less than 90 degrees due to floating point imprecision.
Vec2 push = {};
@notnullnotvoid
notnullnotvoid / compiler-timings.txt
Created August 28, 2018 21:51
raw data collected for "Compiler Cage Fight" article
comparison of compilers for scalar and SIMD code using my software renderer as a guinea pig.
code being compared can be found here:
https://github.com/notnullnotvoid/DIWide/tree/c4fa0b297b1f30794fe01e796e6ca595d106abc3
speed:
cycle counts for core rasterization loop
data is very noisy, so only 3 significant digits were measured
@notnullnotvoid
notnullnotvoid / frog.cpp
Created June 18, 2018 22:17
Monte Carlo sim of the inescapable, eternally relevant frog riddle.
#include <stdio.h>
#include <random>
float random_float() {
static std::random_device rd;
static std::default_random_engine re;
static std::uniform_real_distribution<float> urd(0, 1);
return urd(re);
}
@notnullnotvoid
notnullnotvoid / List.h
Created May 8, 2018 15:19
example of simple type generics in C
#ifndef LIST_H
#define LIST_H
#define LIST IntList
#define TYPE int
#include "ListImpl.h"
#undef LIST
#undef TYPE
#define LIST Vec2List