https://github.com/dmnsgn/glsl-constants
Common GLSL math constants (with 11 decimals) available both as ES modules strings and as GLSL files for use with glslify.
https://github.com/dmnsgn/glsl-constants
constants degrees gamma glsl golden-ratio phi pi radians tau
Last synced: 3 months ago
JSON representation
Common GLSL math constants (with 11 decimals) available both as ES modules strings and as GLSL files for use with glslify.
- Host: GitHub
- URL: https://github.com/dmnsgn/glsl-constants
- Owner: dmnsgn
- License: mit
- Created: 2018-03-27T01:00:50.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-07-06T14:45:25.000Z (11 months ago)
- Last Synced: 2025-02-18T07:56:18.016Z (3 months ago)
- Topics: constants, degrees, gamma, glsl, golden-ratio, phi, pi, radians, tau
- Language: GLSL
- Homepage: https://dmnsgn.github.io/glsl-constants/
- Size: 43 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.MD
Awesome Lists containing this project
README
# glsl-constants
[](https://www.npmjs.com/package/glsl-constants)
[](https://www.npmjs.com/package/glsl-constants)
[](https://bundlephobia.com/package/glsl-constants)
[](https://github.com/dmnsgn/glsl-constants/blob/main/package.json)
[](https://github.com/microsoft/TypeScript)
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
[](https://github.com/eslint/eslint)
[](https://github.com/dmnsgn/glsl-constants/blob/main/LICENSE.md)Common GLSL math constants (with 11 decimals) available both as ES modules strings and as GLSL files for use with glslify.
[](https://paypal.me/dmnsgn)
[](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[](https://twitter.com/dmnsgn)## Installation
```bash
npm install glsl-constants
```## Usage
### ESM
```js
import * as glslConstants from "glsl-constants";
import * as glslRotate from "glsl-rotate";const shader = /* glsl */ `
${glslConstants.GAMMA}
${glslConstants.RECIPROCAL_GAMMA}
${glslConstants.TAU}
${glslConstants.PI}
${glslConstants.HALF_PI}
${glslConstants.QUARTER_PI}
${glslConstants.RECIPROCAL_PI}
${glslConstants.RECIPROCAL_TAU}
${glslConstants.TO_RADIANS}
${glslConstants.TO_DEGREES}// ...
vec3 toGamma(vec3 v) {
return pow(v, vec3(RECIPROCAL_GAMMA));
}${glslRotate.rotate}
void main() {
vec2 p2d = vec2(1.0, 0.0);
p2d = rotate(p2d, TAU);
p2d = rotate(p2d, PI);
p2d = rotate(p2d, HALF_PI);
p2d = rotate(p2d, QUARTER_PI);
p2d = rotate(p2d, PHI);
p2d = rotate(p2d, RECIPROCAL_PI);
p2d = rotate(p2d, RECIPROCAL_TAU);
p2d = rotate(p2d, 90.0 * TO_RADIANS);// ...
gl_FragColor.rgb = toGamma(color.rgb);
}
`;
```### glslify
```glsl
#pragma glslify: GAMMA = require(glsl-constants/GAMMA)
#pragma glslify: TAU = require(glsl-constants/TAU)
#pragma glslify: PI = require(glsl-constants/PI)
#pragma glslify: HALF_PI = require(glsl-constants/HALF_PI)
#pragma glslify: QUARTER_PI = require(glsl-constants/QUARTER_PI)
#pragma glslify: PHI = require(glsl-constants/PHI)
#pragma glslify: RECIPROCAL_PI = require(glsl-constants/RECIPROCAL_PI)
#pragma glslify: RECIPROCAL_TAU = require(glsl-constants/RECIPROCAL_TAU)
#pragma glslify: TO_RADIANS = require(glsl-constants/TO_RADIANS)
#pragma glslify: TO_DEGREES = require(glsl-constants/TO_DEGREES)// ...
vec3 toGamma(vec3 v) {
return pow(v, vec3(RECIPROCAL_GAMMA));
}#pragma glslify: rotate = require(glsl-rotate)
void main() {
vec2 p2d = vec2(1.0, 0.0);
p2d = rotate(p2d, TAU);
p2d = rotate(p2d, PI);
p2d = rotate(p2d, HALF_PI);
p2d = rotate(p2d, QUARTER_PI);
p2d = rotate(p2d, PHI);
p2d = rotate(p2d, RECIPROCAL_PI);
p2d = rotate(p2d, RECIPROCAL_TAU);
p2d = rotate(p2d, 90.0 * TO_RADIANS);// ...
gl_FragColor.rgb = toGamma(color.rgb);
}
```## License
MIT. See [license file](https://github.com/dmnsgn/glsl-constants/blob/main/LICENSE.md).