Skip to content

Instantly share code, notes, and snippets.

Avatar

CNLohr cnlohr

View GitHub Profile
@cnlohr
cnlohr / noeuclid2.cginc
Created Oct 28, 2021
Ray Casting Logic For No Euclid Avatar in VRChat
View noeuclid2.cginc
// This was the version from Dec 12, 2020
/*
NO EUCLID 2: This time written from the ground up for MODERN (2020)
GPUs! No more janky math stuff to support the NVIDIA 460M or some
awful ancient ATI card.
The three textures we have are:
Read only when a collision may be possible.
GeoTex:
@cnlohr
cnlohr / teapot.h
Created Sep 29, 2021
Teapot.h single-file c header
View teapot.h
/* Copyright (c) 2012-2017, ARM Limited and Contributors
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
@cnlohr
cnlohr / authenticate.sh
Created Jul 5, 2021
2021 How to authenticate with the VRChat API
View authenticate.sh
$ echo -n "username:password" | base64
$ echo -e "api.vrchat.cloud\tFALSE\t/\tFALSE\t0\tapiKey\tJlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26" > cookiejar.txt
$ curl -b cookiejar.txt -c cookiejar.txt -A "WorldMon" -H "Authorization: Basic ########################" https://api.vrchat.cloud/api/1/auth/user
{"requiresTwoFactorAuth":["totp","otp"]}
$ curl -X 'POST' \
'https://api.vrchat.cloud/api/1/auth/twofactorauth/totp/verify' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-b cookiejar.txt -c cookiejar.txt \
-d '{
@cnlohr
cnlohr / example_generate_texture.c
Last active Jun 8, 2021
How to write 2D and 3D Unity Texture files from C
View example_generate_texture.c
// Execute this with `tcc testgen.c -run`
#include <stdio.h>
#include "unityassettexture.h"
#include <math.h>
int main()
{
float asset3d[50][50][50][4] = {0};
int x, y, z;
@cnlohr
cnlohr / raw_packet_read_write.c
Last active Jun 7, 2021
Read/write raw packets in C in Linux
View raw_packet_read_write.c
//Based on https://github.com/cnlohr/lamenet/blob/master/librawp.c
#include <stdio.h>
#include <arpa/inet.h>
#include <string.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/ether.h>
@cnlohr
cnlohr / perfeater.shader
Last active May 22, 2021
perfeater - to keep your GPU busy in unity so you can do timing measurements in renderdoc or nsight.
View perfeater.shader
Shader "Unlit/PerfEat"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
@cnlohr
cnlohr / usingtimer14onstm32f042.md
Last active Apr 7, 2021
Using Timer 14 on the STM32F042
View usingtimer14onstm32f042.md
	void Setup()
	{
		RCC->APB1ENR |= RCC_APB1ENR_TIM14EN;
		TIM14->PSC = 48-1; //Counts up in microseconds
		TIM14->ARR = 65535;
		TIM14->CNT = 0;
		TIM14->CR1 = 1;
		TIM14->DIER = TIM_DIER_CC2IE | TIM_DIER_UIE;
    
@cnlohr
cnlohr / CNLohr's Guide for Windows C Apps in 2021.md
Last active Aug 16, 2021
How to Set Up a Windows Computer to Write C applications in 2021
View CNLohr's Guide for Windows C Apps in 2021.md

Building C apps on Windows in 2021

This document was written on April 3, 2021. The procedure may change over time. This is a companion gist to the youtube video here, where I go through every step of both options

Youtube Version Of This Document

@cnlohr
cnlohr / battery_monitor_overlay.c
Last active Nov 5, 2021
How to make a monitor overlay in OpenVR in C
View battery_monitor_overlay.c
// Battery Watcher for OpenVR (make an overlay with the battery left for all connected devices on your left hand)
//
// Compile with:
// tcc battery_monitor_overlay.c -o bmo.exe -luser32 -lgdi32 -lkernel32 -lopengl32 C:\windows\system32\msvcrt.dll openvr_api.dll
// System headers for any extra stuff we need.
#include <stdbool.h>
// Include CNFG (rawdraw) for generating a window and/or OpenGL context.
#define CNFG_IMPLEMENTATION
@cnlohr
cnlohr / hlsl
Last active Dec 11, 2020
Really fast HLSL perlin-like noise (but it does repeat)
View hlsl
// QuickNoise -> Extremely fast noise that does repeat, but "feels" like
// perlin noise. Rewritten to avoid license issues.
//
// The original version of this noise is restrictively licensed. Code was
// re-written for HLSL 2020 <>< CNLohr, code henseforth may be liberally
// licensed under MIT-X11, NewBSD or Any Creative Commons License including
// CC0.
//
// There was also a bug in the version by stubbe which caused a migration in
// x/y/z when there was an applied w value. The matrix undoes the migration