Skip to content

Instantly share code, notes, and snippets.

@kchapelier
Last active August 6, 2026 10:19
Show Gist options
  • Select an option

  • Save kchapelier/1624582bec3ac2625064b3a0195f5745 to your computer and use it in GitHub Desktop.

Select an option

Save kchapelier/1624582bec3ac2625064b3a0195f5745 to your computer and use it in GitHub Desktop.
Lighting technique notes

Schlick's Approximation of the fresnel factor

https://en.wikipedia.org/wiki/Schlick%27s_approximation

http://filmicworlds.com/blog/everything-has-fresnel/

float NdotL = max( 0.0, dot( PixelNormal, LightDir ) );
float fresnelFactor = SpecularColor + ( 1.0 - SpecularColor ) * pow( ( 1.0 - NdotL ), 5.0 );

For microfacet models :

vec3 halfwayVector = normalize(viewDirection + light);
float HdotL = max( 0.0, dot( halfwayVector, light ) );
float fresnelFactor = SpecularColor + ( 1.0 - SpecularColor ) * pow( ( 1.0 - HdotL ), 5.0 );

Lambert Diffuse

https://www.youtube.com/watch?v=gIeCnJbb_UI

https://en.wikipedia.org/wiki/Lambertian_reflectance

float product = dot(normalize(vNormal), light);
float brightness = max(0.0, product);

Half Lambert Diffuse

https://developer.valvesoftware.com/wiki/Half_Lambert

float product = dot(normalize(vNormal), light);
float brightness = pow(product * 0.5 + 0.5, 2.0);

Generalized Lambert Diffuse

float product = dot(normalize(vNormal), light);
float brightness = pow(max(0.0, product * multiply + add), power);

Oren Nayar Diffuse

Model created for rough surfaces (concrete, plaster, sand, cardboard, etc.).

https://en.wikipedia.org/wiki/Oren%E2%80%93Nayar_reflectance_model

http://www1.cs.columbia.edu/CAVE/projects/oren/

float LdotV = dot(light, viewDirection);
float NdotL = dot(light, surfaceNormal);
float NdotV = dot(surfaceNormal, viewDirection);

float s = LdotV - NdotL * NdotV;
float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
float sigma2 = roughness * roughness;
float A = 1.0 + sigma2 * (albedo / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33));
float B = 0.45 * sigma2 / (sigma2 + 0.09);

float brightness = albedo + max(0.0, NdotL) * (A + B * s / t) / PI;

// TOCHECK

Blinn-Phong Specular

https://www.youtube.com/watch?v=hYKK4rIAB48

https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model

// vector from the surface pointing to the camera
vec3 directionToCamera = normalize(cameraPosition - vPosition);

// vector between the previous surface-to-camera vector and surface-to-light vector
vec3 halfwayVector = normalize(directionToCamera + light);

float specularBrightness = specularAmount * (
  pow(
    max(0.0, dot(vNormal, halfwayVector)),
    specularShininess
  )
);

Phong Specular

// TODO

Torrance-Sparrow Specular

Model designed for rough surfaces.

// TODO

GGX Specular

http://www.neilblevins.com/cg_education/ggx/ggx.htm

http://www.shlyaev.com/rnd/37-cpp-category/54-ggx

https://github.com/glslify/glsl-ggx/blob/master/index.glsl

https://graphics.rwth-aachen.de:9000/Glow/glow-extras/blob/cfce9b4c4f5b806e4981c0ccad7de0e46edac68c/material/shader/glow-material/material-ggx.glsl

http://filmicworlds.com/blog/optimizing-ggx-shaders-with-dotlh/

http://filmicworlds.com/blog/optimizing-ggx-update/

Beckmann Specular

https://en.wikipedia.org/wiki/Specular_highlight#Beckmann_distribution

https://github.com/glslify/glsl-specular-beckmann

vec3 halfwayVector = normalize(directionToCamera + light);
float NdotH = max(dot(surfaceNormal, halfwayVector), 0.0001);
float cos2Alpha = NdotH * NdotH;
float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;
float roughness2 = roughness * roughness;
float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;
return exp(tan2Alpha / roughness2) / denom;
@davidwarner771132-cyber

Copy link
Copy Markdown

Texas Lit specializes in austin commercial outdoor lighting, offering premium permanent LED lighting solutions for businesses and residential properties. Their energy-efficient, customizable lighting systems are designed to improve curb appeal, security, and year-round visibility. With professional installation and durable products, Texas Lit delivers reliable outdoor lighting solutions built to last.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment