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;
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
| 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; |
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
| #' 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 |
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
| /* | |
| Colour Rendering of Spectra | |
| by John Walker | |
| http://www.fourmilab.ch/ | |
| Last updated: March 9, 2003 | |
| This program is in the public domain. |
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
| 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 |
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
| 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 |
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
| Shader "Hidden/ComputeOcclusion" | |
| { | |
| Properties | |
| { | |
| _MainTex ("", 2D) = "white" {} | |
| } | |
| SubShader | |
| { | |
| Pass | |
| { |
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
| // | |
| // 1. Add a Quad in Unity | |
| // 2. Parent the quad under camera, to prevent frustum culling. | |
| // 3. Attach this shader. | |
| // | |
| Shader "Quad/Fullscreen" | |
| { | |
| Properties | |
| { | |
| } |
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
| #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{ |
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
| /* | |
| 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: |