Skip to content

Instantly share code, notes, and snippets.

Scott Lembcke slembcke

Block or report user

Report or block slembcke

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@slembcke
slembcke / ProjectedBounds.cs
Last active Apr 29, 2019
Calculate a bounded mvp matrix for an object.
View ProjectedBounds.cs
using UnityEngine;
[ExecuteInEditMode]
public class ProjectedBounds : MonoBehaviour {
private Transform _transform;
private Renderer _renderer;
private Mesh _mesh;
private MaterialPropertyBlock _block;
private void Start(){
View timing.c
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
static const size_t COUNT = 64*(1<<20);
typedef float FLOAT_T;
View disassembler.c
#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,
@slembcke
slembcke / anisotropy.hlsl
Created Jan 30, 2019
Anisotropic reflections
View anisotropy.hlsl
// 'coord.y' is the clip space y-coordinate of the pixel on the water.
// 'ray0.y/ray0.w' is the clip space y-coordinate of the reflected pixel.
// The basic idea is near the horizion where the reflected point is close to the water,
// you should have a strong reflection. The further it gets from the horizon the more it should be blurred vertically.
// The result is pretty good. :D
float aniso = _SSRAniso*abs(coord.y - ray0.y/ray0.w);
float2 ddy_uv = max(ddy(uv), float2(0, aniso));
...
float4 color = tex2Dgrad(_CameraColorTexture, uv, ddx(uv), ddy_uv);
@slembcke
slembcke / decompress_lz4.s
Created Oct 28, 2018
GBZ80 Lz4 decompression function progress.
View decompress_lz4.s
section "lz4-data", hram
token: db ; Most recently read token.
backref: dw
; NOTES:
; dst/src is always stored in de/hl
section "lz4-code", rom0
@slembcke
slembcke / FlickerExample.txt
Created Aug 24, 2018
Code snippets for my flicker issue.
View FlickerExample.txt
static void px_ppu_sync_off(){
px_mask &= ~PX_MASK_RENDER_ENABLE;
px_wait_nmi();
// Without these I get a few garbage lines at the top of the screen
waitvsync();
waitvsync();
}
static void px_ppu_sync_on(){
@slembcke
slembcke / naco.h
Created Jul 17, 2018
libnaco: Nano coroutine library for cc65.
View naco.h
#ifndef NACO_H
#define NACO_H
#include <stdint.h>
#include <stdlib.h>
typedef uintptr_t (*naco_func)(uintptr_t);
void naco_init(naco_func func, void *naco_buffer, size_t buffer_size);
uintptr_t naco_yield(uintptr_t value);
View coro.h
#ifndef CORO_H
#define CORO_H
#include <stdint.h>
typedef uintptr_t (*coro_func)(uintptr_t);
void coro_start(coro_func func);
uintptr_t coro_yield(uintptr_t);
uintptr_t coro_resume(uintptr_t);
@slembcke
slembcke / coro.s
Created Jul 11, 2018
Simple coroutines for cc65.
View coro.s
.include "zeropage.inc"
.macpack generic
.import pusha, popa
.import pushax
.import addysp, subysp
.import _exit
.data
@slembcke
slembcke / sliding
Last active Feb 12, 2018
Falling down a hill.
View sliding
// Gravity pulls the player down,
// but the slope of the hill pushes them in another direction.
static const float G = ...; // Acceleration due to gravity.
// First find what percentage of gravity is wasted opposing the ground normal:
float dotN = Vector3.Dot(groundNormal, -Vector3.up);
// Or simplified, just -groundNormal.y
// Subtract that from the down vector to get the percent
You can’t perform that action at this time.