Shtille's blog A development blog

libjpeg vs libpng performance comparison

Done buffer save/load tests for these libraries, and results are following: JPEG test took 0.017918 seconds PNG test took 0.088861 seconds So libjpeg is 5.5 times faster than libpng. Read more

Custom spinlock vs pthread one speed comparison

#include <cstdlib> #include <cstdio> #include <thread> #include <string> #include <chrono> #include <atomic> #include <pthread.h> class ScopeTimer { typedef std::chrono::high_resolution_clock clock; typedef std::chrono::duration<float> seconds; public: ScopeTimer(const char* message) : messag... Read more

Making Decals (OpenGL Programming)

Suppose you’re drawing a complex three-dimensional picture using depth-buffering to eliminate the hidden surfaces. Suppose further that one part of your picture is composed of coplanar figures A and B, where figure B is a sort of decal that should always appear on top of figure A. Your first approach might be to draw figure B after you’ve drawn ... Read more

Box normal calculation

In ray tracing we need to calculate box normal from ray intersection. Here’s the solution. vec3 BoxNormal(const Box box, const vec3 point) { vec3 center = (box.max + box.min) * 0.5; vec3 size = (box.max - box.min) * 0.5; vec3 pc = point - center; // step(edge,x) : x < edge ? 0 : 1 vec3 normal = vec3(0.0); normal += vec3(sign(pc.x), 0.0... Read more

Program to test intersections

Made a program to test intersections: #include <iostream> #include <string> #include <cmath> struct vec3 { vec3(float x) : x(x), y(x), z(x) {} vec3(float x, float y, float z) : x(x), y(y), z(z) {} vec3 operator +(const vec3& v) const { return vec3(x + v.x, y + v.y, z + v.z); } vec3 operator -(const vec3&am... Read more