p5.env 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +18 -19
  2. package/p5.env.js +21 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -15,10 +15,10 @@ The angular SDFs here take in a surface normal and return two things:
15
15
  ## Builder API
16
16
 
17
17
  ```js
18
- myShader = buildEnvLightShader(() => {
18
+ myShader = buildEnvMaterial(() => {
19
19
  envColor.begin()
20
20
  const l = envLight(baseColor, envColor.dir, envColor.blur)
21
- l.mix(l.envCircle(...), lightColor)
21
+ l.mix(l.circle(...), lightColor)
22
22
  envColor.set(l.get())
23
23
  envColor.end()
24
24
  })
@@ -27,16 +27,16 @@ myShader = buildEnvLightShader(() => {
27
27
  `envLight(baseColor, dir, blur)` creates a builder. `dir` and `blur` are captured once and used by all subsequent method calls.
28
28
 
29
29
  **Shape methods** (return an SDF result to pass to `mix`):
30
- - `l.envCircle(center, radius)` - spherical cap; `center` is a unit vec3, `radius` in radians
31
- - `l.envCapsule(a, b, radius)` - capsule between two unit vec3 endpoints, `radius` in radians
32
- - `l.envStar(center, n, innerRadius, outerRadius, rotation?)` - n-pointed star; radii in radians, `n` is a plain JS integer
33
- - `l.envRect(center, size, rotation?)` - rectangle; `size` is `[halfWidth, halfHeight]` as chord lengths (sine of angle, not radians), `rotation` in radians
34
- - `l.envWindow(center, size, panes, barWidth)` - rectangle subdivided into panes; `panes` is `[nx, ny]`; `size` and `barWidth` are chord lengths (sine of angle, not radians for small shapes the difference is negligible)
30
+ - `l.circle(center, radius)` - spherical cap; `center` is a unit vec3, `radius` in radians
31
+ - `l.capsule(a, b, radius)` - capsule between two unit vec3 endpoints, `radius` in radians
32
+ - `l.star(center, n, innerRadius, outerRadius, rotation?)` - n-pointed star; radii in radians, `n` is a plain JS integer
33
+ - `l.rect(center, size, rotation?)` - rectangle; `size` is `[halfWidth, halfHeight]` as chord lengths (sine of angle, not radians), `rotation` in radians
34
+ - `l.window(center, size, panes, barWidth)` - rectangle subdivided into panes; `panes` is `[nx, ny]`; `size` and `barWidth` are chord lengths (sine of angle, not radians -- for small shapes the difference is negligible)
35
35
 
36
36
  **Color methods** (return a scalar/vec3 usable in expressions or as a base color):
37
- - `l.envGradient(center, ...stops)` - radial gradient; each stop is `{ t, color }` where `t` is angle from `center` in radians and `color` is a vec3; spread stops as individual arguments
38
- - `l.envNoise(size)` - blur-aware fractal noise value; `size` is the angular scale of the largest octave
39
- - `l.envNoisePlane(planeNormal, h, size, { rotation?, offset? })` - projects a planar noise field onto the sphere; `h` is the plane's height, `size` is the noise scale; `offset` is a vec2 that shifts the noise coordinate (use for animation)
37
+ - `l.gradient(center, ...stops)` - radial gradient; each stop is `{ t, color }` where `t` is angle from `center` in radians and `color` is a vec3; spread stops as individual arguments
38
+ - `l.noise(size)` - blur-aware fractal noise value; `size` is the angular scale of the largest octave
39
+ - `l.noisePlane(planeNormal, h, size, { rotation?, offset? })` - projects a planar noise field onto the sphere; `h` is the plane's height, `size` is the noise scale; `offset` is a vec2 that shifts the noise coordinate (use for animation)
40
40
 
41
41
  **Builder methods**:
42
42
  - `l.mix(shape, color)` - blends `color` into the accumulated result using the shape's SDF; returns `l` for chaining
@@ -44,28 +44,27 @@ myShader = buildEnvLightShader(() => {
44
44
 
45
45
  ## Panorama
46
46
 
47
- The same `envColor` hook can also be used to create a version of `panorama()` but using your generative environment, `panoramaEnv`.
47
+ The same `envColor` hook can also drive a background panorama, so the environment visible on surfaces matches the environment visible in the background.
48
48
 
49
49
  ```js
