# glsl-diffuse-oren-nayar

> Oren-Nayar diffuse lighting model

Latest version **1.0.2** (published 2014-10-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install glsl-diffuse-oren-nayar
pnpm add glsl-diffuse-oren-nayar
yarn add glsl-diffuse-oren-nayar
bun add glsl-diffuse-oren-nayar
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2014-10-15 |
| First published | 2014-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko |
| Keywords | oren, nayar, oren-nayar, diffuse, lighting, glsl, glslify |

## Links

- npm: https://www.npmjs.com/package/glsl-diffuse-oren-nayar
- Repository: https://github.com/stackgl/glsl-diffuse-oren-nayar
- Issues: https://github.com/stackgl/glsl-diffuse-oren-nayar/issues
- npm.io page: https://npm.io/package/glsl-diffuse-oren-nayar

## Recent versions

- 1.0.2 (latest) — 2014-10-15
- 1.0.1 — 2014-10-12
- 1.0.0 — 2014-10-12

## README

# glsl-diffuse-oren-nayar

The [Oren-Nayar](https://en.wikipedia.org/wiki/Oren%E2%80%93Nayar_reflectance_model) diffuse lighting model implemented in GLSL.

# Example

```glsl
#pragma glslify: orenNayar = require(glsl-diffuse-orenNayar)

uniform vec3 lightPosition, eyePosition;

varying vec3 surfacePosition, surfaceNormal;

void main() {
  //Light and view geometry
  vec3 lightDirection = normalize(lightPosition - surfacePosition);
  vec3 viewDirection = normalize(eyePosition - surfacePosition);

  //Surface properties
  vec3 normal = normalize(surfaceNormal);
  
  //Compute diffuse light intensity
  float power = orenNayar(
    lightDirection,
    viewDirection, 
    normal,
    0.3,
    0.7);

  gl_FragColor = vec4(power,power,power,1.0);
}
```

# Usage

Install with npm:

```
npm install glsl-diffuse-oren-nayar
```

Then use with [glslify](https://github.com/stackgl/glslify).

# API

```glsl
#pragma glslify: orenNayar = require(glsl-diffuse-oren-nayar)
```

##### `float orenNayar(vec3 lightDir, vec3 viewDir, vec3 normal, float roughness, float albedo)`
Computes the diffuse intensity in the Lambertian model

* `lightDir` is a *unit length* `vec3` pointing from the surface point toward the light
* `viewDir` is a *unit length* `vec3` pointing toward the camera
* `normal` is the *unit length* surface normal at the sample point
* `roughness` is a parameter between 0 and 1 measuring the surface roughness.  0 for smooth, 1 for matte
* `albedo` measures the intensity of the diffuse reflection.  Values `>0.96` do not conserve energy

**Returns** A `float` representing the diffuse light intensity

# License
(c) 2014 Mikola Lysenko. MIT License

---
_Source: https://npm.io/package/glsl-diffuse-oren-nayar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
