Skip to content

Instantly share code, notes, and snippets.

View kkhomyakov3d's full-sized avatar

Konstantin Khomyakov kkhomyakov3d

View GitHub Profile
@kkhomyakov3d
kkhomyakov3d / latency.txt
Created December 18, 2022 21:26 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@kkhomyakov3d
kkhomyakov3d / DrawFullScreenFeature.cs
Created November 25, 2021 14:10 — forked from EricHu33/DrawFullScreenFeature.cs
An example of how to write custom grab pass renderer feature in Unity URP
namespace UnityEngine.Rendering.Universal
{
public enum BufferType
{
CameraColor,
Custom
}
public class DrawFullScreenFeature : ScriptableRendererFeature
{
@kkhomyakov3d
kkhomyakov3d / Tex2DCatmullRom.hlsl
Created September 17, 2021 20:52 — forked from TheRealMJP/Tex2DCatmullRom.hlsl
An HLSL function for sampling a 2D texture with Catmull-Rom filtering, using 9 texture samples instead of 16
// The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
// Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16.
// See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
float4 SampleTextureCatmullRom(in Texture2D<float4> tex, in SamplerState linearSampler, in float2 uv, in float2 texSize)
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
float2 samplePos = uv * texSize;
@kkhomyakov3d
kkhomyakov3d / HelloOpenVR_GLFW.cpp
Created August 9, 2021 10:10 — forked from VirtuosoChris/HelloOpenVR_GLFW.cpp
Minimal OpenVR + GLFW Example
/**** Minimal OpenVR example : outputs textures to the headset, a different color in each eye. No head tracking or input anywhere. Bare minimum. ****/
/// header only extension loader and object oriented bindings -- ref : https://github.com/VirtuosoChris/glhpp
#define GL_ALT_GL_API 1
#define GL_ALT_GLES_API 2
#include <glalt/gl4.5.h> // opengl api
#include <glalt/glext.h>
#include <opengl.hpp> // object oriented bindings
@kkhomyakov3d
kkhomyakov3d / Gerrit comment formatting
Created July 15, 2021 08:03 — forked from dlebech/Gerrit comment formatting
Comment formatting in Gerrit
The documentation for Gerrit when it comes to formatting comments is quite lacking. Here is short list created by trial and error and looking at the source code in:
./gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java
Lists:
* List item 1
* List item 2
- List item 1
- List item 2

Minimal D3D11

Minimal D3D11 reference implementation: An uncluttered Direct3D 11 setup & basic rendering primer / API familiarizer. Complete, runnable Windows application contained in a single function and laid out in a linear, step-by-step fashion that should be easy to follow from the code alone. ~215 LOC. No modern C++ / OOP / obscuring cruft. View on YouTube

hollowcube

#include <stdio.h>
#include "bgfx/bgfx.h"
#include "bgfx/platform.h"
#include "bx/math.h"
#include "GLFW/glfw3.h"
#define GLFW_EXPOSE_NATIVE_WIN32
#include "GLFW/glfw3native.h"
#define WNDW_WIDTH 1600
#define WNDW_HEIGHT 900
@kkhomyakov3d
kkhomyakov3d / MaterialGradientDrawer.cs
Created March 10, 2021 16:16 — forked from totallyRonja/MaterialGradientDrawer.cs
A Material Property Drawer for the [Gradient] attribute which lets you edit gradients and adds them to the shader as textures. More information here: https://twitter.com/totallyRonja/status/1368704187580682240
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class MaterialGradientDrawer : MaterialPropertyDrawer {
private int resolution;
@kkhomyakov3d
kkhomyakov3d / ExamplePass.cs
Created December 15, 2020 10:22 — forked from alexanderameye/TemplatePass.cs
ScriptableRenderPass template
// NOTE: ScriptableRenderPass template created for Unity 2020.1 and URP 8
// SOURCES: some used references to investigate what kind of different setups people use, lots of variety out there!
// https://gist.github.com/Refsa/54da34a9e2fc8e45472286572216ad17
// https://gist.github.com/wonkee-kim/1792cd4fced96f98ae4a09ec500a3177
// https://zhuanlan.zhihu.com/p/232450616 (in chinese, but provides some code for custom render pass)
// https://samdriver.xyz/articles/scriptableRender.htm (2019.3)
// https://gist.github.com/Elringus/69f0da9c71306f1ea0f575cc7568b31a (LWRP)
// https://github.com/Unity-Technologies/UniversalRenderingExamples/tree/release/2020.1 (2020.1 branch for SRP 8.2.0)