Skip to content

Commit

Permalink
deploy: e49cb4f
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Oct 6, 2024
0 parents commit d860b45
Show file tree
Hide file tree
Showing 75 changed files with 9,570 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 1175a46036eec01bc34a11c2c5ef8932
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/autoexposure.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/censustransform.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/chromaticity.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/coordinatespaces.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/cpp.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/gaussianblur.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/logdepth.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/loops.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/opticalflow.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/outerralogdepth.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/pythonengine.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/reshadefx.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/shadermodel3.doctree
Binary file not shown.
Binary file added .doctrees/source/blog/sobel.doctree
Binary file not shown.
Binary file added .doctrees/source/social/instagram.doctree
Binary file not shown.
Binary file added .doctrees/source/social/project.doctree
Binary file not shown.
Binary file added .doctrees/source/social/youtube.doctree
Binary file not shown.
Empty file added .nojekyll
Empty file.
Binary file not shown.
19 changes: 19 additions & 0 deletions _sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

Homepage
========

.. toctree::
:caption: Content Creation Guide
:glob:
:titlesonly:

source/social/project
source/social/*

.. toctree::
:caption: Graphics Programming Blog
:glob:
:titlesonly:

source/blog/cpp
source/blog/*
109 changes: 109 additions & 0 deletions _sources/source/blog/autoexposure.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

Temporal Auto-Exposure with Hardware Blending
=============================================

Some graphics pipelines compute auto-exposure like this:
:Textures:
#. Previous average brightness
#. Current average brightness
:Passes:
#. Store previously generated average brightness
#. Generates current average brightness
#. Smooth average brightnesses and compute auto-exposure

You can use hardware blending for auto-exposure:
:Textures:
#. Average brightnesses (previous + current)
:Passes:
#. Generate and smooth average brightnesses
#. Compute auto-exposure

Source Code
-----------

::

/*
Automatic exposure shader using hardware blending
*/

/*
Vertex shaders
*/

struct APP2VS
{
float4 HPos : POSITION;
float2 Tex0 : TEXCOORD0;
};

struct VS2PS
{
float4 HPos : POSITION;
float2 Tex0 : TEXCOORD0;
};

VS2PS VS_Quad(APP2VS Input)
{
VS2PS Output;
Output.HPos = Input.HPos;
Output.Tex0 = Input.Tex0;
return Output;
}

/*
Pixel shaders
---
AutoExposure(): https://knarkowicz.wordpress.com/2016/01/09/automatic-exposure/
*/

float3 GetAutoExposure(float3 Color, float2 Tex)
{
float LumaAverage = exp(tex2Dlod(SampleLumaTex, float4(Tex, 0.0, 99.0)).r);
float Ev100 = log2(LumaAverage * 100.0 / 12.5);
Ev100 -= _ManualBias; // optional manual bias
float Exposure = 1.0 / (1.2 * exp2(Ev100));
return Color * Exposure;
}

float4 PS_GenerateAverageLuma(VS2PS Input) : COLOR0
{
float4 Color = tex2D(SampleColorTex, Input.Tex0);
float3 Luma = max(Color.r, max(Color.g, Color.b));

// OutputColor0.rgb = Output the highest brightness out of red/green/blue component
// OutputColor0.a = Output the weight for temporal blending
float Delay = 1e-3 * _Frametime;
return float4(log(max(Luma.rgb, 1e-2)), saturate(Delay * _SmoothingSpeed));
}

float3 PS_Exposure(VS2PS Input) : COLOR0
{
float4 Color = tex2D(SampleColorTex, Input.Tex0);
return GetAutoExposure(Color.rgb, Input.Tex0);
}

technique AutoExposure
{
// Pass0: This shader renders to a texture that blends itself
// NOTE: Do not have another shader overwrite the texture
pass GenerateAverageLuma
{
// Use hardware blending
BlendEnable = TRUE;
BlendOp = ADD;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;

VertexShader = VS_Quad;
PixelShader = PS_GenerateAverageLuma;
}

// Pass1: Get the texture generated from Pass0
// Do autoexposure shading here
pass ApplyAutoExposure
{
VertexShader = VS_Quad;
PixelShader = PS_Exposure;
}
}
48 changes: 48 additions & 0 deletions _sources/source/blog/censustransform.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Census Transform in HLSL
========================

The census transform is a filter that represents the pixel's neighborhood relationship in a binary string. The binary string will be ``0000000`` if the center pixel is lesser than all of its neighbors. The binary string will be ``11111111`` if the center pixel is greater than or equal to all of its neighbors.

The filter does not depend on the image's actual intensity. As a result, the filter is robust to illumination.

Source Code
-----------

::

float GetGreyScale(float3 Color)
{
return max(max(Color.r, Color.g), Color.b);
}

float GetCensusTransform(sampler SampleImage, float2 Tex, float2 PixelSize)
{
float OutputColor = 0.0;
float4 ColumnTex[3];
ColumnTex[0] = Tex.xyyy + (float4(-1.0, +1.0, 0.0, -1.0) * PixelSize.xyyy);
ColumnTex[1] = Tex.xyyy + (float4( 0.0, +1.0, 0.0, -1.0) * PixelSize.xyyy);
ColumnTex[2] = Tex.xyyy + (float4(+1.0, +1.0, 0.0, -1.0) * PixelSize.xyyy);
const int Neighbors = 8;
float SampleNeighbor[Neighbors];
SampleNeighbor[0] = GetGreyScale(tex2D(SampleImage, ColumnTex[0].xy).rgb);
SampleNeighbor[1] = GetGreyScale(tex2D(SampleImage, ColumnTex[1].xy).rgb);
SampleNeighbor[2] = GetGreyScale(tex2D(SampleImage, ColumnTex[2].xy).rgb);
SampleNeighbor[3] = GetGreyScale(tex2D(SampleImage, ColumnTex[0].xz).rgb);
SampleNeighbor[4] = GetGreyScale(tex2D(SampleImage, ColumnTex[2].xz).rgb);
SampleNeighbor[5] = GetGreyScale(tex2D(SampleImage, ColumnTex[0].xw).rgb);
SampleNeighbor[6] = GetGreyScale(tex2D(SampleImage, ColumnTex[1].xw).rgb);
SampleNeighbor[7] = GetGreyScale(tex2D(SampleImage, ColumnTex[2].xw).rgb);
float CenterSample = GetGreyScale(tex2D(SampleImage, ColumnTex[1].xz).rgb);

// Generate 8-bit integer from the 8-pixel neighborhood
for(int i = 0; i < Neighbors; i++)
{
float Comparison = step(SampleNeighbor[i], CenterSample);
OutputColor += ldexp(Comparison, i);
}

// Convert the 8-bit integer to float, and average the results from each channel
return OutputColor * (1.0 / (exp2(8) - 1));
}
100 changes: 100 additions & 0 deletions _sources/source/blog/chromaticity.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

Chromaticity in HLSL
====================

Images often represent color in 3 channels: ``(R, G, B)`` - red, green, and blue. You can represent ``(R, G, B)`` in any range. For this post, the range is a minimum of **0.0** and a maximum of **1.0**.

Normalized Chromaticity
-----------------------

Formulas
^^^^^^^^

Normalized RG/RGB
.. math::
r = \frac{R}{R+G+B}\\
g = \frac{G}{R+G+B}\\
b = \frac{B}{R+G+B}\\
\\
r+g+b = 1
Output :math:`(r,g,b)`
:(1.0, 0.0, 0.0): 100% red
:(0.0, 1.0, 0.0): 100% green
:(0.0, 0.0, 1.0): 100% blue

Output :math:`(r,g)`
:\(1.0, 0.0\): 100% red
:\(0.0, 1.0\): 100% green
:\(0.0, 0.0\): 100% blue

Normalized RG/RGB White-Point
.. math::
R=1\\
G=1\\
B=1\\
\\
r = \frac{R}{R+G+B}\\
g = \frac{G}{R+G+B}\\
b = \frac{B}{R+G+B}\\
\\
r+g+b = 1
Source Code
^^^^^^^^^^^

::

float3 GetRGBChromaticity(float3 Color)
{
// Optimizes 2 ADD instructions 1 DP3 instruction
float SumRGB = dot(Color, 1.0);
float3 Chromaticity = saturate(Color / SumRGB);
// Output the chromaticity's white point if the divisor is 0.0
// Prevents undefined behavior happens when you divide by 0
Chromaticity = (SumRGB == 0.0) ? 1.0 / 3.0 : Chromaticity;
return Chromaticity;
}

Spherical Chromaticity
----------------------

This post introduces a color space that computes chromaticity with angles.

Precision Loss in RG Chromaticity
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Pecision is a major drawback to RG chromaticity. In RG chromaticity, all possible values map into a right-triangle, eliminating half of the precision in integer buffers.

We can encode data that fits in the entire ``RG8`` range by calculating the angles between the channels.

Source Code
^^^^^^^^^^^

::

/*
This code is based on the algorithm described in the following paper:
Author(s): Joost van de Weijer, T. Gevers
Title: "Robust optical flow from photometric invariants"
Year: 2004
DOI: 10.1109/ICIP.2004.1421433
Link: https://www.researchgate.net/publication/4138051_Robust_optical_flow_from_photometric_invariants
*/

float2 GetSphericalRG(float3 Color)
{
const float HalfPi = 1.0 / acos(0.0);

// Precalculate (x*x + y*y)^0.5 and (x*x + y*y + z*z)^0.5
float L1 = length(Color.rg);
float L2 = length(Color.rgb);

float2 Angles = 0.0;
Angles[0] = (L1 == 0.0) ? 1.0 / sqrt(2.0) : Color.g / L1;
Angles[1] = (L2 == 0.0) ? 1.0 / sqrt(3.0) : L1 / L2;

return saturate(asin(abs(Angles)) * HalfPi);
}
31 changes: 31 additions & 0 deletions _sources/source/blog/coordinatespaces.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Coordinate Spaces: A Refresher
==============================

Standard Basis
Defines the directions of the x-axis, y-axis, and z-axis.

:(1.0, 0.0, 0.0): x-axis
:(0.0, 1.0, 0.0): y-axis
:(0.0, 0.0, 1.0): z-axis


.. list-table:: Coordinate Spaces
:header-rows: 1

* - Coordinate Space
- Standard-Basis Location
- (0.0, 0.0, 0.0) Location
* - Tangent-Space
- On the **face or vertex**.
- On the center of the **face or vertex**.
* - Object-Space
- On the **object**.
- On the center of the **object**.
* - World-Space
- On the **world**.
- On the center of the **world**.
* - View-Space
- On the **viewer**.
- On the center of the **viewer**.

Loading

0 comments on commit d860b45

Please sign in to comment.