Skip to content

Instantly share code, notes, and snippets.

View shadercoder's full-sized avatar

PeterLiou shadercoder

  • IGG
  • earth
View GitHub Profile
vec2 DFG_Cloth(float roughness, float NoV) {
const vec4 c0 = vec4(0.24, 0.93, 0.01, 0.20);
const vec4 c1 = vec4(2.00, -1.30, 0.40, 0.03);
float s = 1.0 - NoV;
float e = s - c0.y;
float g = c0.x * exp2(-(e * e) / (2.0 * c0.z)) + s * c0.w;
float n = roughness * c1.x + c1.y;
float r = max(1.0 - n * n, c1.z) * g;
@shadercoder
shadercoder / wavelength_to_rgb.R
Created December 13, 2017 06:39 — forked from friendly/wavelength_to_rgb.R
Convert wavelength of color to RGB
#' Wavelength to RGB
#'
#' This function converts a given wavelength of light to an
#' approximate RGB color value.
#'
#' @param wavelength A wavelength value, in nanometers, in the human visual range from 380 nm through 750 nm.
#' These correspond to frequencies in the range from 789 THz through 400 THz.
#' @param gamma The \eqn{\gamma} correction for a given display device. The linear RGB values will require
#' gamma correction if the display device has nonlinear response.
#' @return a color string, corresponding to the result of \code{\link[grDevices]{rgb}} on the
@shadercoder
shadercoder / specrend.c
Created December 11, 2017 10:34 — forked from bert/specrend.c
Colour Rendering of Spectra
/*
Colour Rendering of Spectra
by John Walker
http://www.fourmilab.ch/
Last updated: March 9, 2003
This program is in the public domain.
@shadercoder
shadercoder / GGXApproxDiffuse.brdf
Created November 28, 2017 03:36 — forked from mebiusbox/GGXApproxDiffuse.brdf
GGX Approximation Diffuse for BRDF Explorer
analytic
# variables go here...
# only floats supported right now.
# [type] [name] [min val] [max val] [default val]
::begin parameters
float albedo 0 1 1
float roughness 0 1 1
::end parameters
@shadercoder
shadercoder / d_ggx.glsl
Created September 6, 2017 01:19 — forked from romainguy/d_ggx.glsl
D_GGX in mediump/half float
float D_GGX(float linearRoughness, float NoH, const vec3 h) {
// Walter et al. 2007, "Microfacet Models for Refraction through Rough Surfaces"
// In mediump, there are two problems computing 1.0 - NoH^2
// 1) 1.0 - NoH^2 suffers floating point cancellation when NoH^2 is close to 1 (highlights)
// 2) NoH doesn't have enough precision around 1.0
// Both problem can be fixed by computing 1-NoH^2 in highp and providing NoH in highp as well
// However, we can do better using Lagrange's identity:
// ||a x b||^2 = ||a||^2 ||b||^2 - (a . b)^2
@shadercoder
shadercoder / ComputeOcclusionFromDepth.shader
Created May 23, 2017 03:05 — forked from aras-p/ComputeOcclusionFromDepth.shader
Unity command buffer that modifies screenspace shadow mask
Shader "Hidden/ComputeOcclusion"
{
Properties
{
_MainTex ("", 2D) = "white" {}
}
SubShader
{
Pass
{
@shadercoder
shadercoder / FullScreenQuad.shader
Created May 23, 2017 03:04 — forked from jcowles/FullScreenQuad.shader
Make a standard Unity Quad full-screen, purely in the shader
//
// 1. Add a Quad in Unity
// 2. Parent the quad under camera, to prevent frustum culling.
// 3. Attach this shader.
//
Shader "Quad/Fullscreen"
{
Properties
{
}
@shadercoder
shadercoder / octahedral.shader
Created April 27, 2017 09:29 — forked from pyalot/octahedral.shader
octahedral mapping
#define sectorize(value) step(0.0, (value))*2.0-1.0
#define sum(value) dot(clamp((value), 1.0, 1.0), (value))
#define PI 3.141592653589793
vec2 normalToUvRectOct(vec3 normal){
normal /= sum(abs(normal));
if(normal.y > 0.0){
return normal.xz*0.5+0.5;
}
else{
@shadercoder
shadercoder / sqrt.c
Created March 17, 2017 10:12 — forked from foobaz/sqrt.c
Integer square root algorithm
/*
Just like integer division, these functions round down to an integer.
Running this program should produce the following output:
sqrt(3735928559) == 61122
61122^2 == 3735898884
sqrt(244837814094590) == 15647294
15647294^2 == 244837809522436
This algorithm comes from Jack W. Crenshaw's 1998 article in Embedded:
@shadercoder
shadercoder / GLSL-Math.md
Created March 16, 2017 01:30 — forked from patriciogonzalezvivo/GLSL-Math.md
GLSL Math functions

Trigonometry

const float PI = 3.1415926535897932384626433832795;
const float PI_2 = 1.57079632679489661923;
const float PI_4 = 0.785398163397448309616;

float PHI = (1.0+sqrtf(5.0))/2.0;