• Interactive Poisson Blending on GPU
    Interactive Poisson Blending on GPU
  • 404 Not Found In Two Triangles
    404 Not Found In Two Triangles
  • Simplest and Fastest GLSL Edge Detection using Fwidth
    Simplest and Fastest GLSL Edge Detection using Fwidth
  • Comparison: MagicLeap vs. HoloLens vs. Oculus Rift
    Comparison: MagicLeap vs. HoloLens vs. Oculus Rift

Category: Code

Yet another shader for image fade-In effect

Taken iq’s background transparent code and Dr. Neyret’s advice: This shader can be used for rendering pop-up images in a 3D environment.

     


Foveated Rendering via Quadtree

Today, I wrote a shader for foveated rendering uisng Prof. Neyret’s QuadTree: https://www.shadertoy.com/view/Ml3SDf The basic idea is:  Calculate the depth of the QuadTree using the distance between the current coordinate to the foveat region Use the depth as the mipmap level to sample from the texture Code below:

       


Bilateral Filter to Look Younger on GPU

Bilateral filter can be used to smooth the texture while preserving significant edges / contrast. Below shows a live demo in ShaderToy. Press mouse for comparison. Thanks to mrharicot’s awesome bilateral filter: https://www.shadertoy.com/view/4dfGDH With performance improvement proposed by athlete. With gamma correction by iq: https://www.shadertoy.com/view/XtsSzH   Skin detection forked from carlolsson’s Skin Detection https://www.shadertoy.com/view/MlfSzn#


Interactive Poisson Blending on GPU

Recently, I implemented two fragment shaders for interactive Poisson Blending (seamless blending).  Here is my real-time demo and code on ShaderToy: Press 1 for normal mode, press 2 for mixed gradients, press space to clear the canvas. Technical Brief I followed a simplified routine of the Poisson Image Editing paper [P. Pérez, M. Gangnet, A….


C++ Code Backup for Render-To-Texture (Mult-pass Rendering)

I have found that many code for multipass rendering is complex and redundant to understand, so I would like to write a post for further reference. The key to multi-pass rendering is, instead of rendering to screen (frame buffer 0), reorient the rendering target to a framebuffer (e.g. frame buffer 1), bind the output of the…


Fisher-Yates Shuffle

The correct way to do a shuffle is to choose a random other index to fill in the current index, which is uniform:

  Also, you may need a uniform random generator in C++:

 


Protected: Optimization Using Sum-to-Product Identities

There is no excerpt because this is a protected post.


N Queens Problem Revisit using Bit Operations

Finally, I have some time to revisit the N queens problem using bit operations. The following functions could solve 11 queens in 1 second:

So far to me, this is the most efficient algorithm for N queens. The code is mostly self-explenary. Please comment if anything cannot be understood.

 


Simplest and Fatest GLSL Edge Detection using Fwidth

Yesterday, I read 834144373’s ShaderToy code which did Edge Detection in 97 chars, it was really simple and fast:

However, the result is astonishingly good: Let’s expand the code a little bit:

According to OpenGL manual: fwidth means  abs(dFdx(p)) + abs(dFdy(p)) and fwidthFine is equivalent to abs(dFdxFine(p)) + abs(dFdyFine(p)). One can use a sigmoid function to increase the…


How to Measure Execution Time in C++ 11

Here are my code snippets to measure execution time in C++ as a DebugTimer:

It’s a static class so it’s very easy to use:

That’s it!