
Product
Introducing the Alert Details Page: A Better Way to Explore Alerts
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.
glsl-perturb-normal
Advanced tools

Perturb a normal in the fragment shader using a normal map. This can be used to add surface detail during per-pixel lighting.
Note: You need to enable GL_OES_standard_derivatives.
#extension GL_OES_standard_derivatives : enable
varying vec3 vNormal;
varying vec2 vUv;
varying vec3 vViewPosition;
uniform sampler2D normalMap;
#pragma glslify: perturb = require('glsl-perturb-normal')
void main() {
//extract normal map from your texture
vec3 normalRGB = texture2D(normalMap, vUv).rgb;
//expand into -1.0 .. 1.0 range
vec3 normalMap = normalRGB * 2.0 - 1.0;
//get surface normal and camera-space position
vec3 N = normalize(vNormal);
vec3 V = normalize(vViewPosition);
//perturb the normal
vec3 normal = perturb(normalMap, N, V, vUv);
//... lighting
}
vec3 perturbed = perturb(vec3 M, vec3 N, vec3 V, vec2 texcoord)Perturbs a normal where:
M is a unit vector from your normal map (e.g. decoded from a RGB texture)N is the normalized surface normalV is the normalized camera-space positiontexcoord is the UV coordinates of your meshThis uses GL_OES_standard_derivatives to compute the derivatives, so it may not work on older or low-end devices.
The algorithm here is from ChrisÂtÂian SchĂĽler's blog post Normal Mapping Without Precomputed Tangents.
MIT. See LICENSE.md for details.
FAQs
perturb normal from a normal map
We found that glsl-perturb-normal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 17 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.