50
- function envHooks() {
50
+ const envHooks = () => {
51
51
  envColor.begin()
52
- // Draw something here!
52
+ // ... same hook body as before ...
53
53
  envColor.end()
54
54
  }
55
55
 
56
- let envShader, panoramaShader
56
+ let envShader, pano
57
57
 
58
58
  function setup() {
59
- envShader = buildEnvLightShader(envHooks)
60
- panoramaShader = buildEnvLightPanorama(envHooks)
59
+ envShader = buildEnvMaterial(envHooks)
60
+ pano = buildEnvPanorama(envHooks)
61
61
  }
62
62
 
63
63
  function draw() {
64
- clear()
65
- panoramaEnv(panoramaShader)
64
+ pano()
66
65
  shader(envShader)
67
66
  sphere(150)
68
67
  }
69
68
  ```
70
69
 
71
- The API is `panoramaEnv(shader, blur = 0)`. Pass a nonzero `blur` (in radians) to draw a blurry background instead of a default clear one.
70
+ `buildEnvPanorama` returns a function. Calling it each frame sets the camera uniforms and applies the panorama as a post-process filter. Pass a blur value in radians to match a rough material's specular blur: `pano(blur)`.
package/p5.env.js CHANGED
@@ -37,7 +37,7 @@ function envLight(p5, fn) {
37
37
  return this._baseEnvLightShader
38
38
  }
39
39
 
40
- fn.buildEnvLightShader = function(...args) {
40
+ fn.buildEnvMaterial = function(...args) {
41
41
  return this.baseEnvLightShader().modify(...args)
42
42
  }
43
43
 
@@ -71,19 +71,18 @@ function envLight(p5, fn) {
71
71
  return this._baseEnvLightPanoramaShader
72
72
  }
73
73
 
74
- fn.buildEnvLightPanorama = function(...args) {
75
- return this.baseEnvLightPanoramaShader().modify(...args)
76
- }
77
-
78
- fn.panoramaEnv = function(panoramaShader, blur = 0) {
79
- const renderer = this._renderer
80
- renderer.scratchMat3.inverseTranspose4x4(renderer.states.uViewMatrix)
81
- renderer.scratchMat3.invert(renderer.scratchMat3)
82
- panoramaShader.setUniform('uFovY', renderer.states.curCamera.cameraFOV)
83
- panoramaShader.setUniform('uAspect', renderer.states.curCamera.aspectRatio)
84
- panoramaShader.setUniform('uCameraRotation', renderer.scratchMat3.mat3)
85
- panoramaShader.setUniform('uBlur', Math.min(blur, Math.PI / 2))
86
- this.filter(panoramaShader)
74
+ fn.buildEnvPanorama = function(...args) {
75
+ const panoramaShader = this.baseEnvLightPanoramaShader().modify(...args)
76
+ return (blur = 0) => {
77
+ const renderer = this._renderer
78
+ renderer.scratchMat3.inverseTranspose4x4(renderer.states.uViewMatrix)
79
+ renderer.scratchMat3.invert(renderer.scratchMat3)
80
+ panoramaShader.setUniform('uFovY', renderer.states.curCamera.cameraFOV)
81
+ panoramaShader.setUniform('uAspect', renderer.states.curCamera.aspectRatio)
82
+ panoramaShader.setUniform('uCameraRotation', renderer.scratchMat3.mat3)
83
+ panoramaShader.setUniform('uBlur', Math.min(blur, Math.PI / 2))
84
+ this.filter(panoramaShader)
85
+ }
87
86
  }
88
87
 
89
88
  // Color helpers
@@ -400,28 +399,28 @@ function envLight(p5, fn) {
400
399
  let c = p5.strandsNode(baseColor)
401
400
 
402
401
  return {
403
- envCircle(center, radius) {
402
+ circle(center, radius) {
404
403
  return sketch.envCircle(dir, center, radius)
405
404
  },
406
- envCapsule(a, b, radius) {
405
+ capsule(a, b, radius) {
407
406
  return sketch.envCapsule(dir, a, b, radius)
408
407
  },
409
- envStar(center, n, innerRadius, outerRadius, rotation) {
408
+ star(center, n, innerRadius, outerRadius, rotation) {
410
409
  return sketch.envStar(dir, center, n, innerRadius, outerRadius, rotation)
411
410
  },
412
- envRect(center, size, rotation) {
411
+ rect(center, size, rotation) {
413
412
  return sketch.envRect(dir, center, size, rotation)
414
413
  },
415
- envWindow(center, size, panes, barWidth) {
414
+ window(center, size, panes, barWidth) {
416
415
  return sketch.envWindow(dir, center, size, panes, barWidth)
417
416
  },
418
- envNoise(size) {
417
+ noise(size) {
419
418
  return sketch.envNoise(dir, size, blur)
420
419
  },
421
- envGradient(center, ...stops) {
420
+ gradient(center, ...stops) {
422
421
  return sketch.envGradient(dir, center, blur, ...stops)
423
422
  },
424
- envNoisePlane(planeNormal, h, size, { rotation = 0, offset = [0, 0] } = {}) {
423
+ noisePlane(planeNormal, h, size, { rotation = 0, offset = [0, 0] } = {}) {
425
424
  return sketch.envNoisePlane(dir, planeNormal, h, size, blur, { rotation, offset })
426
425
  },
427
426
  mix(shape, materialColor) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "p5.env",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Generative environment light for p5.strands",
5
5
  "main": "p5.env.js",
6
6
  "scripts": {