List of freely available resources to study computer graphics programming.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <limits> | |
#include <cassert> | |
#include <stdexcept> | |
#define MORTON_CODE_MAX_LEVEL 32 | |
#define UINT8 unsigned char | |
#define UINT32 unsigned int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The MIT License (MIT) | |
// Copyright (c) 2018 cmf028 | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cofactor matrix. drop-in replacement for the traditional transpose(inverse(m)) normal matrix calculation. | |
// this is a substantial performance improvement. | |
// short form found via shadertoy: https://www.shadertoy.com/view/3s33z | |
mat3 cofactor(mat4 m) { | |
return mat3( | |
cross(m[1].xyz, m[2].xyz), | |
cross(m[2].xyz, m[0].xyz), | |
cross(m[0].xyz, m[1].xyz) | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// these matrices are for left-handed coordinate systems, with depth mapped to [1;0] | |
// the derivation for other matrices is analogous | |
// to get a perspective matrix with reversed z, simply swap the near and far plane | |
glm::mat4 perspectiveFovReverseZLH_ZO(float fov, float width, float height, float zNear, float zFar) { | |
return glm::perspectiveFovLH_ZO(fov, width, height, zFar, zNear); | |
}; | |
// now let zFar go towards infinity | |
glm::mat4 infinitePerspectiveFovReverseZLH_ZO(float fov, float width, float height, float zNear) { |
This method stores a full TBN frame using just 3 bytes per vertex (plus a bitfield), instead of the traditional 28 bytes (normal: vec3
, tangent: vec4
). It leverages octahedral encoding for normals and a rotation angle for tangent reconstruction.
Storing both glm::vec3 normal
and glm::vec4 tangent
is costly. Since the bitangent can be reconstructed via a cross product, we only need:
- A unit normal (encoded in 2 bytes)
- An angle to rotate a base tangent around the normal (1 byte)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct vec3f {float x, y, z;}; | |
struct vec4f {float x, y, z, w;}; | |
struct mat44f {vec4f x, y, z, w;}; | |
//============================================================================ | |
// sphere_screen_extents | |
//============================================================================ | |
// Calculates the exact screen extents xyzw=[left, bottom, right, top] in | |
// normalized screen coordinates [-1, 1] for a sphere in view space. For | |
// performance, the projection matrix (v2p) is assumed to be setup so that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 450 | |
// 2D Polyhedral Bounds of a Clipped, Perspective-Projected 3D Sphere. Michael Mara, Morgan McGuire. 2013 | |
bool projectSphereView(vec3 c, float r, float znear, float P00, float P11, out vec4 aabb) | |
{ | |
if (c.z < r + znear) return false; | |
vec3 cr = c * r; | |
float czr2 = c.z * c.z - r * r; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: This bat file can be used to renew Resharper C# and Resharper C++ every time it runs out | |
:: It most likely works for all Jetbrains tools, however, I did not test this. | |
:: I was not able to find the original author for the reg key and the folders that needs to be deleted so if that is you feel free to reach out for credit | |
@echo off | |
setlocal enableDelayedExpansion | |
:confirm | |
echo Did you stop all Jetbrains services? | |
echo Jetbrains toolbox AND any other tool using it such as Rider, Visual Studio, ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulator for depth comparison error (i.e. z-fighting) | |
# Nathan Reed, June 2015 | |
# Written for Python 3.4; requires numpy | |
import math | |
import numpy as np | |
import optparse | |
# Parse command-line options | |
parser = optparse.OptionParser() |
NewerOlder