Skip to content

Instantly share code, notes, and snippets.

@kovrov
kovrov / amortization.py
Created May 27, 2019 22:21
Amortization table
def amortization(loan, apr, years, extra=0):
rate = apr / 100 / 12
periods = years * 12
payment = (loan * rate) / (1 - pow(1 + rate, -periods))
balance = loan
for period in range(periods):
if balance <= 0:
return
interest = balance * rate
principal = payment - interest + extra
@kovrov
kovrov / build-libv8.md
Created December 15, 2018 17:20
Build V8 on Linux

this is not a script

cd $(mktemp -d)
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PATH:$PWD/depot_tools
fetch v8
export CXX=g++-8 CC=gcc-8 AR=gcc-ar-8 NM=gcc-nm-8
gclient sync
cd v8

gn gen out/x64.host --args='custom_toolchain="//build/toolchain/linux/unbundle:default" host_toolchain="//build/toolchain/linux/unbundle:default" is_clang=false is_component_build=true is_debug=false treat_warnings_as_errors =false use_custom_libcxx=false use_sysroot=false v8_use_external_startup_data=false'

@kovrov
kovrov / 7.6.2_uniform_blocks.md
Last active October 20, 2018 16:50
7.6.2 Uniform Blocks

7.6.2.2 Standard Uniform Block Layout

By default, uniforms contained within a uniform block are extracted from buffer storage in an implementation-dependent manner. Applications may query the offsets assig

The layout qualifier provides shaders with control of the layout of uniforms within a uniform block. When the std140 layout is specified, the offset of each uniform in a uniform block can be derived from the definition of the uniform block by applying the set of rules described below.

template <typename T>
class producer_consumer_queue {
public:
void put(T &&data) {
std::unique_lock lock{_mtx};
_queue.push(std::move(data));
_cv.notify_one();
}
T get() {
template <typename T>
uint32_t location() {
return T::kLocation;
}
template <typename T>
VkFormat format() {
return T::kFormat;
}
# https://github.com/scanberg/hbao
cmake_minimum_required (VERSION 3.1)
project (hbao)
find_package (PkgConfig REQUIRED)
file (GLOB_RECURSE SRC_LIST src/*.cpp src/*.h)
@kovrov
kovrov / CMakeLists.txt
Last active June 13, 2017 04:31
~/.config/QtProject/qtcreator/templates/wizards/cmake-with-tests
cmake_minimum_required (VERSION 3.1)
project (%{ProjectName})
option (BUILD_UNIT_TESTS "Build unit-tests" OFF)
option (USE_GLFW "Use glfw" OFF)
file (GLOB SRC_LIST src/*.cpp src/*.h)
list (REMOVE_ITEM SRC_LIST ${CMAKE_SOURCE_DIR}/src/main.cpp)

Стоимость OpenGL команд

http://www.gamedev.ru/code/articles/opengl_overhead

Автор: Анатолий Герлиц

В современных проектах для получения красивой картинки отрисовываются тысячи различных объектов: персонажи, строения, ландшафт, природа, эффекты и т.д.
Разумеется есть разные способы отобразить на экране геометрию. В этой статье мы рассмотрим как сделать это эффективно, посчитаем и сравним стоимость различных API вызовов для отрисовки геометрии.
Рассмотрим стоимость API вызовов:
    - смену различных стейтов по отдельности (фрейм буферов, вершинных буферов, шейдеров, констант, текстур)

@kovrov
kovrov / render.conf
Created January 19, 2017 06:38
Render passes
pass_1: {
uniforms: {
view: camera.view
projection: camera.projection
}
id_tex: {
format: GL_R8UI
size: {width, height}
}
depth_tex: {

Real depth in OpenGL / GLSL

http://olivers.posterous.com/linear-depth-in-glsl-for-real

So, many places will give you clues how to get linear depth from the OpenGL depth buffer, or visualise it, or other things. This, however, is what I believe to be the definitive answer:

This link http://www.songho.ca/opengl/gl_projectionmatrix.html gives a good run-down of the projection matrix, and the link between eye-space Z (z_e below) and normalised device coordinates (NDC) Z (z_n below). From there, we have

A   = -(zFar + zNear) / (zFar - zNear);

B = -2zFarzNear / (zFar - zNear);